1: <?php
2: /**
3: * PetApi
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: * PetApi 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 PetApi
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 addPet
120: *
121: * Add a new pet to the store
122: *
123: * @param \Ally\PetStore\Schema\Pet $pet Pet object that needs to be added to the store (required)
124: *
125: * @throws \Ally\PetStore\ApiException on non-2xx response
126: * @throws \InvalidArgumentException
127: * @return \Ally\PetStore\Schema\Pet
128: */
129: public function addPet($pet)
130: {
131: list($response) = $this->addPetWithHttpInfo($pet);
132: return $response;
133: }
134:
135: /**
136: * Operation addPetWithHttpInfo
137: *
138: * Add a new pet to the store
139: *
140: * @param \Ally\PetStore\Schema\Pet $pet Pet object that needs to be added to the store (required)
141: *
142: * @throws \Ally\PetStore\ApiException on non-2xx response
143: * @throws \InvalidArgumentException
144: * @return array of \Ally\PetStore\Schema\Pet, HTTP status code, HTTP response headers (array of strings)
145: */
146: public function addPetWithHttpInfo($pet)
147: {
148: $request = $this->addPetRequest($pet);
149:
150: try {
151: $options = $this->createHttpClientOption();
152: try {
153: $response = $this->client->send($request, $options);
154: } catch (RequestException $e) {
155: throw new ApiException(
156: "[{$e->getCode()}] {$e->getMessage()}",
157: (int) $e->getCode(),
158: $e->getResponse() ? $e->getResponse()->getHeaders() : null,
159: $e->getResponse() ? (string) $e->getResponse()->getBody() : null
160: );
161: } catch (ConnectException $e) {
162: throw new ApiException(
163: "[{$e->getCode()}] {$e->getMessage()}",
164: (int) $e->getCode(),
165: null,
166: null
167: );
168: }
169:
170: $statusCode = $response->getStatusCode();
171:
172: if ($statusCode < 200 || $statusCode > 299) {
173: throw new ApiException(
174: sprintf(
175: '[%d] Error connecting to the API (%s)',
176: $statusCode,
177: (string) $request->getUri()
178: ),
179: $statusCode,
180: $response->getHeaders(),
181: (string) $response->getBody()
182: );
183: }
184:
185: switch($statusCode) {
186: case 200:
187: if ('\Ally\PetStore\Schema\Pet' === '\SplFileObject') {
188: $content = $response->getBody(); //stream goes to serializer
189: } else {
190: $content = (string) $response->getBody();
191: if ('\Ally\PetStore\Schema\Pet' !== 'string') {
192: $content = json_decode($content);
193: }
194: }
195:
196: return [
197: ObjectSerializer::deserialize($content, '\Ally\PetStore\Schema\Pet', []),
198: $response->getStatusCode(),
199: $response->getHeaders()
200: ];
201: }
202:
203: $returnType = '\Ally\PetStore\Schema\Pet';
204: if ($returnType === '\SplFileObject') {
205: $content = $response->getBody(); //stream goes to serializer
206: } else {
207: $content = (string) $response->getBody();
208: if ($returnType !== 'string') {
209: $content = json_decode($content);
210: }
211: }
212:
213: return [
214: ObjectSerializer::deserialize($content, $returnType, []),
215: $response->getStatusCode(),
216: $response->getHeaders()
217: ];
218:
219: } catch (ApiException $e) {
220: switch ($e->getCode()) {
221: case 200:
222: $data = ObjectSerializer::deserialize(
223: $e->getResponseBody(),
224: '\Ally\PetStore\Schema\Pet',
225: $e->getResponseHeaders()
226: );
227: $e->setResponseObject($data);
228: break;
229: }
230: throw $e;
231: }
232: }
233:
234: /**
235: * Operation addPetAsync
236: *
237: * Add a new pet to the store
238: *
239: * @param \Ally\PetStore\Schema\Pet $pet Pet object that needs to be added to the store (required)
240: *
241: * @throws \InvalidArgumentException
242: * @return \GuzzleHttp\Promise\PromiseInterface
243: */
244: public function addPetAsync($pet)
245: {
246: return $this->addPetAsyncWithHttpInfo($pet)
247: ->then(
248: function ($response) {
249: return $response[0];
250: }
251: );
252: }
253:
254: /**
255: * Operation addPetAsyncWithHttpInfo
256: *
257: * Add a new pet to the store
258: *
259: * @param \Ally\PetStore\Schema\Pet $pet Pet object that needs to be added to the store (required)
260: *
261: * @throws \InvalidArgumentException
262: * @return \GuzzleHttp\Promise\PromiseInterface
263: */
264: public function addPetAsyncWithHttpInfo($pet)
265: {
266: $returnType = '\Ally\PetStore\Schema\Pet';
267: $request = $this->addPetRequest($pet);
268:
269: return $this->client
270: ->sendAsync($request, $this->createHttpClientOption())
271: ->then(
272: function ($response) use ($returnType) {
273: if ($returnType === '\SplFileObject') {
274: $content = $response->getBody(); //stream goes to serializer
275: } else {
276: $content = (string) $response->getBody();
277: if ($returnType !== 'string') {
278: $content = json_decode($content);
279: }
280: }
281:
282: return [
283: ObjectSerializer::deserialize($content, $returnType, []),
284: $response->getStatusCode(),
285: $response->getHeaders()
286: ];
287: },
288: function ($exception) {
289: $response = $exception->getResponse();
290: $statusCode = $response->getStatusCode();
291: throw new ApiException(
292: sprintf(
293: '[%d] Error connecting to the API (%s)',
294: $statusCode,
295: $exception->getRequest()->getUri()
296: ),
297: $statusCode,
298: $response->getHeaders(),
299: (string) $response->getBody()
300: );
301: }
302: );
303: }
304:
305: /**
306: * Create request for operation 'addPet'
307: *
308: * @param \Ally\PetStore\Schema\Pet $pet Pet object that needs to be added to the store (required)
309: *
310: * @throws \InvalidArgumentException
311: * @return \GuzzleHttp\Psr7\Request
312: */
313: public function addPetRequest($pet)
314: {
315:
316: // verify the required parameter 'pet' is set
317: if ($pet === null || (is_array($pet) && count($pet) === 0)) {
318: throw new \InvalidArgumentException(
319: 'Missing the required parameter $pet when calling addPet'
320: );
321: }
322:
323: $resourcePath = '/pet';
324: $formParams = [];
325: $queryParams = [];
326: $headerParams = [];
327: $httpBody = '';
328: $multipart = false;
329:
330:
331:
332:
333:
334: if ($multipart) {
335: $headers = $this->headerSelector->selectHeadersForMultipart(
336: ['application/xml', 'application/json']
337: );
338: } else {
339: $headers = $this->headerSelector->selectHeaders(
340: ['application/xml', 'application/json'],
341: ['application/json', 'application/xml']
342: );
343: }
344:
345: // for model (json/xml)
346: if (isset($pet)) {
347: if ($headers['Content-Type'] === 'application/json') {
348: $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($pet));
349: } else {
350: $httpBody = $pet;
351: }
352: } elseif (count($formParams) > 0) {
353: if ($multipart) {
354: $multipartContents = [];
355: foreach ($formParams as $formParamName => $formParamValue) {
356: $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
357: foreach ($formParamValueItems as $formParamValueItem) {
358: $multipartContents[] = [
359: 'name' => $formParamName,
360: 'contents' => $formParamValueItem
361: ];
362: }
363: }
364: // for HTTP post (form)
365: $httpBody = new MultipartStream($multipartContents);
366:
367: } elseif ($headers['Content-Type'] === 'application/json') {
368: $httpBody = \GuzzleHttp\json_encode($formParams);
369:
370: } else {
371: // for HTTP post (form)
372: $httpBody = ObjectSerializer::buildQuery($formParams);
373: }
374: }
375:
376: // this endpoint requires OAuth (access token)
377: if (!empty($this->config->getAccessToken())) {
378: $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
379: }
380:
381: $defaultHeaders = [];
382: if ($this->config->getUserAgent()) {
383: $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
384: }
385:
386: $headers = array_merge(
387: $defaultHeaders,
388: $headerParams,
389: $headers
390: );
391:
392: $operationHost = $this->config->getHost();
393: $query = ObjectSerializer::buildQuery($queryParams);
394: return new Request(
395: 'POST',
396: $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
397: $headers,
398: $httpBody
399: );
400: }
401:
402: /**
403: * Operation deletePet
404: *
405: * Deletes a pet
406: *
407: * @param int $pet_id Pet id to delete (required)
408: * @param string $api_key api_key (optional)
409: *
410: * @throws \Ally\PetStore\ApiException on non-2xx response
411: * @throws \InvalidArgumentException
412: * @return void
413: */
414: public function deletePet($pet_id, $api_key = null)
415: {
416: $this->deletePetWithHttpInfo($pet_id, $api_key);
417: }
418:
419: /**
420: * Operation deletePetWithHttpInfo
421: *
422: * Deletes a pet
423: *
424: * @param int $pet_id Pet id to delete (required)
425: * @param string $api_key (optional)
426: *
427: * @throws \Ally\PetStore\ApiException on non-2xx response
428: * @throws \InvalidArgumentException
429: * @return array of null, HTTP status code, HTTP response headers (array of strings)
430: */
431: public function deletePetWithHttpInfo($pet_id, $api_key = null)
432: {
433: $request = $this->deletePetRequest($pet_id, $api_key);
434:
435: try {
436: $options = $this->createHttpClientOption();
437: try {
438: $response = $this->client->send($request, $options);
439: } catch (RequestException $e) {
440: throw new ApiException(
441: "[{$e->getCode()}] {$e->getMessage()}",
442: (int) $e->getCode(),
443: $e->getResponse() ? $e->getResponse()->getHeaders() : null,
444: $e->getResponse() ? (string) $e->getResponse()->getBody() : null
445: );
446: } catch (ConnectException $e) {
447: throw new ApiException(
448: "[{$e->getCode()}] {$e->getMessage()}",
449: (int) $e->getCode(),
450: null,
451: null
452: );
453: }
454:
455: $statusCode = $response->getStatusCode();
456:
457: if ($statusCode < 200 || $statusCode > 299) {
458: throw new ApiException(
459: sprintf(
460: '[%d] Error connecting to the API (%s)',
461: $statusCode,
462: (string) $request->getUri()
463: ),
464: $statusCode,
465: $response->getHeaders(),
466: (string) $response->getBody()
467: );
468: }
469:
470: return [null, $statusCode, $response->getHeaders()];
471:
472: } catch (ApiException $e) {
473: switch ($e->getCode()) {
474: }
475: throw $e;
476: }
477: }
478:
479: /**
480: * Operation deletePetAsync
481: *
482: * Deletes a pet
483: *
484: * @param int $pet_id Pet id to delete (required)
485: * @param string $api_key (optional)
486: *
487: * @throws \InvalidArgumentException
488: * @return \GuzzleHttp\Promise\PromiseInterface
489: */
490: public function deletePetAsync($pet_id, $api_key = null)
491: {
492: return $this->deletePetAsyncWithHttpInfo($pet_id, $api_key)
493: ->then(
494: function ($response) {
495: return $response[0];
496: }
497: );
498: }
499:
500: /**
501: * Operation deletePetAsyncWithHttpInfo
502: *
503: * Deletes a pet
504: *
505: * @param int $pet_id Pet id to delete (required)
506: * @param string $api_key (optional)
507: *
508: * @throws \InvalidArgumentException
509: * @return \GuzzleHttp\Promise\PromiseInterface
510: */
511: public function deletePetAsyncWithHttpInfo($pet_id, $api_key = null)
512: {
513: $returnType = '';
514: $request = $this->deletePetRequest($pet_id, $api_key);
515:
516: return $this->client
517: ->sendAsync($request, $this->createHttpClientOption())
518: ->then(
519: function ($response) use ($returnType) {
520: return [null, $response->getStatusCode(), $response->getHeaders()];
521: },
522: function ($exception) {
523: $response = $exception->getResponse();
524: $statusCode = $response->getStatusCode();
525: throw new ApiException(
526: sprintf(
527: '[%d] Error connecting to the API (%s)',
528: $statusCode,
529: $exception->getRequest()->getUri()
530: ),
531: $statusCode,
532: $response->getHeaders(),
533: (string) $response->getBody()
534: );
535: }
536: );
537: }
538:
539: /**
540: * Create request for operation 'deletePet'
541: *
542: * @param int $pet_id Pet id to delete (required)
543: * @param string $api_key (optional)
544: *
545: * @throws \InvalidArgumentException
546: * @return \GuzzleHttp\Psr7\Request
547: */
548: public function deletePetRequest($pet_id, $api_key = null)
549: {
550:
551: // verify the required parameter 'pet_id' is set
552: if ($pet_id === null || (is_array($pet_id) && count($pet_id) === 0)) {
553: throw new \InvalidArgumentException(
554: 'Missing the required parameter $pet_id when calling deletePet'
555: );
556: }
557:
558:
559: $resourcePath = '/pet/{petId}';
560: $formParams = [];
561: $queryParams = [];
562: $headerParams = [];
563: $httpBody = '';
564: $multipart = false;
565:
566:
567: // header params
568: if ($api_key !== null) {
569: $headerParams['api_key'] = ObjectSerializer::toHeaderValue($api_key);
570: }
571:
572: // path params
573: if ($pet_id !== null) {
574: $resourcePath = str_replace(
575: '{' . 'petId' . '}',
576: ObjectSerializer::toPathValue($pet_id),
577: $resourcePath
578: );
579: }
580:
581:
582: if ($multipart) {
583: $headers = $this->headerSelector->selectHeadersForMultipart(
584: []
585: );
586: } else {
587: $headers = $this->headerSelector->selectHeaders(
588: [],
589: []
590: );
591: }
592:
593: // for model (json/xml)
594: if (count($formParams) > 0) {
595: if ($multipart) {
596: $multipartContents = [];
597: foreach ($formParams as $formParamName => $formParamValue) {
598: $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
599: foreach ($formParamValueItems as $formParamValueItem) {
600: $multipartContents[] = [
601: 'name' => $formParamName,
602: 'contents' => $formParamValueItem
603: ];
604: }
605: }
606: // for HTTP post (form)
607: $httpBody = new MultipartStream($multipartContents);
608:
609: } elseif ($headers['Content-Type'] === 'application/json') {
610: $httpBody = \GuzzleHttp\json_encode($formParams);
611:
612: } else {
613: // for HTTP post (form)
614: $httpBody = ObjectSerializer::buildQuery($formParams);
615: }
616: }
617:
618: // this endpoint requires OAuth (access token)
619: if (!empty($this->config->getAccessToken())) {
620: $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
621: }
622:
623: $defaultHeaders = [];
624: if ($this->config->getUserAgent()) {
625: $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
626: }
627:
628: $headers = array_merge(
629: $defaultHeaders,
630: $headerParams,
631: $headers
632: );
633:
634: $operationHost = $this->config->getHost();
635: $query = ObjectSerializer::buildQuery($queryParams);
636: return new Request(
637: 'DELETE',
638: $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
639: $headers,
640: $httpBody
641: );
642: }
643:
644: /**
645: * Operation findPetsByStatus
646: *
647: * Finds Pets by status
648: *
649: * @param string[] $status Status values that need to be considered for filter (required) (deprecated)
650: *
651: * @throws \Ally\PetStore\ApiException on non-2xx response
652: * @throws \InvalidArgumentException
653: * @return \Ally\PetStore\Schema\Pet[]
654: */
655: public function findPetsByStatus($status)
656: {
657: list($response) = $this->findPetsByStatusWithHttpInfo($status);
658: return $response;
659: }
660:
661: /**
662: * Operation findPetsByStatusWithHttpInfo
663: *
664: * Finds Pets by status
665: *
666: * @param string[] $status Status values that need to be considered for filter (required) (deprecated)
667: *
668: * @throws \Ally\PetStore\ApiException on non-2xx response
669: * @throws \InvalidArgumentException
670: * @return array of \Ally\PetStore\Schema\Pet[], HTTP status code, HTTP response headers (array of strings)
671: */
672: public function findPetsByStatusWithHttpInfo($status)
673: {
674: $request = $this->findPetsByStatusRequest($status);
675:
676: try {
677: $options = $this->createHttpClientOption();
678: try {
679: $response = $this->client->send($request, $options);
680: } catch (RequestException $e) {
681: throw new ApiException(
682: "[{$e->getCode()}] {$e->getMessage()}",
683: (int) $e->getCode(),
684: $e->getResponse() ? $e->getResponse()->getHeaders() : null,
685: $e->getResponse() ? (string) $e->getResponse()->getBody() : null
686: );
687: } catch (ConnectException $e) {
688: throw new ApiException(
689: "[{$e->getCode()}] {$e->getMessage()}",
690: (int) $e->getCode(),
691: null,
692: null
693: );
694: }
695:
696: $statusCode = $response->getStatusCode();
697:
698: if ($statusCode < 200 || $statusCode > 299) {
699: throw new ApiException(
700: sprintf(
701: '[%d] Error connecting to the API (%s)',
702: $statusCode,
703: (string) $request->getUri()
704: ),
705: $statusCode,
706: $response->getHeaders(),
707: (string) $response->getBody()
708: );
709: }
710:
711: switch($statusCode) {
712: case 200:
713: if ('\Ally\PetStore\Schema\Pet[]' === '\SplFileObject') {
714: $content = $response->getBody(); //stream goes to serializer
715: } else {
716: $content = (string) $response->getBody();
717: if ('\Ally\PetStore\Schema\Pet[]' !== 'string') {
718: $content = json_decode($content);
719: }
720: }
721:
722: return [
723: ObjectSerializer::deserialize($content, '\Ally\PetStore\Schema\Pet[]', []),
724: $response->getStatusCode(),
725: $response->getHeaders()
726: ];
727: }
728:
729: $returnType = '\Ally\PetStore\Schema\Pet[]';
730: if ($returnType === '\SplFileObject') {
731: $content = $response->getBody(); //stream goes to serializer
732: } else {
733: $content = (string) $response->getBody();
734: if ($returnType !== 'string') {
735: $content = json_decode($content);
736: }
737: }
738:
739: return [
740: ObjectSerializer::deserialize($content, $returnType, []),
741: $response->getStatusCode(),
742: $response->getHeaders()
743: ];
744:
745: } catch (ApiException $e) {
746: switch ($e->getCode()) {
747: case 200:
748: $data = ObjectSerializer::deserialize(
749: $e->getResponseBody(),
750: '\Ally\PetStore\Schema\Pet[]',
751: $e->getResponseHeaders()
752: );
753: $e->setResponseObject($data);
754: break;
755: }
756: throw $e;
757: }
758: }
759:
760: /**
761: * Operation findPetsByStatusAsync
762: *
763: * Finds Pets by status
764: *
765: * @param string[] $status Status values that need to be considered for filter (required) (deprecated)
766: *
767: * @throws \InvalidArgumentException
768: * @return \GuzzleHttp\Promise\PromiseInterface
769: */
770: public function findPetsByStatusAsync($status)
771: {
772: return $this->findPetsByStatusAsyncWithHttpInfo($status)
773: ->then(
774: function ($response) {
775: return $response[0];
776: }
777: );
778: }
779:
780: /**
781: * Operation findPetsByStatusAsyncWithHttpInfo
782: *
783: * Finds Pets by status
784: *
785: * @param string[] $status Status values that need to be considered for filter (required) (deprecated)
786: *
787: * @throws \InvalidArgumentException
788: * @return \GuzzleHttp\Promise\PromiseInterface
789: */
790: public function findPetsByStatusAsyncWithHttpInfo($status)
791: {
792: $returnType = '\Ally\PetStore\Schema\Pet[]';
793: $request = $this->findPetsByStatusRequest($status);
794:
795: return $this->client
796: ->sendAsync($request, $this->createHttpClientOption())
797: ->then(
798: function ($response) use ($returnType) {
799: if ($returnType === '\SplFileObject') {
800: $content = $response->getBody(); //stream goes to serializer
801: } else {
802: $content = (string) $response->getBody();
803: if ($returnType !== 'string') {
804: $content = json_decode($content);
805: }
806: }
807:
808: return [
809: ObjectSerializer::deserialize($content, $returnType, []),
810: $response->getStatusCode(),
811: $response->getHeaders()
812: ];
813: },
814: function ($exception) {
815: $response = $exception->getResponse();
816: $statusCode = $response->getStatusCode();
817: throw new ApiException(
818: sprintf(
819: '[%d] Error connecting to the API (%s)',
820: $statusCode,
821: $exception->getRequest()->getUri()
822: ),
823: $statusCode,
824: $response->getHeaders(),
825: (string) $response->getBody()
826: );
827: }
828: );
829: }
830:
831: /**
832: * Create request for operation 'findPetsByStatus'
833: *
834: * @param string[] $status Status values that need to be considered for filter (required) (deprecated)
835: *
836: * @throws \InvalidArgumentException
837: * @return \GuzzleHttp\Psr7\Request
838: */
839: public function findPetsByStatusRequest($status)
840: {
841:
842: // verify the required parameter 'status' is set
843: if ($status === null || (is_array($status) && count($status) === 0)) {
844: throw new \InvalidArgumentException(
845: 'Missing the required parameter $status when calling findPetsByStatus'
846: );
847: }
848:
849: $resourcePath = '/pet/findByStatus';
850: $formParams = [];
851: $queryParams = [];
852: $headerParams = [];
853: $httpBody = '';
854: $multipart = false;
855:
856: // query params
857: $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
858: $status,
859: 'status', // param base name
860: 'array', // openApiType
861: 'form', // style
862: false, // explode
863: true // required
864: ) ?? []);
865:
866:
867:
868:
869: if ($multipart) {
870: $headers = $this->headerSelector->selectHeadersForMultipart(
871: ['application/xml', 'application/json']
872: );
873: } else {
874: $headers = $this->headerSelector->selectHeaders(
875: ['application/xml', 'application/json'],
876: []
877: );
878: }
879:
880: // for model (json/xml)
881: if (count($formParams) > 0) {
882: if ($multipart) {
883: $multipartContents = [];
884: foreach ($formParams as $formParamName => $formParamValue) {
885: $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
886: foreach ($formParamValueItems as $formParamValueItem) {
887: $multipartContents[] = [
888: 'name' => $formParamName,
889: 'contents' => $formParamValueItem
890: ];
891: }
892: }
893: // for HTTP post (form)
894: $httpBody = new MultipartStream($multipartContents);
895:
896: } elseif ($headers['Content-Type'] === 'application/json') {
897: $httpBody = \GuzzleHttp\json_encode($formParams);
898:
899: } else {
900: // for HTTP post (form)
901: $httpBody = ObjectSerializer::buildQuery($formParams);
902: }
903: }
904:
905: // this endpoint requires OAuth (access token)
906: if (!empty($this->config->getAccessToken())) {
907: $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
908: }
909:
910: $defaultHeaders = [];
911: if ($this->config->getUserAgent()) {
912: $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
913: }
914:
915: $headers = array_merge(
916: $defaultHeaders,
917: $headerParams,
918: $headers
919: );
920:
921: $operationHost = $this->config->getHost();
922: $query = ObjectSerializer::buildQuery($queryParams);
923: return new Request(
924: 'GET',
925: $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
926: $headers,
927: $httpBody
928: );
929: }
930:
931: /**
932: * Operation findPetsByTags
933: *
934: * Finds Pets by tags
935: *
936: * @param string[] $tags Tags to filter by (required)
937: *
938: * @throws \Ally\PetStore\ApiException on non-2xx response
939: * @throws \InvalidArgumentException
940: * @return \Ally\PetStore\Schema\Pet[]
941: * @deprecated
942: */
943: public function findPetsByTags($tags)
944: {
945: list($response) = $this->findPetsByTagsWithHttpInfo($tags);
946: return $response;
947: }
948:
949: /**
950: * Operation findPetsByTagsWithHttpInfo
951: *
952: * Finds Pets by tags
953: *
954: * @param string[] $tags Tags to filter by (required)
955: *
956: * @throws \Ally\PetStore\ApiException on non-2xx response
957: * @throws \InvalidArgumentException
958: * @return array of \Ally\PetStore\Schema\Pet[], HTTP status code, HTTP response headers (array of strings)
959: * @deprecated
960: */
961: public function findPetsByTagsWithHttpInfo($tags)
962: {
963: $request = $this->findPetsByTagsRequest($tags);
964:
965: try {
966: $options = $this->createHttpClientOption();
967: try {
968: $response = $this->client->send($request, $options);
969: } catch (RequestException $e) {
970: throw new ApiException(
971: "[{$e->getCode()}] {$e->getMessage()}",
972: (int) $e->getCode(),
973: $e->getResponse() ? $e->getResponse()->getHeaders() : null,
974: $e->getResponse() ? (string) $e->getResponse()->getBody() : null
975: );
976: } catch (ConnectException $e) {
977: throw new ApiException(
978: "[{$e->getCode()}] {$e->getMessage()}",
979: (int) $e->getCode(),
980: null,
981: null
982: );
983: }
984:
985: $statusCode = $response->getStatusCode();
986:
987: if ($statusCode < 200 || $statusCode > 299) {
988: throw new ApiException(
989: sprintf(
990: '[%d] Error connecting to the API (%s)',
991: $statusCode,
992: (string) $request->getUri()
993: ),
994: $statusCode,
995: $response->getHeaders(),
996: (string) $response->getBody()
997: );
998: }
999:
1000: switch($statusCode) {
1001: case 200:
1002: if ('\Ally\PetStore\Schema\Pet[]' === '\SplFileObject') {
1003: $content = $response->getBody(); //stream goes to serializer
1004: } else {
1005: $content = (string) $response->getBody();
1006: if ('\Ally\PetStore\Schema\Pet[]' !== 'string') {
1007: $content = json_decode($content);
1008: }
1009: }
1010:
1011: return [
1012: ObjectSerializer::deserialize($content, '\Ally\PetStore\Schema\Pet[]', []),
1013: $response->getStatusCode(),
1014: $response->getHeaders()
1015: ];
1016: }
1017:
1018: $returnType = '\Ally\PetStore\Schema\Pet[]';
1019: if ($returnType === '\SplFileObject') {
1020: $content = $response->getBody(); //stream goes to serializer
1021: } else {
1022: $content = (string) $response->getBody();
1023: if ($returnType !== 'string') {
1024: $content = json_decode($content);
1025: }
1026: }
1027:
1028: return [
1029: ObjectSerializer::deserialize($content, $returnType, []),
1030: $response->getStatusCode(),
1031: $response->getHeaders()
1032: ];
1033:
1034: } catch (ApiException $e) {
1035: switch ($e->getCode()) {
1036: case 200:
1037: $data = ObjectSerializer::deserialize(
1038: $e->getResponseBody(),
1039: '\Ally\PetStore\Schema\Pet[]',
1040: $e->getResponseHeaders()
1041: );
1042: $e->setResponseObject($data);
1043: break;
1044: }
1045: throw $e;
1046: }
1047: }
1048:
1049: /**
1050: * Operation findPetsByTagsAsync
1051: *
1052: * Finds Pets by tags
1053: *
1054: * @param string[] $tags Tags to filter by (required)
1055: *
1056: * @throws \InvalidArgumentException
1057: * @return \GuzzleHttp\Promise\PromiseInterface
1058: * @deprecated
1059: */
1060: public function findPetsByTagsAsync($tags)
1061: {
1062: return $this->findPetsByTagsAsyncWithHttpInfo($tags)
1063: ->then(
1064: function ($response) {
1065: return $response[0];
1066: }
1067: );
1068: }
1069:
1070: /**
1071: * Operation findPetsByTagsAsyncWithHttpInfo
1072: *
1073: * Finds Pets by tags
1074: *
1075: * @param string[] $tags Tags to filter by (required)
1076: *
1077: * @throws \InvalidArgumentException
1078: * @return \GuzzleHttp\Promise\PromiseInterface
1079: * @deprecated
1080: */
1081: public function findPetsByTagsAsyncWithHttpInfo($tags)
1082: {
1083: $returnType = '\Ally\PetStore\Schema\Pet[]';
1084: $request = $this->findPetsByTagsRequest($tags);
1085:
1086: return $this->client
1087: ->sendAsync($request, $this->createHttpClientOption())
1088: ->then(
1089: function ($response) use ($returnType) {
1090: if ($returnType === '\SplFileObject') {
1091: $content = $response->getBody(); //stream goes to serializer
1092: } else {
1093: $content = (string) $response->getBody();
1094: if ($returnType !== 'string') {
1095: $content = json_decode($content);
1096: }
1097: }
1098:
1099: return [
1100: ObjectSerializer::deserialize($content, $returnType, []),
1101: $response->getStatusCode(),
1102: $response->getHeaders()
1103: ];
1104: },
1105: function ($exception) {
1106: $response = $exception->getResponse();
1107: $statusCode = $response->getStatusCode();
1108: throw new ApiException(
1109: sprintf(
1110: '[%d] Error connecting to the API (%s)',
1111: $statusCode,
1112: $exception->getRequest()->getUri()
1113: ),
1114: $statusCode,
1115: $response->getHeaders(),
1116: (string) $response->getBody()
1117: );
1118: }
1119: );
1120: }
1121:
1122: /**
1123: * Create request for operation 'findPetsByTags'
1124: *
1125: * @param string[] $tags Tags to filter by (required)
1126: *
1127: * @throws \InvalidArgumentException
1128: * @return \GuzzleHttp\Psr7\Request
1129: * @deprecated
1130: */
1131: public function findPetsByTagsRequest($tags)
1132: {
1133:
1134: // verify the required parameter 'tags' is set
1135: if ($tags === null || (is_array($tags) && count($tags) === 0)) {
1136: throw new \InvalidArgumentException(
1137: 'Missing the required parameter $tags when calling findPetsByTags'
1138: );
1139: }
1140:
1141: $resourcePath = '/pet/findByTags';
1142: $formParams = [];
1143: $queryParams = [];
1144: $headerParams = [];
1145: $httpBody = '';
1146: $multipart = false;
1147:
1148: // query params
1149: $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
1150: $tags,
1151: 'tags', // param base name
1152: 'array', // openApiType
1153: 'form', // style
1154: false, // explode
1155: true // required
1156: ) ?? []);
1157:
1158:
1159:
1160:
1161: if ($multipart) {
1162: $headers = $this->headerSelector->selectHeadersForMultipart(
1163: ['application/xml', 'application/json']
1164: );
1165: } else {
1166: $headers = $this->headerSelector->selectHeaders(
1167: ['application/xml', 'application/json'],
1168: []
1169: );
1170: }
1171:
1172: // for model (json/xml)
1173: if (count($formParams) > 0) {
1174: if ($multipart) {
1175: $multipartContents = [];
1176: foreach ($formParams as $formParamName => $formParamValue) {
1177: $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
1178: foreach ($formParamValueItems as $formParamValueItem) {
1179: $multipartContents[] = [
1180: 'name' => $formParamName,
1181: 'contents' => $formParamValueItem
1182: ];
1183: }
1184: }
1185: // for HTTP post (form)
1186: $httpBody = new MultipartStream($multipartContents);
1187:
1188: } elseif ($headers['Content-Type'] === 'application/json') {
1189: $httpBody = \GuzzleHttp\json_encode($formParams);
1190:
1191: } else {
1192: // for HTTP post (form)
1193: $httpBody = ObjectSerializer::buildQuery($formParams);
1194: }
1195: }
1196:
1197: // this endpoint requires OAuth (access token)
1198: if (!empty($this->config->getAccessToken())) {
1199: $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
1200: }
1201:
1202: $defaultHeaders = [];
1203: if ($this->config->getUserAgent()) {
1204: $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
1205: }
1206:
1207: $headers = array_merge(
1208: $defaultHeaders,
1209: $headerParams,
1210: $headers
1211: );
1212:
1213: $operationHost = $this->config->getHost();
1214: $query = ObjectSerializer::buildQuery($queryParams);
1215: return new Request(
1216: 'GET',
1217: $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
1218: $headers,
1219: $httpBody
1220: );
1221: }
1222:
1223: /**
1224: * Operation getPetById
1225: *
1226: * Find pet by ID
1227: *
1228: * @param int $pet_id ID of pet to return (required)
1229: *
1230: * @throws \Ally\PetStore\ApiException on non-2xx response
1231: * @throws \InvalidArgumentException
1232: * @return \Ally\PetStore\Schema\Pet
1233: */
1234: public function getPetById($pet_id)
1235: {
1236: list($response) = $this->getPetByIdWithHttpInfo($pet_id);
1237: return $response;
1238: }
1239:
1240: /**
1241: * Operation getPetByIdWithHttpInfo
1242: *
1243: * Find pet by ID
1244: *
1245: * @param int $pet_id ID of pet to return (required)
1246: *
1247: * @throws \Ally\PetStore\ApiException on non-2xx response
1248: * @throws \InvalidArgumentException
1249: * @return array of \Ally\PetStore\Schema\Pet, HTTP status code, HTTP response headers (array of strings)
1250: */
1251: public function getPetByIdWithHttpInfo($pet_id)
1252: {
1253: $request = $this->getPetByIdRequest($pet_id);
1254:
1255: try {
1256: $options = $this->createHttpClientOption();
1257: try {
1258: $response = $this->client->send($request, $options);
1259: } catch (RequestException $e) {
1260: throw new ApiException(
1261: "[{$e->getCode()}] {$e->getMessage()}",
1262: (int) $e->getCode(),
1263: $e->getResponse() ? $e->getResponse()->getHeaders() : null,
1264: $e->getResponse() ? (string) $e->getResponse()->getBody() : null
1265: );
1266: } catch (ConnectException $e) {
1267: throw new ApiException(
1268: "[{$e->getCode()}] {$e->getMessage()}",
1269: (int) $e->getCode(),
1270: null,
1271: null
1272: );
1273: }
1274:
1275: $statusCode = $response->getStatusCode();
1276:
1277: if ($statusCode < 200 || $statusCode > 299) {
1278: throw new ApiException(
1279: sprintf(
1280: '[%d] Error connecting to the API (%s)',
1281: $statusCode,
1282: (string) $request->getUri()
1283: ),
1284: $statusCode,
1285: $response->getHeaders(),
1286: (string) $response->getBody()
1287: );
1288: }
1289:
1290: switch($statusCode) {
1291: case 200:
1292: if ('\Ally\PetStore\Schema\Pet' === '\SplFileObject') {
1293: $content = $response->getBody(); //stream goes to serializer
1294: } else {
1295: $content = (string) $response->getBody();
1296: if ('\Ally\PetStore\Schema\Pet' !== 'string') {
1297: $content = json_decode($content);
1298: }
1299: }
1300:
1301: return [
1302: ObjectSerializer::deserialize($content, '\Ally\PetStore\Schema\Pet', []),
1303: $response->getStatusCode(),
1304: $response->getHeaders()
1305: ];
1306: }
1307:
1308: $returnType = '\Ally\PetStore\Schema\Pet';
1309: if ($returnType === '\SplFileObject') {
1310: $content = $response->getBody(); //stream goes to serializer
1311: } else {
1312: $content = (string) $response->getBody();
1313: if ($returnType !== 'string') {
1314: $content = json_decode($content);
1315: }
1316: }
1317:
1318: return [
1319: ObjectSerializer::deserialize($content, $returnType, []),
1320: $response->getStatusCode(),
1321: $response->getHeaders()
1322: ];
1323:
1324: } catch (ApiException $e) {
1325: switch ($e->getCode()) {
1326: case 200:
1327: $data = ObjectSerializer::deserialize(
1328: $e->getResponseBody(),
1329: '\Ally\PetStore\Schema\Pet',
1330: $e->getResponseHeaders()
1331: );
1332: $e->setResponseObject($data);
1333: break;
1334: }
1335: throw $e;
1336: }
1337: }
1338:
1339: /**
1340: * Operation getPetByIdAsync
1341: *
1342: * Find pet by ID
1343: *
1344: * @param int $pet_id ID of pet to return (required)
1345: *
1346: * @throws \InvalidArgumentException
1347: * @return \GuzzleHttp\Promise\PromiseInterface
1348: */
1349: public function getPetByIdAsync($pet_id)
1350: {
1351: return $this->getPetByIdAsyncWithHttpInfo($pet_id)
1352: ->then(
1353: function ($response) {
1354: return $response[0];
1355: }
1356: );
1357: }
1358:
1359: /**
1360: * Operation getPetByIdAsyncWithHttpInfo
1361: *
1362: * Find pet by ID
1363: *
1364: * @param int $pet_id ID of pet to return (required)
1365: *
1366: * @throws \InvalidArgumentException
1367: * @return \GuzzleHttp\Promise\PromiseInterface
1368: */
1369: public function getPetByIdAsyncWithHttpInfo($pet_id)
1370: {
1371: $returnType = '\Ally\PetStore\Schema\Pet';
1372: $request = $this->getPetByIdRequest($pet_id);
1373:
1374: return $this->client
1375: ->sendAsync($request, $this->createHttpClientOption())
1376: ->then(
1377: function ($response) use ($returnType) {
1378: if ($returnType === '\SplFileObject') {
1379: $content = $response->getBody(); //stream goes to serializer
1380: } else {
1381: $content = (string) $response->getBody();
1382: if ($returnType !== 'string') {
1383: $content = json_decode($content);
1384: }
1385: }
1386:
1387: return [
1388: ObjectSerializer::deserialize($content, $returnType, []),
1389: $response->getStatusCode(),
1390: $response->getHeaders()
1391: ];
1392: },
1393: function ($exception) {
1394: $response = $exception->getResponse();
1395: $statusCode = $response->getStatusCode();
1396: throw new ApiException(
1397: sprintf(
1398: '[%d] Error connecting to the API (%s)',
1399: $statusCode,
1400: $exception->getRequest()->getUri()
1401: ),
1402: $statusCode,
1403: $response->getHeaders(),
1404: (string) $response->getBody()
1405: );
1406: }
1407: );
1408: }
1409:
1410: /**
1411: * Create request for operation 'getPetById'
1412: *
1413: * @param int $pet_id ID of pet to return (required)
1414: *
1415: * @throws \InvalidArgumentException
1416: * @return \GuzzleHttp\Psr7\Request
1417: */
1418: public function getPetByIdRequest($pet_id)
1419: {
1420:
1421: // verify the required parameter 'pet_id' is set
1422: if ($pet_id === null || (is_array($pet_id) && count($pet_id) === 0)) {
1423: throw new \InvalidArgumentException(
1424: 'Missing the required parameter $pet_id when calling getPetById'
1425: );
1426: }
1427:
1428: $resourcePath = '/pet/{petId}';
1429: $formParams = [];
1430: $queryParams = [];
1431: $headerParams = [];
1432: $httpBody = '';
1433: $multipart = false;
1434:
1435:
1436:
1437: // path params
1438: if ($pet_id !== null) {
1439: $resourcePath = str_replace(
1440: '{' . 'petId' . '}',
1441: ObjectSerializer::toPathValue($pet_id),
1442: $resourcePath
1443: );
1444: }
1445:
1446:
1447: if ($multipart) {
1448: $headers = $this->headerSelector->selectHeadersForMultipart(
1449: ['application/xml', 'application/json']
1450: );
1451: } else {
1452: $headers = $this->headerSelector->selectHeaders(
1453: ['application/xml', 'application/json'],
1454: []
1455: );
1456: }
1457:
1458: // for model (json/xml)
1459: if (count($formParams) > 0) {
1460: if ($multipart) {
1461: $multipartContents = [];
1462: foreach ($formParams as $formParamName => $formParamValue) {
1463: $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
1464: foreach ($formParamValueItems as $formParamValueItem) {
1465: $multipartContents[] = [
1466: 'name' => $formParamName,
1467: 'contents' => $formParamValueItem
1468: ];
1469: }
1470: }
1471: // for HTTP post (form)
1472: $httpBody = new MultipartStream($multipartContents);
1473:
1474: } elseif ($headers['Content-Type'] === 'application/json') {
1475: $httpBody = \GuzzleHttp\json_encode($formParams);
1476:
1477: } else {
1478: // for HTTP post (form)
1479: $httpBody = ObjectSerializer::buildQuery($formParams);
1480: }
1481: }
1482:
1483: // this endpoint requires API key authentication
1484: $apiKey = $this->config->getApiKeyWithPrefix('api_key');
1485: if ($apiKey !== null) {
1486: $headers['api_key'] = $apiKey;
1487: }
1488:
1489: $defaultHeaders = [];
1490: if ($this->config->getUserAgent()) {
1491: $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
1492: }
1493:
1494: $headers = array_merge(
1495: $defaultHeaders,
1496: $headerParams,
1497: $headers
1498: );
1499:
1500: $operationHost = $this->config->getHost();
1501: $query = ObjectSerializer::buildQuery($queryParams);
1502: return new Request(
1503: 'GET',
1504: $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
1505: $headers,
1506: $httpBody
1507: );
1508: }
1509:
1510: /**
1511: * Operation updatePet
1512: *
1513: * Update an existing pet
1514: *
1515: * @param \Ally\PetStore\Schema\Pet $pet Pet object that needs to be added to the store (required)
1516: *
1517: * @throws \Ally\PetStore\ApiException on non-2xx response
1518: * @throws \InvalidArgumentException
1519: * @return \Ally\PetStore\Schema\Pet
1520: */
1521: public function updatePet($pet)
1522: {
1523: list($response) = $this->updatePetWithHttpInfo($pet);
1524: return $response;
1525: }
1526:
1527: /**
1528: * Operation updatePetWithHttpInfo
1529: *
1530: * Update an existing pet
1531: *
1532: * @param \Ally\PetStore\Schema\Pet $pet Pet object that needs to be added to the store (required)
1533: *
1534: * @throws \Ally\PetStore\ApiException on non-2xx response
1535: * @throws \InvalidArgumentException
1536: * @return array of \Ally\PetStore\Schema\Pet, HTTP status code, HTTP response headers (array of strings)
1537: */
1538: public function updatePetWithHttpInfo($pet)
1539: {
1540: $request = $this->updatePetRequest($pet);
1541:
1542: try {
1543: $options = $this->createHttpClientOption();
1544: try {
1545: $response = $this->client->send($request, $options);
1546: } catch (RequestException $e) {
1547: throw new ApiException(
1548: "[{$e->getCode()}] {$e->getMessage()}",
1549: (int) $e->getCode(),
1550: $e->getResponse() ? $e->getResponse()->getHeaders() : null,
1551: $e->getResponse() ? (string) $e->getResponse()->getBody() : null
1552: );
1553: } catch (ConnectException $e) {
1554: throw new ApiException(
1555: "[{$e->getCode()}] {$e->getMessage()}",
1556: (int) $e->getCode(),
1557: null,
1558: null
1559: );
1560: }
1561:
1562: $statusCode = $response->getStatusCode();
1563:
1564: if ($statusCode < 200 || $statusCode > 299) {
1565: throw new ApiException(
1566: sprintf(
1567: '[%d] Error connecting to the API (%s)',
1568: $statusCode,
1569: (string) $request->getUri()
1570: ),
1571: $statusCode,
1572: $response->getHeaders(),
1573: (string) $response->getBody()
1574: );
1575: }
1576:
1577: switch($statusCode) {
1578: case 200:
1579: if ('\Ally\PetStore\Schema\Pet' === '\SplFileObject') {
1580: $content = $response->getBody(); //stream goes to serializer
1581: } else {
1582: $content = (string) $response->getBody();
1583: if ('\Ally\PetStore\Schema\Pet' !== 'string') {
1584: $content = json_decode($content);
1585: }
1586: }
1587:
1588: return [
1589: ObjectSerializer::deserialize($content, '\Ally\PetStore\Schema\Pet', []),
1590: $response->getStatusCode(),
1591: $response->getHeaders()
1592: ];
1593: }
1594:
1595: $returnType = '\Ally\PetStore\Schema\Pet';
1596: if ($returnType === '\SplFileObject') {
1597: $content = $response->getBody(); //stream goes to serializer
1598: } else {
1599: $content = (string) $response->getBody();
1600: if ($returnType !== 'string') {
1601: $content = json_decode($content);
1602: }
1603: }
1604:
1605: return [
1606: ObjectSerializer::deserialize($content, $returnType, []),
1607: $response->getStatusCode(),
1608: $response->getHeaders()
1609: ];
1610:
1611: } catch (ApiException $e) {
1612: switch ($e->getCode()) {
1613: case 200:
1614: $data = ObjectSerializer::deserialize(
1615: $e->getResponseBody(),
1616: '\Ally\PetStore\Schema\Pet',
1617: $e->getResponseHeaders()
1618: );
1619: $e->setResponseObject($data);
1620: break;
1621: }
1622: throw $e;
1623: }
1624: }
1625:
1626: /**
1627: * Operation updatePetAsync
1628: *
1629: * Update an existing pet
1630: *
1631: * @param \Ally\PetStore\Schema\Pet $pet Pet object that needs to be added to the store (required)
1632: *
1633: * @throws \InvalidArgumentException
1634: * @return \GuzzleHttp\Promise\PromiseInterface
1635: */
1636: public function updatePetAsync($pet)
1637: {
1638: return $this->updatePetAsyncWithHttpInfo($pet)
1639: ->then(
1640: function ($response) {
1641: return $response[0];
1642: }
1643: );
1644: }
1645:
1646: /**
1647: * Operation updatePetAsyncWithHttpInfo
1648: *
1649: * Update an existing pet
1650: *
1651: * @param \Ally\PetStore\Schema\Pet $pet Pet object that needs to be added to the store (required)
1652: *
1653: * @throws \InvalidArgumentException
1654: * @return \GuzzleHttp\Promise\PromiseInterface
1655: */
1656: public function updatePetAsyncWithHttpInfo($pet)
1657: {
1658: $returnType = '\Ally\PetStore\Schema\Pet';
1659: $request = $this->updatePetRequest($pet);
1660:
1661: return $this->client
1662: ->sendAsync($request, $this->createHttpClientOption())
1663: ->then(
1664: function ($response) use ($returnType) {
1665: if ($returnType === '\SplFileObject') {
1666: $content = $response->getBody(); //stream goes to serializer
1667: } else {
1668: $content = (string) $response->getBody();
1669: if ($returnType !== 'string') {
1670: $content = json_decode($content);
1671: }
1672: }
1673:
1674: return [
1675: ObjectSerializer::deserialize($content, $returnType, []),
1676: $response->getStatusCode(),
1677: $response->getHeaders()
1678: ];
1679: },
1680: function ($exception) {
1681: $response = $exception->getResponse();
1682: $statusCode = $response->getStatusCode();
1683: throw new ApiException(
1684: sprintf(
1685: '[%d] Error connecting to the API (%s)',
1686: $statusCode,
1687: $exception->getRequest()->getUri()
1688: ),
1689: $statusCode,
1690: $response->getHeaders(),
1691: (string) $response->getBody()
1692: );
1693: }
1694: );
1695: }
1696:
1697: /**
1698: * Create request for operation 'updatePet'
1699: *
1700: * @param \Ally\PetStore\Schema\Pet $pet Pet object that needs to be added to the store (required)
1701: *
1702: * @throws \InvalidArgumentException
1703: * @return \GuzzleHttp\Psr7\Request
1704: */
1705: public function updatePetRequest($pet)
1706: {
1707:
1708: // verify the required parameter 'pet' is set
1709: if ($pet === null || (is_array($pet) && count($pet) === 0)) {
1710: throw new \InvalidArgumentException(
1711: 'Missing the required parameter $pet when calling updatePet'
1712: );
1713: }
1714:
1715: $resourcePath = '/pet';
1716: $formParams = [];
1717: $queryParams = [];
1718: $headerParams = [];
1719: $httpBody = '';
1720: $multipart = false;
1721:
1722:
1723:
1724:
1725:
1726: if ($multipart) {
1727: $headers = $this->headerSelector->selectHeadersForMultipart(
1728: ['application/xml', 'application/json']
1729: );
1730: } else {
1731: $headers = $this->headerSelector->selectHeaders(
1732: ['application/xml', 'application/json'],
1733: ['application/json', 'application/xml']
1734: );
1735: }
1736:
1737: // for model (json/xml)
1738: if (isset($pet)) {
1739: if ($headers['Content-Type'] === 'application/json') {
1740: $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($pet));
1741: } else {
1742: $httpBody = $pet;
1743: }
1744: } elseif (count($formParams) > 0) {
1745: if ($multipart) {
1746: $multipartContents = [];
1747: foreach ($formParams as $formParamName => $formParamValue) {
1748: $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
1749: foreach ($formParamValueItems as $formParamValueItem) {
1750: $multipartContents[] = [
1751: 'name' => $formParamName,
1752: 'contents' => $formParamValueItem
1753: ];
1754: }
1755: }
1756: // for HTTP post (form)
1757: $httpBody = new MultipartStream($multipartContents);
1758:
1759: } elseif ($headers['Content-Type'] === 'application/json') {
1760: $httpBody = \GuzzleHttp\json_encode($formParams);
1761:
1762: } else {
1763: // for HTTP post (form)
1764: $httpBody = ObjectSerializer::buildQuery($formParams);
1765: }
1766: }
1767:
1768: // this endpoint requires OAuth (access token)
1769: if (!empty($this->config->getAccessToken())) {
1770: $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
1771: }
1772:
1773: $defaultHeaders = [];
1774: if ($this->config->getUserAgent()) {
1775: $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
1776: }
1777:
1778: $headers = array_merge(
1779: $defaultHeaders,
1780: $headerParams,
1781: $headers
1782: );
1783:
1784: $operationHost = $this->config->getHost();
1785: $query = ObjectSerializer::buildQuery($queryParams);
1786: return new Request(
1787: 'PUT',
1788: $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
1789: $headers,
1790: $httpBody
1791: );
1792: }
1793:
1794: /**
1795: * Operation updatePetWithForm
1796: *
1797: * Updates a pet in the store with form data
1798: *
1799: * @param int $pet_id ID of pet that needs to be updated (required)
1800: * @param string $name Updated name of the pet (optional)
1801: * @param string $status Updated status of the pet (optional)
1802: *
1803: * @throws \Ally\PetStore\ApiException on non-2xx response
1804: * @throws \InvalidArgumentException
1805: * @return void
1806: */
1807: public function updatePetWithForm($pet_id, $name = null, $status = null)
1808: {
1809: $this->updatePetWithFormWithHttpInfo($pet_id, $name, $status);
1810: }
1811:
1812: /**
1813: * Operation updatePetWithFormWithHttpInfo
1814: *
1815: * Updates a pet in the store with form data
1816: *
1817: * @param int $pet_id ID of pet that needs to be updated (required)
1818: * @param string $name Updated name of the pet (optional)
1819: * @param string $status Updated status of the pet (optional)
1820: *
1821: * @throws \Ally\PetStore\ApiException on non-2xx response
1822: * @throws \InvalidArgumentException
1823: * @return array of null, HTTP status code, HTTP response headers (array of strings)
1824: */
1825: public function updatePetWithFormWithHttpInfo($pet_id, $name = null, $status = null)
1826: {
1827: $request = $this->updatePetWithFormRequest($pet_id, $name, $status);
1828:
1829: try {
1830: $options = $this->createHttpClientOption();
1831: try {
1832: $response = $this->client->send($request, $options);
1833: } catch (RequestException $e) {
1834: throw new ApiException(
1835: "[{$e->getCode()}] {$e->getMessage()}",
1836: (int) $e->getCode(),
1837: $e->getResponse() ? $e->getResponse()->getHeaders() : null,
1838: $e->getResponse() ? (string) $e->getResponse()->getBody() : null
1839: );
1840: } catch (ConnectException $e) {
1841: throw new ApiException(
1842: "[{$e->getCode()}] {$e->getMessage()}",
1843: (int) $e->getCode(),
1844: null,
1845: null
1846: );
1847: }
1848:
1849: $statusCode = $response->getStatusCode();
1850:
1851: if ($statusCode < 200 || $statusCode > 299) {
1852: throw new ApiException(
1853: sprintf(
1854: '[%d] Error connecting to the API (%s)',
1855: $statusCode,
1856: (string) $request->getUri()
1857: ),
1858: $statusCode,
1859: $response->getHeaders(),
1860: (string) $response->getBody()
1861: );
1862: }
1863:
1864: return [null, $statusCode, $response->getHeaders()];
1865:
1866: } catch (ApiException $e) {
1867: switch ($e->getCode()) {
1868: }
1869: throw $e;
1870: }
1871: }
1872:
1873: /**
1874: * Operation updatePetWithFormAsync
1875: *
1876: * Updates a pet in the store with form data
1877: *
1878: * @param int $pet_id ID of pet that needs to be updated (required)
1879: * @param string $name Updated name of the pet (optional)
1880: * @param string $status Updated status of the pet (optional)
1881: *
1882: * @throws \InvalidArgumentException
1883: * @return \GuzzleHttp\Promise\PromiseInterface
1884: */
1885: public function updatePetWithFormAsync($pet_id, $name = null, $status = null)
1886: {
1887: return $this->updatePetWithFormAsyncWithHttpInfo($pet_id, $name, $status)
1888: ->then(
1889: function ($response) {
1890: return $response[0];
1891: }
1892: );
1893: }
1894:
1895: /**
1896: * Operation updatePetWithFormAsyncWithHttpInfo
1897: *
1898: * Updates a pet in the store with form data
1899: *
1900: * @param int $pet_id ID of pet that needs to be updated (required)
1901: * @param string $name Updated name of the pet (optional)
1902: * @param string $status Updated status of the pet (optional)
1903: *
1904: * @throws \InvalidArgumentException
1905: * @return \GuzzleHttp\Promise\PromiseInterface
1906: */
1907: public function updatePetWithFormAsyncWithHttpInfo($pet_id, $name = null, $status = null)
1908: {
1909: $returnType = '';
1910: $request = $this->updatePetWithFormRequest($pet_id, $name, $status);
1911:
1912: return $this->client
1913: ->sendAsync($request, $this->createHttpClientOption())
1914: ->then(
1915: function ($response) use ($returnType) {
1916: return [null, $response->getStatusCode(), $response->getHeaders()];
1917: },
1918: function ($exception) {
1919: $response = $exception->getResponse();
1920: $statusCode = $response->getStatusCode();
1921: throw new ApiException(
1922: sprintf(
1923: '[%d] Error connecting to the API (%s)',
1924: $statusCode,
1925: $exception->getRequest()->getUri()
1926: ),
1927: $statusCode,
1928: $response->getHeaders(),
1929: (string) $response->getBody()
1930: );
1931: }
1932: );
1933: }
1934:
1935: /**
1936: * Create request for operation 'updatePetWithForm'
1937: *
1938: * @param int $pet_id ID of pet that needs to be updated (required)
1939: * @param string $name Updated name of the pet (optional)
1940: * @param string $status Updated status of the pet (optional)
1941: *
1942: * @throws \InvalidArgumentException
1943: * @return \GuzzleHttp\Psr7\Request
1944: */
1945: public function updatePetWithFormRequest($pet_id, $name = null, $status = null)
1946: {
1947:
1948: // verify the required parameter 'pet_id' is set
1949: if ($pet_id === null || (is_array($pet_id) && count($pet_id) === 0)) {
1950: throw new \InvalidArgumentException(
1951: 'Missing the required parameter $pet_id when calling updatePetWithForm'
1952: );
1953: }
1954:
1955:
1956:
1957: $resourcePath = '/pet/{petId}';
1958: $formParams = [];
1959: $queryParams = [];
1960: $headerParams = [];
1961: $httpBody = '';
1962: $multipart = false;
1963:
1964:
1965:
1966: // path params
1967: if ($pet_id !== null) {
1968: $resourcePath = str_replace(
1969: '{' . 'petId' . '}',
1970: ObjectSerializer::toPathValue($pet_id),
1971: $resourcePath
1972: );
1973: }
1974:
1975: // form params
1976: if ($name !== null) {
1977: $formParams['name'] = ObjectSerializer::toFormValue($name);
1978: }
1979: // form params
1980: if ($status !== null) {
1981: $formParams['status'] = ObjectSerializer::toFormValue($status);
1982: }
1983:
1984: if ($multipart) {
1985: $headers = $this->headerSelector->selectHeadersForMultipart(
1986: []
1987: );
1988: } else {
1989: $headers = $this->headerSelector->selectHeaders(
1990: [],
1991: ['application/x-www-form-urlencoded']
1992: );
1993: }
1994:
1995: // for model (json/xml)
1996: if (count($formParams) > 0) {
1997: if ($multipart) {
1998: $multipartContents = [];
1999: foreach ($formParams as $formParamName => $formParamValue) {
2000: $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
2001: foreach ($formParamValueItems as $formParamValueItem) {
2002: $multipartContents[] = [
2003: 'name' => $formParamName,
2004: 'contents' => $formParamValueItem
2005: ];
2006: }
2007: }
2008: // for HTTP post (form)
2009: $httpBody = new MultipartStream($multipartContents);
2010:
2011: } elseif ($headers['Content-Type'] === 'application/json') {
2012: $httpBody = \GuzzleHttp\json_encode($formParams);
2013:
2014: } else {
2015: // for HTTP post (form)
2016: $httpBody = ObjectSerializer::buildQuery($formParams);
2017: }
2018: }
2019:
2020: // this endpoint requires OAuth (access token)
2021: if (!empty($this->config->getAccessToken())) {
2022: $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
2023: }
2024:
2025: $defaultHeaders = [];
2026: if ($this->config->getUserAgent()) {
2027: $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
2028: }
2029:
2030: $headers = array_merge(
2031: $defaultHeaders,
2032: $headerParams,
2033: $headers
2034: );
2035:
2036: $operationHost = $this->config->getHost();
2037: $query = ObjectSerializer::buildQuery($queryParams);
2038: return new Request(
2039: 'POST',
2040: $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
2041: $headers,
2042: $httpBody
2043: );
2044: }
2045:
2046: /**
2047: * Operation uploadFile
2048: *
2049: * uploads an image
2050: *
2051: * @param int $pet_id ID of pet to update (required)
2052: * @param string $additional_metadata Additional data to pass to server (optional)
2053: * @param \SplFileObject $file file to upload (optional)
2054: *
2055: * @throws \Ally\PetStore\ApiException on non-2xx response
2056: * @throws \InvalidArgumentException
2057: * @return \Ally\PetStore\Schema\ApiResponse
2058: */
2059: public function uploadFile($pet_id, $additional_metadata = null, $file = null)
2060: {
2061: list($response) = $this->uploadFileWithHttpInfo($pet_id, $additional_metadata, $file);
2062: return $response;
2063: }
2064:
2065: /**
2066: * Operation uploadFileWithHttpInfo
2067: *
2068: * uploads an image
2069: *
2070: * @param int $pet_id ID of pet to update (required)
2071: * @param string $additional_metadata Additional data to pass to server (optional)
2072: * @param \SplFileObject $file file to upload (optional)
2073: *
2074: * @throws \Ally\PetStore\ApiException on non-2xx response
2075: * @throws \InvalidArgumentException
2076: * @return array of \Ally\PetStore\Schema\ApiResponse, HTTP status code, HTTP response headers (array of strings)
2077: */
2078: public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $file = null)
2079: {
2080: $request = $this->uploadFileRequest($pet_id, $additional_metadata, $file);
2081:
2082: try {
2083: $options = $this->createHttpClientOption();
2084: try {
2085: $response = $this->client->send($request, $options);
2086: } catch (RequestException $e) {
2087: throw new ApiException(
2088: "[{$e->getCode()}] {$e->getMessage()}",
2089: (int) $e->getCode(),
2090: $e->getResponse() ? $e->getResponse()->getHeaders() : null,
2091: $e->getResponse() ? (string) $e->getResponse()->getBody() : null
2092: );
2093: } catch (ConnectException $e) {
2094: throw new ApiException(
2095: "[{$e->getCode()}] {$e->getMessage()}",
2096: (int) $e->getCode(),
2097: null,
2098: null
2099: );
2100: }
2101:
2102: $statusCode = $response->getStatusCode();
2103:
2104: if ($statusCode < 200 || $statusCode > 299) {
2105: throw new ApiException(
2106: sprintf(
2107: '[%d] Error connecting to the API (%s)',
2108: $statusCode,
2109: (string) $request->getUri()
2110: ),
2111: $statusCode,
2112: $response->getHeaders(),
2113: (string) $response->getBody()
2114: );
2115: }
2116:
2117: switch($statusCode) {
2118: case 200:
2119: if ('\Ally\PetStore\Schema\ApiResponse' === '\SplFileObject') {
2120: $content = $response->getBody(); //stream goes to serializer
2121: } else {
2122: $content = (string) $response->getBody();
2123: if ('\Ally\PetStore\Schema\ApiResponse' !== 'string') {
2124: $content = json_decode($content);
2125: }
2126: }
2127:
2128: return [
2129: ObjectSerializer::deserialize($content, '\Ally\PetStore\Schema\ApiResponse', []),
2130: $response->getStatusCode(),
2131: $response->getHeaders()
2132: ];
2133: }
2134:
2135: $returnType = '\Ally\PetStore\Schema\ApiResponse';
2136: if ($returnType === '\SplFileObject') {
2137: $content = $response->getBody(); //stream goes to serializer
2138: } else {
2139: $content = (string) $response->getBody();
2140: if ($returnType !== 'string') {
2141: $content = json_decode($content);
2142: }
2143: }
2144:
2145: return [
2146: ObjectSerializer::deserialize($content, $returnType, []),
2147: $response->getStatusCode(),
2148: $response->getHeaders()
2149: ];
2150:
2151: } catch (ApiException $e) {
2152: switch ($e->getCode()) {
2153: case 200:
2154: $data = ObjectSerializer::deserialize(
2155: $e->getResponseBody(),
2156: '\Ally\PetStore\Schema\ApiResponse',
2157: $e->getResponseHeaders()
2158: );
2159: $e->setResponseObject($data);
2160: break;
2161: }
2162: throw $e;
2163: }
2164: }
2165:
2166: /**
2167: * Operation uploadFileAsync
2168: *
2169: * uploads an image
2170: *
2171: * @param int $pet_id ID of pet to update (required)
2172: * @param string $additional_metadata Additional data to pass to server (optional)
2173: * @param \SplFileObject $file file to upload (optional)
2174: *
2175: * @throws \InvalidArgumentException
2176: * @return \GuzzleHttp\Promise\PromiseInterface
2177: */
2178: public function uploadFileAsync($pet_id, $additional_metadata = null, $file = null)
2179: {
2180: return $this->uploadFileAsyncWithHttpInfo($pet_id, $additional_metadata, $file)
2181: ->then(
2182: function ($response) {
2183: return $response[0];
2184: }
2185: );
2186: }
2187:
2188: /**
2189: * Operation uploadFileAsyncWithHttpInfo
2190: *
2191: * uploads an image
2192: *
2193: * @param int $pet_id ID of pet to update (required)
2194: * @param string $additional_metadata Additional data to pass to server (optional)
2195: * @param \SplFileObject $file file to upload (optional)
2196: *
2197: * @throws \InvalidArgumentException
2198: * @return \GuzzleHttp\Promise\PromiseInterface
2199: */
2200: public function uploadFileAsyncWithHttpInfo($pet_id, $additional_metadata = null, $file = null)
2201: {
2202: $returnType = '\Ally\PetStore\Schema\ApiResponse';
2203: $request = $this->uploadFileRequest($pet_id, $additional_metadata, $file);
2204:
2205: return $this->client
2206: ->sendAsync($request, $this->createHttpClientOption())
2207: ->then(
2208: function ($response) use ($returnType) {
2209: if ($returnType === '\SplFileObject') {
2210: $content = $response->getBody(); //stream goes to serializer
2211: } else {
2212: $content = (string) $response->getBody();
2213: if ($returnType !== 'string') {
2214: $content = json_decode($content);
2215: }
2216: }
2217:
2218: return [
2219: ObjectSerializer::deserialize($content, $returnType, []),
2220: $response->getStatusCode(),
2221: $response->getHeaders()
2222: ];
2223: },
2224: function ($exception) {
2225: $response = $exception->getResponse();
2226: $statusCode = $response->getStatusCode();
2227: throw new ApiException(
2228: sprintf(
2229: '[%d] Error connecting to the API (%s)',
2230: $statusCode,
2231: $exception->getRequest()->getUri()
2232: ),
2233: $statusCode,
2234: $response->getHeaders(),
2235: (string) $response->getBody()
2236: );
2237: }
2238: );
2239: }
2240:
2241: /**
2242: * Create request for operation 'uploadFile'
2243: *
2244: * @param int $pet_id ID of pet to update (required)
2245: * @param string $additional_metadata Additional data to pass to server (optional)
2246: * @param \SplFileObject $file file to upload (optional)
2247: *
2248: * @throws \InvalidArgumentException
2249: * @return \GuzzleHttp\Psr7\Request
2250: */
2251: public function uploadFileRequest($pet_id, $additional_metadata = null, $file = null)
2252: {
2253:
2254: // verify the required parameter 'pet_id' is set
2255: if ($pet_id === null || (is_array($pet_id) && count($pet_id) === 0)) {
2256: throw new \InvalidArgumentException(
2257: 'Missing the required parameter $pet_id when calling uploadFile'
2258: );
2259: }
2260:
2261:
2262:
2263: $resourcePath = '/pet/{petId}/uploadImage';
2264: $formParams = [];
2265: $queryParams = [];
2266: $headerParams = [];
2267: $httpBody = '';
2268: $multipart = false;
2269:
2270:
2271:
2272: // path params
2273: if ($pet_id !== null) {
2274: $resourcePath = str_replace(
2275: '{' . 'petId' . '}',
2276: ObjectSerializer::toPathValue($pet_id),
2277: $resourcePath
2278: );
2279: }
2280:
2281: // form params
2282: if ($additional_metadata !== null) {
2283: $formParams['additionalMetadata'] = ObjectSerializer::toFormValue($additional_metadata);
2284: }
2285: // form params
2286: if ($file !== null) {
2287: $multipart = true;
2288: $formParams['file'] = [];
2289: $paramFiles = is_array($file) ? $file : [$file];
2290: foreach ($paramFiles as $paramFile) {
2291: $formParams['file'][] = \GuzzleHttp\Psr7\Utils::tryFopen(
2292: ObjectSerializer::toFormValue($paramFile),
2293: 'rb'
2294: );
2295: }
2296: }
2297:
2298: if ($multipart) {
2299: $headers = $this->headerSelector->selectHeadersForMultipart(
2300: ['application/json']
2301: );
2302: } else {
2303: $headers = $this->headerSelector->selectHeaders(
2304: ['application/json'],
2305: ['multipart/form-data']
2306: );
2307: }
2308:
2309: // for model (json/xml)
2310: if (count($formParams) > 0) {
2311: if ($multipart) {
2312: $multipartContents = [];
2313: foreach ($formParams as $formParamName => $formParamValue) {
2314: $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
2315: foreach ($formParamValueItems as $formParamValueItem) {
2316: $multipartContents[] = [
2317: 'name' => $formParamName,
2318: 'contents' => $formParamValueItem
2319: ];
2320: }
2321: }
2322: // for HTTP post (form)
2323: $httpBody = new MultipartStream($multipartContents);
2324:
2325: } elseif ($headers['Content-Type'] === 'application/json') {
2326: $httpBody = \GuzzleHttp\json_encode($formParams);
2327:
2328: } else {
2329: // for HTTP post (form)
2330: $httpBody = ObjectSerializer::buildQuery($formParams);
2331: }
2332: }
2333:
2334: // this endpoint requires OAuth (access token)
2335: if (!empty($this->config->getAccessToken())) {
2336: $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
2337: }
2338:
2339: $defaultHeaders = [];
2340: if ($this->config->getUserAgent()) {
2341: $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
2342: }
2343:
2344: $headers = array_merge(
2345: $defaultHeaders,
2346: $headerParams,
2347: $headers
2348: );
2349:
2350: $operationHost = $this->config->getHost();
2351: $query = ObjectSerializer::buildQuery($queryParams);
2352: return new Request(
2353: 'POST',
2354: $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
2355: $headers,
2356: $httpBody
2357: );
2358: }
2359:
2360: /**
2361: * Create http client option
2362: *
2363: * @throws \RuntimeException on file opening failure
2364: * @return array of http client options
2365: */
2366: protected function createHttpClientOption()
2367: {
2368: $options = [];
2369: if ($this->config->getDebug()) {
2370: $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
2371: if (!$options[RequestOptions::DEBUG]) {
2372: throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
2373: }
2374: }
2375:
2376: return $options;
2377: }
2378: }
2379: