Passed
Pull Request — master (#640)
by Vitor
03:36
created

ClockworkSMS   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 17
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * SPDX-FileCopyrightText: 2024 Mario Klug <[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 getApitoken()
20
 * @method static setApitoken(string $apitoken)
21
 */
22
class ClockworkSMS extends AProvider {
23
	public const SCHEMA = [
24
		'name' => 'ClockworkSMS',
25
		'fields' => [
26
			['field' => 'apitoken', 'prompot' => 'Please enter your clockworksms api token:'],
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
		try {
40
			$response = $this->client->get(
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
41
				'https://api.clockworksms.com/http/send.aspx',
42
				[
43
					'query' => [
44
						'key' => $this->getApiToken(),
45
						'to' => $identifier,
46
						'content' => $message,
47
					],
48
				]
49
			);
50
		} catch (Exception $ex) {
51
			throw new MessageTransmissionException();
52
		}
53
	}
54
}
55