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

Voipbuster   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 17 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * SPDX-FileCopyrightText: 2024 Francois Blackburn <[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 getApiUser()
20
 * @method static setApiUser(string $apiUser)
21
 * @method string getApiPassword()
22
 * @method static setApiPassword(string $apiPassword)
23
 * @method string getDid()
24
 * @method static setDid(string $did)
25
 */
26
class Voipbuster extends AProvider {
27
	public const SCHEMA = [
28
		'name' => 'Voipbuster',
29
		'fields' => [
30
			['field' => 'api_user',     'prompt' => 'Please enter your Voipbuster API username:'],
31
			['field' => 'api_password', 'prompt' => 'Please enter your Voipbuster API password:'],
32
			['field' => 'did',          'prompt' => 'Please enter your Voipbuster DID:'],
33
		],
34
	];
35
	private IClient $client;
36
37
	public function __construct(
38
		IClientService $clientService,
39
	) {
40
		$this->client = $clientService->newClient();
41
	}
42
43
	#[\Override]
44
	public function send(string $identifier, string $message) {
45
		$user = $this->getApiUser();
46
		$password = $this->getApiPassword();
47
		$did = $this->getDid();
48
		try {
49
			$this->client->get('https://www.voipbuster.com/myaccount/sendsms.php', [
50
				'query' => [
51
					'username' => $user,
52
					'password' => $password,
53
					'from' => $did,
54
					'to' => $identifier,
55
					'text' => $message,
56
				],
57
			]);
58
		} catch (Exception $ex) {
59
			throw new MessageTransmissionException();
60
		}
61
	}
62
}
63