Completed
Pull Request — master (#268)
by
unknown
03:27
created

AndroidGSMmodem::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider;
6
7
use Exception;
8
use OCA\TwoFactorGateway\Exception\SmsTransmissionException;
9
use OCP\Http\Client\IClient;
10
use OCP\Http\Client\IClientService;
11
12
class AndroidGSMmodem implements IProvider {
13
14
	const PROVIDER_ID = 'android_gsm_modem';
15
16
	/** @var IClient */
17
	private $client;
18
19
	/** @var AndroidGSMmodemConfig */
20
	private $config;
21
22
	public function __construct(IClientService $clientService,
23
								AndroidGSMmodemConfig $config) {
24
		$this->client = $clientService->newClient();
25
		$this->config = $config;
26
	}
27
28
	/**
29
	 * @param string $identifier
30
	 * @param string $message
31
	 *
32
	 * @throws SmsTransmissionException
33
	 */
34
	public function send(string $identifier, string $message) {
35
		$config = $this->getConfig();
36
		$user = $config->getUser();
37
		$password = $config->getPassword();
38
		$host = $config->getHost();
39
		try {
40
			$this->client->get('http://'.$host.'/SendSMS?username='.$user.'&password='.$password.'&phone='.$identifier.'&message='.$message);
41
		} catch (Exception $ex) {
42
			throw new SmsTransmissionException();
43
		}
44
	}
45
46
	/**
47
	 * @return AndroidGSMmodemConfig
48
	 */
49
	public function getConfig(): IProviderConfig {
50
		return $this->config;
51
	}
52
}
53