Sms77Io::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * SPDX-FileCopyrightText: 2024 André Matthies <[email protected]>
7
 * SPDX-License-Identifier: AGPL-3.0-or-later
8
 */
9
10
namespace OCA\TwoFactorGateway\Provider\Channel\SMS\Provider\Drivers;
11
12
use Exception;
13
use OCA\TwoFactorGateway\Exception\MessageTransmissionException;
14
use OCA\TwoFactorGateway\Provider\Channel\SMS\Provider\AProvider;
15
use OCP\Http\Client\IClient;
16
use OCP\Http\Client\IClientService;
17
18
/**
19
 * @method string getApiKey()
20
 * @method static setApiKey(string $apiKey)
21
 */
22
class Sms77Io extends AProvider {
23
	public const SCHEMA = [
24
		'name' => 'sms77.io',
25
		'fields' => [
26
			['field' => 'api_key', 'prompt' => 'Please enter your sms77.io API key:'],
27
		],
28
	];
29
	private IClient $client;
30
31
	public function __construct(
32
		IClientService $clientService,
33
	) {
34
		$this->client = $clientService->newClient();
35
	}
36
37
	#[\Override]
38
	public function send(string $identifier, string $message) {
39
		$apiKey = $this->getApiKey();
40
		try {
41
			$this->client->get('https://gateway.sms77.io/api/sms', [
42
				'query' => [
43
					'p' => $apiKey,
44
					'to' => $identifier,
45
					'text' => $message,
46
					'sendWith' => 'nextcloud'
47
				],
48
			]);
49
		} catch (Exception $ex) {
50
			throw new MessageTransmissionException();
51
		}
52
	}
53
}
54