Completed
Push — master ( 52f4c9...5c1107 )
by Sergey
02:22
created

JSONRequest::getContacts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
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
            'getContacts',
14
            'addContact',
15
            'requestSource',
16
            'createGroup',
17
            'getGroups',
18
            'editGroup',
19
            'removeContact',
20
            'send',
21
            'getPhoneInfo',
22
        ];
23
    }
24
25
    /**
26
     * @param string|array $to
27
     * @param string $from
28
     * @param string $message
29
     * @param array $params
30
     * @return array|null
31
     */
32
    public function send($to, $from, $message, $params = [ ])
33
    {
34
        $to = is_array($to) ? $to : [ $to ];
35
36
        $requestParams = array_merge(
37
            [
38
                'to'     => $to,
39
                'txt'   => $message,
40
                'source' => $from,
41
            ],
42
            $params
43
        );
44
45
        return $this->exec('sendSms', $requestParams);
46
    }
47
48
    /**
49
     * @param string $name
50
     * @return array|null
51
     */
52
    public function requestSource($name)
53
    {
54
        return $this->exec('requestSource', ['source' => $name]);
55
    }
56
57
    /**
58
     * @param null|string $groupId
59
     * @param null|string $phone
60
     * @return array|null
61
     */
62
    public function getContacts($groupId = null, $phone = null)
63
    {
64
        return $this->exec(
65
            'getContacts',
66
            ['idGroup' => $groupId, 'phone' => $phone]
67
        );
68
    }
69
    
70
    /**
71
     * @param string $phone
72
     * @return array|null
73
     */
74
    public function getPhoneInfo($phone)
75
    {
76
        return $this->exec('getPhoneInfo', ['phone' => $phone]);
77
    }
78
79
    /**
80
     * @param array $contactInfo
81
     * @return array|null
82
     */
83
    public function addContact(array $contactInfo)
84
    {
85
        return $this->exec('addContact', $contactInfo);
86
    }
87
88
    /**
89
     * @param string|null $groupId
90
     * @param string|null $groupName
91
     * @return array|null
92
     */
93
    public function getGroups($groupId = null,  $groupName = null)
94
    {
95
        return $this->exec(
96
            'getGroups',
97
            ['id' => $groupId, 'name' => $groupName]
98
        );
99
    }
100
101
    /**
102
     * @param string $name
103
     * @return array|null
104
     */
105
    public function createGroup($name)
106
    {
107
        return $this->editGroup($name, null);
108
    }
109
110
    /**
111
     * @param string $id
112
     * @param string $name
113
     * @return array|null
114
     */
115
    public function editGroup($name, $id)
116
    {
117
        return $this->exec('saveGroup', ['id' => $id, 'name' => $name]);
118
    }
119
120
    /**
121
     * @return array|null
122
     */
123
    public function getAccountInfo()
124
    {
125
        return $this->exec('info');
126
    }
127
128
    /**
129
     * @param string $phone
130
     * @param string|null $groupId
131
     * @return array|null
132
     */
133
    public function removeContact($phone, $groupId = null)
134
    {
135
        return $this->exec('removeContact', ['phone' => $phone, 'groupId' => $groupId]);
136
    }
137
138
    /**
139
     * @param string $action
140
     * @return string
141
     */
142
    public function makeEndPoint($action)
143
    {
144
        return 'https://lcab.smsintel.ru/lcabApi/' . $action . '.php';
145
    }
146
147
    /**
148
     * @param array $requestBody
149
     * @return mixed
150
     */
151
    protected function formatRequestBody(array $requestBody)
152
    {
153
        return $requestBody;
154
    }
155
156
    /**
157
     * @param string $response
158
     * @return array
159
     */
160
    protected function parseResponse($response)
161
    {
162
        return json_decode($response, true);
163
    }
164
}