Completed
Push — master ( d22dba...39712c )
by Sergey
02:07
created

JSONRequest::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 8
nc 2
nop 4
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
            'send'
15
        ];
16
    }
17
18
    /**
19
     * @param string $source
20
     * @return array|null
21
     */
22
    public function getSource($source)
23
    {
24
        return $this->exec('requestSource', ['source' => $source]);
25
    }
26
27
    /**
28
     * @param string|array $to
29
     * @param string $from
30
     * @param string $message
31
     * @param array $params
32
     * @return array|null
33
     */
34
    public function send($to, $from, $message, $params = [ ])
35
    {
36
        $to = is_array($to) ? $to : [ $to ];
37
38
        $requestParams = array_merge(
39
            [
40
                'to'     => $to,
41
                'txt'   => $message,
42
                'source' => $from,
43
            ],
44
            $params
45
        );
46
47
        return $this->exec('sendSms', $requestParams);
48
    }
49
50
51
    /**
52
     * @param string $action
53
     * @return string
54
     */
55
    public function makeEndPoint($action)
56
    {
57
        return 'https://lcab.smsintel.ru/lcabApi/' . $action . '.php';
58
    }
59
60
    /**
61
     * @param array $requestBody
62
     * @return mixed
63
     */
64
    protected function formatRequestBody(array $requestBody)
65
    {
66
        return $requestBody;
67
    }
68
69
    /**
70
     * @param string $response
71
     * @return array
72
     */
73
    protected function parseResponse($response)
74
    {
75
        return json_decode($response, true);
76
    }
77
}