1 | <?php |
||
9 | class HttpClient |
||
10 | { |
||
11 | const API_URL = 'https://api.smslabs.net.pl/apiSms'; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $appKey = null; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $secretKey = null; |
||
22 | |||
23 | /** |
||
24 | * @var Client |
||
25 | */ |
||
26 | private $client = null; |
||
27 | |||
28 | /** |
||
29 | * HttpClient constructor. |
||
30 | * @param string $appKey |
||
31 | * @param string $secretKey |
||
32 | */ |
||
33 | 27 | public function __construct(string $appKey, string $secretKey) |
|
38 | |||
39 | /** |
||
40 | * @param string $url |
||
41 | * @param array $data |
||
42 | * @param string $method |
||
43 | * @return array |
||
44 | * @throws InvalidResponseException |
||
45 | */ |
||
46 | 5 | public function sendRequest(string $url, array $data = null, string $method = 'GET') : array |
|
63 | |||
64 | /** |
||
65 | * @param string $json |
||
66 | * @return array |
||
67 | * @throws InvalidResponseException |
||
68 | */ |
||
69 | 3 | private function parseJsonData(string $json) : array |
|
83 | |||
84 | /** |
||
85 | * @param string $method |
||
86 | * @return bool |
||
87 | */ |
||
88 | 5 | private function validateHttpMethod(string $method) : bool |
|
92 | |||
93 | /** |
||
94 | * @return Client |
||
95 | */ |
||
96 | 5 | public function getClient() : Client |
|
104 | |||
105 | /** |
||
106 | * @param Client $client |
||
107 | * @return HttpClient $this |
||
108 | */ |
||
109 | 4 | public function setClient(Client $client) : HttpClient |
|
115 | |||
116 | /** |
||
117 | * @return string |
||
118 | */ |
||
119 | 3 | public function getAppKey() : string |
|
123 | |||
124 | /** |
||
125 | * @param string $appKey |
||
126 | * @return HttpClient $this |
||
127 | */ |
||
128 | 1 | public function setAppKey(string $appKey) : HttpClient |
|
134 | |||
135 | /** |
||
136 | * @return string |
||
137 | */ |
||
138 | 3 | public function getSecretKey() : string |
|
142 | |||
143 | /** |
||
144 | * @param string $secretKey |
||
145 | * @return HttpClient $this |
||
146 | */ |
||
147 | 1 | public function setSecretKey(string $secretKey) : HttpClient |
|
153 | } |
||
154 |