Overview

Namespaces

  • Inventorus
    • Models

Classes

  • Inventorus\Configuration
  • Inventorus\InventorusClient
  • Inventorus\Models\ExportRequest
  • Inventorus\Models\ImportRequest

Exceptions

  • Inventorus\APIException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: namespace Inventorus;
  3: 
  4: use Inventorus\APIException;
  5: use Inventorus\APIHelper;
  6: use Inventorus\Configuration;
  7: use Inventorus\Models;
  8: use Inventorus\Http\HttpRequest;
  9: use Inventorus\Http\HttpResponse;
 10: use Inventorus\Http\HttpMethod;
 11: use Inventorus\Http\HttpContext;
 12: use Inventorus\Http\HttpCallBack;
 13: use Unirest\Request;
 14: 
 15: /**
 16:  * Inventorus client class
 17:  */
 18: class InventorusClient {
 19: 
 20:     /**
 21:      * HttpCallBack instance associated with this controller
 22:      * @var HttpCallBack
 23:      */
 24:     private $httpCallBack = null;
 25: 
 26:     /**
 27:      * Constructor with authentication and configuration parameters
 28:      */
 29:     public function __construct($apiKey = NULL)
 30:     {
 31:         Configuration::$apiKey = $apiKey ? $apiKey : Configuration::$apiKey;
 32:     }
 33: 
 34:     /**
 35:      * Set HttpCallBack for this controller
 36:      * @param HttpCallBack $httpCallBack Http Callbacks called before/after each API call
 37:      */
 38:     public function setHttpCallBack(HttpCallBack $httpCallBack)
 39:     {
 40:         $this->httpCallBack = $httpCallBack;
 41:     }
 42: 
 43:     /**
 44:      * Get HttpCallBack for this controller
 45:      * @return HttpCallBack The HttpCallBack object set for this controller
 46:      */
 47:     public function getHttpCallBack()
 48:     {
 49:         return $this->httpCallBack;
 50:     }
 51: 
 52:     /**
 53:      * Returns ids of all export transactions you have created.
 54:      * @return array
 55:      * @throws APIException Thrown if API call fails
 56:      */
 57:     public function getExportHistory ()
 58:     {
 59:         //the base uri for api requests
 60:         $_queryBuilder = Configuration::$BASEURI;
 61: 
 62:         //prepare query string for API call
 63:         $_queryBuilder = $_queryBuilder.'/warehouse/exports/history';
 64: 
 65:         //process optional query parameters
 66:         APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
 67:             'apiKey' => Configuration::$apiKey,
 68:         ));
 69: 
 70:         //validate and preprocess url
 71:         $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
 72: 
 73:         //prepare headers
 74:         $_headers = array (
 75:             'user-agent'    => 'APIMATIC 2.0',
 76:             'Accept'        => 'application/json'
 77:         );
 78: 
 79:         //call on-before Http callback
 80:         $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
 81:         if($this->getHttpCallBack() != null) {
 82:             $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
 83:         }
 84: 
 85:         //and invoke the API call request to fetch the response
 86:         $response = Request::get($_queryUrl, $_headers);
 87: 
 88:         //call on-after Http callback
 89:         if($this->getHttpCallBack() != null) {
 90:             $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
 91:             $_httpContext = new HttpContext($_httpRequest, $_httpResponse);
 92: 
 93:             $this->getHttpCallBack()->callOnAfterRequest($_httpContext);
 94:         }
 95: 
 96:         if (!isset($response->body->status)) {
 97:           throw new APIException('Unexpected error in API call. See HTTP response body for details.', $response->code, $response->body);
 98:         }
 99:         else if ($response->body->status == 'error') {
100:           throw new APIException('API responded with error status.', $response->code, $response->body);
101:         }
102: 
103:         return $response->body->response->data->ids;
104:     }
105: 
106:     /**
107:      * Returns user's items from specific application.
108:      * @param  string     $steamid        Required parameter: SteamID64 of user's profile
109:      * @param  uint       $appid          Required parameter: ID of target application
110:      * @param  array      $contextids     Optional parameter: Array containing numbers representing context ids. By default all contexts are included, but it's recommended to achieve better performance and lower costs.
111:      * @return array
112:      * @throws APIException Thrown if API call fails
113:      */
114:     public function getUsersItems ($steamid, $appid, $contextids = NULL)
115:     {
116:         //the base uri for api requests
117:         $_queryBuilder = Configuration::$BASEURI;
118: 
119:         //prepare query string for API call
120:         $_queryBuilder = $_queryBuilder.'/steam/items/{steamid}/{appid}';
121: 
122:         //process optional query parameters
123:         APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
124:             'steamid'    => $steamid,
125:             'appid'      => $appid,
126:             ));
127: 
128:         //process optional query parameters
129:         APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
130:             'contextids' => $contextids,
131:             'apiKey' => Configuration::$apiKey,
132:         ));
133: 
134:         //validate and preprocess url
135:         $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
136: 
137:         //prepare headers
138:         $_headers = array (
139:             'user-agent'    => 'APIMATIC 2.0',
140:             'Accept'        => 'application/json'
141:         );
142: 
143:         //call on-before Http callback
144:         $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
145:         if ($this->getHttpCallBack() != null) {
146:             $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
147:         }
148: 
149:         //and invoke the API call request to fetch the response
150:         $response = Request::get($_queryUrl, $_headers);
151: 
152:         //call on-after Http callback
153:         if($this->getHttpCallBack() != null) {
154:             $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
155:             $_httpContext = new HttpContext($_httpRequest, $_httpResponse);
156: 
157:             $this->getHttpCallBack()->callOnAfterRequest($_httpContext);
158:         }
159: 
160:         if (!isset($response->body->status)) {
161:           throw new APIException('Unexpected error in API call. See HTTP response body for details.', $response->code, $response->body);
162:         }
163:         else if ($response->body->status == 'error') {
164:           throw new APIException('API responded with error status.', $response->code, $response->body);
165:         }
166: 
167:         return array(
168:           $response->body->response->data->inventory,
169:           $response->body->response->data->currency
170:         );
171:     }
172: 
173:     /**
174:      * Returns applications with inventory items owned by Steam user.
175:      * @param  string     $steamid          Required parameter: SteamID64 of user's profile
176:      * @param  bool       $includeEmpty     Optional parameter: Include user's apps currently containing no items inside his inventory. Default is set to false.
177:      * @return array
178:      * @throws APIException Thrown if API call fails
179:      */
180:     public function getUsersApps ($steamid, $includeEmpty = NULL)
181:     {
182:         //the base uri for api requests
183:         $_queryBuilder = Configuration::$BASEURI;
184: 
185:         //prepare query string for API call
186:         $_queryBuilder = $_queryBuilder.'/steam/apps/{steamid}';
187: 
188:         //process optional query parameters
189:         APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
190:             'steamid'      => $steamid,
191:             ));
192: 
193:         //process optional query parameters
194:         APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
195:             'includeEmpty' => var_export($includeEmpty, true),
196:             'apiKey' => Configuration::$apiKey,
197:         ));
198: 
199:         //validate and preprocess url
200:         $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
201: 
202:         //prepare headers
203:         $_headers = array (
204:             'user-agent'    => 'APIMATIC 2.0',
205:             'Accept'        => 'application/json'
206:         );
207: 
208:         //call on-before Http callback
209:         $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
210:         if($this->getHttpCallBack() != null) {
211:             $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
212:         }
213: 
214:         //and invoke the API call request to fetch the response
215:         $response = Request::get($_queryUrl, $_headers);
216: 
217:         //call on-after Http callback
218:         if($this->getHttpCallBack() != null) {
219:             $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
220:             $_httpContext = new HttpContext($_httpRequest, $_httpResponse);
221: 
222:             $this->getHttpCallBack()->callOnAfterRequest($_httpContext);
223:         }
224: 
225:         if (!isset($response->body->status)) {
226:           throw new APIException('Unexpected error in API call. See HTTP response body for details.', $response->code, $response->body);
227:         }
228:         else if ($response->body->status == 'error') {
229:           throw new APIException('API responded with error status.', $response->code, $response->body);
230:         }
231: 
232:         return $response->body->response->data->apps;
233:     }
234: 
235:     /**
236:      * Returns export transaction.
237:      * @param  string     $id         Required parameter: ID of requested Import transaction
238:      * @return mixed
239:      * @throws APIException Thrown if API call fails
240:      */
241:     public function getExport ($id)
242:     {
243:         //the base uri for api requests
244:         $_queryBuilder = Configuration::$BASEURI;
245: 
246:         //prepare query string for API call
247:         $_queryBuilder = $_queryBuilder.'/warehouse/exports/{id}';
248: 
249:         //process optional query parameters
250:         APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
251:             'id'     => $id,
252:             ));
253: 
254:         //process optional query parameters
255:         APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
256:             'apiKey' => Configuration::$apiKey,
257:         ));
258: 
259:         //validate and preprocess url
260:         $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
261: 
262:         //prepare headers
263:         $_headers = array (
264:             'user-agent'    => 'APIMATIC 2.0',
265:             'Accept'        => 'application/json'
266:         );
267: 
268:         //call on-before Http callback
269:         $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
270:         if($this->getHttpCallBack() != null) {
271:             $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
272:         }
273: 
274:         //and invoke the API call request to fetch the response
275:         $response = Request::get($_queryUrl, $_headers);
276: 
277:         //call on-after Http callback
278:         if($this->getHttpCallBack() != null) {
279:             $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
280:             $_httpContext = new HttpContext($_httpRequest, $_httpResponse);
281: 
282:             $this->getHttpCallBack()->callOnAfterRequest($_httpContext);
283:         }
284: 
285:         if (!isset($response->body->status)) {
286:           throw new APIException('Unexpected error in API call. See HTTP response body for details.', $response->code, $response->body);
287:         }
288:         else if ($response->body->status == 'error') {
289:           throw new APIException('API responded with error status.', $response->code, $response->body);
290:         }
291: 
292:         return $response->body->response->data->export;
293:     }
294: 
295:     /**
296:      * Creates a new export.
297:      * @param  Models\ExportRequest $body       Required parameter
298:      * @return string
299:      * @throws APIException Thrown if API call fails
300:      */
301:     public function createExport ($body)
302:     {
303:         //the base uri for api requests
304:         $_queryBuilder = Configuration::$BASEURI;
305: 
306:         //prepare query string for API call
307:         $_queryBuilder = $_queryBuilder.'/warehouse/exports';
308: 
309:         //process optional query parameters
310:         APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
311:             'apiKey' => Configuration::$apiKey,
312:         ));
313: 
314:         //validate and preprocess url
315:         $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
316: 
317:         //prepare headers
318:         $_headers = array (
319:             'user-agent'    => 'APIMATIC 2.0',
320:             'Accept'        => 'application/json',
321:             'content-type'  => 'application/json; charset=utf-8'
322:         );
323: 
324:         //call on-before Http callback
325:         $_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl);
326:         if($this->getHttpCallBack() != null) {
327:             $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
328:         }
329: 
330:         //and invoke the API call request to fetch the response
331:         $response = Request::post($_queryUrl, $_headers, Request\Body::Json($body));
332: 
333:         //call on-after Http callback
334:         if($this->getHttpCallBack() != null) {
335:             $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
336:             $_httpContext = new HttpContext($_httpRequest, $_httpResponse);
337: 
338:             $this->getHttpCallBack()->callOnAfterRequest($_httpContext);
339:         }
340: 
341:         if (!isset($response->body->status)) {
342:           throw new APIException('Unexpected error in API call. See HTTP response body for details.', $response->code, $response->body);
343:         }
344:         else if ($response->body->status == 'error') {
345:           throw new APIException('API responded with error status.', $response->code, $response->body);
346:         }
347: 
348:         return $response->body->response->data->id;
349:     }
350: 
351:     /**
352:      * Returns ids of all import transactions you have created.
353:      * @return array
354:      * @throws APIException Thrown if API call fails
355:      */
356:     public function getImportHistory ()
357:     {
358:         //the base uri for api requests
359:         $_queryBuilder = Configuration::$BASEURI;
360: 
361:         //prepare query string for API call
362:         $_queryBuilder = $_queryBuilder.'/warehouse/imports/history';
363: 
364:         //process optional query parameters
365:         APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
366:             'apiKey' => Configuration::$apiKey,
367:         ));
368: 
369:         //validate and preprocess url
370:         $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
371: 
372:         //prepare headers
373:         $_headers = array (
374:             'user-agent'    => 'APIMATIC 2.0',
375:             'Accept'        => 'application/json'
376:         );
377: 
378:         //call on-before Http callback
379:         $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
380:         if($this->getHttpCallBack() != null) {
381:             $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
382:         }
383: 
384:         //and invoke the API call request to fetch the response
385:         $response = Request::get($_queryUrl, $_headers);
386: 
387:         //call on-after Http callback
388:         if($this->getHttpCallBack() != null) {
389:             $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
390:             $_httpContext = new HttpContext($_httpRequest, $_httpResponse);
391: 
392:             $this->getHttpCallBack()->callOnAfterRequest($_httpContext);
393:         }
394: 
395:         if (!isset($response->body->status)) {
396:           throw new APIException('Unexpected error in API call. See HTTP response body for details.', $response->code, $response->body);
397:         }
398:         else if ($response->body->status == 'error') {
399:           throw new APIException('API responded with error status.', $response->code, $response->body);
400:         }
401: 
402:         return $response->body->response->data->ids;
403:     }
404: 
405:     /**
406:      * Returns import transaction.
407:      * @param  string     $id         Required parameter: ID of requested Import transaction
408:      * @return mixed
409:      * @throws APIException Thrown if API call fails
410:      */
411:     public function getImport ($id)
412:     {
413:         //the base uri for api requests
414:         $_queryBuilder = Configuration::$BASEURI;
415: 
416:         //prepare query string for API call
417:         $_queryBuilder = $_queryBuilder.'/warehouse/imports/{id}';
418: 
419:         //process optional query parameters
420:         APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
421:             'id'     => $id,
422:             ));
423: 
424:         //process optional query parameters
425:         APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
426:             'apiKey' => Configuration::$apiKey,
427:         ));
428: 
429:         //validate and preprocess url
430:         $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
431: 
432:         //prepare headers
433:         $_headers = array (
434:             'user-agent'    => 'APIMATIC 2.0',
435:             'Accept'        => 'application/json'
436:         );
437: 
438:         //call on-before Http callback
439:         $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
440:         if($this->getHttpCallBack() != null) {
441:             $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
442:         }
443: 
444:         //and invoke the API call request to fetch the response
445:         $response = Request::get($_queryUrl, $_headers);
446: 
447:         //call on-after Http callback
448:         if($this->getHttpCallBack() != null) {
449:             $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
450:             $_httpContext = new HttpContext($_httpRequest, $_httpResponse);
451: 
452:             $this->getHttpCallBack()->callOnAfterRequest($_httpContext);
453:         }
454: 
455:         if (!isset($response->body->status)) {
456:           throw new APIException('Unexpected error in API call. See HTTP response body for details.', $response->code, $response->body);
457:         }
458:         else if ($response->body->status == 'error') {
459:           throw new APIException('API responded with error status.', $response->code, $response->body);
460:         }
461: 
462:         return $response->body->response->data->import;
463:     }
464: 
465:     /**
466:      * Returns all currently owned items.
467:      * @return array
468:      * @throws APIException Thrown if API call fails
469:      */
470:     public function listWarehouse ()
471:     {
472:         //the base uri for api requests
473:         $_queryBuilder = Configuration::$BASEURI;
474: 
475:         //prepare query string for API call
476:         $_queryBuilder = $_queryBuilder.'/warehouse';
477: 
478:         //process optional query parameters
479:         APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
480:             'apiKey' => Configuration::$apiKey,
481:         ));
482: 
483:         //validate and preprocess url
484:         $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
485: 
486:         //prepare headers
487:         $_headers = array (
488:             'user-agent'    => 'APIMATIC 2.0',
489:             'Accept'        => 'application/json'
490:         );
491: 
492:         //call on-before Http callback
493:         $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
494:         if($this->getHttpCallBack() != null) {
495:             $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
496:         }
497: 
498:         //and invoke the API call request to fetch the response
499:         $response = Request::get($_queryUrl, $_headers);
500: 
501:         //call on-after Http callback
502:         if($this->getHttpCallBack() != null) {
503:             $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
504:             $_httpContext = new HttpContext($_httpRequest, $_httpResponse);
505: 
506:             $this->getHttpCallBack()->callOnAfterRequest($_httpContext);
507:         }
508: 
509:         if (!isset($response->body->status)) {
510:           throw new APIException('Unexpected error in API call. See HTTP response body for details.', $response->code, $response->body);
511:         }
512:         else if ($response->body->status == 'error') {
513:           throw new APIException('API responded with error status.', $response->code, $response->body);
514:         }
515: 
516:         return $response->body->response->data->items;
517:     }
518: 
519:     /**
520:      * Creates a new import.
521:      * @param  string     $id         Required parameter: ID of Import transaction
522:      * @return string
523:      * @throws APIException Thrown if API call fails
524:      */
525:     public function createImport ($body)
526:     {
527:         //the base uri for api requests
528:         $_queryBuilder = Configuration::$BASEURI;
529: 
530:         //prepare query string for API call
531:         $_queryBuilder = $_queryBuilder.'/warehouse/imports';
532: 
533:         //process optional query parameters
534:         APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
535:             'apiKey' => Configuration::$apiKey,
536:         ));
537: 
538:         //validate and preprocess url
539:         $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
540: 
541:         //prepare headers
542:         $_headers = array (
543:             'user-agent'    => 'APIMATIC 2.0',
544:             'Accept'        => 'application/json',
545:             'content-type'  => 'application/json; charset=utf-8'
546:         );
547: 
548:         //call on-before Http callback
549:         $_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl);
550:         if($this->getHttpCallBack() != null) {
551:             $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
552:         }
553: 
554:         //and invoke the API call request to fetch the response
555:         $response = Request::post($_queryUrl, $_headers, Request\Body::Json($body));
556: 
557:         //call on-after Http callback
558:         if($this->getHttpCallBack() != null) {
559:             $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
560:             $_httpContext = new HttpContext($_httpRequest, $_httpResponse);
561: 
562:             $this->getHttpCallBack()->callOnAfterRequest($_httpContext);
563:         }
564: 
565:         if (!isset($response->body->status)) {
566:           throw new APIException('Unexpected error in API call. See HTTP response body for details.', $response->code, $response->body);
567:         }
568:         else if ($response->body->status == 'error') {
569:           throw new APIException('API responded with error status.', $response->code, $response->body);
570:         }
571: 
572:         return $response->body->response->data->id;
573:     }
574: 
575:     /**
576:      * Cancels an unfinished import.
577:      * @param  $id       Required parameter
578:      * @return boolean
579:      * @throws APIException Thrown if API call fails
580:      */
581:     public function cancelImport ($id)
582:     {
583:         //the base uri for api requests
584:         $_queryBuilder = Configuration::$BASEURI;
585: 
586:         //prepare query string for API call
587:         $_queryBuilder = $_queryBuilder.'/warehouse/imports/{id}/cancel/';
588: 
589:         //process optional query parameters
590:         APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
591:           'id'     => $id,
592:         ));
593: 
594:         //process optional query parameters
595:         APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
596:           'apiKey' => Configuration::$apiKey,
597:         ));
598: 
599:         //validate and preprocess url
600:         $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
601: 
602:         //prepare headers
603:         $_headers = array (
604:           'user-agent'    => 'APIMATIC 2.0',
605:           'Accept'        => 'application/json',
606:           'content-type'  => 'application/json; charset=utf-8'
607:         );
608: 
609:         //call on-before Http callback
610:         $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
611:         if($this->getHttpCallBack() != null) {
612:             $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
613:         }
614: 
615:         //and invoke the API call request to fetch the response
616:         $response = Request::post($_queryUrl, $_headers);
617: 
618:         //call on-after Http callback
619:         if($this->getHttpCallBack() != null) {
620:             $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
621:             $_httpContext = new HttpContext($_httpRequest, $_httpResponse);
622: 
623:             $this->getHttpCallBack()->callOnAfterRequest($_httpContext);
624:         }
625: 
626:         if (!isset($response->body->status)) {
627:           throw new APIException('Unexpected error in API call. See HTTP response body for details.', $response->code, $response->body);
628:         }
629:         else if ($response->body->status == 'error') {
630:           throw new APIException('API responded with error status.', $response->code, $response->body);
631:         }
632: 
633:         return true;
634:     }
635: 
636:     /**
637:      * Returns item details.
638:      * @param  string     $id         Required parameter: ID of requested item
639:      * @return mixed
640:      * @throws APIException Thrown if API call fails
641:      */
642:     public function getItemDetails ($id)
643:     {
644:         //the base uri for api requests
645:         $_queryBuilder = Configuration::$BASEURI;
646: 
647:         //prepare query string for API call
648:         $_queryBuilder = $_queryBuilder.'/warehouse/items/{id}';
649: 
650:         //process optional query parameters
651:         APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
652:             'id'     => $id,
653:             ));
654: 
655:         //process optional query parameters
656:         APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
657:             'apiKey' => Configuration::$apiKey,
658:         ));
659: 
660:         //validate and preprocess url
661:         $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
662: 
663:         //prepare headers
664:         $_headers = array (
665:             'user-agent'    => 'APIMATIC 2.0',
666:             'Accept'        => 'application/json'
667:         );
668: 
669:         //call on-before Http callback
670:         $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
671:         if($this->getHttpCallBack() != null) {
672:             $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
673:         }
674: 
675:         //and invoke the API call request to fetch the response
676:         $response = Request::get($_queryUrl, $_headers);
677: 
678:         //call on-after Http callback
679:         if($this->getHttpCallBack() != null) {
680:             $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
681:             $_httpContext = new HttpContext($_httpRequest, $_httpResponse);
682: 
683:             $this->getHttpCallBack()->callOnAfterRequest($_httpContext);
684:         }
685: 
686:         if (!isset($response->body->status)) {
687:           throw new APIException('Unexpected error in API call. See HTTP response body for details.', $response->code, $response->body);
688:         }
689:         else if ($response->body->status == 'error') {
690:           throw new APIException('API responded with error status.', $response->code, $response->body);
691:         }
692: 
693:         return $response->body->response->data->item;
694:     }
695: }
696: 
API documentation generated by ApiGen