2
0

InvitesApi.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. <?php
  2. /**
  3. * InvitesApi
  4. * PHP version 8.1
  5. *
  6. * @category Class
  7. * @package WikipaliApi
  8. * @author OpenAPI Generator team
  9. * @link https://openapi-generator.tech
  10. */
  11. /**
  12. * MINT API
  13. *
  14. * International Academy Of Pali Tipitaka(国际巴利三藏学院) 由 `php openapi/scripts/generate.php` 依据 api-v13 的路由与控制器源码生成。 响应统一封装为 `{ok, message, data}`;`ok=false` 时 `message` 为错误信息。
  15. *
  16. * The version of the OpenAPI document: 2026.10.8
  17. * Generated by: https://openapi-generator.tech
  18. * Generator version: 7.25.0
  19. */
  20. /**
  21. * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
  22. * https://openapi-generator.tech
  23. * Do not edit the class manually.
  24. */
  25. namespace WikipaliApi\Api;
  26. use GuzzleHttp\Client;
  27. use GuzzleHttp\ClientInterface;
  28. use GuzzleHttp\Exception\ConnectException;
  29. use GuzzleHttp\Exception\RequestException;
  30. use GuzzleHttp\Psr7\MultipartStream;
  31. use GuzzleHttp\Psr7\Request;
  32. use GuzzleHttp\RequestOptions;
  33. use Psr\Http\Message\RequestInterface;
  34. use Psr\Http\Message\ResponseInterface;
  35. use WikipaliApi\ApiException;
  36. use WikipaliApi\Configuration;
  37. use WikipaliApi\FormDataProcessor;
  38. use WikipaliApi\HeaderSelector;
  39. use WikipaliApi\ObjectSerializer;
  40. /**
  41. * InvitesApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class InvitesApi
  49. {
  50. /**
  51. * @var ClientInterface
  52. */
  53. protected $client;
  54. /**
  55. * @var Configuration
  56. */
  57. protected $config;
  58. /**
  59. * @var HeaderSelector
  60. */
  61. protected $headerSelector;
  62. /**
  63. * @var int Host index
  64. */
  65. protected $hostIndex;
  66. /** @var string[] $contentTypes **/
  67. public const contentTypes = [
  68. 'getApiV3InvitesInvite' => [
  69. 'application/json',
  70. ],
  71. 'postApiV3Invites' => [
  72. 'application/json',
  73. ],
  74. ];
  75. /**
  76. * @param ClientInterface $client
  77. * @param Configuration $config
  78. * @param HeaderSelector $selector
  79. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  80. */
  81. public function __construct(
  82. ?ClientInterface $client = null,
  83. ?Configuration $config = null,
  84. ?HeaderSelector $selector = null,
  85. int $hostIndex = 0
  86. ) {
  87. $this->client = $client ?: new Client();
  88. $this->config = $config ?: Configuration::getDefaultConfiguration();
  89. $this->headerSelector = $selector ?: new HeaderSelector();
  90. $this->hostIndex = $hostIndex;
  91. }
  92. /**
  93. * Set the host index
  94. *
  95. * @param int $hostIndex Host index (required)
  96. */
  97. public function setHostIndex($hostIndex): void
  98. {
  99. $this->hostIndex = $hostIndex;
  100. }
  101. /**
  102. * Get the host index
  103. *
  104. * @return int Host index
  105. */
  106. public function getHostIndex()
  107. {
  108. return $this->hostIndex;
  109. }
  110. /**
  111. * @return Configuration
  112. */
  113. public function getConfig()
  114. {
  115. return $this->config;
  116. }
  117. /**
  118. * Operation getApiV3InvitesInvite
  119. *
  120. * 查看一条可用的注册邀请
  121. *
  122. * @param string $invite 邀请邮件链接里的 uuid (required)
  123. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3InvitesInvite'] to see the possible values for this operation
  124. *
  125. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  126. * @throws \InvalidArgumentException
  127. * @return \WikipaliApi\Model\PostApiV3Invites200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  128. */
  129. public function getApiV3InvitesInvite($invite, string $contentType = self::contentTypes['getApiV3InvitesInvite'][0])
  130. {
  131. list($response) = $this->getApiV3InvitesInviteWithHttpInfo($invite, $contentType);
  132. return $response;
  133. }
  134. /**
  135. * Operation getApiV3InvitesInviteWithHttpInfo
  136. *
  137. * 查看一条可用的注册邀请
  138. *
  139. * @param string $invite 邀请邮件链接里的 uuid (required)
  140. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3InvitesInvite'] to see the possible values for this operation
  141. *
  142. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  143. * @throws \InvalidArgumentException
  144. * @return array of \WikipaliApi\Model\PostApiV3Invites200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  145. */
  146. public function getApiV3InvitesInviteWithHttpInfo($invite, string $contentType = self::contentTypes['getApiV3InvitesInvite'][0])
  147. {
  148. $request = $this->getApiV3InvitesInviteRequest($invite, $contentType);
  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. $statusCode = $response->getStatusCode();
  169. switch($statusCode) {
  170. case 200:
  171. return $this->handleResponseWithDataType(
  172. '\WikipaliApi\Model\PostApiV3Invites200Response',
  173. $request,
  174. $response,
  175. );
  176. case 404:
  177. return $this->handleResponseWithDataType(
  178. '\WikipaliApi\Model\ProblemDetails',
  179. $request,
  180. $response,
  181. );
  182. case 422:
  183. return $this->handleResponseWithDataType(
  184. '\WikipaliApi\Model\ProblemDetails',
  185. $request,
  186. $response,
  187. );
  188. }
  189. if ($statusCode < 200 || $statusCode > 299) {
  190. throw new ApiException(
  191. sprintf(
  192. '[%d] Error connecting to the API (%s)',
  193. $statusCode,
  194. (string) $request->getUri()
  195. ),
  196. $statusCode,
  197. $response->getHeaders(),
  198. (string) $response->getBody()
  199. );
  200. }
  201. return $this->handleResponseWithDataType(
  202. '\WikipaliApi\Model\PostApiV3Invites200Response',
  203. $request,
  204. $response,
  205. );
  206. } catch (ApiException $e) {
  207. switch ($e->getCode()) {
  208. case 200:
  209. $data = ObjectSerializer::deserialize(
  210. $e->getResponseBody(),
  211. '\WikipaliApi\Model\PostApiV3Invites200Response',
  212. $e->getResponseHeaders()
  213. );
  214. $e->setResponseObject($data);
  215. throw $e;
  216. case 404:
  217. $data = ObjectSerializer::deserialize(
  218. $e->getResponseBody(),
  219. '\WikipaliApi\Model\ProblemDetails',
  220. $e->getResponseHeaders()
  221. );
  222. $e->setResponseObject($data);
  223. throw $e;
  224. case 422:
  225. $data = ObjectSerializer::deserialize(
  226. $e->getResponseBody(),
  227. '\WikipaliApi\Model\ProblemDetails',
  228. $e->getResponseHeaders()
  229. );
  230. $e->setResponseObject($data);
  231. throw $e;
  232. }
  233. throw $e;
  234. }
  235. }
  236. /**
  237. * Operation getApiV3InvitesInviteAsync
  238. *
  239. * 查看一条可用的注册邀请
  240. *
  241. * @param string $invite 邀请邮件链接里的 uuid (required)
  242. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3InvitesInvite'] to see the possible values for this operation
  243. *
  244. * @throws \InvalidArgumentException
  245. * @return \GuzzleHttp\Promise\PromiseInterface
  246. */
  247. public function getApiV3InvitesInviteAsync($invite, string $contentType = self::contentTypes['getApiV3InvitesInvite'][0])
  248. {
  249. return $this->getApiV3InvitesInviteAsyncWithHttpInfo($invite, $contentType)
  250. ->then(
  251. function ($response) {
  252. return $response[0];
  253. }
  254. );
  255. }
  256. /**
  257. * Operation getApiV3InvitesInviteAsyncWithHttpInfo
  258. *
  259. * 查看一条可用的注册邀请
  260. *
  261. * @param string $invite 邀请邮件链接里的 uuid (required)
  262. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3InvitesInvite'] to see the possible values for this operation
  263. *
  264. * @throws \InvalidArgumentException
  265. * @return \GuzzleHttp\Promise\PromiseInterface
  266. */
  267. public function getApiV3InvitesInviteAsyncWithHttpInfo($invite, string $contentType = self::contentTypes['getApiV3InvitesInvite'][0])
  268. {
  269. $returnType = '\WikipaliApi\Model\PostApiV3Invites200Response';
  270. $request = $this->getApiV3InvitesInviteRequest($invite, $contentType);
  271. return $this->client
  272. ->sendAsync($request, $this->createHttpClientOption())
  273. ->then(
  274. function ($response) use ($returnType) {
  275. if ($returnType === '\SplFileObject') {
  276. $content = $response->getBody(); //stream goes to serializer
  277. } else {
  278. $content = (string) $response->getBody();
  279. if ($returnType !== 'string') {
  280. $content = json_decode($content);
  281. }
  282. }
  283. return [
  284. ObjectSerializer::deserialize($content, $returnType, []),
  285. $response->getStatusCode(),
  286. $response->getHeaders()
  287. ];
  288. },
  289. function ($exception) {
  290. $response = $exception->getResponse();
  291. $statusCode = $response->getStatusCode();
  292. throw new ApiException(
  293. sprintf(
  294. '[%d] Error connecting to the API (%s)',
  295. $statusCode,
  296. $exception->getRequest()->getUri()
  297. ),
  298. $statusCode,
  299. $response->getHeaders(),
  300. (string) $response->getBody()
  301. );
  302. }
  303. );
  304. }
  305. /**
  306. * Create request for operation 'getApiV3InvitesInvite'
  307. *
  308. * @param string $invite 邀请邮件链接里的 uuid (required)
  309. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3InvitesInvite'] to see the possible values for this operation
  310. *
  311. * @throws \InvalidArgumentException
  312. * @return \GuzzleHttp\Psr7\Request
  313. */
  314. public function getApiV3InvitesInviteRequest($invite, string $contentType = self::contentTypes['getApiV3InvitesInvite'][0])
  315. {
  316. // verify the required parameter 'invite' is set
  317. if ($invite === null || (is_array($invite) && count($invite) === 0)) {
  318. throw new \InvalidArgumentException(
  319. 'Missing the required parameter $invite when calling getApiV3InvitesInvite'
  320. );
  321. }
  322. $resourcePath = '/v3/invites/{invite}';
  323. $formParams = [];
  324. $queryParams = [];
  325. $headerParams = [];
  326. $httpBody = '';
  327. $multipart = false;
  328. // path params
  329. if ($invite !== null) {
  330. $resourcePath = str_replace(
  331. '{invite}',
  332. ObjectSerializer::toPathValue($invite),
  333. $resourcePath
  334. );
  335. }
  336. $headers = $this->headerSelector->selectHeaders(
  337. ['application/json', 'application/problem+json', ],
  338. $contentType,
  339. $multipart
  340. );
  341. // for model (json/xml)
  342. if (count($formParams) > 0) {
  343. if ($multipart) {
  344. $multipartContents = [];
  345. foreach ($formParams as $formParamName => $formParamValue) {
  346. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  347. foreach ($formParamValueItems as $formParamValueItem) {
  348. $multipartContents[] = [
  349. 'name' => $formParamName,
  350. 'contents' => $formParamValueItem
  351. ];
  352. }
  353. }
  354. // for HTTP post (form)
  355. $httpBody = new MultipartStream($multipartContents);
  356. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  357. # if Content-Type contains "application/json", json_encode the form parameters
  358. try {
  359. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  360. } catch (\JsonException $e) {
  361. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  362. }
  363. } else {
  364. // for HTTP post (form)
  365. $httpBody = ObjectSerializer::buildQuery($formParams);
  366. }
  367. }
  368. $defaultHeaders = [];
  369. if ($this->config->getUserAgent()) {
  370. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  371. }
  372. $headers = array_merge(
  373. $defaultHeaders,
  374. $headerParams,
  375. $headers
  376. );
  377. $operationHost = $this->config->getHost();
  378. $query = ObjectSerializer::buildQuery($queryParams);
  379. return new Request(
  380. 'GET',
  381. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  382. $headers,
  383. $httpBody
  384. );
  385. }
  386. /**
  387. * Operation postApiV3Invites
  388. *
  389. * 用验证码换注册邀请
  390. *
  391. * @param \WikipaliApi\Model\PostApiV3InvitesRequest $post_api_v3_invites_request post_api_v3_invites_request (required)
  392. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Invites'] to see the possible values for this operation
  393. *
  394. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  395. * @throws \InvalidArgumentException
  396. * @return \WikipaliApi\Model\PostApiV3Invites200Response|\WikipaliApi\Model\PostApiV3Invites200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  397. */
  398. public function postApiV3Invites($post_api_v3_invites_request, string $contentType = self::contentTypes['postApiV3Invites'][0])
  399. {
  400. list($response) = $this->postApiV3InvitesWithHttpInfo($post_api_v3_invites_request, $contentType);
  401. return $response;
  402. }
  403. /**
  404. * Operation postApiV3InvitesWithHttpInfo
  405. *
  406. * 用验证码换注册邀请
  407. *
  408. * @param \WikipaliApi\Model\PostApiV3InvitesRequest $post_api_v3_invites_request (required)
  409. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Invites'] to see the possible values for this operation
  410. *
  411. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  412. * @throws \InvalidArgumentException
  413. * @return array of \WikipaliApi\Model\PostApiV3Invites200Response|\WikipaliApi\Model\PostApiV3Invites200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  414. */
  415. public function postApiV3InvitesWithHttpInfo($post_api_v3_invites_request, string $contentType = self::contentTypes['postApiV3Invites'][0])
  416. {
  417. $request = $this->postApiV3InvitesRequest($post_api_v3_invites_request, $contentType);
  418. try {
  419. $options = $this->createHttpClientOption();
  420. try {
  421. $response = $this->client->send($request, $options);
  422. } catch (RequestException $e) {
  423. throw new ApiException(
  424. "[{$e->getCode()}] {$e->getMessage()}",
  425. (int) $e->getCode(),
  426. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  427. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  428. );
  429. } catch (ConnectException $e) {
  430. throw new ApiException(
  431. "[{$e->getCode()}] {$e->getMessage()}",
  432. (int) $e->getCode(),
  433. null,
  434. null
  435. );
  436. }
  437. $statusCode = $response->getStatusCode();
  438. switch($statusCode) {
  439. case 200:
  440. return $this->handleResponseWithDataType(
  441. '\WikipaliApi\Model\PostApiV3Invites200Response',
  442. $request,
  443. $response,
  444. );
  445. case 201:
  446. return $this->handleResponseWithDataType(
  447. '\WikipaliApi\Model\PostApiV3Invites200Response',
  448. $request,
  449. $response,
  450. );
  451. case 422:
  452. return $this->handleResponseWithDataType(
  453. '\WikipaliApi\Model\ProblemDetails',
  454. $request,
  455. $response,
  456. );
  457. case 429:
  458. return $this->handleResponseWithDataType(
  459. '\WikipaliApi\Model\ProblemDetails',
  460. $request,
  461. $response,
  462. );
  463. }
  464. if ($statusCode < 200 || $statusCode > 299) {
  465. throw new ApiException(
  466. sprintf(
  467. '[%d] Error connecting to the API (%s)',
  468. $statusCode,
  469. (string) $request->getUri()
  470. ),
  471. $statusCode,
  472. $response->getHeaders(),
  473. (string) $response->getBody()
  474. );
  475. }
  476. return $this->handleResponseWithDataType(
  477. '\WikipaliApi\Model\PostApiV3Invites200Response',
  478. $request,
  479. $response,
  480. );
  481. } catch (ApiException $e) {
  482. switch ($e->getCode()) {
  483. case 200:
  484. $data = ObjectSerializer::deserialize(
  485. $e->getResponseBody(),
  486. '\WikipaliApi\Model\PostApiV3Invites200Response',
  487. $e->getResponseHeaders()
  488. );
  489. $e->setResponseObject($data);
  490. throw $e;
  491. case 201:
  492. $data = ObjectSerializer::deserialize(
  493. $e->getResponseBody(),
  494. '\WikipaliApi\Model\PostApiV3Invites200Response',
  495. $e->getResponseHeaders()
  496. );
  497. $e->setResponseObject($data);
  498. throw $e;
  499. case 422:
  500. $data = ObjectSerializer::deserialize(
  501. $e->getResponseBody(),
  502. '\WikipaliApi\Model\ProblemDetails',
  503. $e->getResponseHeaders()
  504. );
  505. $e->setResponseObject($data);
  506. throw $e;
  507. case 429:
  508. $data = ObjectSerializer::deserialize(
  509. $e->getResponseBody(),
  510. '\WikipaliApi\Model\ProblemDetails',
  511. $e->getResponseHeaders()
  512. );
  513. $e->setResponseObject($data);
  514. throw $e;
  515. }
  516. throw $e;
  517. }
  518. }
  519. /**
  520. * Operation postApiV3InvitesAsync
  521. *
  522. * 用验证码换注册邀请
  523. *
  524. * @param \WikipaliApi\Model\PostApiV3InvitesRequest $post_api_v3_invites_request (required)
  525. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Invites'] to see the possible values for this operation
  526. *
  527. * @throws \InvalidArgumentException
  528. * @return \GuzzleHttp\Promise\PromiseInterface
  529. */
  530. public function postApiV3InvitesAsync($post_api_v3_invites_request, string $contentType = self::contentTypes['postApiV3Invites'][0])
  531. {
  532. return $this->postApiV3InvitesAsyncWithHttpInfo($post_api_v3_invites_request, $contentType)
  533. ->then(
  534. function ($response) {
  535. return $response[0];
  536. }
  537. );
  538. }
  539. /**
  540. * Operation postApiV3InvitesAsyncWithHttpInfo
  541. *
  542. * 用验证码换注册邀请
  543. *
  544. * @param \WikipaliApi\Model\PostApiV3InvitesRequest $post_api_v3_invites_request (required)
  545. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Invites'] to see the possible values for this operation
  546. *
  547. * @throws \InvalidArgumentException
  548. * @return \GuzzleHttp\Promise\PromiseInterface
  549. */
  550. public function postApiV3InvitesAsyncWithHttpInfo($post_api_v3_invites_request, string $contentType = self::contentTypes['postApiV3Invites'][0])
  551. {
  552. $returnType = '\WikipaliApi\Model\PostApiV3Invites200Response';
  553. $request = $this->postApiV3InvitesRequest($post_api_v3_invites_request, $contentType);
  554. return $this->client
  555. ->sendAsync($request, $this->createHttpClientOption())
  556. ->then(
  557. function ($response) use ($returnType) {
  558. if ($returnType === '\SplFileObject') {
  559. $content = $response->getBody(); //stream goes to serializer
  560. } else {
  561. $content = (string) $response->getBody();
  562. if ($returnType !== 'string') {
  563. $content = json_decode($content);
  564. }
  565. }
  566. return [
  567. ObjectSerializer::deserialize($content, $returnType, []),
  568. $response->getStatusCode(),
  569. $response->getHeaders()
  570. ];
  571. },
  572. function ($exception) {
  573. $response = $exception->getResponse();
  574. $statusCode = $response->getStatusCode();
  575. throw new ApiException(
  576. sprintf(
  577. '[%d] Error connecting to the API (%s)',
  578. $statusCode,
  579. $exception->getRequest()->getUri()
  580. ),
  581. $statusCode,
  582. $response->getHeaders(),
  583. (string) $response->getBody()
  584. );
  585. }
  586. );
  587. }
  588. /**
  589. * Create request for operation 'postApiV3Invites'
  590. *
  591. * @param \WikipaliApi\Model\PostApiV3InvitesRequest $post_api_v3_invites_request (required)
  592. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Invites'] to see the possible values for this operation
  593. *
  594. * @throws \InvalidArgumentException
  595. * @return \GuzzleHttp\Psr7\Request
  596. */
  597. public function postApiV3InvitesRequest($post_api_v3_invites_request, string $contentType = self::contentTypes['postApiV3Invites'][0])
  598. {
  599. // verify the required parameter 'post_api_v3_invites_request' is set
  600. if ($post_api_v3_invites_request === null || (is_array($post_api_v3_invites_request) && count($post_api_v3_invites_request) === 0)) {
  601. throw new \InvalidArgumentException(
  602. 'Missing the required parameter $post_api_v3_invites_request when calling postApiV3Invites'
  603. );
  604. }
  605. $resourcePath = '/v3/invites';
  606. $formParams = [];
  607. $queryParams = [];
  608. $headerParams = [];
  609. $httpBody = '';
  610. $multipart = false;
  611. $headers = $this->headerSelector->selectHeaders(
  612. ['application/json', 'application/problem+json', ],
  613. $contentType,
  614. $multipart
  615. );
  616. // for model (json/xml)
  617. if (isset($post_api_v3_invites_request)) {
  618. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  619. # if Content-Type contains "application/json", json_encode the body
  620. try {
  621. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_invites_request), JSON_THROW_ON_ERROR);
  622. } catch (\JsonException $e) {
  623. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  624. }
  625. } else {
  626. $httpBody = $post_api_v3_invites_request;
  627. }
  628. } elseif (count($formParams) > 0) {
  629. if ($multipart) {
  630. $multipartContents = [];
  631. foreach ($formParams as $formParamName => $formParamValue) {
  632. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  633. foreach ($formParamValueItems as $formParamValueItem) {
  634. $multipartContents[] = [
  635. 'name' => $formParamName,
  636. 'contents' => $formParamValueItem
  637. ];
  638. }
  639. }
  640. // for HTTP post (form)
  641. $httpBody = new MultipartStream($multipartContents);
  642. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  643. # if Content-Type contains "application/json", json_encode the form parameters
  644. try {
  645. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  646. } catch (\JsonException $e) {
  647. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  648. }
  649. } else {
  650. // for HTTP post (form)
  651. $httpBody = ObjectSerializer::buildQuery($formParams);
  652. }
  653. }
  654. $defaultHeaders = [];
  655. if ($this->config->getUserAgent()) {
  656. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  657. }
  658. $headers = array_merge(
  659. $defaultHeaders,
  660. $headerParams,
  661. $headers
  662. );
  663. $operationHost = $this->config->getHost();
  664. $query = ObjectSerializer::buildQuery($queryParams);
  665. return new Request(
  666. 'POST',
  667. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  668. $headers,
  669. $httpBody
  670. );
  671. }
  672. /**
  673. * Create http client option
  674. *
  675. * @throws \RuntimeException on file opening failure
  676. * @return array of http client options
  677. */
  678. protected function createHttpClientOption()
  679. {
  680. $options = [];
  681. if ($this->config->getDebug()) {
  682. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  683. if (!$options[RequestOptions::DEBUG]) {
  684. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  685. }
  686. }
  687. if ($this->config->getCertFile()) {
  688. $options[RequestOptions::CERT] = $this->config->getCertFile();
  689. }
  690. if ($this->config->getKeyFile()) {
  691. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  692. }
  693. return $options;
  694. }
  695. private function handleResponseWithDataType(
  696. string $dataType,
  697. RequestInterface $request,
  698. ResponseInterface $response
  699. ): array {
  700. if ($dataType === '\SplFileObject') {
  701. $content = $response->getBody(); //stream goes to serializer
  702. } else {
  703. $content = (string) $response->getBody();
  704. if ($dataType !== 'string') {
  705. try {
  706. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  707. } catch (\JsonException $exception) {
  708. throw new ApiException(
  709. sprintf(
  710. 'Error JSON decoding server response (%s)',
  711. $request->getUri()
  712. ),
  713. $response->getStatusCode(),
  714. $response->getHeaders(),
  715. $content
  716. );
  717. }
  718. }
  719. }
  720. return [
  721. ObjectSerializer::deserialize($content, $dataType, []),
  722. $response->getStatusCode(),
  723. $response->getHeaders()
  724. ];
  725. }
  726. private function responseWithinRangeCode(
  727. string $rangeCode,
  728. int $statusCode
  729. ): bool {
  730. $left = (int) ($rangeCode[0].'00');
  731. $right = (int) ($rangeCode[0].'99');
  732. return $statusCode >= $left && $statusCode <= $right;
  733. }
  734. }