ReactionsApi.php 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751
  1. <?php
  2. /**
  3. * ReactionsApi
  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. * ReactionsApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class ReactionsApi
  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. 'getApiV3Reactions' => [
  75. 'application/json',
  76. ],
  77. 'getApiV3ReactionsTally' => [
  78. 'application/json',
  79. ],
  80. 'postApiV3MeReactions' => [
  81. 'application/json',
  82. ],
  83. ];
  84. /**
  85. * @param ClientInterface $client
  86. * @param Configuration $config
  87. * @param HeaderSelector $selector
  88. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  89. */
  90. public function __construct(
  91. ?ClientInterface $client = null,
  92. ?Configuration $config = null,
  93. ?HeaderSelector $selector = null,
  94. int $hostIndex = 0
  95. ) {
  96. $this->client = $client ?: new Client();
  97. $this->config = $config ?: Configuration::getDefaultConfiguration();
  98. $this->headerSelector = $selector ?: new HeaderSelector();
  99. $this->hostIndex = $hostIndex;
  100. }
  101. /**
  102. * Set the host index
  103. *
  104. * @param int $hostIndex Host index (required)
  105. */
  106. public function setHostIndex($hostIndex): void
  107. {
  108. $this->hostIndex = $hostIndex;
  109. }
  110. /**
  111. * Get the host index
  112. *
  113. * @return int Host index
  114. */
  115. public function getHostIndex()
  116. {
  117. return $this->hostIndex;
  118. }
  119. /**
  120. * @return Configuration
  121. */
  122. public function getConfig()
  123. {
  124. return $this->config;
  125. }
  126. /**
  127. * Operation deleteApiV3MeReactionsReaction
  128. *
  129. * 删除我自己的 reaction
  130. *
  131. * @param string $reaction reaction 的 uuid (required)
  132. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  133. *
  134. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  135. * @throws \InvalidArgumentException
  136. * @return void
  137. */
  138. public function deleteApiV3MeReactionsReaction($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  139. {
  140. $this->deleteApiV3MeReactionsReactionWithHttpInfo($reaction, $contentType);
  141. }
  142. /**
  143. * Operation deleteApiV3MeReactionsReactionWithHttpInfo
  144. *
  145. * 删除我自己的 reaction
  146. *
  147. * @param string $reaction reaction 的 uuid (required)
  148. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  149. *
  150. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  151. * @throws \InvalidArgumentException
  152. * @return array of null, HTTP status code, HTTP response headers (array of strings)
  153. */
  154. public function deleteApiV3MeReactionsReactionWithHttpInfo($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  155. {
  156. $request = $this->deleteApiV3MeReactionsReactionRequest($reaction, $contentType);
  157. try {
  158. $options = $this->createHttpClientOption();
  159. try {
  160. $response = $this->client->send($request, $options);
  161. } catch (RequestException $e) {
  162. throw new ApiException(
  163. "[{$e->getCode()}] {$e->getMessage()}",
  164. (int) $e->getCode(),
  165. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  166. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  167. );
  168. } catch (ConnectException $e) {
  169. throw new ApiException(
  170. "[{$e->getCode()}] {$e->getMessage()}",
  171. (int) $e->getCode(),
  172. null,
  173. null
  174. );
  175. }
  176. $statusCode = $response->getStatusCode();
  177. return [null, $statusCode, $response->getHeaders()];
  178. } catch (ApiException $e) {
  179. switch ($e->getCode()) {
  180. case 401:
  181. $data = ObjectSerializer::deserialize(
  182. $e->getResponseBody(),
  183. '\WikipaliApi\Model\ProblemDetails',
  184. $e->getResponseHeaders()
  185. );
  186. $e->setResponseObject($data);
  187. throw $e;
  188. case 403:
  189. $data = ObjectSerializer::deserialize(
  190. $e->getResponseBody(),
  191. '\WikipaliApi\Model\ProblemDetails',
  192. $e->getResponseHeaders()
  193. );
  194. $e->setResponseObject($data);
  195. throw $e;
  196. case 422:
  197. $data = ObjectSerializer::deserialize(
  198. $e->getResponseBody(),
  199. '\WikipaliApi\Model\ProblemDetails',
  200. $e->getResponseHeaders()
  201. );
  202. $e->setResponseObject($data);
  203. throw $e;
  204. }
  205. throw $e;
  206. }
  207. }
  208. /**
  209. * Operation deleteApiV3MeReactionsReactionAsync
  210. *
  211. * 删除我自己的 reaction
  212. *
  213. * @param string $reaction reaction 的 uuid (required)
  214. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  215. *
  216. * @throws \InvalidArgumentException
  217. * @return \GuzzleHttp\Promise\PromiseInterface
  218. */
  219. public function deleteApiV3MeReactionsReactionAsync($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  220. {
  221. return $this->deleteApiV3MeReactionsReactionAsyncWithHttpInfo($reaction, $contentType)
  222. ->then(
  223. function ($response) {
  224. return $response[0];
  225. }
  226. );
  227. }
  228. /**
  229. * Operation deleteApiV3MeReactionsReactionAsyncWithHttpInfo
  230. *
  231. * 删除我自己的 reaction
  232. *
  233. * @param string $reaction reaction 的 uuid (required)
  234. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  235. *
  236. * @throws \InvalidArgumentException
  237. * @return \GuzzleHttp\Promise\PromiseInterface
  238. */
  239. public function deleteApiV3MeReactionsReactionAsyncWithHttpInfo($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  240. {
  241. $returnType = '';
  242. $request = $this->deleteApiV3MeReactionsReactionRequest($reaction, $contentType);
  243. return $this->client
  244. ->sendAsync($request, $this->createHttpClientOption())
  245. ->then(
  246. function ($response) use ($returnType) {
  247. return [null, $response->getStatusCode(), $response->getHeaders()];
  248. },
  249. function ($exception) {
  250. $response = $exception->getResponse();
  251. $statusCode = $response->getStatusCode();
  252. throw new ApiException(
  253. sprintf(
  254. '[%d] Error connecting to the API (%s)',
  255. $statusCode,
  256. $exception->getRequest()->getUri()
  257. ),
  258. $statusCode,
  259. $response->getHeaders(),
  260. (string) $response->getBody()
  261. );
  262. }
  263. );
  264. }
  265. /**
  266. * Create request for operation 'deleteApiV3MeReactionsReaction'
  267. *
  268. * @param string $reaction reaction 的 uuid (required)
  269. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  270. *
  271. * @throws \InvalidArgumentException
  272. * @return \GuzzleHttp\Psr7\Request
  273. */
  274. public function deleteApiV3MeReactionsReactionRequest($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  275. {
  276. // verify the required parameter 'reaction' is set
  277. if ($reaction === null || (is_array($reaction) && count($reaction) === 0)) {
  278. throw new \InvalidArgumentException(
  279. 'Missing the required parameter $reaction when calling deleteApiV3MeReactionsReaction'
  280. );
  281. }
  282. $resourcePath = '/v3/me/reactions/{reaction}';
  283. $formParams = [];
  284. $queryParams = [];
  285. $headerParams = [];
  286. $httpBody = '';
  287. $multipart = false;
  288. // path params
  289. if ($reaction !== null) {
  290. $resourcePath = str_replace(
  291. '{reaction}',
  292. ObjectSerializer::toPathValue($reaction),
  293. $resourcePath
  294. );
  295. }
  296. $headers = $this->headerSelector->selectHeaders(
  297. ['application/problem+json', ],
  298. $contentType,
  299. $multipart
  300. );
  301. // for model (json/xml)
  302. if (count($formParams) > 0) {
  303. if ($multipart) {
  304. $multipartContents = [];
  305. foreach ($formParams as $formParamName => $formParamValue) {
  306. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  307. foreach ($formParamValueItems as $formParamValueItem) {
  308. $multipartContents[] = [
  309. 'name' => $formParamName,
  310. 'contents' => $formParamValueItem
  311. ];
  312. }
  313. }
  314. // for HTTP post (form)
  315. $httpBody = new MultipartStream($multipartContents);
  316. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  317. # if Content-Type contains "application/json", json_encode the form parameters
  318. try {
  319. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  320. } catch (\JsonException $e) {
  321. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  322. }
  323. } else {
  324. // for HTTP post (form)
  325. $httpBody = ObjectSerializer::buildQuery($formParams);
  326. }
  327. }
  328. // this endpoint requires Bearer authentication (access token)
  329. if (!empty($this->config->getAccessToken())) {
  330. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  331. }
  332. $defaultHeaders = [];
  333. if ($this->config->getUserAgent()) {
  334. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  335. }
  336. $headers = array_merge(
  337. $defaultHeaders,
  338. $headerParams,
  339. $headers
  340. );
  341. $operationHost = $this->config->getHost();
  342. $query = ObjectSerializer::buildQuery($queryParams);
  343. return new Request(
  344. 'DELETE',
  345. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  346. $headers,
  347. $httpBody
  348. );
  349. }
  350. /**
  351. * Operation getApiV3MeReactions
  352. *
  353. * 列出我自己的 reactions
  354. *
  355. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  356. * @param string|null $type 操作类型 (optional)
  357. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  358. * @param int|null $page 页码 (optional, default to 1)
  359. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  360. *
  361. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  362. * @throws \InvalidArgumentException
  363. * @return \WikipaliApi\Model\GetApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  364. */
  365. public function getApiV3MeReactions($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  366. {
  367. list($response) = $this->getApiV3MeReactionsWithHttpInfo($per_page, $type, $target_type, $page, $contentType);
  368. return $response;
  369. }
  370. /**
  371. * Operation getApiV3MeReactionsWithHttpInfo
  372. *
  373. * 列出我自己的 reactions
  374. *
  375. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  376. * @param string|null $type 操作类型 (optional)
  377. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  378. * @param int|null $page 页码 (optional, default to 1)
  379. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  380. *
  381. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  382. * @throws \InvalidArgumentException
  383. * @return array of \WikipaliApi\Model\GetApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  384. */
  385. public function getApiV3MeReactionsWithHttpInfo($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  386. {
  387. $request = $this->getApiV3MeReactionsRequest($per_page, $type, $target_type, $page, $contentType);
  388. try {
  389. $options = $this->createHttpClientOption();
  390. try {
  391. $response = $this->client->send($request, $options);
  392. } catch (RequestException $e) {
  393. throw new ApiException(
  394. "[{$e->getCode()}] {$e->getMessage()}",
  395. (int) $e->getCode(),
  396. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  397. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  398. );
  399. } catch (ConnectException $e) {
  400. throw new ApiException(
  401. "[{$e->getCode()}] {$e->getMessage()}",
  402. (int) $e->getCode(),
  403. null,
  404. null
  405. );
  406. }
  407. $statusCode = $response->getStatusCode();
  408. switch($statusCode) {
  409. case 200:
  410. return $this->handleResponseWithDataType(
  411. '\WikipaliApi\Model\GetApiV3MeReactions200Response',
  412. $request,
  413. $response,
  414. );
  415. case 401:
  416. return $this->handleResponseWithDataType(
  417. '\WikipaliApi\Model\ProblemDetails',
  418. $request,
  419. $response,
  420. );
  421. case 422:
  422. return $this->handleResponseWithDataType(
  423. '\WikipaliApi\Model\ProblemDetails',
  424. $request,
  425. $response,
  426. );
  427. }
  428. if ($statusCode < 200 || $statusCode > 299) {
  429. throw new ApiException(
  430. sprintf(
  431. '[%d] Error connecting to the API (%s)',
  432. $statusCode,
  433. (string) $request->getUri()
  434. ),
  435. $statusCode,
  436. $response->getHeaders(),
  437. (string) $response->getBody()
  438. );
  439. }
  440. return $this->handleResponseWithDataType(
  441. '\WikipaliApi\Model\GetApiV3MeReactions200Response',
  442. $request,
  443. $response,
  444. );
  445. } catch (ApiException $e) {
  446. switch ($e->getCode()) {
  447. case 200:
  448. $data = ObjectSerializer::deserialize(
  449. $e->getResponseBody(),
  450. '\WikipaliApi\Model\GetApiV3MeReactions200Response',
  451. $e->getResponseHeaders()
  452. );
  453. $e->setResponseObject($data);
  454. throw $e;
  455. case 401:
  456. $data = ObjectSerializer::deserialize(
  457. $e->getResponseBody(),
  458. '\WikipaliApi\Model\ProblemDetails',
  459. $e->getResponseHeaders()
  460. );
  461. $e->setResponseObject($data);
  462. throw $e;
  463. case 422:
  464. $data = ObjectSerializer::deserialize(
  465. $e->getResponseBody(),
  466. '\WikipaliApi\Model\ProblemDetails',
  467. $e->getResponseHeaders()
  468. );
  469. $e->setResponseObject($data);
  470. throw $e;
  471. }
  472. throw $e;
  473. }
  474. }
  475. /**
  476. * Operation getApiV3MeReactionsAsync
  477. *
  478. * 列出我自己的 reactions
  479. *
  480. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  481. * @param string|null $type 操作类型 (optional)
  482. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  483. * @param int|null $page 页码 (optional, default to 1)
  484. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  485. *
  486. * @throws \InvalidArgumentException
  487. * @return \GuzzleHttp\Promise\PromiseInterface
  488. */
  489. public function getApiV3MeReactionsAsync($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  490. {
  491. return $this->getApiV3MeReactionsAsyncWithHttpInfo($per_page, $type, $target_type, $page, $contentType)
  492. ->then(
  493. function ($response) {
  494. return $response[0];
  495. }
  496. );
  497. }
  498. /**
  499. * Operation getApiV3MeReactionsAsyncWithHttpInfo
  500. *
  501. * 列出我自己的 reactions
  502. *
  503. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  504. * @param string|null $type 操作类型 (optional)
  505. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  506. * @param int|null $page 页码 (optional, default to 1)
  507. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  508. *
  509. * @throws \InvalidArgumentException
  510. * @return \GuzzleHttp\Promise\PromiseInterface
  511. */
  512. public function getApiV3MeReactionsAsyncWithHttpInfo($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  513. {
  514. $returnType = '\WikipaliApi\Model\GetApiV3MeReactions200Response';
  515. $request = $this->getApiV3MeReactionsRequest($per_page, $type, $target_type, $page, $contentType);
  516. return $this->client
  517. ->sendAsync($request, $this->createHttpClientOption())
  518. ->then(
  519. function ($response) use ($returnType) {
  520. if ($returnType === '\SplFileObject') {
  521. $content = $response->getBody(); //stream goes to serializer
  522. } else {
  523. $content = (string) $response->getBody();
  524. if ($returnType !== 'string') {
  525. $content = json_decode($content);
  526. }
  527. }
  528. return [
  529. ObjectSerializer::deserialize($content, $returnType, []),
  530. $response->getStatusCode(),
  531. $response->getHeaders()
  532. ];
  533. },
  534. function ($exception) {
  535. $response = $exception->getResponse();
  536. $statusCode = $response->getStatusCode();
  537. throw new ApiException(
  538. sprintf(
  539. '[%d] Error connecting to the API (%s)',
  540. $statusCode,
  541. $exception->getRequest()->getUri()
  542. ),
  543. $statusCode,
  544. $response->getHeaders(),
  545. (string) $response->getBody()
  546. );
  547. }
  548. );
  549. }
  550. /**
  551. * Create request for operation 'getApiV3MeReactions'
  552. *
  553. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  554. * @param string|null $type 操作类型 (optional)
  555. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  556. * @param int|null $page 页码 (optional, default to 1)
  557. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  558. *
  559. * @throws \InvalidArgumentException
  560. * @return \GuzzleHttp\Psr7\Request
  561. */
  562. public function getApiV3MeReactionsRequest($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  563. {
  564. $resourcePath = '/v3/me/reactions';
  565. $formParams = [];
  566. $queryParams = [];
  567. $headerParams = [];
  568. $httpBody = '';
  569. $multipart = false;
  570. // query params
  571. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  572. $per_page,
  573. 'per_page', // param base name
  574. 'integer', // openApiType
  575. 'form', // style
  576. true, // explode
  577. false // required
  578. ) ?? []);
  579. // query params
  580. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  581. $type,
  582. 'type', // param base name
  583. 'string', // openApiType
  584. 'form', // style
  585. true, // explode
  586. false // required
  587. ) ?? []);
  588. // query params
  589. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  590. $target_type,
  591. 'target_type', // param base name
  592. 'string', // openApiType
  593. 'form', // style
  594. true, // explode
  595. false // required
  596. ) ?? []);
  597. // query params
  598. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  599. $page,
  600. 'page', // param base name
  601. 'integer', // openApiType
  602. 'form', // style
  603. true, // explode
  604. false // required
  605. ) ?? []);
  606. $headers = $this->headerSelector->selectHeaders(
  607. ['application/json', 'application/problem+json', ],
  608. $contentType,
  609. $multipart
  610. );
  611. // for model (json/xml)
  612. if (count($formParams) > 0) {
  613. if ($multipart) {
  614. $multipartContents = [];
  615. foreach ($formParams as $formParamName => $formParamValue) {
  616. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  617. foreach ($formParamValueItems as $formParamValueItem) {
  618. $multipartContents[] = [
  619. 'name' => $formParamName,
  620. 'contents' => $formParamValueItem
  621. ];
  622. }
  623. }
  624. // for HTTP post (form)
  625. $httpBody = new MultipartStream($multipartContents);
  626. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  627. # if Content-Type contains "application/json", json_encode the form parameters
  628. try {
  629. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  630. } catch (\JsonException $e) {
  631. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  632. }
  633. } else {
  634. // for HTTP post (form)
  635. $httpBody = ObjectSerializer::buildQuery($formParams);
  636. }
  637. }
  638. // this endpoint requires Bearer authentication (access token)
  639. if (!empty($this->config->getAccessToken())) {
  640. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  641. }
  642. $defaultHeaders = [];
  643. if ($this->config->getUserAgent()) {
  644. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  645. }
  646. $headers = array_merge(
  647. $defaultHeaders,
  648. $headerParams,
  649. $headers
  650. );
  651. $operationHost = $this->config->getHost();
  652. $query = ObjectSerializer::buildQuery($queryParams);
  653. return new Request(
  654. 'GET',
  655. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  656. $headers,
  657. $httpBody
  658. );
  659. }
  660. /**
  661. * Operation getApiV3Reactions
  662. *
  663. * 列出某个 target 下的 reactions
  664. *
  665. * @param string $target_id target 的 uuid (required)
  666. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  667. * @param string|null $type 操作类型 (optional)
  668. * @param int|null $page 页码 (optional, default to 1)
  669. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Reactions'] to see the possible values for this operation
  670. *
  671. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  672. * @throws \InvalidArgumentException
  673. * @return \WikipaliApi\Model\GetApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails
  674. */
  675. public function getApiV3Reactions($target_id, $per_page = 15, $type = null, $page = 1, string $contentType = self::contentTypes['getApiV3Reactions'][0])
  676. {
  677. list($response) = $this->getApiV3ReactionsWithHttpInfo($target_id, $per_page, $type, $page, $contentType);
  678. return $response;
  679. }
  680. /**
  681. * Operation getApiV3ReactionsWithHttpInfo
  682. *
  683. * 列出某个 target 下的 reactions
  684. *
  685. * @param string $target_id target 的 uuid (required)
  686. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  687. * @param string|null $type 操作类型 (optional)
  688. * @param int|null $page 页码 (optional, default to 1)
  689. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Reactions'] to see the possible values for this operation
  690. *
  691. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  692. * @throws \InvalidArgumentException
  693. * @return array of \WikipaliApi\Model\GetApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  694. */
  695. public function getApiV3ReactionsWithHttpInfo($target_id, $per_page = 15, $type = null, $page = 1, string $contentType = self::contentTypes['getApiV3Reactions'][0])
  696. {
  697. $request = $this->getApiV3ReactionsRequest($target_id, $per_page, $type, $page, $contentType);
  698. try {
  699. $options = $this->createHttpClientOption();
  700. try {
  701. $response = $this->client->send($request, $options);
  702. } catch (RequestException $e) {
  703. throw new ApiException(
  704. "[{$e->getCode()}] {$e->getMessage()}",
  705. (int) $e->getCode(),
  706. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  707. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  708. );
  709. } catch (ConnectException $e) {
  710. throw new ApiException(
  711. "[{$e->getCode()}] {$e->getMessage()}",
  712. (int) $e->getCode(),
  713. null,
  714. null
  715. );
  716. }
  717. $statusCode = $response->getStatusCode();
  718. switch($statusCode) {
  719. case 200:
  720. return $this->handleResponseWithDataType(
  721. '\WikipaliApi\Model\GetApiV3MeReactions200Response',
  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\GetApiV3MeReactions200Response',
  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\GetApiV3MeReactions200Response',
  755. $e->getResponseHeaders()
  756. );
  757. $e->setResponseObject($data);
  758. throw $e;
  759. case 422:
  760. $data = ObjectSerializer::deserialize(
  761. $e->getResponseBody(),
  762. '\WikipaliApi\Model\ProblemDetails',
  763. $e->getResponseHeaders()
  764. );
  765. $e->setResponseObject($data);
  766. throw $e;
  767. }
  768. throw $e;
  769. }
  770. }
  771. /**
  772. * Operation getApiV3ReactionsAsync
  773. *
  774. * 列出某个 target 下的 reactions
  775. *
  776. * @param string $target_id target 的 uuid (required)
  777. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  778. * @param string|null $type 操作类型 (optional)
  779. * @param int|null $page 页码 (optional, default to 1)
  780. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Reactions'] to see the possible values for this operation
  781. *
  782. * @throws \InvalidArgumentException
  783. * @return \GuzzleHttp\Promise\PromiseInterface
  784. */
  785. public function getApiV3ReactionsAsync($target_id, $per_page = 15, $type = null, $page = 1, string $contentType = self::contentTypes['getApiV3Reactions'][0])
  786. {
  787. return $this->getApiV3ReactionsAsyncWithHttpInfo($target_id, $per_page, $type, $page, $contentType)
  788. ->then(
  789. function ($response) {
  790. return $response[0];
  791. }
  792. );
  793. }
  794. /**
  795. * Operation getApiV3ReactionsAsyncWithHttpInfo
  796. *
  797. * 列出某个 target 下的 reactions
  798. *
  799. * @param string $target_id target 的 uuid (required)
  800. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  801. * @param string|null $type 操作类型 (optional)
  802. * @param int|null $page 页码 (optional, default to 1)
  803. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Reactions'] to see the possible values for this operation
  804. *
  805. * @throws \InvalidArgumentException
  806. * @return \GuzzleHttp\Promise\PromiseInterface
  807. */
  808. public function getApiV3ReactionsAsyncWithHttpInfo($target_id, $per_page = 15, $type = null, $page = 1, string $contentType = self::contentTypes['getApiV3Reactions'][0])
  809. {
  810. $returnType = '\WikipaliApi\Model\GetApiV3MeReactions200Response';
  811. $request = $this->getApiV3ReactionsRequest($target_id, $per_page, $type, $page, $contentType);
  812. return $this->client
  813. ->sendAsync($request, $this->createHttpClientOption())
  814. ->then(
  815. function ($response) use ($returnType) {
  816. if ($returnType === '\SplFileObject') {
  817. $content = $response->getBody(); //stream goes to serializer
  818. } else {
  819. $content = (string) $response->getBody();
  820. if ($returnType !== 'string') {
  821. $content = json_decode($content);
  822. }
  823. }
  824. return [
  825. ObjectSerializer::deserialize($content, $returnType, []),
  826. $response->getStatusCode(),
  827. $response->getHeaders()
  828. ];
  829. },
  830. function ($exception) {
  831. $response = $exception->getResponse();
  832. $statusCode = $response->getStatusCode();
  833. throw new ApiException(
  834. sprintf(
  835. '[%d] Error connecting to the API (%s)',
  836. $statusCode,
  837. $exception->getRequest()->getUri()
  838. ),
  839. $statusCode,
  840. $response->getHeaders(),
  841. (string) $response->getBody()
  842. );
  843. }
  844. );
  845. }
  846. /**
  847. * Create request for operation 'getApiV3Reactions'
  848. *
  849. * @param string $target_id target 的 uuid (required)
  850. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  851. * @param string|null $type 操作类型 (optional)
  852. * @param int|null $page 页码 (optional, default to 1)
  853. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Reactions'] to see the possible values for this operation
  854. *
  855. * @throws \InvalidArgumentException
  856. * @return \GuzzleHttp\Psr7\Request
  857. */
  858. public function getApiV3ReactionsRequest($target_id, $per_page = 15, $type = null, $page = 1, string $contentType = self::contentTypes['getApiV3Reactions'][0])
  859. {
  860. // verify the required parameter 'target_id' is set
  861. if ($target_id === null || (is_array($target_id) && count($target_id) === 0)) {
  862. throw new \InvalidArgumentException(
  863. 'Missing the required parameter $target_id when calling getApiV3Reactions'
  864. );
  865. }
  866. $resourcePath = '/v3/reactions';
  867. $formParams = [];
  868. $queryParams = [];
  869. $headerParams = [];
  870. $httpBody = '';
  871. $multipart = false;
  872. // query params
  873. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  874. $per_page,
  875. 'per_page', // param base name
  876. 'integer', // openApiType
  877. 'form', // style
  878. true, // explode
  879. false // required
  880. ) ?? []);
  881. // query params
  882. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  883. $target_id,
  884. 'target_id', // param base name
  885. 'string', // openApiType
  886. 'form', // style
  887. true, // explode
  888. true // required
  889. ) ?? []);
  890. // query params
  891. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  892. $type,
  893. 'type', // param base name
  894. 'string', // openApiType
  895. 'form', // style
  896. true, // explode
  897. false // required
  898. ) ?? []);
  899. // query params
  900. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  901. $page,
  902. 'page', // param base name
  903. 'integer', // openApiType
  904. 'form', // style
  905. true, // explode
  906. false // required
  907. ) ?? []);
  908. $headers = $this->headerSelector->selectHeaders(
  909. ['application/json', 'application/problem+json', ],
  910. $contentType,
  911. $multipart
  912. );
  913. // for model (json/xml)
  914. if (count($formParams) > 0) {
  915. if ($multipart) {
  916. $multipartContents = [];
  917. foreach ($formParams as $formParamName => $formParamValue) {
  918. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  919. foreach ($formParamValueItems as $formParamValueItem) {
  920. $multipartContents[] = [
  921. 'name' => $formParamName,
  922. 'contents' => $formParamValueItem
  923. ];
  924. }
  925. }
  926. // for HTTP post (form)
  927. $httpBody = new MultipartStream($multipartContents);
  928. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  929. # if Content-Type contains "application/json", json_encode the form parameters
  930. try {
  931. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  932. } catch (\JsonException $e) {
  933. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  934. }
  935. } else {
  936. // for HTTP post (form)
  937. $httpBody = ObjectSerializer::buildQuery($formParams);
  938. }
  939. }
  940. // this endpoint requires Bearer authentication (access token)
  941. if (!empty($this->config->getAccessToken())) {
  942. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  943. }
  944. $defaultHeaders = [];
  945. if ($this->config->getUserAgent()) {
  946. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  947. }
  948. $headers = array_merge(
  949. $defaultHeaders,
  950. $headerParams,
  951. $headers
  952. );
  953. $operationHost = $this->config->getHost();
  954. $query = ObjectSerializer::buildQuery($queryParams);
  955. return new Request(
  956. 'GET',
  957. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  958. $headers,
  959. $httpBody
  960. );
  961. }
  962. /**
  963. * Operation getApiV3ReactionsTally
  964. *
  965. * 统计某个 target 下各 type 的计数
  966. *
  967. * @param string $target_id target 的 uuid (required)
  968. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ReactionsTally'] to see the possible values for this operation
  969. *
  970. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  971. * @throws \InvalidArgumentException
  972. * @return \WikipaliApi\Model\GetApiV3ReactionsTally200Response|\WikipaliApi\Model\ProblemDetails
  973. */
  974. public function getApiV3ReactionsTally($target_id, string $contentType = self::contentTypes['getApiV3ReactionsTally'][0])
  975. {
  976. list($response) = $this->getApiV3ReactionsTallyWithHttpInfo($target_id, $contentType);
  977. return $response;
  978. }
  979. /**
  980. * Operation getApiV3ReactionsTallyWithHttpInfo
  981. *
  982. * 统计某个 target 下各 type 的计数
  983. *
  984. * @param string $target_id target 的 uuid (required)
  985. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ReactionsTally'] to see the possible values for this operation
  986. *
  987. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  988. * @throws \InvalidArgumentException
  989. * @return array of \WikipaliApi\Model\GetApiV3ReactionsTally200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  990. */
  991. public function getApiV3ReactionsTallyWithHttpInfo($target_id, string $contentType = self::contentTypes['getApiV3ReactionsTally'][0])
  992. {
  993. $request = $this->getApiV3ReactionsTallyRequest($target_id, $contentType);
  994. try {
  995. $options = $this->createHttpClientOption();
  996. try {
  997. $response = $this->client->send($request, $options);
  998. } catch (RequestException $e) {
  999. throw new ApiException(
  1000. "[{$e->getCode()}] {$e->getMessage()}",
  1001. (int) $e->getCode(),
  1002. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1003. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1004. );
  1005. } catch (ConnectException $e) {
  1006. throw new ApiException(
  1007. "[{$e->getCode()}] {$e->getMessage()}",
  1008. (int) $e->getCode(),
  1009. null,
  1010. null
  1011. );
  1012. }
  1013. $statusCode = $response->getStatusCode();
  1014. switch($statusCode) {
  1015. case 200:
  1016. return $this->handleResponseWithDataType(
  1017. '\WikipaliApi\Model\GetApiV3ReactionsTally200Response',
  1018. $request,
  1019. $response,
  1020. );
  1021. case 422:
  1022. return $this->handleResponseWithDataType(
  1023. '\WikipaliApi\Model\ProblemDetails',
  1024. $request,
  1025. $response,
  1026. );
  1027. }
  1028. if ($statusCode < 200 || $statusCode > 299) {
  1029. throw new ApiException(
  1030. sprintf(
  1031. '[%d] Error connecting to the API (%s)',
  1032. $statusCode,
  1033. (string) $request->getUri()
  1034. ),
  1035. $statusCode,
  1036. $response->getHeaders(),
  1037. (string) $response->getBody()
  1038. );
  1039. }
  1040. return $this->handleResponseWithDataType(
  1041. '\WikipaliApi\Model\GetApiV3ReactionsTally200Response',
  1042. $request,
  1043. $response,
  1044. );
  1045. } catch (ApiException $e) {
  1046. switch ($e->getCode()) {
  1047. case 200:
  1048. $data = ObjectSerializer::deserialize(
  1049. $e->getResponseBody(),
  1050. '\WikipaliApi\Model\GetApiV3ReactionsTally200Response',
  1051. $e->getResponseHeaders()
  1052. );
  1053. $e->setResponseObject($data);
  1054. throw $e;
  1055. case 422:
  1056. $data = ObjectSerializer::deserialize(
  1057. $e->getResponseBody(),
  1058. '\WikipaliApi\Model\ProblemDetails',
  1059. $e->getResponseHeaders()
  1060. );
  1061. $e->setResponseObject($data);
  1062. throw $e;
  1063. }
  1064. throw $e;
  1065. }
  1066. }
  1067. /**
  1068. * Operation getApiV3ReactionsTallyAsync
  1069. *
  1070. * 统计某个 target 下各 type 的计数
  1071. *
  1072. * @param string $target_id target 的 uuid (required)
  1073. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ReactionsTally'] to see the possible values for this operation
  1074. *
  1075. * @throws \InvalidArgumentException
  1076. * @return \GuzzleHttp\Promise\PromiseInterface
  1077. */
  1078. public function getApiV3ReactionsTallyAsync($target_id, string $contentType = self::contentTypes['getApiV3ReactionsTally'][0])
  1079. {
  1080. return $this->getApiV3ReactionsTallyAsyncWithHttpInfo($target_id, $contentType)
  1081. ->then(
  1082. function ($response) {
  1083. return $response[0];
  1084. }
  1085. );
  1086. }
  1087. /**
  1088. * Operation getApiV3ReactionsTallyAsyncWithHttpInfo
  1089. *
  1090. * 统计某个 target 下各 type 的计数
  1091. *
  1092. * @param string $target_id target 的 uuid (required)
  1093. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ReactionsTally'] to see the possible values for this operation
  1094. *
  1095. * @throws \InvalidArgumentException
  1096. * @return \GuzzleHttp\Promise\PromiseInterface
  1097. */
  1098. public function getApiV3ReactionsTallyAsyncWithHttpInfo($target_id, string $contentType = self::contentTypes['getApiV3ReactionsTally'][0])
  1099. {
  1100. $returnType = '\WikipaliApi\Model\GetApiV3ReactionsTally200Response';
  1101. $request = $this->getApiV3ReactionsTallyRequest($target_id, $contentType);
  1102. return $this->client
  1103. ->sendAsync($request, $this->createHttpClientOption())
  1104. ->then(
  1105. function ($response) use ($returnType) {
  1106. if ($returnType === '\SplFileObject') {
  1107. $content = $response->getBody(); //stream goes to serializer
  1108. } else {
  1109. $content = (string) $response->getBody();
  1110. if ($returnType !== 'string') {
  1111. $content = json_decode($content);
  1112. }
  1113. }
  1114. return [
  1115. ObjectSerializer::deserialize($content, $returnType, []),
  1116. $response->getStatusCode(),
  1117. $response->getHeaders()
  1118. ];
  1119. },
  1120. function ($exception) {
  1121. $response = $exception->getResponse();
  1122. $statusCode = $response->getStatusCode();
  1123. throw new ApiException(
  1124. sprintf(
  1125. '[%d] Error connecting to the API (%s)',
  1126. $statusCode,
  1127. $exception->getRequest()->getUri()
  1128. ),
  1129. $statusCode,
  1130. $response->getHeaders(),
  1131. (string) $response->getBody()
  1132. );
  1133. }
  1134. );
  1135. }
  1136. /**
  1137. * Create request for operation 'getApiV3ReactionsTally'
  1138. *
  1139. * @param string $target_id target 的 uuid (required)
  1140. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ReactionsTally'] to see the possible values for this operation
  1141. *
  1142. * @throws \InvalidArgumentException
  1143. * @return \GuzzleHttp\Psr7\Request
  1144. */
  1145. public function getApiV3ReactionsTallyRequest($target_id, string $contentType = self::contentTypes['getApiV3ReactionsTally'][0])
  1146. {
  1147. // verify the required parameter 'target_id' is set
  1148. if ($target_id === null || (is_array($target_id) && count($target_id) === 0)) {
  1149. throw new \InvalidArgumentException(
  1150. 'Missing the required parameter $target_id when calling getApiV3ReactionsTally'
  1151. );
  1152. }
  1153. $resourcePath = '/v3/reactions/tally';
  1154. $formParams = [];
  1155. $queryParams = [];
  1156. $headerParams = [];
  1157. $httpBody = '';
  1158. $multipart = false;
  1159. // query params
  1160. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1161. $target_id,
  1162. 'target_id', // param base name
  1163. 'string', // openApiType
  1164. 'form', // style
  1165. true, // explode
  1166. true // required
  1167. ) ?? []);
  1168. $headers = $this->headerSelector->selectHeaders(
  1169. ['application/json', 'application/problem+json', ],
  1170. $contentType,
  1171. $multipart
  1172. );
  1173. // for model (json/xml)
  1174. if (count($formParams) > 0) {
  1175. if ($multipart) {
  1176. $multipartContents = [];
  1177. foreach ($formParams as $formParamName => $formParamValue) {
  1178. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1179. foreach ($formParamValueItems as $formParamValueItem) {
  1180. $multipartContents[] = [
  1181. 'name' => $formParamName,
  1182. 'contents' => $formParamValueItem
  1183. ];
  1184. }
  1185. }
  1186. // for HTTP post (form)
  1187. $httpBody = new MultipartStream($multipartContents);
  1188. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1189. # if Content-Type contains "application/json", json_encode the form parameters
  1190. try {
  1191. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1192. } catch (\JsonException $e) {
  1193. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1194. }
  1195. } else {
  1196. // for HTTP post (form)
  1197. $httpBody = ObjectSerializer::buildQuery($formParams);
  1198. }
  1199. }
  1200. // this endpoint requires Bearer authentication (access token)
  1201. if (!empty($this->config->getAccessToken())) {
  1202. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1203. }
  1204. $defaultHeaders = [];
  1205. if ($this->config->getUserAgent()) {
  1206. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1207. }
  1208. $headers = array_merge(
  1209. $defaultHeaders,
  1210. $headerParams,
  1211. $headers
  1212. );
  1213. $operationHost = $this->config->getHost();
  1214. $query = ObjectSerializer::buildQuery($queryParams);
  1215. return new Request(
  1216. 'GET',
  1217. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1218. $headers,
  1219. $httpBody
  1220. );
  1221. }
  1222. /**
  1223. * Operation postApiV3MeReactions
  1224. *
  1225. * 添加一条我自己的 reaction(幂等)
  1226. *
  1227. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request post_api_v3_me_reactions_request (required)
  1228. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  1229. *
  1230. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1231. * @throws \InvalidArgumentException
  1232. * @return \WikipaliApi\Model\PostApiV3MeReactions200Response|\WikipaliApi\Model\PostApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  1233. */
  1234. public function postApiV3MeReactions($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  1235. {
  1236. list($response) = $this->postApiV3MeReactionsWithHttpInfo($post_api_v3_me_reactions_request, $contentType);
  1237. return $response;
  1238. }
  1239. /**
  1240. * Operation postApiV3MeReactionsWithHttpInfo
  1241. *
  1242. * 添加一条我自己的 reaction(幂等)
  1243. *
  1244. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request (required)
  1245. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  1246. *
  1247. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1248. * @throws \InvalidArgumentException
  1249. * @return array of \WikipaliApi\Model\PostApiV3MeReactions200Response|\WikipaliApi\Model\PostApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  1250. */
  1251. public function postApiV3MeReactionsWithHttpInfo($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  1252. {
  1253. $request = $this->postApiV3MeReactionsRequest($post_api_v3_me_reactions_request, $contentType);
  1254. try {
  1255. $options = $this->createHttpClientOption();
  1256. try {
  1257. $response = $this->client->send($request, $options);
  1258. } catch (RequestException $e) {
  1259. throw new ApiException(
  1260. "[{$e->getCode()}] {$e->getMessage()}",
  1261. (int) $e->getCode(),
  1262. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1263. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1264. );
  1265. } catch (ConnectException $e) {
  1266. throw new ApiException(
  1267. "[{$e->getCode()}] {$e->getMessage()}",
  1268. (int) $e->getCode(),
  1269. null,
  1270. null
  1271. );
  1272. }
  1273. $statusCode = $response->getStatusCode();
  1274. switch($statusCode) {
  1275. case 200:
  1276. return $this->handleResponseWithDataType(
  1277. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  1278. $request,
  1279. $response,
  1280. );
  1281. case 201:
  1282. return $this->handleResponseWithDataType(
  1283. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  1284. $request,
  1285. $response,
  1286. );
  1287. case 401:
  1288. return $this->handleResponseWithDataType(
  1289. '\WikipaliApi\Model\ProblemDetails',
  1290. $request,
  1291. $response,
  1292. );
  1293. case 422:
  1294. return $this->handleResponseWithDataType(
  1295. '\WikipaliApi\Model\ProblemDetails',
  1296. $request,
  1297. $response,
  1298. );
  1299. }
  1300. if ($statusCode < 200 || $statusCode > 299) {
  1301. throw new ApiException(
  1302. sprintf(
  1303. '[%d] Error connecting to the API (%s)',
  1304. $statusCode,
  1305. (string) $request->getUri()
  1306. ),
  1307. $statusCode,
  1308. $response->getHeaders(),
  1309. (string) $response->getBody()
  1310. );
  1311. }
  1312. return $this->handleResponseWithDataType(
  1313. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  1314. $request,
  1315. $response,
  1316. );
  1317. } catch (ApiException $e) {
  1318. switch ($e->getCode()) {
  1319. case 200:
  1320. $data = ObjectSerializer::deserialize(
  1321. $e->getResponseBody(),
  1322. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  1323. $e->getResponseHeaders()
  1324. );
  1325. $e->setResponseObject($data);
  1326. throw $e;
  1327. case 201:
  1328. $data = ObjectSerializer::deserialize(
  1329. $e->getResponseBody(),
  1330. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  1331. $e->getResponseHeaders()
  1332. );
  1333. $e->setResponseObject($data);
  1334. throw $e;
  1335. case 401:
  1336. $data = ObjectSerializer::deserialize(
  1337. $e->getResponseBody(),
  1338. '\WikipaliApi\Model\ProblemDetails',
  1339. $e->getResponseHeaders()
  1340. );
  1341. $e->setResponseObject($data);
  1342. throw $e;
  1343. case 422:
  1344. $data = ObjectSerializer::deserialize(
  1345. $e->getResponseBody(),
  1346. '\WikipaliApi\Model\ProblemDetails',
  1347. $e->getResponseHeaders()
  1348. );
  1349. $e->setResponseObject($data);
  1350. throw $e;
  1351. }
  1352. throw $e;
  1353. }
  1354. }
  1355. /**
  1356. * Operation postApiV3MeReactionsAsync
  1357. *
  1358. * 添加一条我自己的 reaction(幂等)
  1359. *
  1360. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request (required)
  1361. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  1362. *
  1363. * @throws \InvalidArgumentException
  1364. * @return \GuzzleHttp\Promise\PromiseInterface
  1365. */
  1366. public function postApiV3MeReactionsAsync($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  1367. {
  1368. return $this->postApiV3MeReactionsAsyncWithHttpInfo($post_api_v3_me_reactions_request, $contentType)
  1369. ->then(
  1370. function ($response) {
  1371. return $response[0];
  1372. }
  1373. );
  1374. }
  1375. /**
  1376. * Operation postApiV3MeReactionsAsyncWithHttpInfo
  1377. *
  1378. * 添加一条我自己的 reaction(幂等)
  1379. *
  1380. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request (required)
  1381. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  1382. *
  1383. * @throws \InvalidArgumentException
  1384. * @return \GuzzleHttp\Promise\PromiseInterface
  1385. */
  1386. public function postApiV3MeReactionsAsyncWithHttpInfo($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  1387. {
  1388. $returnType = '\WikipaliApi\Model\PostApiV3MeReactions200Response';
  1389. $request = $this->postApiV3MeReactionsRequest($post_api_v3_me_reactions_request, $contentType);
  1390. return $this->client
  1391. ->sendAsync($request, $this->createHttpClientOption())
  1392. ->then(
  1393. function ($response) use ($returnType) {
  1394. if ($returnType === '\SplFileObject') {
  1395. $content = $response->getBody(); //stream goes to serializer
  1396. } else {
  1397. $content = (string) $response->getBody();
  1398. if ($returnType !== 'string') {
  1399. $content = json_decode($content);
  1400. }
  1401. }
  1402. return [
  1403. ObjectSerializer::deserialize($content, $returnType, []),
  1404. $response->getStatusCode(),
  1405. $response->getHeaders()
  1406. ];
  1407. },
  1408. function ($exception) {
  1409. $response = $exception->getResponse();
  1410. $statusCode = $response->getStatusCode();
  1411. throw new ApiException(
  1412. sprintf(
  1413. '[%d] Error connecting to the API (%s)',
  1414. $statusCode,
  1415. $exception->getRequest()->getUri()
  1416. ),
  1417. $statusCode,
  1418. $response->getHeaders(),
  1419. (string) $response->getBody()
  1420. );
  1421. }
  1422. );
  1423. }
  1424. /**
  1425. * Create request for operation 'postApiV3MeReactions'
  1426. *
  1427. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request (required)
  1428. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  1429. *
  1430. * @throws \InvalidArgumentException
  1431. * @return \GuzzleHttp\Psr7\Request
  1432. */
  1433. public function postApiV3MeReactionsRequest($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  1434. {
  1435. // verify the required parameter 'post_api_v3_me_reactions_request' is set
  1436. if ($post_api_v3_me_reactions_request === null || (is_array($post_api_v3_me_reactions_request) && count($post_api_v3_me_reactions_request) === 0)) {
  1437. throw new \InvalidArgumentException(
  1438. 'Missing the required parameter $post_api_v3_me_reactions_request when calling postApiV3MeReactions'
  1439. );
  1440. }
  1441. $resourcePath = '/v3/me/reactions';
  1442. $formParams = [];
  1443. $queryParams = [];
  1444. $headerParams = [];
  1445. $httpBody = '';
  1446. $multipart = false;
  1447. $headers = $this->headerSelector->selectHeaders(
  1448. ['application/json', 'application/problem+json', ],
  1449. $contentType,
  1450. $multipart
  1451. );
  1452. // for model (json/xml)
  1453. if (isset($post_api_v3_me_reactions_request)) {
  1454. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  1455. # if Content-Type contains "application/json", json_encode the body
  1456. try {
  1457. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_me_reactions_request), JSON_THROW_ON_ERROR);
  1458. } catch (\JsonException $e) {
  1459. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1460. }
  1461. } else {
  1462. $httpBody = $post_api_v3_me_reactions_request;
  1463. }
  1464. } elseif (count($formParams) > 0) {
  1465. if ($multipart) {
  1466. $multipartContents = [];
  1467. foreach ($formParams as $formParamName => $formParamValue) {
  1468. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1469. foreach ($formParamValueItems as $formParamValueItem) {
  1470. $multipartContents[] = [
  1471. 'name' => $formParamName,
  1472. 'contents' => $formParamValueItem
  1473. ];
  1474. }
  1475. }
  1476. // for HTTP post (form)
  1477. $httpBody = new MultipartStream($multipartContents);
  1478. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1479. # if Content-Type contains "application/json", json_encode the form parameters
  1480. try {
  1481. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1482. } catch (\JsonException $e) {
  1483. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1484. }
  1485. } else {
  1486. // for HTTP post (form)
  1487. $httpBody = ObjectSerializer::buildQuery($formParams);
  1488. }
  1489. }
  1490. // this endpoint requires Bearer authentication (access token)
  1491. if (!empty($this->config->getAccessToken())) {
  1492. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1493. }
  1494. $defaultHeaders = [];
  1495. if ($this->config->getUserAgent()) {
  1496. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1497. }
  1498. $headers = array_merge(
  1499. $defaultHeaders,
  1500. $headerParams,
  1501. $headers
  1502. );
  1503. $operationHost = $this->config->getHost();
  1504. $query = ObjectSerializer::buildQuery($queryParams);
  1505. return new Request(
  1506. 'POST',
  1507. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1508. $headers,
  1509. $httpBody
  1510. );
  1511. }
  1512. /**
  1513. * Create http client option
  1514. *
  1515. * @throws \RuntimeException on file opening failure
  1516. * @return array of http client options
  1517. */
  1518. protected function createHttpClientOption()
  1519. {
  1520. $options = [];
  1521. if ($this->config->getDebug()) {
  1522. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  1523. if (!$options[RequestOptions::DEBUG]) {
  1524. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  1525. }
  1526. }
  1527. if ($this->config->getCertFile()) {
  1528. $options[RequestOptions::CERT] = $this->config->getCertFile();
  1529. }
  1530. if ($this->config->getKeyFile()) {
  1531. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  1532. }
  1533. return $options;
  1534. }
  1535. private function handleResponseWithDataType(
  1536. string $dataType,
  1537. RequestInterface $request,
  1538. ResponseInterface $response
  1539. ): array {
  1540. if ($dataType === '\SplFileObject') {
  1541. $content = $response->getBody(); //stream goes to serializer
  1542. } else {
  1543. $content = (string) $response->getBody();
  1544. if ($dataType !== 'string') {
  1545. try {
  1546. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  1547. } catch (\JsonException $exception) {
  1548. throw new ApiException(
  1549. sprintf(
  1550. 'Error JSON decoding server response (%s)',
  1551. $request->getUri()
  1552. ),
  1553. $response->getStatusCode(),
  1554. $response->getHeaders(),
  1555. $content
  1556. );
  1557. }
  1558. }
  1559. }
  1560. return [
  1561. ObjectSerializer::deserialize($content, $dataType, []),
  1562. $response->getStatusCode(),
  1563. $response->getHeaders()
  1564. ];
  1565. }
  1566. private function responseWithinRangeCode(
  1567. string $rangeCode,
  1568. int $statusCode
  1569. ): bool {
  1570. $left = (int) ($rangeCode[0].'00');
  1571. $right = (int) ($rangeCode[0].'99');
  1572. return $statusCode >= $left && $statusCode <= $right;
  1573. }
  1574. }