Plivo::buyNumber()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
namespace LeadThread\Sms\Drivers;
4
5
use Plivo\RestAPI as Service;
6
use LeadThread\Sms\Drivers\Driver;
7
use LeadThread\Sms\Interfaces\PhoneSearchParams;
8
use LeadThread\Sms\Responses\Plivo as PlivoResponse;
9
10
class Plivo extends Driver
11
{
12
13
    protected $handle;
14
15 18
    public function __construct($auth_id, $auth_token)
16
    {
17 18
        $this->handle = new Service($auth_id, $auth_token);
18 18
    }
19
20
    public function send($msg, $to, $from, $callback = null)
21
    {
22
        if (!empty($callback)) {
23
            throw new \Exception("Callback URLs are not implemented for Plivo", 1);
24
        }
25
26
        $params = [
27
            'src'  => $from,
28
            'dst'  => $to,
29
            'text' => $msg,
30
            'type' => 'sms'
31
        ];
32
33
        return new PlivoResponse($this->handle->send_message($params));
34
    }
35
36
    public function searchNumber(PhoneSearchParams $search)
37
    {
38
        return new PlivoResponse($this->handle->search_phone_numbers($search->toArray()));
39
    }
40
41
    public function buyNumber($phone)
42
    {
43
        $params = [
44
            'number' => $phone
45
        ];
46
47
        return new PlivoResponse($this->handle->buy_phone_number($params));
48
    }
49
50
    public function sellNumber($phone)
51
    {
52
        $phone = str_replace("+", "", $phone);
53
        $params = [
54
            'number' => $phone
55
        ];
56
        return new PlivoResponse($this->handle->unrent_number($params));
57
    }
58
}
59