Sms77Io   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 4
eloc 18
c 3
b 0
f 2
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 2 1
A send() 0 14 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author André Matthies <[email protected]>
7
 *
8
 * Sms77io - 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
31
class Sms77Io implements IProvider {
32
	public const PROVIDER_ID = 'sms77io';
33
34
	/** @var IClient */
35
	private $client;
36
37
	/** @var Sms77IoConfig */
38
	private $config;
39
40
	public function __construct(IClientService $clientService,
41
		Sms77IoConfig $config) {
42
		$this->client = $clientService->newClient();
43
		$this->config = $config;
44
	}
45
46
	/**
47
	 * @param string $identifier
48
	 * @param string $message
49
	 *
50
	 * @throws SmsTransmissionException
51
	 */
52
	public function send(string $identifier, string $message) {
53
		$config = $this->getConfig();
54
		$apiKey = $config->getApiKey();
55
		try {
56
			$this->client->get('https://gateway.sms77.io/api/sms', [
57
				'query' => [
58
					'p' => $apiKey,
59
					'to' => $identifier,
60
					'text' => $message,
61
					'sendWith' => 'nextcloud'
62
				],
63
			]);
64
		} catch (Exception $ex) {
65
			throw new SmsTransmissionException();
66
		}
67
	}
68
69
	/**
70
	 * @return Sms77IoConfig
71
	 */
72
	public function getConfig(): IProviderConfig {
73
		return $this->config;
74
	}
75
}
76