SMSDRRegisterCallbackRequest::uri()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Mediumart\Orange\SMS\Http\Requests;
4
5
use Exception;
6
use Mediumart\Orange\SMS\Http\SMSClientRequest;
7
8
class SMSDRRegisterCallbackRequest extends SMSClientRequest
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $body;
14
    /**
15
     * @var string
16
     */
17
    private $senderAddress;
18
19
    /**
20
     * RegisterSMSDRCallbackRequest constructor.
21
     *
22
     * @param $callbackUri
23
     * @param $senderAddress
24
     * @throws \Exception
25
     */
26 2
    public function __construct($callbackUri, $senderAddress)
27
    {
28 2
        $this->enforceHttpSecureProtocol($callbackUri);
29
30 1
        if (! $senderAddress) {
31
            throw new Exception('Missing sender address');
32
        }
33
34 1
        $this->senderAddress = 'tel:'.$this->normalizePhoneNumber($senderAddress);
35
36 1
        $this->body = [
37
            "deliveryReceiptSubscription" => [
38
                "callbackReference" => [
39 1
                    "notifyURL" => $callbackUri
40
                ]
41
            ]
42
        ];
43 1
    }
44
45
    /**
46
     * Http request method.
47
     *
48
     * @return string
49
     */
50 1
    public function method()
51
    {
52 1
        return 'POST';
53
    }
54
55
    /**
56
     * The uri for the current request.
57
     *
58
     * @return string
59
     */
60 1
    public function uri()
61
    {
62 1
        return static::BASE_URI.'/smsmessaging/v1/outbound/'.urlencode($this->senderAddress).'/subscriptions';
63
    }
64
65
    /**
66
     * Http request options.
67
     *
68
     * @return array
69
     */
70 1
    public function options()
71
    {
72
        return [
73 1
            'headers' => ['Content-Type' => 'application/json'],
74 1
            'body' => json_encode($this->body)
75
        ];
76
    }
77
78
    /**
79
     * @param $callbackUri
80
     */
81 2
    protected function enforceHttpSecureProtocol($callbackUri)
82
    {
83 2
        if (substr($callbackUri, 0, strlen('https://')) !== 'https://') {
84 1
            throw new \InvalidArgumentException(
85 1
                "Url callback protocol must be secured and starts with: 'https://'"
86
            );
87
        }
88 1
    }
89
}
90