MeApi.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. <?php
  2. /**
  3. * MeApi
  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.9.28
  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. * MeApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class MeApi
  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. 'deleteApiV3MeReactionsReaction' => [
  69. 'application/json',
  70. ],
  71. 'getApiV3MeReactions' => [
  72. 'application/json',
  73. ],
  74. 'postApiV3MeReactions' => [
  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 deleteApiV3MeReactionsReaction
  122. *
  123. * 删除我自己的 reaction
  124. *
  125. * @param string $reaction reaction 的 uuid (required)
  126. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] 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 void
  131. */
  132. public function deleteApiV3MeReactionsReaction($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  133. {
  134. $this->deleteApiV3MeReactionsReactionWithHttpInfo($reaction, $contentType);
  135. }
  136. /**
  137. * Operation deleteApiV3MeReactionsReactionWithHttpInfo
  138. *
  139. * 删除我自己的 reaction
  140. *
  141. * @param string $reaction reaction 的 uuid (required)
  142. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  143. *
  144. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  145. * @throws \InvalidArgumentException
  146. * @return array of null, HTTP status code, HTTP response headers (array of strings)
  147. */
  148. public function deleteApiV3MeReactionsReactionWithHttpInfo($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  149. {
  150. $request = $this->deleteApiV3MeReactionsReactionRequest($reaction, $contentType);
  151. try {
  152. $options = $this->createHttpClientOption();
  153. try {
  154. $response = $this->client->send($request, $options);
  155. } catch (RequestException $e) {
  156. throw new ApiException(
  157. "[{$e->getCode()}] {$e->getMessage()}",
  158. (int) $e->getCode(),
  159. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  160. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  161. );
  162. } catch (ConnectException $e) {
  163. throw new ApiException(
  164. "[{$e->getCode()}] {$e->getMessage()}",
  165. (int) $e->getCode(),
  166. null,
  167. null
  168. );
  169. }
  170. $statusCode = $response->getStatusCode();
  171. return [null, $statusCode, $response->getHeaders()];
  172. } catch (ApiException $e) {
  173. switch ($e->getCode()) {
  174. case 401:
  175. $data = ObjectSerializer::deserialize(
  176. $e->getResponseBody(),
  177. '\WikipaliApi\Model\ProblemDetails',
  178. $e->getResponseHeaders()
  179. );
  180. $e->setResponseObject($data);
  181. throw $e;
  182. case 403:
  183. $data = ObjectSerializer::deserialize(
  184. $e->getResponseBody(),
  185. '\WikipaliApi\Model\ProblemDetails',
  186. $e->getResponseHeaders()
  187. );
  188. $e->setResponseObject($data);
  189. throw $e;
  190. case 422:
  191. $data = ObjectSerializer::deserialize(
  192. $e->getResponseBody(),
  193. '\WikipaliApi\Model\ProblemDetails',
  194. $e->getResponseHeaders()
  195. );
  196. $e->setResponseObject($data);
  197. throw $e;
  198. }
  199. throw $e;
  200. }
  201. }
  202. /**
  203. * Operation deleteApiV3MeReactionsReactionAsync
  204. *
  205. * 删除我自己的 reaction
  206. *
  207. * @param string $reaction reaction 的 uuid (required)
  208. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  209. *
  210. * @throws \InvalidArgumentException
  211. * @return \GuzzleHttp\Promise\PromiseInterface
  212. */
  213. public function deleteApiV3MeReactionsReactionAsync($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  214. {
  215. return $this->deleteApiV3MeReactionsReactionAsyncWithHttpInfo($reaction, $contentType)
  216. ->then(
  217. function ($response) {
  218. return $response[0];
  219. }
  220. );
  221. }
  222. /**
  223. * Operation deleteApiV3MeReactionsReactionAsyncWithHttpInfo
  224. *
  225. * 删除我自己的 reaction
  226. *
  227. * @param string $reaction reaction 的 uuid (required)
  228. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  229. *
  230. * @throws \InvalidArgumentException
  231. * @return \GuzzleHttp\Promise\PromiseInterface
  232. */
  233. public function deleteApiV3MeReactionsReactionAsyncWithHttpInfo($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  234. {
  235. $returnType = '';
  236. $request = $this->deleteApiV3MeReactionsReactionRequest($reaction, $contentType);
  237. return $this->client
  238. ->sendAsync($request, $this->createHttpClientOption())
  239. ->then(
  240. function ($response) use ($returnType) {
  241. return [null, $response->getStatusCode(), $response->getHeaders()];
  242. },
  243. function ($exception) {
  244. $response = $exception->getResponse();
  245. $statusCode = $response->getStatusCode();
  246. throw new ApiException(
  247. sprintf(
  248. '[%d] Error connecting to the API (%s)',
  249. $statusCode,
  250. $exception->getRequest()->getUri()
  251. ),
  252. $statusCode,
  253. $response->getHeaders(),
  254. (string) $response->getBody()
  255. );
  256. }
  257. );
  258. }
  259. /**
  260. * Create request for operation 'deleteApiV3MeReactionsReaction'
  261. *
  262. * @param string $reaction reaction 的 uuid (required)
  263. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  264. *
  265. * @throws \InvalidArgumentException
  266. * @return \GuzzleHttp\Psr7\Request
  267. */
  268. public function deleteApiV3MeReactionsReactionRequest($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  269. {
  270. // verify the required parameter 'reaction' is set
  271. if ($reaction === null || (is_array($reaction) && count($reaction) === 0)) {
  272. throw new \InvalidArgumentException(
  273. 'Missing the required parameter $reaction when calling deleteApiV3MeReactionsReaction'
  274. );
  275. }
  276. $resourcePath = '/v3/me/reactions/{reaction}';
  277. $formParams = [];
  278. $queryParams = [];
  279. $headerParams = [];
  280. $httpBody = '';
  281. $multipart = false;
  282. // path params
  283. if ($reaction !== null) {
  284. $resourcePath = str_replace(
  285. '{reaction}',
  286. ObjectSerializer::toPathValue($reaction),
  287. $resourcePath
  288. );
  289. }
  290. $headers = $this->headerSelector->selectHeaders(
  291. ['application/problem+json', ],
  292. $contentType,
  293. $multipart
  294. );
  295. // for model (json/xml)
  296. if (count($formParams) > 0) {
  297. if ($multipart) {
  298. $multipartContents = [];
  299. foreach ($formParams as $formParamName => $formParamValue) {
  300. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  301. foreach ($formParamValueItems as $formParamValueItem) {
  302. $multipartContents[] = [
  303. 'name' => $formParamName,
  304. 'contents' => $formParamValueItem
  305. ];
  306. }
  307. }
  308. // for HTTP post (form)
  309. $httpBody = new MultipartStream($multipartContents);
  310. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  311. # if Content-Type contains "application/json", json_encode the form parameters
  312. try {
  313. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  314. } catch (\JsonException $e) {
  315. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  316. }
  317. } else {
  318. // for HTTP post (form)
  319. $httpBody = ObjectSerializer::buildQuery($formParams);
  320. }
  321. }
  322. // this endpoint requires Bearer authentication (access token)
  323. if (!empty($this->config->getAccessToken())) {
  324. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  325. }
  326. $defaultHeaders = [];
  327. if ($this->config->getUserAgent()) {
  328. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  329. }
  330. $headers = array_merge(
  331. $defaultHeaders,
  332. $headerParams,
  333. $headers
  334. );
  335. $operationHost = $this->config->getHost();
  336. $query = ObjectSerializer::buildQuery($queryParams);
  337. return new Request(
  338. 'DELETE',
  339. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  340. $headers,
  341. $httpBody
  342. );
  343. }
  344. /**
  345. * Operation getApiV3MeReactions
  346. *
  347. * 列出我自己的 reactions
  348. *
  349. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  350. * @param string|null $type 操作类型 (optional)
  351. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  352. * @param int|null $page 页码 (optional, default to 1)
  353. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  354. *
  355. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  356. * @throws \InvalidArgumentException
  357. * @return \WikipaliApi\Model\GetApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  358. */
  359. public function getApiV3MeReactions($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  360. {
  361. list($response) = $this->getApiV3MeReactionsWithHttpInfo($per_page, $type, $target_type, $page, $contentType);
  362. return $response;
  363. }
  364. /**
  365. * Operation getApiV3MeReactionsWithHttpInfo
  366. *
  367. * 列出我自己的 reactions
  368. *
  369. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  370. * @param string|null $type 操作类型 (optional)
  371. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  372. * @param int|null $page 页码 (optional, default to 1)
  373. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  374. *
  375. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  376. * @throws \InvalidArgumentException
  377. * @return array of \WikipaliApi\Model\GetApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  378. */
  379. public function getApiV3MeReactionsWithHttpInfo($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  380. {
  381. $request = $this->getApiV3MeReactionsRequest($per_page, $type, $target_type, $page, $contentType);
  382. try {
  383. $options = $this->createHttpClientOption();
  384. try {
  385. $response = $this->client->send($request, $options);
  386. } catch (RequestException $e) {
  387. throw new ApiException(
  388. "[{$e->getCode()}] {$e->getMessage()}",
  389. (int) $e->getCode(),
  390. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  391. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  392. );
  393. } catch (ConnectException $e) {
  394. throw new ApiException(
  395. "[{$e->getCode()}] {$e->getMessage()}",
  396. (int) $e->getCode(),
  397. null,
  398. null
  399. );
  400. }
  401. $statusCode = $response->getStatusCode();
  402. switch($statusCode) {
  403. case 200:
  404. return $this->handleResponseWithDataType(
  405. '\WikipaliApi\Model\GetApiV3MeReactions200Response',
  406. $request,
  407. $response,
  408. );
  409. case 401:
  410. return $this->handleResponseWithDataType(
  411. '\WikipaliApi\Model\ProblemDetails',
  412. $request,
  413. $response,
  414. );
  415. case 422:
  416. return $this->handleResponseWithDataType(
  417. '\WikipaliApi\Model\ProblemDetails',
  418. $request,
  419. $response,
  420. );
  421. }
  422. if ($statusCode < 200 || $statusCode > 299) {
  423. throw new ApiException(
  424. sprintf(
  425. '[%d] Error connecting to the API (%s)',
  426. $statusCode,
  427. (string) $request->getUri()
  428. ),
  429. $statusCode,
  430. $response->getHeaders(),
  431. (string) $response->getBody()
  432. );
  433. }
  434. return $this->handleResponseWithDataType(
  435. '\WikipaliApi\Model\GetApiV3MeReactions200Response',
  436. $request,
  437. $response,
  438. );
  439. } catch (ApiException $e) {
  440. switch ($e->getCode()) {
  441. case 200:
  442. $data = ObjectSerializer::deserialize(
  443. $e->getResponseBody(),
  444. '\WikipaliApi\Model\GetApiV3MeReactions200Response',
  445. $e->getResponseHeaders()
  446. );
  447. $e->setResponseObject($data);
  448. throw $e;
  449. case 401:
  450. $data = ObjectSerializer::deserialize(
  451. $e->getResponseBody(),
  452. '\WikipaliApi\Model\ProblemDetails',
  453. $e->getResponseHeaders()
  454. );
  455. $e->setResponseObject($data);
  456. throw $e;
  457. case 422:
  458. $data = ObjectSerializer::deserialize(
  459. $e->getResponseBody(),
  460. '\WikipaliApi\Model\ProblemDetails',
  461. $e->getResponseHeaders()
  462. );
  463. $e->setResponseObject($data);
  464. throw $e;
  465. }
  466. throw $e;
  467. }
  468. }
  469. /**
  470. * Operation getApiV3MeReactionsAsync
  471. *
  472. * 列出我自己的 reactions
  473. *
  474. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  475. * @param string|null $type 操作类型 (optional)
  476. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  477. * @param int|null $page 页码 (optional, default to 1)
  478. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  479. *
  480. * @throws \InvalidArgumentException
  481. * @return \GuzzleHttp\Promise\PromiseInterface
  482. */
  483. public function getApiV3MeReactionsAsync($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  484. {
  485. return $this->getApiV3MeReactionsAsyncWithHttpInfo($per_page, $type, $target_type, $page, $contentType)
  486. ->then(
  487. function ($response) {
  488. return $response[0];
  489. }
  490. );
  491. }
  492. /**
  493. * Operation getApiV3MeReactionsAsyncWithHttpInfo
  494. *
  495. * 列出我自己的 reactions
  496. *
  497. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  498. * @param string|null $type 操作类型 (optional)
  499. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  500. * @param int|null $page 页码 (optional, default to 1)
  501. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  502. *
  503. * @throws \InvalidArgumentException
  504. * @return \GuzzleHttp\Promise\PromiseInterface
  505. */
  506. public function getApiV3MeReactionsAsyncWithHttpInfo($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  507. {
  508. $returnType = '\WikipaliApi\Model\GetApiV3MeReactions200Response';
  509. $request = $this->getApiV3MeReactionsRequest($per_page, $type, $target_type, $page, $contentType);
  510. return $this->client
  511. ->sendAsync($request, $this->createHttpClientOption())
  512. ->then(
  513. function ($response) use ($returnType) {
  514. if ($returnType === '\SplFileObject') {
  515. $content = $response->getBody(); //stream goes to serializer
  516. } else {
  517. $content = (string) $response->getBody();
  518. if ($returnType !== 'string') {
  519. $content = json_decode($content);
  520. }
  521. }
  522. return [
  523. ObjectSerializer::deserialize($content, $returnType, []),
  524. $response->getStatusCode(),
  525. $response->getHeaders()
  526. ];
  527. },
  528. function ($exception) {
  529. $response = $exception->getResponse();
  530. $statusCode = $response->getStatusCode();
  531. throw new ApiException(
  532. sprintf(
  533. '[%d] Error connecting to the API (%s)',
  534. $statusCode,
  535. $exception->getRequest()->getUri()
  536. ),
  537. $statusCode,
  538. $response->getHeaders(),
  539. (string) $response->getBody()
  540. );
  541. }
  542. );
  543. }
  544. /**
  545. * Create request for operation 'getApiV3MeReactions'
  546. *
  547. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  548. * @param string|null $type 操作类型 (optional)
  549. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  550. * @param int|null $page 页码 (optional, default to 1)
  551. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  552. *
  553. * @throws \InvalidArgumentException
  554. * @return \GuzzleHttp\Psr7\Request
  555. */
  556. public function getApiV3MeReactionsRequest($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  557. {
  558. $resourcePath = '/v3/me/reactions';
  559. $formParams = [];
  560. $queryParams = [];
  561. $headerParams = [];
  562. $httpBody = '';
  563. $multipart = false;
  564. // query params
  565. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  566. $per_page,
  567. 'per_page', // param base name
  568. 'integer', // openApiType
  569. 'form', // style
  570. true, // explode
  571. false // required
  572. ) ?? []);
  573. // query params
  574. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  575. $type,
  576. 'type', // param base name
  577. 'string', // openApiType
  578. 'form', // style
  579. true, // explode
  580. false // required
  581. ) ?? []);
  582. // query params
  583. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  584. $target_type,
  585. 'target_type', // param base name
  586. 'string', // openApiType
  587. 'form', // style
  588. true, // explode
  589. false // required
  590. ) ?? []);
  591. // query params
  592. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  593. $page,
  594. 'page', // param base name
  595. 'integer', // openApiType
  596. 'form', // style
  597. true, // explode
  598. false // required
  599. ) ?? []);
  600. $headers = $this->headerSelector->selectHeaders(
  601. ['application/json', 'application/problem+json', ],
  602. $contentType,
  603. $multipart
  604. );
  605. // for model (json/xml)
  606. if (count($formParams) > 0) {
  607. if ($multipart) {
  608. $multipartContents = [];
  609. foreach ($formParams as $formParamName => $formParamValue) {
  610. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  611. foreach ($formParamValueItems as $formParamValueItem) {
  612. $multipartContents[] = [
  613. 'name' => $formParamName,
  614. 'contents' => $formParamValueItem
  615. ];
  616. }
  617. }
  618. // for HTTP post (form)
  619. $httpBody = new MultipartStream($multipartContents);
  620. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  621. # if Content-Type contains "application/json", json_encode the form parameters
  622. try {
  623. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  624. } catch (\JsonException $e) {
  625. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  626. }
  627. } else {
  628. // for HTTP post (form)
  629. $httpBody = ObjectSerializer::buildQuery($formParams);
  630. }
  631. }
  632. // this endpoint requires Bearer authentication (access token)
  633. if (!empty($this->config->getAccessToken())) {
  634. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  635. }
  636. $defaultHeaders = [];
  637. if ($this->config->getUserAgent()) {
  638. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  639. }
  640. $headers = array_merge(
  641. $defaultHeaders,
  642. $headerParams,
  643. $headers
  644. );
  645. $operationHost = $this->config->getHost();
  646. $query = ObjectSerializer::buildQuery($queryParams);
  647. return new Request(
  648. 'GET',
  649. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  650. $headers,
  651. $httpBody
  652. );
  653. }
  654. /**
  655. * Operation postApiV3MeReactions
  656. *
  657. * 添加一条我自己的 reaction(幂等)
  658. *
  659. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request post_api_v3_me_reactions_request (required)
  660. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  661. *
  662. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  663. * @throws \InvalidArgumentException
  664. * @return \WikipaliApi\Model\PostApiV3MeReactions200Response|\WikipaliApi\Model\PostApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  665. */
  666. public function postApiV3MeReactions($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  667. {
  668. list($response) = $this->postApiV3MeReactionsWithHttpInfo($post_api_v3_me_reactions_request, $contentType);
  669. return $response;
  670. }
  671. /**
  672. * Operation postApiV3MeReactionsWithHttpInfo
  673. *
  674. * 添加一条我自己的 reaction(幂等)
  675. *
  676. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request (required)
  677. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  678. *
  679. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  680. * @throws \InvalidArgumentException
  681. * @return array of \WikipaliApi\Model\PostApiV3MeReactions200Response|\WikipaliApi\Model\PostApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  682. */
  683. public function postApiV3MeReactionsWithHttpInfo($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  684. {
  685. $request = $this->postApiV3MeReactionsRequest($post_api_v3_me_reactions_request, $contentType);
  686. try {
  687. $options = $this->createHttpClientOption();
  688. try {
  689. $response = $this->client->send($request, $options);
  690. } catch (RequestException $e) {
  691. throw new ApiException(
  692. "[{$e->getCode()}] {$e->getMessage()}",
  693. (int) $e->getCode(),
  694. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  695. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  696. );
  697. } catch (ConnectException $e) {
  698. throw new ApiException(
  699. "[{$e->getCode()}] {$e->getMessage()}",
  700. (int) $e->getCode(),
  701. null,
  702. null
  703. );
  704. }
  705. $statusCode = $response->getStatusCode();
  706. switch($statusCode) {
  707. case 200:
  708. return $this->handleResponseWithDataType(
  709. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  710. $request,
  711. $response,
  712. );
  713. case 201:
  714. return $this->handleResponseWithDataType(
  715. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  716. $request,
  717. $response,
  718. );
  719. case 401:
  720. return $this->handleResponseWithDataType(
  721. '\WikipaliApi\Model\ProblemDetails',
  722. $request,
  723. $response,
  724. );
  725. case 422:
  726. return $this->handleResponseWithDataType(
  727. '\WikipaliApi\Model\ProblemDetails',
  728. $request,
  729. $response,
  730. );
  731. }
  732. if ($statusCode < 200 || $statusCode > 299) {
  733. throw new ApiException(
  734. sprintf(
  735. '[%d] Error connecting to the API (%s)',
  736. $statusCode,
  737. (string) $request->getUri()
  738. ),
  739. $statusCode,
  740. $response->getHeaders(),
  741. (string) $response->getBody()
  742. );
  743. }
  744. return $this->handleResponseWithDataType(
  745. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  746. $request,
  747. $response,
  748. );
  749. } catch (ApiException $e) {
  750. switch ($e->getCode()) {
  751. case 200:
  752. $data = ObjectSerializer::deserialize(
  753. $e->getResponseBody(),
  754. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  755. $e->getResponseHeaders()
  756. );
  757. $e->setResponseObject($data);
  758. throw $e;
  759. case 201:
  760. $data = ObjectSerializer::deserialize(
  761. $e->getResponseBody(),
  762. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  763. $e->getResponseHeaders()
  764. );
  765. $e->setResponseObject($data);
  766. throw $e;
  767. case 401:
  768. $data = ObjectSerializer::deserialize(
  769. $e->getResponseBody(),
  770. '\WikipaliApi\Model\ProblemDetails',
  771. $e->getResponseHeaders()
  772. );
  773. $e->setResponseObject($data);
  774. throw $e;
  775. case 422:
  776. $data = ObjectSerializer::deserialize(
  777. $e->getResponseBody(),
  778. '\WikipaliApi\Model\ProblemDetails',
  779. $e->getResponseHeaders()
  780. );
  781. $e->setResponseObject($data);
  782. throw $e;
  783. }
  784. throw $e;
  785. }
  786. }
  787. /**
  788. * Operation postApiV3MeReactionsAsync
  789. *
  790. * 添加一条我自己的 reaction(幂等)
  791. *
  792. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request (required)
  793. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  794. *
  795. * @throws \InvalidArgumentException
  796. * @return \GuzzleHttp\Promise\PromiseInterface
  797. */
  798. public function postApiV3MeReactionsAsync($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  799. {
  800. return $this->postApiV3MeReactionsAsyncWithHttpInfo($post_api_v3_me_reactions_request, $contentType)
  801. ->then(
  802. function ($response) {
  803. return $response[0];
  804. }
  805. );
  806. }
  807. /**
  808. * Operation postApiV3MeReactionsAsyncWithHttpInfo
  809. *
  810. * 添加一条我自己的 reaction(幂等)
  811. *
  812. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request (required)
  813. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  814. *
  815. * @throws \InvalidArgumentException
  816. * @return \GuzzleHttp\Promise\PromiseInterface
  817. */
  818. public function postApiV3MeReactionsAsyncWithHttpInfo($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  819. {
  820. $returnType = '\WikipaliApi\Model\PostApiV3MeReactions200Response';
  821. $request = $this->postApiV3MeReactionsRequest($post_api_v3_me_reactions_request, $contentType);
  822. return $this->client
  823. ->sendAsync($request, $this->createHttpClientOption())
  824. ->then(
  825. function ($response) use ($returnType) {
  826. if ($returnType === '\SplFileObject') {
  827. $content = $response->getBody(); //stream goes to serializer
  828. } else {
  829. $content = (string) $response->getBody();
  830. if ($returnType !== 'string') {
  831. $content = json_decode($content);
  832. }
  833. }
  834. return [
  835. ObjectSerializer::deserialize($content, $returnType, []),
  836. $response->getStatusCode(),
  837. $response->getHeaders()
  838. ];
  839. },
  840. function ($exception) {
  841. $response = $exception->getResponse();
  842. $statusCode = $response->getStatusCode();
  843. throw new ApiException(
  844. sprintf(
  845. '[%d] Error connecting to the API (%s)',
  846. $statusCode,
  847. $exception->getRequest()->getUri()
  848. ),
  849. $statusCode,
  850. $response->getHeaders(),
  851. (string) $response->getBody()
  852. );
  853. }
  854. );
  855. }
  856. /**
  857. * Create request for operation 'postApiV3MeReactions'
  858. *
  859. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request (required)
  860. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  861. *
  862. * @throws \InvalidArgumentException
  863. * @return \GuzzleHttp\Psr7\Request
  864. */
  865. public function postApiV3MeReactionsRequest($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  866. {
  867. // verify the required parameter 'post_api_v3_me_reactions_request' is set
  868. if ($post_api_v3_me_reactions_request === null || (is_array($post_api_v3_me_reactions_request) && count($post_api_v3_me_reactions_request) === 0)) {
  869. throw new \InvalidArgumentException(
  870. 'Missing the required parameter $post_api_v3_me_reactions_request when calling postApiV3MeReactions'
  871. );
  872. }
  873. $resourcePath = '/v3/me/reactions';
  874. $formParams = [];
  875. $queryParams = [];
  876. $headerParams = [];
  877. $httpBody = '';
  878. $multipart = false;
  879. $headers = $this->headerSelector->selectHeaders(
  880. ['application/json', 'application/problem+json', ],
  881. $contentType,
  882. $multipart
  883. );
  884. // for model (json/xml)
  885. if (isset($post_api_v3_me_reactions_request)) {
  886. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  887. # if Content-Type contains "application/json", json_encode the body
  888. try {
  889. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_me_reactions_request), JSON_THROW_ON_ERROR);
  890. } catch (\JsonException $e) {
  891. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  892. }
  893. } else {
  894. $httpBody = $post_api_v3_me_reactions_request;
  895. }
  896. } elseif (count($formParams) > 0) {
  897. if ($multipart) {
  898. $multipartContents = [];
  899. foreach ($formParams as $formParamName => $formParamValue) {
  900. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  901. foreach ($formParamValueItems as $formParamValueItem) {
  902. $multipartContents[] = [
  903. 'name' => $formParamName,
  904. 'contents' => $formParamValueItem
  905. ];
  906. }
  907. }
  908. // for HTTP post (form)
  909. $httpBody = new MultipartStream($multipartContents);
  910. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  911. # if Content-Type contains "application/json", json_encode the form parameters
  912. try {
  913. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  914. } catch (\JsonException $e) {
  915. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  916. }
  917. } else {
  918. // for HTTP post (form)
  919. $httpBody = ObjectSerializer::buildQuery($formParams);
  920. }
  921. }
  922. // this endpoint requires Bearer authentication (access token)
  923. if (!empty($this->config->getAccessToken())) {
  924. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  925. }
  926. $defaultHeaders = [];
  927. if ($this->config->getUserAgent()) {
  928. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  929. }
  930. $headers = array_merge(
  931. $defaultHeaders,
  932. $headerParams,
  933. $headers
  934. );
  935. $operationHost = $this->config->getHost();
  936. $query = ObjectSerializer::buildQuery($queryParams);
  937. return new Request(
  938. 'POST',
  939. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  940. $headers,
  941. $httpBody
  942. );
  943. }
  944. /**
  945. * Create http client option
  946. *
  947. * @throws \RuntimeException on file opening failure
  948. * @return array of http client options
  949. */
  950. protected function createHttpClientOption()
  951. {
  952. $options = [];
  953. if ($this->config->getDebug()) {
  954. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  955. if (!$options[RequestOptions::DEBUG]) {
  956. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  957. }
  958. }
  959. if ($this->config->getCertFile()) {
  960. $options[RequestOptions::CERT] = $this->config->getCertFile();
  961. }
  962. if ($this->config->getKeyFile()) {
  963. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  964. }
  965. return $options;
  966. }
  967. private function handleResponseWithDataType(
  968. string $dataType,
  969. RequestInterface $request,
  970. ResponseInterface $response
  971. ): array {
  972. if ($dataType === '\SplFileObject') {
  973. $content = $response->getBody(); //stream goes to serializer
  974. } else {
  975. $content = (string) $response->getBody();
  976. if ($dataType !== 'string') {
  977. try {
  978. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  979. } catch (\JsonException $exception) {
  980. throw new ApiException(
  981. sprintf(
  982. 'Error JSON decoding server response (%s)',
  983. $request->getUri()
  984. ),
  985. $response->getStatusCode(),
  986. $response->getHeaders(),
  987. $content
  988. );
  989. }
  990. }
  991. }
  992. return [
  993. ObjectSerializer::deserialize($content, $dataType, []),
  994. $response->getStatusCode(),
  995. $response->getHeaders()
  996. ];
  997. }
  998. private function responseWithinRangeCode(
  999. string $rangeCode,
  1000. int $statusCode
  1001. ): bool {
  1002. $left = (int) ($rangeCode[0].'00');
  1003. $right = (int) ($rangeCode[0].'99');
  1004. return $statusCode >= $left && $statusCode <= $right;
  1005. }
  1006. }