ReactionsApi.php 29 KB

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