PasswordResetsApi.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. <?php
  2. /**
  3. * PasswordResetsApi
  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. * PasswordResetsApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class PasswordResetsApi
  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. 'getApiV3PasswordResetsToken' => [
  69. 'application/json',
  70. ],
  71. 'patchApiV3PasswordResetsToken' => [
  72. 'application/json',
  73. ],
  74. 'postApiV3PasswordResets' => [
  75. 'application/json',
  76. ],
  77. ];
  78. /**
  79. * @param ClientInterface $client
  80. * @param Configuration $config
  81. * @param HeaderSelector $selector
  82. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  83. */
  84. public function __construct(
  85. ?ClientInterface $client = null,
  86. ?Configuration $config = null,
  87. ?HeaderSelector $selector = null,
  88. int $hostIndex = 0
  89. ) {
  90. $this->client = $client ?: new Client();
  91. $this->config = $config ?: Configuration::getDefaultConfiguration();
  92. $this->headerSelector = $selector ?: new HeaderSelector();
  93. $this->hostIndex = $hostIndex;
  94. }
  95. /**
  96. * Set the host index
  97. *
  98. * @param int $hostIndex Host index (required)
  99. */
  100. public function setHostIndex($hostIndex): void
  101. {
  102. $this->hostIndex = $hostIndex;
  103. }
  104. /**
  105. * Get the host index
  106. *
  107. * @return int Host index
  108. */
  109. public function getHostIndex()
  110. {
  111. return $this->hostIndex;
  112. }
  113. /**
  114. * @return Configuration
  115. */
  116. public function getConfig()
  117. {
  118. return $this->config;
  119. }
  120. /**
  121. * Operation getApiV3PasswordResetsToken
  122. *
  123. * 查看一次待完成的重置
  124. *
  125. * @param string $token 邮件链接里的 token (required)
  126. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3PasswordResetsToken'] to see the possible values for this operation
  127. *
  128. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  129. * @throws \InvalidArgumentException
  130. * @return \WikipaliApi\Model\GetApiV3PasswordResetsToken200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  131. */
  132. public function getApiV3PasswordResetsToken($token, string $contentType = self::contentTypes['getApiV3PasswordResetsToken'][0])
  133. {
  134. list($response) = $this->getApiV3PasswordResetsTokenWithHttpInfo($token, $contentType);
  135. return $response;
  136. }
  137. /**
  138. * Operation getApiV3PasswordResetsTokenWithHttpInfo
  139. *
  140. * 查看一次待完成的重置
  141. *
  142. * @param string $token 邮件链接里的 token (required)
  143. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3PasswordResetsToken'] to see the possible values for this operation
  144. *
  145. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  146. * @throws \InvalidArgumentException
  147. * @return array of \WikipaliApi\Model\GetApiV3PasswordResetsToken200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  148. */
  149. public function getApiV3PasswordResetsTokenWithHttpInfo($token, string $contentType = self::contentTypes['getApiV3PasswordResetsToken'][0])
  150. {
  151. $request = $this->getApiV3PasswordResetsTokenRequest($token, $contentType);
  152. try {
  153. $options = $this->createHttpClientOption();
  154. try {
  155. $response = $this->client->send($request, $options);
  156. } catch (RequestException $e) {
  157. throw new ApiException(
  158. "[{$e->getCode()}] {$e->getMessage()}",
  159. (int) $e->getCode(),
  160. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  161. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  162. );
  163. } catch (ConnectException $e) {
  164. throw new ApiException(
  165. "[{$e->getCode()}] {$e->getMessage()}",
  166. (int) $e->getCode(),
  167. null,
  168. null
  169. );
  170. }
  171. $statusCode = $response->getStatusCode();
  172. switch($statusCode) {
  173. case 200:
  174. return $this->handleResponseWithDataType(
  175. '\WikipaliApi\Model\GetApiV3PasswordResetsToken200Response',
  176. $request,
  177. $response,
  178. );
  179. case 404:
  180. return $this->handleResponseWithDataType(
  181. '\WikipaliApi\Model\ProblemDetails',
  182. $request,
  183. $response,
  184. );
  185. case 422:
  186. return $this->handleResponseWithDataType(
  187. '\WikipaliApi\Model\ProblemDetails',
  188. $request,
  189. $response,
  190. );
  191. }
  192. if ($statusCode < 200 || $statusCode > 299) {
  193. throw new ApiException(
  194. sprintf(
  195. '[%d] Error connecting to the API (%s)',
  196. $statusCode,
  197. (string) $request->getUri()
  198. ),
  199. $statusCode,
  200. $response->getHeaders(),
  201. (string) $response->getBody()
  202. );
  203. }
  204. return $this->handleResponseWithDataType(
  205. '\WikipaliApi\Model\GetApiV3PasswordResetsToken200Response',
  206. $request,
  207. $response,
  208. );
  209. } catch (ApiException $e) {
  210. switch ($e->getCode()) {
  211. case 200:
  212. $data = ObjectSerializer::deserialize(
  213. $e->getResponseBody(),
  214. '\WikipaliApi\Model\GetApiV3PasswordResetsToken200Response',
  215. $e->getResponseHeaders()
  216. );
  217. $e->setResponseObject($data);
  218. throw $e;
  219. case 404:
  220. $data = ObjectSerializer::deserialize(
  221. $e->getResponseBody(),
  222. '\WikipaliApi\Model\ProblemDetails',
  223. $e->getResponseHeaders()
  224. );
  225. $e->setResponseObject($data);
  226. throw $e;
  227. case 422:
  228. $data = ObjectSerializer::deserialize(
  229. $e->getResponseBody(),
  230. '\WikipaliApi\Model\ProblemDetails',
  231. $e->getResponseHeaders()
  232. );
  233. $e->setResponseObject($data);
  234. throw $e;
  235. }
  236. throw $e;
  237. }
  238. }
  239. /**
  240. * Operation getApiV3PasswordResetsTokenAsync
  241. *
  242. * 查看一次待完成的重置
  243. *
  244. * @param string $token 邮件链接里的 token (required)
  245. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3PasswordResetsToken'] to see the possible values for this operation
  246. *
  247. * @throws \InvalidArgumentException
  248. * @return \GuzzleHttp\Promise\PromiseInterface
  249. */
  250. public function getApiV3PasswordResetsTokenAsync($token, string $contentType = self::contentTypes['getApiV3PasswordResetsToken'][0])
  251. {
  252. return $this->getApiV3PasswordResetsTokenAsyncWithHttpInfo($token, $contentType)
  253. ->then(
  254. function ($response) {
  255. return $response[0];
  256. }
  257. );
  258. }
  259. /**
  260. * Operation getApiV3PasswordResetsTokenAsyncWithHttpInfo
  261. *
  262. * 查看一次待完成的重置
  263. *
  264. * @param string $token 邮件链接里的 token (required)
  265. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3PasswordResetsToken'] to see the possible values for this operation
  266. *
  267. * @throws \InvalidArgumentException
  268. * @return \GuzzleHttp\Promise\PromiseInterface
  269. */
  270. public function getApiV3PasswordResetsTokenAsyncWithHttpInfo($token, string $contentType = self::contentTypes['getApiV3PasswordResetsToken'][0])
  271. {
  272. $returnType = '\WikipaliApi\Model\GetApiV3PasswordResetsToken200Response';
  273. $request = $this->getApiV3PasswordResetsTokenRequest($token, $contentType);
  274. return $this->client
  275. ->sendAsync($request, $this->createHttpClientOption())
  276. ->then(
  277. function ($response) use ($returnType) {
  278. if ($returnType === '\SplFileObject') {
  279. $content = $response->getBody(); //stream goes to serializer
  280. } else {
  281. $content = (string) $response->getBody();
  282. if ($returnType !== 'string') {
  283. $content = json_decode($content);
  284. }
  285. }
  286. return [
  287. ObjectSerializer::deserialize($content, $returnType, []),
  288. $response->getStatusCode(),
  289. $response->getHeaders()
  290. ];
  291. },
  292. function ($exception) {
  293. $response = $exception->getResponse();
  294. $statusCode = $response->getStatusCode();
  295. throw new ApiException(
  296. sprintf(
  297. '[%d] Error connecting to the API (%s)',
  298. $statusCode,
  299. $exception->getRequest()->getUri()
  300. ),
  301. $statusCode,
  302. $response->getHeaders(),
  303. (string) $response->getBody()
  304. );
  305. }
  306. );
  307. }
  308. /**
  309. * Create request for operation 'getApiV3PasswordResetsToken'
  310. *
  311. * @param string $token 邮件链接里的 token (required)
  312. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3PasswordResetsToken'] to see the possible values for this operation
  313. *
  314. * @throws \InvalidArgumentException
  315. * @return \GuzzleHttp\Psr7\Request
  316. */
  317. public function getApiV3PasswordResetsTokenRequest($token, string $contentType = self::contentTypes['getApiV3PasswordResetsToken'][0])
  318. {
  319. // verify the required parameter 'token' is set
  320. if ($token === null || (is_array($token) && count($token) === 0)) {
  321. throw new \InvalidArgumentException(
  322. 'Missing the required parameter $token when calling getApiV3PasswordResetsToken'
  323. );
  324. }
  325. $resourcePath = '/v3/password-resets/{token}';
  326. $formParams = [];
  327. $queryParams = [];
  328. $headerParams = [];
  329. $httpBody = '';
  330. $multipart = false;
  331. // path params
  332. if ($token !== null) {
  333. $resourcePath = str_replace(
  334. '{token}',
  335. ObjectSerializer::toPathValue($token),
  336. $resourcePath
  337. );
  338. }
  339. $headers = $this->headerSelector->selectHeaders(
  340. ['application/json', 'application/problem+json', ],
  341. $contentType,
  342. $multipart
  343. );
  344. // for model (json/xml)
  345. if (count($formParams) > 0) {
  346. if ($multipart) {
  347. $multipartContents = [];
  348. foreach ($formParams as $formParamName => $formParamValue) {
  349. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  350. foreach ($formParamValueItems as $formParamValueItem) {
  351. $multipartContents[] = [
  352. 'name' => $formParamName,
  353. 'contents' => $formParamValueItem
  354. ];
  355. }
  356. }
  357. // for HTTP post (form)
  358. $httpBody = new MultipartStream($multipartContents);
  359. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  360. # if Content-Type contains "application/json", json_encode the form parameters
  361. try {
  362. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  363. } catch (\JsonException $e) {
  364. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  365. }
  366. } else {
  367. // for HTTP post (form)
  368. $httpBody = ObjectSerializer::buildQuery($formParams);
  369. }
  370. }
  371. $defaultHeaders = [];
  372. if ($this->config->getUserAgent()) {
  373. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  374. }
  375. $headers = array_merge(
  376. $defaultHeaders,
  377. $headerParams,
  378. $headers
  379. );
  380. $operationHost = $this->config->getHost();
  381. $query = ObjectSerializer::buildQuery($queryParams);
  382. return new Request(
  383. 'GET',
  384. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  385. $headers,
  386. $httpBody
  387. );
  388. }
  389. /**
  390. * Operation patchApiV3PasswordResetsToken
  391. *
  392. * 设置新密码
  393. *
  394. * @param string $token 邮件链接里的 token (required)
  395. * @param \WikipaliApi\Model\PatchApiV3PasswordResetsTokenRequest $patch_api_v3_password_resets_token_request patch_api_v3_password_resets_token_request (required)
  396. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3PasswordResetsToken'] 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 void
  401. */
  402. public function patchApiV3PasswordResetsToken($token, $patch_api_v3_password_resets_token_request, string $contentType = self::contentTypes['patchApiV3PasswordResetsToken'][0])
  403. {
  404. $this->patchApiV3PasswordResetsTokenWithHttpInfo($token, $patch_api_v3_password_resets_token_request, $contentType);
  405. }
  406. /**
  407. * Operation patchApiV3PasswordResetsTokenWithHttpInfo
  408. *
  409. * 设置新密码
  410. *
  411. * @param string $token 邮件链接里的 token (required)
  412. * @param \WikipaliApi\Model\PatchApiV3PasswordResetsTokenRequest $patch_api_v3_password_resets_token_request (required)
  413. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3PasswordResetsToken'] 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 null, HTTP status code, HTTP response headers (array of strings)
  418. */
  419. public function patchApiV3PasswordResetsTokenWithHttpInfo($token, $patch_api_v3_password_resets_token_request, string $contentType = self::contentTypes['patchApiV3PasswordResetsToken'][0])
  420. {
  421. $request = $this->patchApiV3PasswordResetsTokenRequest($token, $patch_api_v3_password_resets_token_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. return [null, $statusCode, $response->getHeaders()];
  443. } catch (ApiException $e) {
  444. switch ($e->getCode()) {
  445. case 404:
  446. $data = ObjectSerializer::deserialize(
  447. $e->getResponseBody(),
  448. '\WikipaliApi\Model\ProblemDetails',
  449. $e->getResponseHeaders()
  450. );
  451. $e->setResponseObject($data);
  452. throw $e;
  453. case 422:
  454. $data = ObjectSerializer::deserialize(
  455. $e->getResponseBody(),
  456. '\WikipaliApi\Model\ProblemDetails',
  457. $e->getResponseHeaders()
  458. );
  459. $e->setResponseObject($data);
  460. throw $e;
  461. }
  462. throw $e;
  463. }
  464. }
  465. /**
  466. * Operation patchApiV3PasswordResetsTokenAsync
  467. *
  468. * 设置新密码
  469. *
  470. * @param string $token 邮件链接里的 token (required)
  471. * @param \WikipaliApi\Model\PatchApiV3PasswordResetsTokenRequest $patch_api_v3_password_resets_token_request (required)
  472. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3PasswordResetsToken'] to see the possible values for this operation
  473. *
  474. * @throws \InvalidArgumentException
  475. * @return \GuzzleHttp\Promise\PromiseInterface
  476. */
  477. public function patchApiV3PasswordResetsTokenAsync($token, $patch_api_v3_password_resets_token_request, string $contentType = self::contentTypes['patchApiV3PasswordResetsToken'][0])
  478. {
  479. return $this->patchApiV3PasswordResetsTokenAsyncWithHttpInfo($token, $patch_api_v3_password_resets_token_request, $contentType)
  480. ->then(
  481. function ($response) {
  482. return $response[0];
  483. }
  484. );
  485. }
  486. /**
  487. * Operation patchApiV3PasswordResetsTokenAsyncWithHttpInfo
  488. *
  489. * 设置新密码
  490. *
  491. * @param string $token 邮件链接里的 token (required)
  492. * @param \WikipaliApi\Model\PatchApiV3PasswordResetsTokenRequest $patch_api_v3_password_resets_token_request (required)
  493. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3PasswordResetsToken'] to see the possible values for this operation
  494. *
  495. * @throws \InvalidArgumentException
  496. * @return \GuzzleHttp\Promise\PromiseInterface
  497. */
  498. public function patchApiV3PasswordResetsTokenAsyncWithHttpInfo($token, $patch_api_v3_password_resets_token_request, string $contentType = self::contentTypes['patchApiV3PasswordResetsToken'][0])
  499. {
  500. $returnType = '';
  501. $request = $this->patchApiV3PasswordResetsTokenRequest($token, $patch_api_v3_password_resets_token_request, $contentType);
  502. return $this->client
  503. ->sendAsync($request, $this->createHttpClientOption())
  504. ->then(
  505. function ($response) use ($returnType) {
  506. return [null, $response->getStatusCode(), $response->getHeaders()];
  507. },
  508. function ($exception) {
  509. $response = $exception->getResponse();
  510. $statusCode = $response->getStatusCode();
  511. throw new ApiException(
  512. sprintf(
  513. '[%d] Error connecting to the API (%s)',
  514. $statusCode,
  515. $exception->getRequest()->getUri()
  516. ),
  517. $statusCode,
  518. $response->getHeaders(),
  519. (string) $response->getBody()
  520. );
  521. }
  522. );
  523. }
  524. /**
  525. * Create request for operation 'patchApiV3PasswordResetsToken'
  526. *
  527. * @param string $token 邮件链接里的 token (required)
  528. * @param \WikipaliApi\Model\PatchApiV3PasswordResetsTokenRequest $patch_api_v3_password_resets_token_request (required)
  529. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3PasswordResetsToken'] to see the possible values for this operation
  530. *
  531. * @throws \InvalidArgumentException
  532. * @return \GuzzleHttp\Psr7\Request
  533. */
  534. public function patchApiV3PasswordResetsTokenRequest($token, $patch_api_v3_password_resets_token_request, string $contentType = self::contentTypes['patchApiV3PasswordResetsToken'][0])
  535. {
  536. // verify the required parameter 'token' is set
  537. if ($token === null || (is_array($token) && count($token) === 0)) {
  538. throw new \InvalidArgumentException(
  539. 'Missing the required parameter $token when calling patchApiV3PasswordResetsToken'
  540. );
  541. }
  542. // verify the required parameter 'patch_api_v3_password_resets_token_request' is set
  543. if ($patch_api_v3_password_resets_token_request === null || (is_array($patch_api_v3_password_resets_token_request) && count($patch_api_v3_password_resets_token_request) === 0)) {
  544. throw new \InvalidArgumentException(
  545. 'Missing the required parameter $patch_api_v3_password_resets_token_request when calling patchApiV3PasswordResetsToken'
  546. );
  547. }
  548. $resourcePath = '/v3/password-resets/{token}';
  549. $formParams = [];
  550. $queryParams = [];
  551. $headerParams = [];
  552. $httpBody = '';
  553. $multipart = false;
  554. // path params
  555. if ($token !== null) {
  556. $resourcePath = str_replace(
  557. '{token}',
  558. ObjectSerializer::toPathValue($token),
  559. $resourcePath
  560. );
  561. }
  562. $headers = $this->headerSelector->selectHeaders(
  563. ['application/problem+json', ],
  564. $contentType,
  565. $multipart
  566. );
  567. // for model (json/xml)
  568. if (isset($patch_api_v3_password_resets_token_request)) {
  569. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  570. # if Content-Type contains "application/json", json_encode the body
  571. try {
  572. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($patch_api_v3_password_resets_token_request), JSON_THROW_ON_ERROR);
  573. } catch (\JsonException $e) {
  574. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  575. }
  576. } else {
  577. $httpBody = $patch_api_v3_password_resets_token_request;
  578. }
  579. } elseif (count($formParams) > 0) {
  580. if ($multipart) {
  581. $multipartContents = [];
  582. foreach ($formParams as $formParamName => $formParamValue) {
  583. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  584. foreach ($formParamValueItems as $formParamValueItem) {
  585. $multipartContents[] = [
  586. 'name' => $formParamName,
  587. 'contents' => $formParamValueItem
  588. ];
  589. }
  590. }
  591. // for HTTP post (form)
  592. $httpBody = new MultipartStream($multipartContents);
  593. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  594. # if Content-Type contains "application/json", json_encode the form parameters
  595. try {
  596. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  597. } catch (\JsonException $e) {
  598. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  599. }
  600. } else {
  601. // for HTTP post (form)
  602. $httpBody = ObjectSerializer::buildQuery($formParams);
  603. }
  604. }
  605. $defaultHeaders = [];
  606. if ($this->config->getUserAgent()) {
  607. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  608. }
  609. $headers = array_merge(
  610. $defaultHeaders,
  611. $headerParams,
  612. $headers
  613. );
  614. $operationHost = $this->config->getHost();
  615. $query = ObjectSerializer::buildQuery($queryParams);
  616. return new Request(
  617. 'PATCH',
  618. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  619. $headers,
  620. $httpBody
  621. );
  622. }
  623. /**
  624. * Operation postApiV3PasswordResets
  625. *
  626. * 申请重置密码(发邮件)
  627. *
  628. * @param \WikipaliApi\Model\PostApiV3PasswordResetsRequest $post_api_v3_password_resets_request post_api_v3_password_resets_request (required)
  629. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3PasswordResets'] to see the possible values for this operation
  630. *
  631. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  632. * @throws \InvalidArgumentException
  633. * @return void
  634. */
  635. public function postApiV3PasswordResets($post_api_v3_password_resets_request, string $contentType = self::contentTypes['postApiV3PasswordResets'][0])
  636. {
  637. $this->postApiV3PasswordResetsWithHttpInfo($post_api_v3_password_resets_request, $contentType);
  638. }
  639. /**
  640. * Operation postApiV3PasswordResetsWithHttpInfo
  641. *
  642. * 申请重置密码(发邮件)
  643. *
  644. * @param \WikipaliApi\Model\PostApiV3PasswordResetsRequest $post_api_v3_password_resets_request (required)
  645. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3PasswordResets'] to see the possible values for this operation
  646. *
  647. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  648. * @throws \InvalidArgumentException
  649. * @return array of null, HTTP status code, HTTP response headers (array of strings)
  650. */
  651. public function postApiV3PasswordResetsWithHttpInfo($post_api_v3_password_resets_request, string $contentType = self::contentTypes['postApiV3PasswordResets'][0])
  652. {
  653. $request = $this->postApiV3PasswordResetsRequest($post_api_v3_password_resets_request, $contentType);
  654. try {
  655. $options = $this->createHttpClientOption();
  656. try {
  657. $response = $this->client->send($request, $options);
  658. } catch (RequestException $e) {
  659. throw new ApiException(
  660. "[{$e->getCode()}] {$e->getMessage()}",
  661. (int) $e->getCode(),
  662. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  663. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  664. );
  665. } catch (ConnectException $e) {
  666. throw new ApiException(
  667. "[{$e->getCode()}] {$e->getMessage()}",
  668. (int) $e->getCode(),
  669. null,
  670. null
  671. );
  672. }
  673. $statusCode = $response->getStatusCode();
  674. return [null, $statusCode, $response->getHeaders()];
  675. } catch (ApiException $e) {
  676. switch ($e->getCode()) {
  677. case 422:
  678. $data = ObjectSerializer::deserialize(
  679. $e->getResponseBody(),
  680. '\WikipaliApi\Model\ProblemDetails',
  681. $e->getResponseHeaders()
  682. );
  683. $e->setResponseObject($data);
  684. throw $e;
  685. case 429:
  686. $data = ObjectSerializer::deserialize(
  687. $e->getResponseBody(),
  688. '\WikipaliApi\Model\ProblemDetails',
  689. $e->getResponseHeaders()
  690. );
  691. $e->setResponseObject($data);
  692. throw $e;
  693. case 503:
  694. $data = ObjectSerializer::deserialize(
  695. $e->getResponseBody(),
  696. '\WikipaliApi\Model\ProblemDetails',
  697. $e->getResponseHeaders()
  698. );
  699. $e->setResponseObject($data);
  700. throw $e;
  701. }
  702. throw $e;
  703. }
  704. }
  705. /**
  706. * Operation postApiV3PasswordResetsAsync
  707. *
  708. * 申请重置密码(发邮件)
  709. *
  710. * @param \WikipaliApi\Model\PostApiV3PasswordResetsRequest $post_api_v3_password_resets_request (required)
  711. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3PasswordResets'] to see the possible values for this operation
  712. *
  713. * @throws \InvalidArgumentException
  714. * @return \GuzzleHttp\Promise\PromiseInterface
  715. */
  716. public function postApiV3PasswordResetsAsync($post_api_v3_password_resets_request, string $contentType = self::contentTypes['postApiV3PasswordResets'][0])
  717. {
  718. return $this->postApiV3PasswordResetsAsyncWithHttpInfo($post_api_v3_password_resets_request, $contentType)
  719. ->then(
  720. function ($response) {
  721. return $response[0];
  722. }
  723. );
  724. }
  725. /**
  726. * Operation postApiV3PasswordResetsAsyncWithHttpInfo
  727. *
  728. * 申请重置密码(发邮件)
  729. *
  730. * @param \WikipaliApi\Model\PostApiV3PasswordResetsRequest $post_api_v3_password_resets_request (required)
  731. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3PasswordResets'] to see the possible values for this operation
  732. *
  733. * @throws \InvalidArgumentException
  734. * @return \GuzzleHttp\Promise\PromiseInterface
  735. */
  736. public function postApiV3PasswordResetsAsyncWithHttpInfo($post_api_v3_password_resets_request, string $contentType = self::contentTypes['postApiV3PasswordResets'][0])
  737. {
  738. $returnType = '';
  739. $request = $this->postApiV3PasswordResetsRequest($post_api_v3_password_resets_request, $contentType);
  740. return $this->client
  741. ->sendAsync($request, $this->createHttpClientOption())
  742. ->then(
  743. function ($response) use ($returnType) {
  744. return [null, $response->getStatusCode(), $response->getHeaders()];
  745. },
  746. function ($exception) {
  747. $response = $exception->getResponse();
  748. $statusCode = $response->getStatusCode();
  749. throw new ApiException(
  750. sprintf(
  751. '[%d] Error connecting to the API (%s)',
  752. $statusCode,
  753. $exception->getRequest()->getUri()
  754. ),
  755. $statusCode,
  756. $response->getHeaders(),
  757. (string) $response->getBody()
  758. );
  759. }
  760. );
  761. }
  762. /**
  763. * Create request for operation 'postApiV3PasswordResets'
  764. *
  765. * @param \WikipaliApi\Model\PostApiV3PasswordResetsRequest $post_api_v3_password_resets_request (required)
  766. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3PasswordResets'] to see the possible values for this operation
  767. *
  768. * @throws \InvalidArgumentException
  769. * @return \GuzzleHttp\Psr7\Request
  770. */
  771. public function postApiV3PasswordResetsRequest($post_api_v3_password_resets_request, string $contentType = self::contentTypes['postApiV3PasswordResets'][0])
  772. {
  773. // verify the required parameter 'post_api_v3_password_resets_request' is set
  774. if ($post_api_v3_password_resets_request === null || (is_array($post_api_v3_password_resets_request) && count($post_api_v3_password_resets_request) === 0)) {
  775. throw new \InvalidArgumentException(
  776. 'Missing the required parameter $post_api_v3_password_resets_request when calling postApiV3PasswordResets'
  777. );
  778. }
  779. $resourcePath = '/v3/password-resets';
  780. $formParams = [];
  781. $queryParams = [];
  782. $headerParams = [];
  783. $httpBody = '';
  784. $multipart = false;
  785. $headers = $this->headerSelector->selectHeaders(
  786. ['application/problem+json', ],
  787. $contentType,
  788. $multipart
  789. );
  790. // for model (json/xml)
  791. if (isset($post_api_v3_password_resets_request)) {
  792. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  793. # if Content-Type contains "application/json", json_encode the body
  794. try {
  795. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_password_resets_request), JSON_THROW_ON_ERROR);
  796. } catch (\JsonException $e) {
  797. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  798. }
  799. } else {
  800. $httpBody = $post_api_v3_password_resets_request;
  801. }
  802. } elseif (count($formParams) > 0) {
  803. if ($multipart) {
  804. $multipartContents = [];
  805. foreach ($formParams as $formParamName => $formParamValue) {
  806. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  807. foreach ($formParamValueItems as $formParamValueItem) {
  808. $multipartContents[] = [
  809. 'name' => $formParamName,
  810. 'contents' => $formParamValueItem
  811. ];
  812. }
  813. }
  814. // for HTTP post (form)
  815. $httpBody = new MultipartStream($multipartContents);
  816. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  817. # if Content-Type contains "application/json", json_encode the form parameters
  818. try {
  819. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  820. } catch (\JsonException $e) {
  821. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  822. }
  823. } else {
  824. // for HTTP post (form)
  825. $httpBody = ObjectSerializer::buildQuery($formParams);
  826. }
  827. }
  828. $defaultHeaders = [];
  829. if ($this->config->getUserAgent()) {
  830. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  831. }
  832. $headers = array_merge(
  833. $defaultHeaders,
  834. $headerParams,
  835. $headers
  836. );
  837. $operationHost = $this->config->getHost();
  838. $query = ObjectSerializer::buildQuery($queryParams);
  839. return new Request(
  840. 'POST',
  841. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  842. $headers,
  843. $httpBody
  844. );
  845. }
  846. /**
  847. * Create http client option
  848. *
  849. * @throws \RuntimeException on file opening failure
  850. * @return array of http client options
  851. */
  852. protected function createHttpClientOption()
  853. {
  854. $options = [];
  855. if ($this->config->getDebug()) {
  856. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  857. if (!$options[RequestOptions::DEBUG]) {
  858. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  859. }
  860. }
  861. if ($this->config->getCertFile()) {
  862. $options[RequestOptions::CERT] = $this->config->getCertFile();
  863. }
  864. if ($this->config->getKeyFile()) {
  865. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  866. }
  867. return $options;
  868. }
  869. private function handleResponseWithDataType(
  870. string $dataType,
  871. RequestInterface $request,
  872. ResponseInterface $response
  873. ): array {
  874. if ($dataType === '\SplFileObject') {
  875. $content = $response->getBody(); //stream goes to serializer
  876. } else {
  877. $content = (string) $response->getBody();
  878. if ($dataType !== 'string') {
  879. try {
  880. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  881. } catch (\JsonException $exception) {
  882. throw new ApiException(
  883. sprintf(
  884. 'Error JSON decoding server response (%s)',
  885. $request->getUri()
  886. ),
  887. $response->getStatusCode(),
  888. $response->getHeaders(),
  889. $content
  890. );
  891. }
  892. }
  893. }
  894. return [
  895. ObjectSerializer::deserialize($content, $dataType, []),
  896. $response->getStatusCode(),
  897. $response->getHeaders()
  898. ];
  899. }
  900. private function responseWithinRangeCode(
  901. string $rangeCode,
  902. int $statusCode
  903. ): bool {
  904. $left = (int) ($rangeCode[0].'00');
  905. $right = (int) ($rangeCode[0].'99');
  906. return $statusCode >= $left && $statusCode <= $right;
  907. }
  908. }