1: <?php
2: /**
3: * StoreApi
4: * PHP version 7.4
5: *
6: * @category Class
7: * @package Ally\PetStore
8: * @author OpenAPI Generator team
9: * @link https://openapi-generator.tech
10: */
11:
12: /**
13: * OpenAPI Petstore
14: *
15: * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
16: *
17: * The version of the OpenAPI document: 1.0.0
18: * Generated by: https://openapi-generator.tech
19: * OpenAPI Generator version: 6.1.0-SNAPSHOT
20: */
21:
22: /**
23: * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
24: * https://openapi-generator.tech
25: * Do not edit the class manually.
26: */
27:
28: namespace Ally\PetStore\Api;
29:
30: use GuzzleHttp\Client;
31: use GuzzleHttp\ClientInterface;
32: use GuzzleHttp\Exception\ConnectException;
33: use GuzzleHttp\Exception\RequestException;
34: use GuzzleHttp\Psr7\MultipartStream;
35: use GuzzleHttp\Psr7\Request;
36: use GuzzleHttp\RequestOptions;
37: use Ally\PetStore\ApiException;
38: use Ally\PetStore\Configuration;
39: use Ally\PetStore\HeaderSelector;
40: use Ally\PetStore\ObjectSerializer;
41:
42: /**
43: * StoreApi Class Doc Comment
44: *
45: * @category Class
46: * @package Ally\PetStore
47: * @author OpenAPI Generator team
48: * @link https://openapi-generator.tech
49: */
50: class StoreApi
51: {
52: /**
53: * @var ClientInterface
54: */
55: protected $client;
56:
57: /**
58: * @var Configuration
59: */
60: protected $config;
61:
62: /**
63: * @var HeaderSelector
64: */
65: protected $headerSelector;
66:
67: /**
68: * @var int Host index
69: */
70: protected $hostIndex;
71:
72: /**
73: * @param ClientInterface $client
74: * @param Configuration $config
75: * @param HeaderSelector $selector
76: * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
77: */
78: public function __construct(
79: ClientInterface $client = null,
80: Configuration $config = null,
81: HeaderSelector $selector = null,
82: $hostIndex = 0
83: ) {
84: $this->client = $client ?: new Client();
85: $this->config = $config ?: new Configuration();
86: $this->headerSelector = $selector ?: new HeaderSelector();
87: $this->hostIndex = $hostIndex;
88: }
89:
90: /**
91: * Set the host index
92: *
93: * @param int $hostIndex Host index (required)
94: */
95: public function setHostIndex($hostIndex): void
96: {
97: $this->hostIndex = $hostIndex;
98: }
99:
100: /**
101: * Get the host index
102: *
103: * @return int Host index
104: */
105: public function getHostIndex()
106: {
107: return $this->hostIndex;
108: }
109:
110: /**
111: * @return Configuration
112: */
113: public function getConfig()
114: {
115: return $this->config;
116: }
117:
118: /**
119: * Operation deleteOrder
120: *
121: * Delete purchase order by ID
122: *
123: * @param string $order_id ID of the order that needs to be deleted (required)
124: *
125: * @throws \Ally\PetStore\ApiException on non-2xx response
126: * @throws \InvalidArgumentException
127: * @return void
128: */
129: public function deleteOrder($order_id)
130: {
131: $this->deleteOrderWithHttpInfo($order_id);
132: }
133:
134: /**
135: * Operation deleteOrderWithHttpInfo
136: *
137: * Delete purchase order by ID
138: *
139: * @param string $order_id ID of the order that needs to be deleted (required)
140: *
141: * @throws \Ally\PetStore\ApiException on non-2xx response
142: * @throws \InvalidArgumentException
143: * @return array of null, HTTP status code, HTTP response headers (array of strings)
144: */
145: public function deleteOrderWithHttpInfo($order_id)
146: {
147: $request = $this->deleteOrderRequest($order_id);
148:
149: try {
150: $options = $this->createHttpClientOption();
151: try {
152: $response = $this->client->send($request, $options);
153: } catch (RequestException $e) {
154: throw new ApiException(
155: "[{$e->getCode()}] {$e->getMessage()}",
156: (int) $e->getCode(),
157: $e->getResponse() ? $e->getResponse()->getHeaders() : null,
158: $e->getResponse() ? (string) $e->getResponse()->getBody() : null
159: );
160: } catch (ConnectException $e) {
161: throw new ApiException(
162: "[{$e->getCode()}] {$e->getMessage()}",
163: (int) $e->getCode(),
164: null,
165: null
166: );
167: }
168:
169: $statusCode = $response->getStatusCode();
170:
171: if ($statusCode < 200 || $statusCode > 299) {
172: throw new ApiException(
173: sprintf(
174: '[%d] Error connecting to the API (%s)',
175: $statusCode,
176: (string) $request->getUri()
177: ),
178: $statusCode,
179: $response->getHeaders(),
180: (string) $response->getBody()
181: );
182: }
183:
184: return [null, $statusCode, $response->getHeaders()];
185:
186: } catch (ApiException $e) {
187: switch ($e->getCode()) {
188: }
189: throw $e;
190: }
191: }
192:
193: /**
194: * Operation deleteOrderAsync
195: *
196: * Delete purchase order by ID
197: *
198: * @param string $order_id ID of the order that needs to be deleted (required)
199: *
200: * @throws \InvalidArgumentException
201: * @return \GuzzleHttp\Promise\PromiseInterface
202: */
203: public function deleteOrderAsync($order_id)
204: {
205: return $this->deleteOrderAsyncWithHttpInfo($order_id)
206: ->then(
207: function ($response) {
208: return $response[0];
209: }
210: );
211: }
212:
213: /**
214: * Operation deleteOrderAsyncWithHttpInfo
215: *
216: * Delete purchase order by ID
217: *
218: * @param string $order_id ID of the order that needs to be deleted (required)
219: *
220: * @throws \InvalidArgumentException
221: * @return \GuzzleHttp\Promise\PromiseInterface
222: */
223: public function deleteOrderAsyncWithHttpInfo($order_id)
224: {
225: $returnType = '';
226: $request = $this->deleteOrderRequest($order_id);
227:
228: return $this->client
229: ->sendAsync($request, $this->createHttpClientOption())
230: ->then(
231: function ($response) use ($returnType) {
232: return [null, $response->getStatusCode(), $response->getHeaders()];
233: },
234: function ($exception) {
235: $response = $exception->getResponse();
236: $statusCode = $response->getStatusCode();
237: throw new ApiException(
238: sprintf(
239: '[%d] Error connecting to the API (%s)',
240: $statusCode,
241: $exception->getRequest()->getUri()
242: ),
243: $statusCode,
244: $response->getHeaders(),
245: (string) $response->getBody()
246: );
247: }
248: );
249: }
250:
251: /**
252: * Create request for operation 'deleteOrder'
253: *
254: * @param string $order_id ID of the order that needs to be deleted (required)
255: *
256: * @throws \InvalidArgumentException
257: * @return \GuzzleHttp\Psr7\Request
258: */
259: public function deleteOrderRequest($order_id)
260: {
261:
262: // verify the required parameter 'order_id' is set
263: if ($order_id === null || (is_array($order_id) && count($order_id) === 0)) {
264: throw new \InvalidArgumentException(
265: 'Missing the required parameter $order_id when calling deleteOrder'
266: );
267: }
268:
269: $resourcePath = '/store/order/{orderId}';
270: $formParams = [];
271: $queryParams = [];
272: $headerParams = [];
273: $httpBody = '';
274: $multipart = false;
275:
276:
277:
278: // path params
279: if ($order_id !== null) {
280: $resourcePath = str_replace(
281: '{' . 'orderId' . '}',
282: ObjectSerializer::toPathValue($order_id),
283: $resourcePath
284: );
285: }
286:
287:
288: if ($multipart) {
289: $headers = $this->headerSelector->selectHeadersForMultipart(
290: []
291: );
292: } else {
293: $headers = $this->headerSelector->selectHeaders(
294: [],
295: []
296: );
297: }
298:
299: // for model (json/xml)
300: if (count($formParams) > 0) {
301: if ($multipart) {
302: $multipartContents = [];
303: foreach ($formParams as $formParamName => $formParamValue) {
304: $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
305: foreach ($formParamValueItems as $formParamValueItem) {
306: $multipartContents[] = [
307: 'name' => $formParamName,
308: 'contents' => $formParamValueItem
309: ];
310: }
311: }
312: // for HTTP post (form)
313: $httpBody = new MultipartStream($multipartContents);
314:
315: } elseif ($headers['Content-Type'] === 'application/json') {
316: $httpBody = \GuzzleHttp\json_encode($formParams);
317:
318: } else {
319: // for HTTP post (form)
320: $httpBody = ObjectSerializer::buildQuery($formParams);
321: }
322: }
323:
324:
325: $defaultHeaders = [];
326: if ($this->config->getUserAgent()) {
327: $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
328: }
329:
330: $headers = array_merge(
331: $defaultHeaders,
332: $headerParams,
333: $headers
334: );
335:
336: $operationHost = $this->config->getHost();
337: $query = ObjectSerializer::buildQuery($queryParams);
338: return new Request(
339: 'DELETE',
340: $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
341: $headers,
342: $httpBody
343: );
344: }
345:
346: /**
347: * Operation getInventory
348: *
349: * Returns pet inventories by status
350: *
351: *
352: * @throws \Ally\PetStore\ApiException on non-2xx response
353: * @throws \InvalidArgumentException
354: * @return array<string,int>
355: */
356: public function getInventory()
357: {
358: list($response) = $this->getInventoryWithHttpInfo();
359: return $response;
360: }
361:
362: /**
363: * Operation getInventoryWithHttpInfo
364: *
365: * Returns pet inventories by status
366: *
367: *
368: * @throws \Ally\PetStore\ApiException on non-2xx response
369: * @throws \InvalidArgumentException
370: * @return array of array<string,int>, HTTP status code, HTTP response headers (array of strings)
371: */
372: public function getInventoryWithHttpInfo()
373: {
374: $request = $this->getInventoryRequest();
375:
376: try {
377: $options = $this->createHttpClientOption();
378: try {
379: $response = $this->client->send($request, $options);
380: } catch (RequestException $e) {
381: throw new ApiException(
382: "[{$e->getCode()}] {$e->getMessage()}",
383: (int) $e->getCode(),
384: $e->getResponse() ? $e->getResponse()->getHeaders() : null,
385: $e->getResponse() ? (string) $e->getResponse()->getBody() : null
386: );
387: } catch (ConnectException $e) {
388: throw new ApiException(
389: "[{$e->getCode()}] {$e->getMessage()}",
390: (int) $e->getCode(),
391: null,
392: null
393: );
394: }
395:
396: $statusCode = $response->getStatusCode();
397:
398: if ($statusCode < 200 || $statusCode > 299) {
399: throw new ApiException(
400: sprintf(
401: '[%d] Error connecting to the API (%s)',
402: $statusCode,
403: (string) $request->getUri()
404: ),
405: $statusCode,
406: $response->getHeaders(),
407: (string) $response->getBody()
408: );
409: }
410:
411: switch($statusCode) {
412: case 200:
413: if ('array<string,int>' === '\SplFileObject') {
414: $content = $response->getBody(); //stream goes to serializer
415: } else {
416: $content = (string) $response->getBody();
417: if ('array<string,int>' !== 'string') {
418: $content = json_decode($content);
419: }
420: }
421:
422: return [
423: ObjectSerializer::deserialize($content, 'array<string,int>', []),
424: $response->getStatusCode(),
425: $response->getHeaders()
426: ];
427: }
428:
429: $returnType = 'array<string,int>';
430: if ($returnType === '\SplFileObject') {
431: $content = $response->getBody(); //stream goes to serializer
432: } else {
433: $content = (string) $response->getBody();
434: if ($returnType !== 'string') {
435: $content = json_decode($content);
436: }
437: }
438:
439: return [
440: ObjectSerializer::deserialize($content, $returnType, []),
441: $response->getStatusCode(),
442: $response->getHeaders()
443: ];
444:
445: } catch (ApiException $e) {
446: switch ($e->getCode()) {
447: case 200:
448: $data = ObjectSerializer::deserialize(
449: $e->getResponseBody(),
450: 'array<string,int>',
451: $e->getResponseHeaders()
452: );
453: $e->setResponseObject($data);
454: break;
455: }
456: throw $e;
457: }
458: }
459:
460: /**
461: * Operation getInventoryAsync
462: *
463: * Returns pet inventories by status
464: *
465: *
466: * @throws \InvalidArgumentException
467: * @return \GuzzleHttp\Promise\PromiseInterface
468: */
469: public function getInventoryAsync()
470: {
471: return $this->getInventoryAsyncWithHttpInfo()
472: ->then(
473: function ($response) {
474: return $response[0];
475: }
476: );
477: }
478:
479: /**
480: * Operation getInventoryAsyncWithHttpInfo
481: *
482: * Returns pet inventories by status
483: *
484: *
485: * @throws \InvalidArgumentException
486: * @return \GuzzleHttp\Promise\PromiseInterface
487: */
488: public function getInventoryAsyncWithHttpInfo()
489: {
490: $returnType = 'array<string,int>';
491: $request = $this->getInventoryRequest();
492:
493: return $this->client
494: ->sendAsync($request, $this->createHttpClientOption())
495: ->then(
496: function ($response) use ($returnType) {
497: if ($returnType === '\SplFileObject') {
498: $content = $response->getBody(); //stream goes to serializer
499: } else {
500: $content = (string) $response->getBody();
501: if ($returnType !== 'string') {
502: $content = json_decode($content);
503: }
504: }
505:
506: return [
507: ObjectSerializer::deserialize($content, $returnType, []),
508: $response->getStatusCode(),
509: $response->getHeaders()
510: ];
511: },
512: function ($exception) {
513: $response = $exception->getResponse();
514: $statusCode = $response->getStatusCode();
515: throw new ApiException(
516: sprintf(
517: '[%d] Error connecting to the API (%s)',
518: $statusCode,
519: $exception->getRequest()->getUri()
520: ),
521: $statusCode,
522: $response->getHeaders(),
523: (string) $response->getBody()
524: );
525: }
526: );
527: }
528:
529: /**
530: * Create request for operation 'getInventory'
531: *
532: *
533: * @throws \InvalidArgumentException
534: * @return \GuzzleHttp\Psr7\Request
535: */
536: public function getInventoryRequest()
537: {
538:
539: $resourcePath = '/store/inventory';
540: $formParams = [];
541: $queryParams = [];
542: $headerParams = [];
543: $httpBody = '';
544: $multipart = false;
545:
546:
547:
548:
549:
550: if ($multipart) {
551: $headers = $this->headerSelector->selectHeadersForMultipart(
552: ['application/json']
553: );
554: } else {
555: $headers = $this->headerSelector->selectHeaders(
556: ['application/json'],
557: []
558: );
559: }
560:
561: // for model (json/xml)
562: if (count($formParams) > 0) {
563: if ($multipart) {
564: $multipartContents = [];
565: foreach ($formParams as $formParamName => $formParamValue) {
566: $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
567: foreach ($formParamValueItems as $formParamValueItem) {
568: $multipartContents[] = [
569: 'name' => $formParamName,
570: 'contents' => $formParamValueItem
571: ];
572: }
573: }
574: // for HTTP post (form)
575: $httpBody = new MultipartStream($multipartContents);
576:
577: } elseif ($headers['Content-Type'] === 'application/json') {
578: $httpBody = \GuzzleHttp\json_encode($formParams);
579:
580: } else {
581: // for HTTP post (form)
582: $httpBody = ObjectSerializer::buildQuery($formParams);
583: }
584: }
585:
586: // this endpoint requires API key authentication
587: $apiKey = $this->config->getApiKeyWithPrefix('api_key');
588: if ($apiKey !== null) {
589: $headers['api_key'] = $apiKey;
590: }
591:
592: $defaultHeaders = [];
593: if ($this->config->getUserAgent()) {
594: $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
595: }
596:
597: $headers = array_merge(
598: $defaultHeaders,
599: $headerParams,
600: $headers
601: );
602:
603: $operationHost = $this->config->getHost();
604: $query = ObjectSerializer::buildQuery($queryParams);
605: return new Request(
606: 'GET',
607: $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
608: $headers,
609: $httpBody
610: );
611: }
612:
613: /**
614: * Operation getOrderById
615: *
616: * Find purchase order by ID
617: *
618: * @param int $order_id ID of pet that needs to be fetched (required)
619: *
620: * @throws \Ally\PetStore\ApiException on non-2xx response
621: * @throws \InvalidArgumentException
622: * @return \Ally\PetStore\Schema\Order
623: */
624: public function getOrderById($order_id)
625: {
626: list($response) = $this->getOrderByIdWithHttpInfo($order_id);
627: return $response;
628: }
629:
630: /**
631: * Operation getOrderByIdWithHttpInfo
632: *
633: * Find purchase order by ID
634: *
635: * @param int $order_id ID of pet that needs to be fetched (required)
636: *
637: * @throws \Ally\PetStore\ApiException on non-2xx response
638: * @throws \InvalidArgumentException
639: * @return array of \Ally\PetStore\Schema\Order, HTTP status code, HTTP response headers (array of strings)
640: */
641: public function getOrderByIdWithHttpInfo($order_id)
642: {
643: $request = $this->getOrderByIdRequest($order_id);
644:
645: try {
646: $options = $this->createHttpClientOption();
647: try {
648: $response = $this->client->send($request, $options);
649: } catch (RequestException $e) {
650: throw new ApiException(
651: "[{$e->getCode()}] {$e->getMessage()}",
652: (int) $e->getCode(),
653: $e->getResponse() ? $e->getResponse()->getHeaders() : null,
654: $e->getResponse() ? (string) $e->getResponse()->getBody() : null
655: );
656: } catch (ConnectException $e) {
657: throw new ApiException(
658: "[{$e->getCode()}] {$e->getMessage()}",
659: (int) $e->getCode(),
660: null,
661: null
662: );
663: }
664:
665: $statusCode = $response->getStatusCode();
666:
667: if ($statusCode < 200 || $statusCode > 299) {
668: throw new ApiException(
669: sprintf(
670: '[%d] Error connecting to the API (%s)',
671: $statusCode,
672: (string) $request->getUri()
673: ),
674: $statusCode,
675: $response->getHeaders(),
676: (string) $response->getBody()
677: );
678: }
679:
680: switch($statusCode) {
681: case 200:
682: if ('\Ally\PetStore\Schema\Order' === '\SplFileObject') {
683: $content = $response->getBody(); //stream goes to serializer
684: } else {
685: $content = (string) $response->getBody();
686: if ('\Ally\PetStore\Schema\Order' !== 'string') {
687: $content = json_decode($content);
688: }
689: }
690:
691: return [
692: ObjectSerializer::deserialize($content, '\Ally\PetStore\Schema\Order', []),
693: $response->getStatusCode(),
694: $response->getHeaders()
695: ];
696: }
697:
698: $returnType = '\Ally\PetStore\Schema\Order';
699: if ($returnType === '\SplFileObject') {
700: $content = $response->getBody(); //stream goes to serializer
701: } else {
702: $content = (string) $response->getBody();
703: if ($returnType !== 'string') {
704: $content = json_decode($content);
705: }
706: }
707:
708: return [
709: ObjectSerializer::deserialize($content, $returnType, []),
710: $response->getStatusCode(),
711: $response->getHeaders()
712: ];
713:
714: } catch (ApiException $e) {
715: switch ($e->getCode()) {
716: case 200:
717: $data = ObjectSerializer::deserialize(
718: $e->getResponseBody(),
719: '\Ally\PetStore\Schema\Order',
720: $e->getResponseHeaders()
721: );
722: $e->setResponseObject($data);
723: break;
724: }
725: throw $e;
726: }
727: }
728:
729: /**
730: * Operation getOrderByIdAsync
731: *
732: * Find purchase order by ID
733: *
734: * @param int $order_id ID of pet that needs to be fetched (required)
735: *
736: * @throws \InvalidArgumentException
737: * @return \GuzzleHttp\Promise\PromiseInterface
738: */
739: public function getOrderByIdAsync($order_id)
740: {
741: return $this->getOrderByIdAsyncWithHttpInfo($order_id)
742: ->then(
743: function ($response) {
744: return $response[0];
745: }
746: );
747: }
748:
749: /**
750: * Operation getOrderByIdAsyncWithHttpInfo
751: *
752: * Find purchase order by ID
753: *
754: * @param int $order_id ID of pet that needs to be fetched (required)
755: *
756: * @throws \InvalidArgumentException
757: * @return \GuzzleHttp\Promise\PromiseInterface
758: */
759: public function getOrderByIdAsyncWithHttpInfo($order_id)
760: {
761: $returnType = '\Ally\PetStore\Schema\Order';
762: $request = $this->getOrderByIdRequest($order_id);
763:
764: return $this->client
765: ->sendAsync($request, $this->createHttpClientOption())
766: ->then(
767: function ($response) use ($returnType) {
768: if ($returnType === '\SplFileObject') {
769: $content = $response->getBody(); //stream goes to serializer
770: } else {
771: $content = (string) $response->getBody();
772: if ($returnType !== 'string') {
773: $content = json_decode($content);
774: }
775: }
776:
777: return [
778: ObjectSerializer::deserialize($content, $returnType, []),
779: $response->getStatusCode(),
780: $response->getHeaders()
781: ];
782: },
783: function ($exception) {
784: $response = $exception->getResponse();
785: $statusCode = $response->getStatusCode();
786: throw new ApiException(
787: sprintf(
788: '[%d] Error connecting to the API (%s)',
789: $statusCode,
790: $exception->getRequest()->getUri()
791: ),
792: $statusCode,
793: $response->getHeaders(),
794: (string) $response->getBody()
795: );
796: }
797: );
798: }
799:
800: /**
801: * Create request for operation 'getOrderById'
802: *
803: * @param int $order_id ID of pet that needs to be fetched (required)
804: *
805: * @throws \InvalidArgumentException
806: * @return \GuzzleHttp\Psr7\Request
807: */
808: public function getOrderByIdRequest($order_id)
809: {
810:
811: // verify the required parameter 'order_id' is set
812: if ($order_id === null || (is_array($order_id) && count($order_id) === 0)) {
813: throw new \InvalidArgumentException(
814: 'Missing the required parameter $order_id when calling getOrderById'
815: );
816: }
817: if ($order_id > 5) {
818: throw new \InvalidArgumentException('invalid value for "$order_id" when calling StoreApi.getOrderById, must be smaller than or equal to 5.');
819: }
820: if ($order_id < 1) {
821: throw new \InvalidArgumentException('invalid value for "$order_id" when calling StoreApi.getOrderById, must be bigger than or equal to 1.');
822: }
823:
824:
825: $resourcePath = '/store/order/{orderId}';
826: $formParams = [];
827: $queryParams = [];
828: $headerParams = [];
829: $httpBody = '';
830: $multipart = false;
831:
832:
833:
834: // path params
835: if ($order_id !== null) {
836: $resourcePath = str_replace(
837: '{' . 'orderId' . '}',
838: ObjectSerializer::toPathValue($order_id),
839: $resourcePath
840: );
841: }
842:
843:
844: if ($multipart) {
845: $headers = $this->headerSelector->selectHeadersForMultipart(
846: ['application/xml', 'application/json']
847: );
848: } else {
849: $headers = $this->headerSelector->selectHeaders(
850: ['application/xml', 'application/json'],
851: []
852: );
853: }
854:
855: // for model (json/xml)
856: if (count($formParams) > 0) {
857: if ($multipart) {
858: $multipartContents = [];
859: foreach ($formParams as $formParamName => $formParamValue) {
860: $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
861: foreach ($formParamValueItems as $formParamValueItem) {
862: $multipartContents[] = [
863: 'name' => $formParamName,
864: 'contents' => $formParamValueItem
865: ];
866: }
867: }
868: // for HTTP post (form)
869: $httpBody = new MultipartStream($multipartContents);
870:
871: } elseif ($headers['Content-Type'] === 'application/json') {
872: $httpBody = \GuzzleHttp\json_encode($formParams);
873:
874: } else {
875: // for HTTP post (form)
876: $httpBody = ObjectSerializer::buildQuery($formParams);
877: }
878: }
879:
880:
881: $defaultHeaders = [];
882: if ($this->config->getUserAgent()) {
883: $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
884: }
885:
886: $headers = array_merge(
887: $defaultHeaders,
888: $headerParams,
889: $headers
890: );
891:
892: $operationHost = $this->config->getHost();
893: $query = ObjectSerializer::buildQuery($queryParams);
894: return new Request(
895: 'GET',
896: $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
897: $headers,
898: $httpBody
899: );
900: }
901:
902: /**
903: * Operation placeOrder
904: *
905: * Place an order for a pet
906: *
907: * @param \Ally\PetStore\Schema\Order $order order placed for purchasing the pet (required)
908: *
909: * @throws \Ally\PetStore\ApiException on non-2xx response
910: * @throws \InvalidArgumentException
911: * @return \Ally\PetStore\Schema\Order
912: */
913: public function placeOrder($order)
914: {
915: list($response) = $this->placeOrderWithHttpInfo($order);
916: return $response;
917: }
918:
919: /**
920: * Operation placeOrderWithHttpInfo
921: *
922: * Place an order for a pet
923: *
924: * @param \Ally\PetStore\Schema\Order $order order placed for purchasing the pet (required)
925: *
926: * @throws \Ally\PetStore\ApiException on non-2xx response
927: * @throws \InvalidArgumentException
928: * @return array of \Ally\PetStore\Schema\Order, HTTP status code, HTTP response headers (array of strings)
929: */
930: public function placeOrderWithHttpInfo($order)
931: {
932: $request = $this->placeOrderRequest($order);
933:
934: try {
935: $options = $this->createHttpClientOption();
936: try {
937: $response = $this->client->send($request, $options);
938: } catch (RequestException $e) {
939: throw new ApiException(
940: "[{$e->getCode()}] {$e->getMessage()}",
941: (int) $e->getCode(),
942: $e->getResponse() ? $e->getResponse()->getHeaders() : null,
943: $e->getResponse() ? (string) $e->getResponse()->getBody() : null
944: );
945: } catch (ConnectException $e) {
946: throw new ApiException(
947: "[{$e->getCode()}] {$e->getMessage()}",
948: (int) $e->getCode(),
949: null,
950: null
951: );
952: }
953:
954: $statusCode = $response->getStatusCode();
955:
956: if ($statusCode < 200 || $statusCode > 299) {
957: throw new ApiException(
958: sprintf(
959: '[%d] Error connecting to the API (%s)',
960: $statusCode,
961: (string) $request->getUri()
962: ),
963: $statusCode,
964: $response->getHeaders(),
965: (string) $response->getBody()
966: );
967: }
968:
969: switch($statusCode) {
970: case 200:
971: if ('\Ally\PetStore\Schema\Order' === '\SplFileObject') {
972: $content = $response->getBody(); //stream goes to serializer
973: } else {
974: $content = (string) $response->getBody();
975: if ('\Ally\PetStore\Schema\Order' !== 'string') {
976: $content = json_decode($content);
977: }
978: }
979:
980: return [
981: ObjectSerializer::deserialize($content, '\Ally\PetStore\Schema\Order', []),
982: $response->getStatusCode(),
983: $response->getHeaders()
984: ];
985: }
986:
987: $returnType = '\Ally\PetStore\Schema\Order';
988: if ($returnType === '\SplFileObject') {
989: $content = $response->getBody(); //stream goes to serializer
990: } else {
991: $content = (string) $response->getBody();
992: if ($returnType !== 'string') {
993: $content = json_decode($content);
994: }
995: }
996:
997: return [
998: ObjectSerializer::deserialize($content, $returnType, []),
999: $response->getStatusCode(),
1000: $response->getHeaders()
1001: ];
1002:
1003: } catch (ApiException $e) {
1004: switch ($e->getCode()) {
1005: case 200:
1006: $data = ObjectSerializer::deserialize(
1007: $e->getResponseBody(),
1008: '\Ally\PetStore\Schema\Order',
1009: $e->getResponseHeaders()
1010: );
1011: $e->setResponseObject($data);
1012: break;
1013: }
1014: throw $e;
1015: }
1016: }
1017:
1018: /**
1019: * Operation placeOrderAsync
1020: *
1021: * Place an order for a pet
1022: *
1023: * @param \Ally\PetStore\Schema\Order $order order placed for purchasing the pet (required)
1024: *
1025: * @throws \InvalidArgumentException
1026: * @return \GuzzleHttp\Promise\PromiseInterface
1027: */
1028: public function placeOrderAsync($order)
1029: {
1030: return $this->placeOrderAsyncWithHttpInfo($order)
1031: ->then(
1032: function ($response) {
1033: return $response[0];
1034: }
1035: );
1036: }
1037:
1038: /**
1039: * Operation placeOrderAsyncWithHttpInfo
1040: *
1041: * Place an order for a pet
1042: *
1043: * @param \Ally\PetStore\Schema\Order $order order placed for purchasing the pet (required)
1044: *
1045: * @throws \InvalidArgumentException
1046: * @return \GuzzleHttp\Promise\PromiseInterface
1047: */
1048: public function placeOrderAsyncWithHttpInfo($order)
1049: {
1050: $returnType = '\Ally\PetStore\Schema\Order';
1051: $request = $this->placeOrderRequest($order);
1052:
1053: return $this->client
1054: ->sendAsync($request, $this->createHttpClientOption())
1055: ->then(
1056: function ($response) use ($returnType) {
1057: if ($returnType === '\SplFileObject') {
1058: $content = $response->getBody(); //stream goes to serializer
1059: } else {
1060: $content = (string) $response->getBody();
1061: if ($returnType !== 'string') {
1062: $content = json_decode($content);
1063: }
1064: }
1065:
1066: return [
1067: ObjectSerializer::deserialize($content, $returnType, []),
1068: $response->getStatusCode(),
1069: $response->getHeaders()
1070: ];
1071: },
1072: function ($exception) {
1073: $response = $exception->getResponse();
1074: $statusCode = $response->getStatusCode();
1075: throw new ApiException(
1076: sprintf(
1077: '[%d] Error connecting to the API (%s)',
1078: $statusCode,
1079: $exception->getRequest()->getUri()
1080: ),
1081: $statusCode,
1082: $response->getHeaders(),
1083: (string) $response->getBody()
1084: );
1085: }
1086: );
1087: }
1088:
1089: /**
1090: * Create request for operation 'placeOrder'
1091: *
1092: * @param \Ally\PetStore\Schema\Order $order order placed for purchasing the pet (required)
1093: *
1094: * @throws \InvalidArgumentException
1095: * @return \GuzzleHttp\Psr7\Request
1096: */
1097: public function placeOrderRequest($order)
1098: {
1099:
1100: // verify the required parameter 'order' is set
1101: if ($order === null || (is_array($order) && count($order) === 0)) {
1102: throw new \InvalidArgumentException(
1103: 'Missing the required parameter $order when calling placeOrder'
1104: );
1105: }
1106:
1107: $resourcePath = '/store/order';
1108: $formParams = [];
1109: $queryParams = [];
1110: $headerParams = [];
1111: $httpBody = '';
1112: $multipart = false;
1113:
1114:
1115:
1116:
1117:
1118: if ($multipart) {
1119: $headers = $this->headerSelector->selectHeadersForMultipart(
1120: ['application/xml', 'application/json']
1121: );
1122: } else {
1123: $headers = $this->headerSelector->selectHeaders(
1124: ['application/xml', 'application/json'],
1125: ['application/json']
1126: );
1127: }
1128:
1129: // for model (json/xml)
1130: if (isset($order)) {
1131: if ($headers['Content-Type'] === 'application/json') {
1132: $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($order));
1133: } else {
1134: $httpBody = $order;
1135: }
1136: } elseif (count($formParams) > 0) {
1137: if ($multipart) {
1138: $multipartContents = [];
1139: foreach ($formParams as $formParamName => $formParamValue) {
1140: $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
1141: foreach ($formParamValueItems as $formParamValueItem) {
1142: $multipartContents[] = [
1143: 'name' => $formParamName,
1144: 'contents' => $formParamValueItem
1145: ];
1146: }
1147: }
1148: // for HTTP post (form)
1149: $httpBody = new MultipartStream($multipartContents);
1150:
1151: } elseif ($headers['Content-Type'] === 'application/json') {
1152: $httpBody = \GuzzleHttp\json_encode($formParams);
1153:
1154: } else {
1155: // for HTTP post (form)
1156: $httpBody = ObjectSerializer::buildQuery($formParams);
1157: }
1158: }
1159:
1160:
1161: $defaultHeaders = [];
1162: if ($this->config->getUserAgent()) {
1163: $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
1164: }
1165:
1166: $headers = array_merge(
1167: $defaultHeaders,
1168: $headerParams,
1169: $headers
1170: );
1171:
1172: $operationHost = $this->config->getHost();
1173: $query = ObjectSerializer::buildQuery($queryParams);
1174: return new Request(
1175: 'POST',
1176: $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
1177: $headers,
1178: $httpBody
1179: );
1180: }
1181:
1182: /**
1183: * Create http client option
1184: *
1185: * @throws \RuntimeException on file opening failure
1186: * @return array of http client options
1187: */
1188: protected function createHttpClientOption()
1189: {
1190: $options = [];
1191: if ($this->config->getDebug()) {
1192: $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
1193: if (!$options[RequestOptions::DEBUG]) {
1194: throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
1195: }
1196: }
1197:
1198: return $options;
1199: }
1200: }
1201: