| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 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: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | class UserApi |
| 51: | { |
| 52: | |
| 53: | |
| 54: | |
| 55: | protected $client; |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | protected $config; |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | protected $headerSelector; |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | protected $hostIndex; |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 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: | |
| 92: | |
| 93: | |
| 94: | |
| 95: | public function setHostIndex($hostIndex): void |
| 96: | { |
| 97: | $this->hostIndex = $hostIndex; |
| 98: | } |
| 99: | |
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | public function getHostIndex() |
| 106: | { |
| 107: | return $this->hostIndex; |
| 108: | } |
| 109: | |
| 110: | |
| 111: | |
| 112: | |
| 113: | public function getConfig() |
| 114: | { |
| 115: | return $this->config; |
| 116: | } |
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | |
| 122: | |
| 123: | |
| 124: | |
| 125: | |
| 126: | |
| 127: | |
| 128: | |
| 129: | public function createUser($user) |
| 130: | { |
| 131: | $this->createUserWithHttpInfo($user); |
| 132: | } |
| 133: | |
| 134: | |
| 135: | |
| 136: | |
| 137: | |
| 138: | |
| 139: | |
| 140: | |
| 141: | |
| 142: | |
| 143: | |
| 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: | |
| 195: | |
| 196: | |
| 197: | |
| 198: | |
| 199: | |
| 200: | |
| 201: | |
| 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: | |
| 215: | |
| 216: | |
| 217: | |
| 218: | |
| 219: | |
| 220: | |
| 221: | |
| 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: | |
| 253: | |
| 254: | |
| 255: | |
| 256: | |
| 257: | |
| 258: | |
| 259: | public function createUserRequest($user) |
| 260: | { |
| 261: | |
| 262: | |
| 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: | |
| 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: | |
| 311: | $httpBody = new MultipartStream($multipartContents); |
| 312: | |
| 313: | } elseif ($headers['Content-Type'] === 'application/json') { |
| 314: | $httpBody = \GuzzleHttp\json_encode($formParams); |
| 315: | |
| 316: | } else { |
| 317: | |
| 318: | $httpBody = ObjectSerializer::buildQuery($formParams); |
| 319: | } |
| 320: | } |
| 321: | |
| 322: | |
| 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: | |
| 351: | |
| 352: | |
| 353: | |
| 354: | |
| 355: | |
| 356: | |
| 357: | |
| 358: | |
| 359: | |
| 360: | public function createUsersWithArrayInput($user) |
| 361: | { |
| 362: | $this->createUsersWithArrayInputWithHttpInfo($user); |
| 363: | } |
| 364: | |
| 365: | |
| 366: | |
| 367: | |
| 368: | |
| 369: | |
| 370: | |
| 371: | |
| 372: | |
| 373: | |
| 374: | |
| 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: | |
| 426: | |
| 427: | |
| 428: | |
| 429: | |
| 430: | |
| 431: | |
| 432: | |
| 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: | |
| 446: | |
| 447: | |
| 448: | |
| 449: | |
| 450: | |
| 451: | |
| 452: | |
| 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: | |
| 484: | |
| 485: | |
| 486: | |
| 487: | |
| 488: | |
| 489: | |
| 490: | public function createUsersWithArrayInputRequest($user) |
| 491: | { |
| 492: | |
| 493: | |
| 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: | |
| 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: | |
| 542: | $httpBody = new MultipartStream($multipartContents); |
| 543: | |
| 544: | } elseif ($headers['Content-Type'] === 'application/json') { |
| 545: | $httpBody = \GuzzleHttp\json_encode($formParams); |
| 546: | |
| 547: | } else { |
| 548: | |
| 549: | $httpBody = ObjectSerializer::buildQuery($formParams); |
| 550: | } |
| 551: | } |
| 552: | |
| 553: | |
| 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: | |
| 582: | |
| 583: | |
| 584: | |
| 585: | |
| 586: | |
| 587: | |
| 588: | |
| 589: | |
| 590: | |
| 591: | public function createUsersWithListInput($user) |
| 592: | { |
| 593: | $this->createUsersWithListInputWithHttpInfo($user); |
| 594: | } |
| 595: | |
| 596: | |
| 597: | |
| 598: | |
| 599: | |
| 600: | |
| 601: | |
| 602: | |
| 603: | |
| 604: | |
| 605: | |
| 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: | |
| 657: | |
| 658: | |
| 659: | |
| 660: | |
| 661: | |
| 662: | |
| 663: | |
| 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: | |
| 677: | |
| 678: | |
| 679: | |
| 680: | |
| 681: | |
| 682: | |
| 683: | |
| 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: | |
| 715: | |
| 716: | |
| 717: | |
| 718: | |
| 719: | |
| 720: | |
| 721: | public function createUsersWithListInputRequest($user) |
| 722: | { |
| 723: | |
| 724: | |
| 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: | |
| 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: | |
| 773: | $httpBody = new MultipartStream($multipartContents); |
| 774: | |
| 775: | } elseif ($headers['Content-Type'] === 'application/json') { |
| 776: | $httpBody = \GuzzleHttp\json_encode($formParams); |
| 777: | |
| 778: | } else { |
| 779: | |
| 780: | $httpBody = ObjectSerializer::buildQuery($formParams); |
| 781: | } |
| 782: | } |
| 783: | |
| 784: | |
| 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: | |
| 813: | |
| 814: | |
| 815: | |
| 816: | |
| 817: | |
| 818: | |
| 819: | |
| 820: | |
| 821: | |
| 822: | public function deleteUser($username) |
| 823: | { |
| 824: | $this->deleteUserWithHttpInfo($username); |
| 825: | } |
| 826: | |
| 827: | |
| 828: | |
| 829: | |
| 830: | |
| 831: | |
| 832: | |
| 833: | |
| 834: | |
| 835: | |
| 836: | |
| 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: | |
| 888: | |
| 889: | |
| 890: | |
| 891: | |
| 892: | |
| 893: | |
| 894: | |
| 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: | |
| 908: | |
| 909: | |
| 910: | |
| 911: | |
| 912: | |
| 913: | |
| 914: | |
| 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: | |
| 946: | |
| 947: | |
| 948: | |
| 949: | |
| 950: | |
| 951: | |
| 952: | public function deleteUserRequest($username) |
| 953: | { |
| 954: | |
| 955: | |
| 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: | |
| 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: | |
| 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: | |
| 1006: | $httpBody = new MultipartStream($multipartContents); |
| 1007: | |
| 1008: | } elseif ($headers['Content-Type'] === 'application/json') { |
| 1009: | $httpBody = \GuzzleHttp\json_encode($formParams); |
| 1010: | |
| 1011: | } else { |
| 1012: | |
| 1013: | $httpBody = ObjectSerializer::buildQuery($formParams); |
| 1014: | } |
| 1015: | } |
| 1016: | |
| 1017: | |
| 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: | |
| 1046: | |
| 1047: | |
| 1048: | |
| 1049: | |
| 1050: | |
| 1051: | |
| 1052: | |
| 1053: | |
| 1054: | |
| 1055: | public function getUserByName($username) |
| 1056: | { |
| 1057: | list($response) = $this->getUserByNameWithHttpInfo($username); |
| 1058: | return $response; |
| 1059: | } |
| 1060: | |
| 1061: | |
| 1062: | |
| 1063: | |
| 1064: | |
| 1065: | |
| 1066: | |
| 1067: | |
| 1068: | |
| 1069: | |
| 1070: | |
| 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(); |
| 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(); |
| 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: | |
| 1162: | |
| 1163: | |
| 1164: | |
| 1165: | |
| 1166: | |
| 1167: | |
| 1168: | |
| 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: | |
| 1182: | |
| 1183: | |
| 1184: | |
| 1185: | |
| 1186: | |
| 1187: | |
| 1188: | |
| 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(); |
| 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: | |
| 1233: | |
| 1234: | |
| 1235: | |
| 1236: | |
| 1237: | |
| 1238: | |
| 1239: | public function getUserByNameRequest($username) |
| 1240: | { |
| 1241: | |
| 1242: | |
| 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: | |
| 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: | |
| 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: | |
| 1293: | $httpBody = new MultipartStream($multipartContents); |
| 1294: | |
| 1295: | } elseif ($headers['Content-Type'] === 'application/json') { |
| 1296: | $httpBody = \GuzzleHttp\json_encode($formParams); |
| 1297: | |
| 1298: | } else { |
| 1299: | |
| 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: | |
| 1328: | |
| 1329: | |
| 1330: | |
| 1331: | |
| 1332: | |
| 1333: | |
| 1334: | |
| 1335: | |
| 1336: | |
| 1337: | |
| 1338: | public function loginUser($username, $password) |
| 1339: | { |
| 1340: | list($response) = $this->loginUserWithHttpInfo($username, $password); |
| 1341: | return $response; |
| 1342: | } |
| 1343: | |
| 1344: | |
| 1345: | |
| 1346: | |
| 1347: | |
| 1348: | |
| 1349: | |
| 1350: | |
| 1351: | |
| 1352: | |
| 1353: | |
| 1354: | |
| 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(); |
| 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(); |
| 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: | |
| 1446: | |
| 1447: | |
| 1448: | |
| 1449: | |
| 1450: | |
| 1451: | |
| 1452: | |
| 1453: | |
| 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: | |
| 1467: | |
| 1468: | |
| 1469: | |
| 1470: | |
| 1471: | |
| 1472: | |
| 1473: | |
| 1474: | |
| 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(); |
| 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: | |
| 1519: | |
| 1520: | |
| 1521: | |
| 1522: | |
| 1523: | |
| 1524: | |
| 1525: | |
| 1526: | public function loginUserRequest($username, $password) |
| 1527: | { |
| 1528: | |
| 1529: | |
| 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: | |
| 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: | |
| 1555: | $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( |
| 1556: | $username, |
| 1557: | 'username', |
| 1558: | 'string', |
| 1559: | 'form', |
| 1560: | true, |
| 1561: | true |
| 1562: | ) ?? []); |
| 1563: | |
| 1564: | $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( |
| 1565: | $password, |
| 1566: | 'password', |
| 1567: | 'string', |
| 1568: | 'form', |
| 1569: | true, |
| 1570: | true |
| 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: | |
| 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: | |
| 1601: | $httpBody = new MultipartStream($multipartContents); |
| 1602: | |
| 1603: | } elseif ($headers['Content-Type'] === 'application/json') { |
| 1604: | $httpBody = \GuzzleHttp\json_encode($formParams); |
| 1605: | |
| 1606: | } else { |
| 1607: | |
| 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: | |
| 1636: | |
| 1637: | |
| 1638: | |
| 1639: | |
| 1640: | |
| 1641: | |
| 1642: | |
| 1643: | |
| 1644: | public function logoutUser() |
| 1645: | { |
| 1646: | $this->logoutUserWithHttpInfo(); |
| 1647: | } |
| 1648: | |
| 1649: | |
| 1650: | |
| 1651: | |
| 1652: | |
| 1653: | |
| 1654: | |
| 1655: | |
| 1656: | |
| 1657: | |
| 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: | |
| 1709: | |
| 1710: | |
| 1711: | |
| 1712: | |
| 1713: | |
| 1714: | |
| 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: | |
| 1728: | |
| 1729: | |
| 1730: | |
| 1731: | |
| 1732: | |
| 1733: | |
| 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: | |
| 1765: | |
| 1766: | |
| 1767: | |
| 1768: | |
| 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: | |
| 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: | |
| 1809: | $httpBody = new MultipartStream($multipartContents); |
| 1810: | |
| 1811: | } elseif ($headers['Content-Type'] === 'application/json') { |
| 1812: | $httpBody = \GuzzleHttp\json_encode($formParams); |
| 1813: | |
| 1814: | } else { |
| 1815: | |
| 1816: | $httpBody = ObjectSerializer::buildQuery($formParams); |
| 1817: | } |
| 1818: | } |
| 1819: | |
| 1820: | |
| 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: | |
| 1849: | |
| 1850: | |
| 1851: | |
| 1852: | |
| 1853: | |
| 1854: | |
| 1855: | |
| 1856: | |
| 1857: | |
| 1858: | |
| 1859: | public function updateUser($username, $user) |
| 1860: | { |
| 1861: | $this->updateUserWithHttpInfo($username, $user); |
| 1862: | } |
| 1863: | |
| 1864: | |
| 1865: | |
| 1866: | |
| 1867: | |
| 1868: | |
| 1869: | |
| 1870: | |
| 1871: | |
| 1872: | |
| 1873: | |
| 1874: | |
| 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: | |
| 1926: | |
| 1927: | |
| 1928: | |
| 1929: | |
| 1930: | |
| 1931: | |
| 1932: | |
| 1933: | |
| 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: | |
| 1947: | |
| 1948: | |
| 1949: | |
| 1950: | |
| 1951: | |
| 1952: | |
| 1953: | |
| 1954: | |
| 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: | |
| 1986: | |
| 1987: | |
| 1988: | |
| 1989: | |
| 1990: | |
| 1991: | |
| 1992: | |
| 1993: | public function updateUserRequest($username, $user) |
| 1994: | { |
| 1995: | |
| 1996: | |
| 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: | |
| 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: | |
| 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: | |
| 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: | |
| 2060: | $httpBody = new MultipartStream($multipartContents); |
| 2061: | |
| 2062: | } elseif ($headers['Content-Type'] === 'application/json') { |
| 2063: | $httpBody = \GuzzleHttp\json_encode($formParams); |
| 2064: | |
| 2065: | } else { |
| 2066: | |
| 2067: | $httpBody = ObjectSerializer::buildQuery($formParams); |
| 2068: | } |
| 2069: | } |
| 2070: | |
| 2071: | |
| 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: | |
| 2100: | |
| 2101: | |
| 2102: | |
| 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: | |