@@ -24,6 +24,13 @@ abstract class MoipResource implements JsonSerializable
24
24
*/
25
25
const VERSION = 'v2 ' ;
26
26
27
+ /**
28
+ * Api version content type.
29
+ *
30
+ * @cont string
31
+ */
32
+ const ACCEPT_VERSION = 'application/json;version=2.1 ' ;
33
+
27
34
/**
28
35
* @var \Moip\Moip
29
36
*/
@@ -210,25 +217,27 @@ public function generateListPath(Pagination $pagination = null, Filters $filters
210
217
* Execute a http request. If payload == null no body will be sent. Empty body ('{}') is supported by sending a
211
218
* empty stdClass.
212
219
*
213
- * @param string $path
214
- * @param string $method
215
- * @param mixed|null $payload
220
+ * @param string $path request path
221
+ * @param string $method http method
222
+ * @param mixed|null $payload request body
223
+ * @param array $headers request headers
216
224
*
217
225
* @throws Exceptions\ValidationException if the API returns a 4xx http status code. Usually means invalid data was sent.
218
226
* @throws Exceptions\UnautorizedException if the API returns a 401 http status code. Check API token and key.
219
227
* @throws Exceptions\UnexpectedException if the API returns a 500 http status code or something unexpected happens (ie.: Network error).
220
228
*
221
229
* @return stdClass
222
230
*/
223
- protected function httpRequest ($ path , $ method , $ payload = null )
231
+ protected function httpRequest ($ path , $ method , $ payload = null , $ headers = [] )
224
232
{
225
233
$ http_sess = $ this ->moip ->getSession ();
226
- $ headers = [];
227
234
$ body = null ;
228
235
if ($ payload !== null ) {
229
236
$ body = json_encode ($ payload , JSON_UNESCAPED_SLASHES );
230
- if ($ body ) {// if it's json serializable
231
- $ headers ['Content-Type ' ] = 'application/json ' ;
237
+ if ($ body ) { // if it's json serializable
238
+ if (!isset ($ headers ['Content-Type ' ])) {
239
+ $ headers ['Content-Type ' ] = 'application/json ' ;
240
+ }
232
241
} else {
233
242
$ body = null ;
234
243
}
@@ -258,13 +267,14 @@ protected function httpRequest($path, $method, $payload = null)
258
267
/**
259
268
* Find by path.
260
269
*
261
- * @param string $path
270
+ * @param string $path resource path
271
+ * @param array $headers request headers
262
272
*
263
273
* @return stdClass
264
274
*/
265
- public function getByPath ($ path )
275
+ public function getByPath ($ path, $ headers = [] )
266
276
{
267
- $ response = $ this ->httpRequest ($ path , Requests::GET );
277
+ $ response = $ this ->httpRequest ($ path , Requests::GET , null , $ headers );
268
278
269
279
if (is_array ($ response )) {
270
280
$ response = (object ) $ response ;
0 commit comments