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

PuzzelSMS   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 23
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 17 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * SPDX-FileCopyrightText: 2024 Kim Syversen <[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 getUrl()
20
 * @method static setUrl(string $url)
21
 * @method string getUser()
22
 * @method static setUser(string $user)
23
 * @method string getPassword()
24
 * @method static setPassword(string $password)
25
 * @method string getServiceid()
26
 * @method static setServiceid(string $serviceid)
27
 */
28
class PuzzelSMS extends AProvider {
29
	public const SCHEMA = [
30
		'id' => 'puzzel',
31
		'name' => 'Puzzel SMS',
32
		'fields' => [
33
			['field' => 'url',       'prompt' => 'Please enter your PuzzelSMS URL:'],
34
			['field' => 'user',      'prompt' => 'Please enter your PuzzelSMS username:'],
35
			['field' => 'password',  'prompt' => 'Please enter your PuzzelSMS password:'],
36
			['field' => 'serviceid', 'prompt' => 'Please enter your PuzzelSMS service ID:'],
37
		],
38
	];
39
	private IClient $client;
40
41
	public function __construct(
42
		IClientService $clientService,
43
	) {
44
		$this->client = $clientService->newClient();
45
	}
46
47
	#[\Override]
48
	public function send(string $identifier, string $message) {
49
		try {
50
			$this->client->get(
51
				$this->getUrl(),
52
				[
53
					'query' => [
54
						'username' => $this->getUser(),
55
						'password' => $this->getPassword(),
56
						'message[0].recipient' => '+' . $identifier,
57
						'message[0].content' => $message,
58
						'serviceId' => $this->getServiceid(),
59
					],
60
				]
61
			);
62
		} catch (Exception $ex) {
63
			throw new MessageTransmissionException();
64
		}
65
	}
66
}
67