Completed
Push — master ( 241032...67be65 )
by Sergey
02:51
created

XMLRequest::getReportBySms()   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
use seregazhuk\SmsIntel\XMLFormatter;
6
7
class XMLRequest extends Request
8
{
9
    public static function getAllowedMethods()
10
    {
11
        return [
12
            'cancel',
13
            'getBalance',
14
            'checkCoupon',
15
            'getReportBySms',
16
            'getReportBySource',
17
            'getReportByNumber',
18
        ];
19
    }
20
21
    /**
22
     * @param string $smsId
23
     * @return array|null
24
     */
25
    public function cancel($smsId)
26
    {
27
        return $this->exec('cancel', [ 'smsid' => $smsId ]);
28
    }
29
30
    /**
31
     * @param string $coupon
32
     * @param bool $markAsUsed
33
     * @param null|string $phone
34
     * @return array|null
35
     */
36
    public function checkCoupon($coupon, $markAsUsed = true, $phone = null)
37
    {
38
        return $this->exec(
39
            'checkcode',
40
            [
41
                'code'       => $coupon,
42
                'markAsUsed' => (int)$markAsUsed,
43
                'phone'      => $phone,
44
            ]
45
        );
46
    }
47
48
    /**
49
     * @param string $dateFrom
50
     * @param string $dateTo
51
     * @param null|string $source
52
     * @return array|null
53
     */
54
    public function getReportBySource($dateFrom, $dateTo, $source = null)
55
    {
56
        return $this->exec(
57
            'report',
58
            [
59
                'start'  => $dateFrom,
60
                'stop'   => $dateTo,
61
                'source' => $source,
62
            ]
63
        );
64
    }
65
66
    /**
67
     * @param string $smsId
68
     * @return array|null
69
     */
70
    public function getReportBySms($smsId)
71
    {
72
        return $this->exec('report', [ 'smsid' => $smsId ]);
73
    }
74
75
    /**
76
     * @param string $dateFrom
77
     * @param string $dateTo
78
     * @param null|string $number
79
     * @return array|null
80
     */
81
    public function getReportByNumber($dateFrom , $dateTo, $number = null)
82
    {
83
        return $this->exec('reportNumber',
84
            [
85
                'start'  => $dateFrom,
86
                'stop'   => $dateTo,
87
                'number' => $number,
88
            ]);
89
    }
90
91
    /**
92
     * @return array|null
93
     */
94
    public function getBalance()
95
    {
96
        return $this->exec('balance');
97
    }
98
99
    /**
100
     * @param string $action
101
     * @return string
102
     */
103
    public function makeEndPoint($action)
104
    {
105
        return 'https://lcab.smsintel.ru/API/XML/' . $action . '.php';
106
    }
107
108
    /**
109
     * @param array $requestBody
110
     * @return mixed
111
     */
112
    protected function formatRequestBody(array $requestBody)
113
    {
114
        return (new XMLFormatter($requestBody))->toXml();
115
    }
116
117
    /**
118
     * Parses XML from response and returns it as an array
119
     *
120
     * @param string $response
121
     * @return array
122
     */
123
    protected function parseResponse($response)
124
    {
125
        $xml = simplexml_load_string($response);
126
        return (array)$xml->children();
127
    }
128
}