Completed
Push — master ( 4474f6...7e8ad4 )
by Sergey
04:22 queued 02:10
created

XMLRequest::getReportByNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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