Completed
Pull Request — master (#268)
by
unknown
22:37 queued 21:20
created

AndroidGsmModem::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
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
		$protocol = $config->getProtocol();
40
		try {
41
			$this->client->get("$protocol://$host/SendSMS", [
42
				'query' => [
43
					'user' => $user,
44
					'password' => $password,
45
					'phone' => $identifier,
46
					'message' => $message,
47
				],
48
			]);
49
		} catch (Exception $ex) {
50
			throw new SmsTransmissionException();
51
		}
52
	}
53
54
	/**
55
	 * @return AndroidGsmModemConfig
56
	 */
57
	public function getConfig(): IProviderConfig {
58
		return $this->config;
59
	}
60
}
61