Completed
Push — master ( 0fc82a...70c409 )
by Christoph
15s queued 12s
created

Voipbuster::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 17
rs 9.7998
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author Francois Blackburn <[email protected]>
7
 *
8
 * Nextcloud - 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 Voipbuster implements IProvider {
32
	public const PROVIDER_ID = 'voipbuster';
33
34
	/** @var IClient */
35
	private $client;
36
37
	/** @var VoipbusterConfig */
38
	private $config;
39
40
	public function __construct(IClientService $clientService,
41
								VoipbusterConfig $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
		$user = $config->getUser();
55
		$password = $config->getPassword();
56
		$did = $config->getDid();
57
		try {
58
			$this->client->get('https://www.voipbuster.com/myaccount/sendsms.php', [
59
				'query' => [
60
					'username' => $user,
61
					'password' => $password,
62
					'from' => $did,
63
					'to' => $identifier,
64
					'text' => $message,
65
				],
66
			]);
67
		} catch (Exception $ex) {
68
			throw new SmsTransmissionException();
69
		}
70
	}
71
72
	/**
73
	 * @return VoipMsConfig
74
	 */
75
	public function getConfig(): IProviderConfig {
76
		return $this->config;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->config returns the type OCA\TwoFactorGateway\Ser...ovider\VoipbusterConfig which is incompatible with the documented return type OCA\TwoFactorGateway\Ser...S\Provider\VoipMsConfig.
Loading history...
77
	}
78
}
79