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