Completed
Push — master ( 39712c...02e5d6 )
by Sergey
02:48
created

JSONRequest::requestSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace seregazhuk\SmsIntel\Requests;
4
5
class JSONRequest extends Request
6
{
7
    /**
8
     * @return array
9
     */
10
    public static function getAllowedMethods()
11
    {
12
        return [
13
            'getSource',
14
            'getContacts',
15
            'requestSource',
16
            'send',
17
            'getPhoneInfo',
18
        ];
19
    }
20
21
    /**
22
     * @param string $source
23
     * @return array|null
24
     */
25
    public function getSource($source)
26
    {
27
        return $this->exec('requestSource', ['source' => $source]);
28
    }
29
30
    /**
31
     * @param string|array $to
32
     * @param string $from
33
     * @param string $message
34
     * @param array $params
35
     * @return array|null
36
     */
37
    public function send($to, $from, $message, $params = [ ])
38
    {
39
        $to = is_array($to) ? $to : [ $to ];
40
41
        $requestParams = array_merge(
42
            [
43
                'to'     => $to,
44
                'txt'   => $message,
45
                'source' => $from,
46
            ],
47
            $params
48
        );
49
50
        return $this->exec('sendSms', $requestParams);
51
    }
52
53
    /**
54
     * @param string $name
55
     * @return array|null
56
     */
57
    public function requestSource($name)
58
    {
59
        return $this->exec('requestSource', ['source' => $name]);
60
    }
61
62
    /**
63
     * @param null|string $groupId
64
     * @param null|string $phone
65
     * @return array|null
66
     */
67
    public function getContacts($groupId = null, $phone = null)
68
    {
69
        return $this->exec(
70
            'getContacts',
71
            ['idGroup' => $groupId, 'phone' => $phone]
72
        );
73
    }
74
    
75
    /**
76
     * @param string $phone
77
     * @return array|null
78
     */
79
    public function getPhoneInfo($phone)
80
    {
81
        return $this->exec('getPhoneInfo', ['phone' => $phone]);
82
    }
83
84
85
    /**
86
     * @param string $action
87
     * @return string
88
     */
89
    public function makeEndPoint($action)
90
    {
91
        return 'https://lcab.smsintel.ru/lcabApi/' . $action . '.php';
92
    }
93
94
    /**
95
     * @param array $requestBody
96
     * @return mixed
97
     */
98
    protected function formatRequestBody(array $requestBody)
99
    {
100
        return $requestBody;
101
    }
102
103
    /**
104
     * @param string $response
105
     * @return array
106
     */
107
    protected function parseResponse($response)
108
    {
109
        return json_decode($response, true);
110
    }
111
}