InvitesApi.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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.15
  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. // this endpoint requires Bearer authentication (access token)
  369. if (!empty($this->config->getAccessToken())) {
  370. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  371. }
  372. $defaultHeaders = [];
  373. if ($this->config->getUserAgent()) {
  374. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  375. }
  376. $headers = array_merge(
  377. $defaultHeaders,
  378. $headerParams,
  379. $headers
  380. );
  381. $operationHost = $this->config->getHost();
  382. $query = ObjectSerializer::buildQuery($queryParams);
  383. return new Request(
  384. 'GET',
  385. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  386. $headers,
  387. $httpBody
  388. );
  389. }
  390. /**
  391. * Operation postApiV3Invites
  392. *
  393. * 用验证码换注册邀请
  394. *
  395. * @param \WikipaliApi\Model\PostApiV3InvitesRequest $post_api_v3_invites_request post_api_v3_invites_request (required)
  396. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Invites'] to see the possible values for this operation
  397. *
  398. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  399. * @throws \InvalidArgumentException
  400. * @return \WikipaliApi\Model\PostApiV3Invites200Response|\WikipaliApi\Model\PostApiV3Invites200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  401. */
  402. public function postApiV3Invites($post_api_v3_invites_request, string $contentType = self::contentTypes['postApiV3Invites'][0])
  403. {
  404. list($response) = $this->postApiV3InvitesWithHttpInfo($post_api_v3_invites_request, $contentType);
  405. return $response;
  406. }
  407. /**
  408. * Operation postApiV3InvitesWithHttpInfo
  409. *
  410. * 用验证码换注册邀请
  411. *
  412. * @param \WikipaliApi\Model\PostApiV3InvitesRequest $post_api_v3_invites_request (required)
  413. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Invites'] to see the possible values for this operation
  414. *
  415. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  416. * @throws \InvalidArgumentException
  417. * @return array of \WikipaliApi\Model\PostApiV3Invites200Response|\WikipaliApi\Model\PostApiV3Invites200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  418. */
  419. public function postApiV3InvitesWithHttpInfo($post_api_v3_invites_request, string $contentType = self::contentTypes['postApiV3Invites'][0])
  420. {
  421. $request = $this->postApiV3InvitesRequest($post_api_v3_invites_request, $contentType);
  422. try {
  423. $options = $this->createHttpClientOption();
  424. try {
  425. $response = $this->client->send($request, $options);
  426. } catch (RequestException $e) {
  427. throw new ApiException(
  428. "[{$e->getCode()}] {$e->getMessage()}",
  429. (int) $e->getCode(),
  430. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  431. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  432. );
  433. } catch (ConnectException $e) {
  434. throw new ApiException(
  435. "[{$e->getCode()}] {$e->getMessage()}",
  436. (int) $e->getCode(),
  437. null,
  438. null
  439. );
  440. }
  441. $statusCode = $response->getStatusCode();
  442. switch($statusCode) {
  443. case 200:
  444. return $this->handleResponseWithDataType(
  445. '\WikipaliApi\Model\PostApiV3Invites200Response',
  446. $request,
  447. $response,
  448. );
  449. case 201:
  450. return $this->handleResponseWithDataType(
  451. '\WikipaliApi\Model\PostApiV3Invites200Response',
  452. $request,
  453. $response,
  454. );
  455. case 422:
  456. return $this->handleResponseWithDataType(
  457. '\WikipaliApi\Model\ProblemDetails',
  458. $request,
  459. $response,
  460. );
  461. case 429:
  462. return $this->handleResponseWithDataType(
  463. '\WikipaliApi\Model\ProblemDetails',
  464. $request,
  465. $response,
  466. );
  467. }
  468. if ($statusCode < 200 || $statusCode > 299) {
  469. throw new ApiException(
  470. sprintf(
  471. '[%d] Error connecting to the API (%s)',
  472. $statusCode,
  473. (string) $request->getUri()
  474. ),
  475. $statusCode,
  476. $response->getHeaders(),
  477. (string) $response->getBody()
  478. );
  479. }
  480. return $this->handleResponseWithDataType(
  481. '\WikipaliApi\Model\PostApiV3Invites200Response',
  482. $request,
  483. $response,
  484. );
  485. } catch (ApiException $e) {
  486. switch ($e->getCode()) {
  487. case 200:
  488. $data = ObjectSerializer::deserialize(
  489. $e->getResponseBody(),
  490. '\WikipaliApi\Model\PostApiV3Invites200Response',
  491. $e->getResponseHeaders()
  492. );
  493. $e->setResponseObject($data);
  494. throw $e;
  495. case 201:
  496. $data = ObjectSerializer::deserialize(
  497. $e->getResponseBody(),
  498. '\WikipaliApi\Model\PostApiV3Invites200Response',
  499. $e->getResponseHeaders()
  500. );
  501. $e->setResponseObject($data);
  502. throw $e;
  503. case 422:
  504. $data = ObjectSerializer::deserialize(
  505. $e->getResponseBody(),
  506. '\WikipaliApi\Model\ProblemDetails',
  507. $e->getResponseHeaders()
  508. );
  509. $e->setResponseObject($data);
  510. throw $e;
  511. case 429:
  512. $data = ObjectSerializer::deserialize(
  513. $e->getResponseBody(),
  514. '\WikipaliApi\Model\ProblemDetails',
  515. $e->getResponseHeaders()
  516. );
  517. $e->setResponseObject($data);
  518. throw $e;
  519. }
  520. throw $e;
  521. }
  522. }
  523. /**
  524. * Operation postApiV3InvitesAsync
  525. *
  526. * 用验证码换注册邀请
  527. *
  528. * @param \WikipaliApi\Model\PostApiV3InvitesRequest $post_api_v3_invites_request (required)
  529. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Invites'] to see the possible values for this operation
  530. *
  531. * @throws \InvalidArgumentException
  532. * @return \GuzzleHttp\Promise\PromiseInterface
  533. */
  534. public function postApiV3InvitesAsync($post_api_v3_invites_request, string $contentType = self::contentTypes['postApiV3Invites'][0])
  535. {
  536. return $this->postApiV3InvitesAsyncWithHttpInfo($post_api_v3_invites_request, $contentType)
  537. ->then(
  538. function ($response) {
  539. return $response[0];
  540. }
  541. );
  542. }
  543. /**
  544. * Operation postApiV3InvitesAsyncWithHttpInfo
  545. *
  546. * 用验证码换注册邀请
  547. *
  548. * @param \WikipaliApi\Model\PostApiV3InvitesRequest $post_api_v3_invites_request (required)
  549. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Invites'] to see the possible values for this operation
  550. *
  551. * @throws \InvalidArgumentException
  552. * @return \GuzzleHttp\Promise\PromiseInterface
  553. */
  554. public function postApiV3InvitesAsyncWithHttpInfo($post_api_v3_invites_request, string $contentType = self::contentTypes['postApiV3Invites'][0])
  555. {
  556. $returnType = '\WikipaliApi\Model\PostApiV3Invites200Response';
  557. $request = $this->postApiV3InvitesRequest($post_api_v3_invites_request, $contentType);
  558. return $this->client
  559. ->sendAsync($request, $this->createHttpClientOption())
  560. ->then(
  561. function ($response) use ($returnType) {
  562. if ($returnType === '\SplFileObject') {
  563. $content = $response->getBody(); //stream goes to serializer
  564. } else {
  565. $content = (string) $response->getBody();
  566. if ($returnType !== 'string') {
  567. $content = json_decode($content);
  568. }
  569. }
  570. return [
  571. ObjectSerializer::deserialize($content, $returnType, []),
  572. $response->getStatusCode(),
  573. $response->getHeaders()
  574. ];
  575. },
  576. function ($exception) {
  577. $response = $exception->getResponse();
  578. $statusCode = $response->getStatusCode();
  579. throw new ApiException(
  580. sprintf(
  581. '[%d] Error connecting to the API (%s)',
  582. $statusCode,
  583. $exception->getRequest()->getUri()
  584. ),
  585. $statusCode,
  586. $response->getHeaders(),
  587. (string) $response->getBody()
  588. );
  589. }
  590. );
  591. }
  592. /**
  593. * Create request for operation 'postApiV3Invites'
  594. *
  595. * @param \WikipaliApi\Model\PostApiV3InvitesRequest $post_api_v3_invites_request (required)
  596. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Invites'] to see the possible values for this operation
  597. *
  598. * @throws \InvalidArgumentException
  599. * @return \GuzzleHttp\Psr7\Request
  600. */
  601. public function postApiV3InvitesRequest($post_api_v3_invites_request, string $contentType = self::contentTypes['postApiV3Invites'][0])
  602. {
  603. // verify the required parameter 'post_api_v3_invites_request' is set
  604. if ($post_api_v3_invites_request === null || (is_array($post_api_v3_invites_request) && count($post_api_v3_invites_request) === 0)) {
  605. throw new \InvalidArgumentException(
  606. 'Missing the required parameter $post_api_v3_invites_request when calling postApiV3Invites'
  607. );
  608. }
  609. $resourcePath = '/v3/invites';
  610. $formParams = [];
  611. $queryParams = [];
  612. $headerParams = [];
  613. $httpBody = '';
  614. $multipart = false;
  615. $headers = $this->headerSelector->selectHeaders(
  616. ['application/json', 'application/problem+json', ],
  617. $contentType,
  618. $multipart
  619. );
  620. // for model (json/xml)
  621. if (isset($post_api_v3_invites_request)) {
  622. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  623. # if Content-Type contains "application/json", json_encode the body
  624. try {
  625. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_invites_request), JSON_THROW_ON_ERROR);
  626. } catch (\JsonException $e) {
  627. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  628. }
  629. } else {
  630. $httpBody = $post_api_v3_invites_request;
  631. }
  632. } elseif (count($formParams) > 0) {
  633. if ($multipart) {
  634. $multipartContents = [];
  635. foreach ($formParams as $formParamName => $formParamValue) {
  636. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  637. foreach ($formParamValueItems as $formParamValueItem) {
  638. $multipartContents[] = [
  639. 'name' => $formParamName,
  640. 'contents' => $formParamValueItem
  641. ];
  642. }
  643. }
  644. // for HTTP post (form)
  645. $httpBody = new MultipartStream($multipartContents);
  646. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  647. # if Content-Type contains "application/json", json_encode the form parameters
  648. try {
  649. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  650. } catch (\JsonException $e) {
  651. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  652. }
  653. } else {
  654. // for HTTP post (form)
  655. $httpBody = ObjectSerializer::buildQuery($formParams);
  656. }
  657. }
  658. // this endpoint requires Bearer authentication (access token)
  659. if (!empty($this->config->getAccessToken())) {
  660. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  661. }
  662. $defaultHeaders = [];
  663. if ($this->config->getUserAgent()) {
  664. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  665. }
  666. $headers = array_merge(
  667. $defaultHeaders,
  668. $headerParams,
  669. $headers
  670. );
  671. $operationHost = $this->config->getHost();
  672. $query = ObjectSerializer::buildQuery($queryParams);
  673. return new Request(
  674. 'POST',
  675. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  676. $headers,
  677. $httpBody
  678. );
  679. }
  680. /**
  681. * Create http client option
  682. *
  683. * @throws \RuntimeException on file opening failure
  684. * @return array of http client options
  685. */
  686. protected function createHttpClientOption()
  687. {
  688. $options = [];
  689. if ($this->config->getDebug()) {
  690. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  691. if (!$options[RequestOptions::DEBUG]) {
  692. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  693. }
  694. }
  695. if ($this->config->getCertFile()) {
  696. $options[RequestOptions::CERT] = $this->config->getCertFile();
  697. }
  698. if ($this->config->getKeyFile()) {
  699. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  700. }
  701. return $options;
  702. }
  703. private function handleResponseWithDataType(
  704. string $dataType,
  705. RequestInterface $request,
  706. ResponseInterface $response
  707. ): array {
  708. if ($dataType === '\SplFileObject') {
  709. $content = $response->getBody(); //stream goes to serializer
  710. } else {
  711. $content = (string) $response->getBody();
  712. if ($dataType !== 'string') {
  713. try {
  714. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  715. } catch (\JsonException $exception) {
  716. throw new ApiException(
  717. sprintf(
  718. 'Error JSON decoding server response (%s)',
  719. $request->getUri()
  720. ),
  721. $response->getStatusCode(),
  722. $response->getHeaders(),
  723. $content
  724. );
  725. }
  726. }
  727. }
  728. return [
  729. ObjectSerializer::deserialize($content, $dataType, []),
  730. $response->getStatusCode(),
  731. $response->getHeaders()
  732. ];
  733. }
  734. private function responseWithinRangeCode(
  735. string $rangeCode,
  736. int $statusCode
  737. ): bool {
  738. $left = (int) ($rangeCode[0].'00');
  739. $right = (int) ($rangeCode[0].'99');
  740. return $statusCode >= $left && $statusCode <= $right;
  741. }
  742. }