Completed
Push — master ( f29952...b4aff8 )
by Christoph
12s
created

ClockworkSMS   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 17
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 16 2
A getConfig() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author Mario Klug <[email protected]>
7
 *
8
 * Nextcloud - Two-factor Gateway
9
 *
10
 * This code is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License, version 3,
12
 * as published by the Free Software Foundation.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License, version 3,
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
21
 *
22
 */
23
24
namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider;
25
26
use Exception;
27
use OCA\TwoFactorGateway\Exception\SmsTransmissionException;
28
use OCP\Http\Client\IClient;
29
use OCP\Http\Client\IClientService;
30
use OCP\IConfig;
31
32
class ClockworkSMS implements IProvider {
33
34
	const PROVIDER_ID = 'clockworksms';
35
36
	/** @var IClient */
37
	private $client;
38
39
	/** @var ClockworkSMSConfig */
40
	private $config;
41
42
	public function __construct(IClientService $clientService,
43
								ClockworkSMSConfig $config) {
44
		$this->client = $clientService->newClient();
45
		$this->config = $config;
46
	}
47
48
	/**
49
	 * @param string $identifier
50
	 * @param string $message
51
	 *
52
	 * @throws SmsTransmissionException
53
	 */
54
	public function send(string $identifier, string $message) {
55
		$config = $this->getConfig();
56
57
		try {
58
			$response = $this->client->get(
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
59
				'https://api.clockworksms.com/http/send.aspx',
60
				[
61
					'query' => [
62
						'key' => $config->getApiToken(),
63
						'to' => $identifier,
64
						'content' => $message,
65
					],
66
				]
67
			);
68
		} catch (Exception $ex) {
69
			throw new SmsTransmissionException();
70
		}
71
	}
72
73
	/**
74
	 * @return ClockworkSMSConfig
75
	 */
76
	public function getConfig(): IProviderConfig {
77
		return $this->config;
78
	}
79
80
}
81