1 | <?php |
||
9 | class InktaleApiClient |
||
10 | { |
||
11 | const USER_AGENT = 'Inktale PHP wrapper (https://github.com/inktale/php-api-sdk)'; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | public $url = 'https://inktale.com/api/v1/'; |
||
17 | |||
18 | /** |
||
19 | * Last JSON encoded response |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | private $lastResponseRaw; |
||
24 | |||
25 | /** |
||
26 | * Last parsed response (json decoded) |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | private $lastResponse; |
||
31 | |||
32 | /** |
||
33 | * Authorization token |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | private $apiKey; |
||
38 | |||
39 | /** |
||
40 | * Your API key |
||
41 | * |
||
42 | * @param string|null $apiKey |
||
43 | */ |
||
44 | public function __construct($apiKey = null) |
||
48 | |||
49 | /** |
||
50 | * Set authorization header key |
||
51 | * @param string $apiKey |
||
52 | */ |
||
53 | public function setApiKey($apiKey) |
||
57 | |||
58 | /** |
||
59 | * Perform a GET request to the API |
||
60 | * |
||
61 | * @param string $path Request path |
||
62 | * @param array $params Additional GET parameters as an associative array |
||
63 | * @return mixed |
||
64 | */ |
||
65 | public function get($path, $params = []) |
||
69 | |||
70 | /** |
||
71 | * Perform a DELETE request to the API |
||
72 | * |
||
73 | * @param string $path Request path |
||
74 | * @param array $params Additional GET parameters as an associative array |
||
75 | * @return mixed |
||
76 | */ |
||
77 | public function delete($path, $params = []) |
||
81 | |||
82 | /** |
||
83 | * Perform a POST request to the API |
||
84 | * |
||
85 | * @param string $path Request path |
||
86 | * @param array $data Request body data as an associative array |
||
87 | * @param array $params Additional GET parameters as an associative array |
||
88 | * @return mixed |
||
89 | */ |
||
90 | public function post($path, $data = [], $params = []) |
||
94 | |||
95 | /** |
||
96 | * Perform a PUT request to the API |
||
97 | * |
||
98 | * @param string $path Request path |
||
99 | * @param array $data Request body data as an associative array |
||
100 | * @param array $params Additional GET parameters as an associative array |
||
101 | * @return mixed |
||
102 | */ |
||
103 | public function put($path, $data = [], $params = []) |
||
107 | |||
108 | /** |
||
109 | * Return raw response data from the last request |
||
110 | * |
||
111 | * @return string|null Response data |
||
112 | */ |
||
113 | public function getLastResponseRaw() |
||
117 | |||
118 | /** |
||
119 | * Return decoded response data from the last request |
||
120 | * |
||
121 | * @return array|null Response data |
||
122 | */ |
||
123 | public function getLastResponse() |
||
127 | |||
128 | /** |
||
129 | * Internal request implementation |
||
130 | * @param string $method POST, GET, etc. |
||
131 | * @param string $path API endpoint path |
||
132 | * @param array $query Query parameters |
||
133 | * @param array|mixed $data Post data |
||
134 | * @return mixed |
||
135 | * @throws InktaleApiException |
||
136 | */ |
||
137 | protected function request($method, $path, array $query = [], $data = null) |
||
154 | |||
155 | /** |
||
156 | * @param string $method |
||
157 | * @param string $path |
||
158 | * @param array $query Query parameters |
||
159 | * @return resource cURL handler |
||
160 | */ |
||
161 | protected function initCurl($method, $path, array $query) |
||
177 | |||
178 | /** |
||
179 | * @param string $path |
||
180 | * @param array $query |
||
181 | * @return string |
||
182 | */ |
||
183 | private function getUrl($path, array $query) |
||
191 | |||
192 | /** |
||
193 | * Execute cURL handler and return response |
||
194 | * @param resource $curl |
||
195 | * @return mixed |
||
196 | * @throws InktaleApiException |
||
197 | */ |
||
198 | private function execute($curl) |
||
239 | |||
240 | /** |
||
241 | * @param int $contentLength |
||
242 | * @param string $contentType |
||
243 | * @return string[] |
||
244 | */ |
||
245 | private function getCurlHeaders($contentLength, $contentType) |
||
258 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.