1 | <?php |
||
8 | class InetworxClient |
||
9 | { |
||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $baseUrl = 'https://sms.inetworx.ch/'; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $broadcastUrl = 'smsapp/sendsms.php'; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $optionsUrl = 'smsapp/options.php'; |
||
24 | |||
25 | /** |
||
26 | * @var Client |
||
27 | */ |
||
28 | protected $httpClient; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $apiPassword; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $apiUsername; |
||
39 | |||
40 | /** |
||
41 | * Inetworx Client Constructor. |
||
42 | * |
||
43 | * @param string $authHeaderUsername |
||
44 | * @param string $authHeaderPassword |
||
45 | * @param string $apiUsername |
||
46 | * @param string $apiPassword |
||
47 | * @param $client |
||
48 | */ |
||
49 | public function __construct($authHeaderUsername, $authHeaderPassword, $apiUsername, $apiPassword, $client = null) |
||
60 | |||
61 | /** |
||
62 | * Send the message. |
||
63 | * |
||
64 | * @param $phoneNumber |
||
65 | * @param $message |
||
66 | * @param $fromNumber |
||
67 | * |
||
68 | * @return array $response |
||
69 | */ |
||
70 | public function send($phoneNumber, $message, $fromNumber) |
||
79 | |||
80 | /** |
||
81 | * Get the remaining SMS credits. |
||
82 | * |
||
83 | * @throws ApiErrorException |
||
84 | * |
||
85 | * @return int $credit |
||
86 | */ |
||
87 | public function credit() |
||
91 | |||
92 | /** |
||
93 | * @param $url |
||
94 | * @param $params |
||
95 | * |
||
96 | * @throws ApiErrorException |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | protected function sendRequest($url, $params) |
||
124 | |||
125 | /** |
||
126 | * The Inetworx API doesn't respond with a useful HTTP Status Code if the request fails. |
||
127 | * It puts the status code into the response body. |
||
128 | * for example: 404: Invalid Option. |
||
129 | * |
||
130 | * @return int $code |
||
131 | */ |
||
132 | protected function responseCodeFromBody($response) |
||
136 | |||
137 | /** |
||
138 | * Inetworx puts the status code in the response body too. |
||
139 | * Because of that, we have to parse the answer. |
||
140 | * |
||
141 | * @param $response |
||
142 | * |
||
143 | * @return string $body |
||
144 | */ |
||
145 | protected function responseBody($response) |
||
149 | |||
150 | /** |
||
151 | * @return string |
||
152 | */ |
||
153 | public function getBaseUrl() |
||
157 | |||
158 | /** |
||
159 | * @param string $baseUrl |
||
160 | */ |
||
161 | public function setBaseUrl($baseUrl) |
||
165 | |||
166 | /** |
||
167 | * @return string |
||
168 | */ |
||
169 | public function getBroadcastUrl() |
||
173 | |||
174 | /** |
||
175 | * @param string $broadcastUrl |
||
176 | */ |
||
177 | public function setBroadcastUrl($broadcastUrl) |
||
181 | |||
182 | /** |
||
183 | * @return string |
||
184 | */ |
||
185 | public function getOptionsUrl() |
||
189 | |||
190 | /** |
||
191 | * @param string $optionsUrl |
||
192 | */ |
||
193 | public function setOptionsUrl($optionsUrl) |
||
197 | |||
198 | /** |
||
199 | * @return Client |
||
200 | */ |
||
201 | protected function getHttpClient() |
||
205 | |||
206 | /** |
||
207 | * @param $client |
||
208 | * |
||
209 | * @return void |
||
210 | */ |
||
211 | protected function setHttpClient($client) |
||
215 | |||
216 | /** |
||
217 | * @return void |
||
218 | */ |
||
219 | protected function createHttpClient($authHeaderUsername, $authHeaderPassword) |
||
229 | } |
||
230 |