MeApi.php 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. <?php
  2. /**
  3. * MeApi
  4. * PHP version 8.1
  5. *
  6. * @category Class
  7. * @package WikipaliApi
  8. * @author OpenAPI Generator team
  9. * @link https://openapi-generator.tech
  10. */
  11. /**
  12. * MINT API
  13. *
  14. * International Academy Of Pali Tipitaka(国际巴利三藏学院) 由 `php openapi/scripts/generate.php` 依据 api-v13 的路由与控制器源码生成。 响应统一封装为 `{ok, message, data}`;`ok=false` 时 `message` 为错误信息。
  15. *
  16. * The version of the OpenAPI document: 2026.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. * MeApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class MeApi
  49. {
  50. /**
  51. * @var ClientInterface
  52. */
  53. protected $client;
  54. /**
  55. * @var Configuration
  56. */
  57. protected $config;
  58. /**
  59. * @var HeaderSelector
  60. */
  61. protected $headerSelector;
  62. /**
  63. * @var int Host index
  64. */
  65. protected $hostIndex;
  66. /** @var string[] $contentTypes **/
  67. public const contentTypes = [
  68. 'deleteApiV3MeReactionsReaction' => [
  69. 'application/json',
  70. ],
  71. 'getApiV3Me' => [
  72. 'application/json',
  73. ],
  74. 'getApiV3MeReactions' => [
  75. 'application/json',
  76. ],
  77. 'postApiV3MeReactions' => [
  78. 'application/json',
  79. ],
  80. ];
  81. /**
  82. * @param ClientInterface $client
  83. * @param Configuration $config
  84. * @param HeaderSelector $selector
  85. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  86. */
  87. public function __construct(
  88. ?ClientInterface $client = null,
  89. ?Configuration $config = null,
  90. ?HeaderSelector $selector = null,
  91. int $hostIndex = 0
  92. ) {
  93. $this->client = $client ?: new Client();
  94. $this->config = $config ?: Configuration::getDefaultConfiguration();
  95. $this->headerSelector = $selector ?: new HeaderSelector();
  96. $this->hostIndex = $hostIndex;
  97. }
  98. /**
  99. * Set the host index
  100. *
  101. * @param int $hostIndex Host index (required)
  102. */
  103. public function setHostIndex($hostIndex): void
  104. {
  105. $this->hostIndex = $hostIndex;
  106. }
  107. /**
  108. * Get the host index
  109. *
  110. * @return int Host index
  111. */
  112. public function getHostIndex()
  113. {
  114. return $this->hostIndex;
  115. }
  116. /**
  117. * @return Configuration
  118. */
  119. public function getConfig()
  120. {
  121. return $this->config;
  122. }
  123. /**
  124. * Operation deleteApiV3MeReactionsReaction
  125. *
  126. * 删除我自己的 reaction
  127. *
  128. * @param string $reaction reaction 的 uuid (required)
  129. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  130. *
  131. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  132. * @throws \InvalidArgumentException
  133. * @return void
  134. */
  135. public function deleteApiV3MeReactionsReaction($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  136. {
  137. $this->deleteApiV3MeReactionsReactionWithHttpInfo($reaction, $contentType);
  138. }
  139. /**
  140. * Operation deleteApiV3MeReactionsReactionWithHttpInfo
  141. *
  142. * 删除我自己的 reaction
  143. *
  144. * @param string $reaction reaction 的 uuid (required)
  145. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  146. *
  147. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  148. * @throws \InvalidArgumentException
  149. * @return array of null, HTTP status code, HTTP response headers (array of strings)
  150. */
  151. public function deleteApiV3MeReactionsReactionWithHttpInfo($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  152. {
  153. $request = $this->deleteApiV3MeReactionsReactionRequest($reaction, $contentType);
  154. try {
  155. $options = $this->createHttpClientOption();
  156. try {
  157. $response = $this->client->send($request, $options);
  158. } catch (RequestException $e) {
  159. throw new ApiException(
  160. "[{$e->getCode()}] {$e->getMessage()}",
  161. (int) $e->getCode(),
  162. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  163. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  164. );
  165. } catch (ConnectException $e) {
  166. throw new ApiException(
  167. "[{$e->getCode()}] {$e->getMessage()}",
  168. (int) $e->getCode(),
  169. null,
  170. null
  171. );
  172. }
  173. $statusCode = $response->getStatusCode();
  174. return [null, $statusCode, $response->getHeaders()];
  175. } catch (ApiException $e) {
  176. switch ($e->getCode()) {
  177. case 401:
  178. $data = ObjectSerializer::deserialize(
  179. $e->getResponseBody(),
  180. '\WikipaliApi\Model\ProblemDetails',
  181. $e->getResponseHeaders()
  182. );
  183. $e->setResponseObject($data);
  184. throw $e;
  185. case 403:
  186. $data = ObjectSerializer::deserialize(
  187. $e->getResponseBody(),
  188. '\WikipaliApi\Model\ProblemDetails',
  189. $e->getResponseHeaders()
  190. );
  191. $e->setResponseObject($data);
  192. throw $e;
  193. case 422:
  194. $data = ObjectSerializer::deserialize(
  195. $e->getResponseBody(),
  196. '\WikipaliApi\Model\ProblemDetails',
  197. $e->getResponseHeaders()
  198. );
  199. $e->setResponseObject($data);
  200. throw $e;
  201. }
  202. throw $e;
  203. }
  204. }
  205. /**
  206. * Operation deleteApiV3MeReactionsReactionAsync
  207. *
  208. * 删除我自己的 reaction
  209. *
  210. * @param string $reaction reaction 的 uuid (required)
  211. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  212. *
  213. * @throws \InvalidArgumentException
  214. * @return \GuzzleHttp\Promise\PromiseInterface
  215. */
  216. public function deleteApiV3MeReactionsReactionAsync($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  217. {
  218. return $this->deleteApiV3MeReactionsReactionAsyncWithHttpInfo($reaction, $contentType)
  219. ->then(
  220. function ($response) {
  221. return $response[0];
  222. }
  223. );
  224. }
  225. /**
  226. * Operation deleteApiV3MeReactionsReactionAsyncWithHttpInfo
  227. *
  228. * 删除我自己的 reaction
  229. *
  230. * @param string $reaction reaction 的 uuid (required)
  231. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  232. *
  233. * @throws \InvalidArgumentException
  234. * @return \GuzzleHttp\Promise\PromiseInterface
  235. */
  236. public function deleteApiV3MeReactionsReactionAsyncWithHttpInfo($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  237. {
  238. $returnType = '';
  239. $request = $this->deleteApiV3MeReactionsReactionRequest($reaction, $contentType);
  240. return $this->client
  241. ->sendAsync($request, $this->createHttpClientOption())
  242. ->then(
  243. function ($response) use ($returnType) {
  244. return [null, $response->getStatusCode(), $response->getHeaders()];
  245. },
  246. function ($exception) {
  247. $response = $exception->getResponse();
  248. $statusCode = $response->getStatusCode();
  249. throw new ApiException(
  250. sprintf(
  251. '[%d] Error connecting to the API (%s)',
  252. $statusCode,
  253. $exception->getRequest()->getUri()
  254. ),
  255. $statusCode,
  256. $response->getHeaders(),
  257. (string) $response->getBody()
  258. );
  259. }
  260. );
  261. }
  262. /**
  263. * Create request for operation 'deleteApiV3MeReactionsReaction'
  264. *
  265. * @param string $reaction reaction 的 uuid (required)
  266. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeReactionsReaction'] to see the possible values for this operation
  267. *
  268. * @throws \InvalidArgumentException
  269. * @return \GuzzleHttp\Psr7\Request
  270. */
  271. public function deleteApiV3MeReactionsReactionRequest($reaction, string $contentType = self::contentTypes['deleteApiV3MeReactionsReaction'][0])
  272. {
  273. // verify the required parameter 'reaction' is set
  274. if ($reaction === null || (is_array($reaction) && count($reaction) === 0)) {
  275. throw new \InvalidArgumentException(
  276. 'Missing the required parameter $reaction when calling deleteApiV3MeReactionsReaction'
  277. );
  278. }
  279. $resourcePath = '/v3/me/reactions/{reaction}';
  280. $formParams = [];
  281. $queryParams = [];
  282. $headerParams = [];
  283. $httpBody = '';
  284. $multipart = false;
  285. // path params
  286. if ($reaction !== null) {
  287. $resourcePath = str_replace(
  288. '{reaction}',
  289. ObjectSerializer::toPathValue($reaction),
  290. $resourcePath
  291. );
  292. }
  293. $headers = $this->headerSelector->selectHeaders(
  294. ['application/problem+json', ],
  295. $contentType,
  296. $multipart
  297. );
  298. // for model (json/xml)
  299. if (count($formParams) > 0) {
  300. if ($multipart) {
  301. $multipartContents = [];
  302. foreach ($formParams as $formParamName => $formParamValue) {
  303. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  304. foreach ($formParamValueItems as $formParamValueItem) {
  305. $multipartContents[] = [
  306. 'name' => $formParamName,
  307. 'contents' => $formParamValueItem
  308. ];
  309. }
  310. }
  311. // for HTTP post (form)
  312. $httpBody = new MultipartStream($multipartContents);
  313. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  314. # if Content-Type contains "application/json", json_encode the form parameters
  315. try {
  316. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  317. } catch (\JsonException $e) {
  318. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  319. }
  320. } else {
  321. // for HTTP post (form)
  322. $httpBody = ObjectSerializer::buildQuery($formParams);
  323. }
  324. }
  325. // this endpoint requires Bearer authentication (access token)
  326. if (!empty($this->config->getAccessToken())) {
  327. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  328. }
  329. $defaultHeaders = [];
  330. if ($this->config->getUserAgent()) {
  331. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  332. }
  333. $headers = array_merge(
  334. $defaultHeaders,
  335. $headerParams,
  336. $headers
  337. );
  338. $operationHost = $this->config->getHost();
  339. $query = ObjectSerializer::buildQuery($queryParams);
  340. return new Request(
  341. 'DELETE',
  342. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  343. $headers,
  344. $httpBody
  345. );
  346. }
  347. /**
  348. * Operation getApiV3Me
  349. *
  350. * 我的资料
  351. *
  352. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Me'] to see the possible values for this operation
  353. *
  354. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  355. * @throws \InvalidArgumentException
  356. * @return \WikipaliApi\Model\GetApiV3Me200Response|\WikipaliApi\Model\ProblemDetails
  357. */
  358. public function getApiV3Me(string $contentType = self::contentTypes['getApiV3Me'][0])
  359. {
  360. list($response) = $this->getApiV3MeWithHttpInfo($contentType);
  361. return $response;
  362. }
  363. /**
  364. * Operation getApiV3MeWithHttpInfo
  365. *
  366. * 我的资料
  367. *
  368. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Me'] to see the possible values for this operation
  369. *
  370. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  371. * @throws \InvalidArgumentException
  372. * @return array of \WikipaliApi\Model\GetApiV3Me200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  373. */
  374. public function getApiV3MeWithHttpInfo(string $contentType = self::contentTypes['getApiV3Me'][0])
  375. {
  376. $request = $this->getApiV3MeRequest($contentType);
  377. try {
  378. $options = $this->createHttpClientOption();
  379. try {
  380. $response = $this->client->send($request, $options);
  381. } catch (RequestException $e) {
  382. throw new ApiException(
  383. "[{$e->getCode()}] {$e->getMessage()}",
  384. (int) $e->getCode(),
  385. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  386. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  387. );
  388. } catch (ConnectException $e) {
  389. throw new ApiException(
  390. "[{$e->getCode()}] {$e->getMessage()}",
  391. (int) $e->getCode(),
  392. null,
  393. null
  394. );
  395. }
  396. $statusCode = $response->getStatusCode();
  397. switch($statusCode) {
  398. case 200:
  399. return $this->handleResponseWithDataType(
  400. '\WikipaliApi\Model\GetApiV3Me200Response',
  401. $request,
  402. $response,
  403. );
  404. case 401:
  405. return $this->handleResponseWithDataType(
  406. '\WikipaliApi\Model\ProblemDetails',
  407. $request,
  408. $response,
  409. );
  410. }
  411. if ($statusCode < 200 || $statusCode > 299) {
  412. throw new ApiException(
  413. sprintf(
  414. '[%d] Error connecting to the API (%s)',
  415. $statusCode,
  416. (string) $request->getUri()
  417. ),
  418. $statusCode,
  419. $response->getHeaders(),
  420. (string) $response->getBody()
  421. );
  422. }
  423. return $this->handleResponseWithDataType(
  424. '\WikipaliApi\Model\GetApiV3Me200Response',
  425. $request,
  426. $response,
  427. );
  428. } catch (ApiException $e) {
  429. switch ($e->getCode()) {
  430. case 200:
  431. $data = ObjectSerializer::deserialize(
  432. $e->getResponseBody(),
  433. '\WikipaliApi\Model\GetApiV3Me200Response',
  434. $e->getResponseHeaders()
  435. );
  436. $e->setResponseObject($data);
  437. throw $e;
  438. case 401:
  439. $data = ObjectSerializer::deserialize(
  440. $e->getResponseBody(),
  441. '\WikipaliApi\Model\ProblemDetails',
  442. $e->getResponseHeaders()
  443. );
  444. $e->setResponseObject($data);
  445. throw $e;
  446. }
  447. throw $e;
  448. }
  449. }
  450. /**
  451. * Operation getApiV3MeAsync
  452. *
  453. * 我的资料
  454. *
  455. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Me'] to see the possible values for this operation
  456. *
  457. * @throws \InvalidArgumentException
  458. * @return \GuzzleHttp\Promise\PromiseInterface
  459. */
  460. public function getApiV3MeAsync(string $contentType = self::contentTypes['getApiV3Me'][0])
  461. {
  462. return $this->getApiV3MeAsyncWithHttpInfo($contentType)
  463. ->then(
  464. function ($response) {
  465. return $response[0];
  466. }
  467. );
  468. }
  469. /**
  470. * Operation getApiV3MeAsyncWithHttpInfo
  471. *
  472. * 我的资料
  473. *
  474. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Me'] to see the possible values for this operation
  475. *
  476. * @throws \InvalidArgumentException
  477. * @return \GuzzleHttp\Promise\PromiseInterface
  478. */
  479. public function getApiV3MeAsyncWithHttpInfo(string $contentType = self::contentTypes['getApiV3Me'][0])
  480. {
  481. $returnType = '\WikipaliApi\Model\GetApiV3Me200Response';
  482. $request = $this->getApiV3MeRequest($contentType);
  483. return $this->client
  484. ->sendAsync($request, $this->createHttpClientOption())
  485. ->then(
  486. function ($response) use ($returnType) {
  487. if ($returnType === '\SplFileObject') {
  488. $content = $response->getBody(); //stream goes to serializer
  489. } else {
  490. $content = (string) $response->getBody();
  491. if ($returnType !== 'string') {
  492. $content = json_decode($content);
  493. }
  494. }
  495. return [
  496. ObjectSerializer::deserialize($content, $returnType, []),
  497. $response->getStatusCode(),
  498. $response->getHeaders()
  499. ];
  500. },
  501. function ($exception) {
  502. $response = $exception->getResponse();
  503. $statusCode = $response->getStatusCode();
  504. throw new ApiException(
  505. sprintf(
  506. '[%d] Error connecting to the API (%s)',
  507. $statusCode,
  508. $exception->getRequest()->getUri()
  509. ),
  510. $statusCode,
  511. $response->getHeaders(),
  512. (string) $response->getBody()
  513. );
  514. }
  515. );
  516. }
  517. /**
  518. * Create request for operation 'getApiV3Me'
  519. *
  520. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Me'] to see the possible values for this operation
  521. *
  522. * @throws \InvalidArgumentException
  523. * @return \GuzzleHttp\Psr7\Request
  524. */
  525. public function getApiV3MeRequest(string $contentType = self::contentTypes['getApiV3Me'][0])
  526. {
  527. $resourcePath = '/v3/me';
  528. $formParams = [];
  529. $queryParams = [];
  530. $headerParams = [];
  531. $httpBody = '';
  532. $multipart = false;
  533. $headers = $this->headerSelector->selectHeaders(
  534. ['application/json', 'application/problem+json', ],
  535. $contentType,
  536. $multipart
  537. );
  538. // for model (json/xml)
  539. if (count($formParams) > 0) {
  540. if ($multipart) {
  541. $multipartContents = [];
  542. foreach ($formParams as $formParamName => $formParamValue) {
  543. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  544. foreach ($formParamValueItems as $formParamValueItem) {
  545. $multipartContents[] = [
  546. 'name' => $formParamName,
  547. 'contents' => $formParamValueItem
  548. ];
  549. }
  550. }
  551. // for HTTP post (form)
  552. $httpBody = new MultipartStream($multipartContents);
  553. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  554. # if Content-Type contains "application/json", json_encode the form parameters
  555. try {
  556. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  557. } catch (\JsonException $e) {
  558. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  559. }
  560. } else {
  561. // for HTTP post (form)
  562. $httpBody = ObjectSerializer::buildQuery($formParams);
  563. }
  564. }
  565. // this endpoint requires Bearer authentication (access token)
  566. if (!empty($this->config->getAccessToken())) {
  567. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  568. }
  569. $defaultHeaders = [];
  570. if ($this->config->getUserAgent()) {
  571. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  572. }
  573. $headers = array_merge(
  574. $defaultHeaders,
  575. $headerParams,
  576. $headers
  577. );
  578. $operationHost = $this->config->getHost();
  579. $query = ObjectSerializer::buildQuery($queryParams);
  580. return new Request(
  581. 'GET',
  582. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  583. $headers,
  584. $httpBody
  585. );
  586. }
  587. /**
  588. * Operation getApiV3MeReactions
  589. *
  590. * 列出我自己的 reactions
  591. *
  592. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  593. * @param string|null $type 操作类型 (optional)
  594. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  595. * @param int|null $page 页码 (optional, default to 1)
  596. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  597. *
  598. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  599. * @throws \InvalidArgumentException
  600. * @return \WikipaliApi\Model\GetApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  601. */
  602. public function getApiV3MeReactions($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  603. {
  604. list($response) = $this->getApiV3MeReactionsWithHttpInfo($per_page, $type, $target_type, $page, $contentType);
  605. return $response;
  606. }
  607. /**
  608. * Operation getApiV3MeReactionsWithHttpInfo
  609. *
  610. * 列出我自己的 reactions
  611. *
  612. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  613. * @param string|null $type 操作类型 (optional)
  614. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  615. * @param int|null $page 页码 (optional, default to 1)
  616. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  617. *
  618. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  619. * @throws \InvalidArgumentException
  620. * @return array of \WikipaliApi\Model\GetApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  621. */
  622. public function getApiV3MeReactionsWithHttpInfo($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  623. {
  624. $request = $this->getApiV3MeReactionsRequest($per_page, $type, $target_type, $page, $contentType);
  625. try {
  626. $options = $this->createHttpClientOption();
  627. try {
  628. $response = $this->client->send($request, $options);
  629. } catch (RequestException $e) {
  630. throw new ApiException(
  631. "[{$e->getCode()}] {$e->getMessage()}",
  632. (int) $e->getCode(),
  633. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  634. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  635. );
  636. } catch (ConnectException $e) {
  637. throw new ApiException(
  638. "[{$e->getCode()}] {$e->getMessage()}",
  639. (int) $e->getCode(),
  640. null,
  641. null
  642. );
  643. }
  644. $statusCode = $response->getStatusCode();
  645. switch($statusCode) {
  646. case 200:
  647. return $this->handleResponseWithDataType(
  648. '\WikipaliApi\Model\GetApiV3MeReactions200Response',
  649. $request,
  650. $response,
  651. );
  652. case 401:
  653. return $this->handleResponseWithDataType(
  654. '\WikipaliApi\Model\ProblemDetails',
  655. $request,
  656. $response,
  657. );
  658. case 422:
  659. return $this->handleResponseWithDataType(
  660. '\WikipaliApi\Model\ProblemDetails',
  661. $request,
  662. $response,
  663. );
  664. }
  665. if ($statusCode < 200 || $statusCode > 299) {
  666. throw new ApiException(
  667. sprintf(
  668. '[%d] Error connecting to the API (%s)',
  669. $statusCode,
  670. (string) $request->getUri()
  671. ),
  672. $statusCode,
  673. $response->getHeaders(),
  674. (string) $response->getBody()
  675. );
  676. }
  677. return $this->handleResponseWithDataType(
  678. '\WikipaliApi\Model\GetApiV3MeReactions200Response',
  679. $request,
  680. $response,
  681. );
  682. } catch (ApiException $e) {
  683. switch ($e->getCode()) {
  684. case 200:
  685. $data = ObjectSerializer::deserialize(
  686. $e->getResponseBody(),
  687. '\WikipaliApi\Model\GetApiV3MeReactions200Response',
  688. $e->getResponseHeaders()
  689. );
  690. $e->setResponseObject($data);
  691. throw $e;
  692. case 401:
  693. $data = ObjectSerializer::deserialize(
  694. $e->getResponseBody(),
  695. '\WikipaliApi\Model\ProblemDetails',
  696. $e->getResponseHeaders()
  697. );
  698. $e->setResponseObject($data);
  699. throw $e;
  700. case 422:
  701. $data = ObjectSerializer::deserialize(
  702. $e->getResponseBody(),
  703. '\WikipaliApi\Model\ProblemDetails',
  704. $e->getResponseHeaders()
  705. );
  706. $e->setResponseObject($data);
  707. throw $e;
  708. }
  709. throw $e;
  710. }
  711. }
  712. /**
  713. * Operation getApiV3MeReactionsAsync
  714. *
  715. * 列出我自己的 reactions
  716. *
  717. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  718. * @param string|null $type 操作类型 (optional)
  719. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  720. * @param int|null $page 页码 (optional, default to 1)
  721. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  722. *
  723. * @throws \InvalidArgumentException
  724. * @return \GuzzleHttp\Promise\PromiseInterface
  725. */
  726. public function getApiV3MeReactionsAsync($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  727. {
  728. return $this->getApiV3MeReactionsAsyncWithHttpInfo($per_page, $type, $target_type, $page, $contentType)
  729. ->then(
  730. function ($response) {
  731. return $response[0];
  732. }
  733. );
  734. }
  735. /**
  736. * Operation getApiV3MeReactionsAsyncWithHttpInfo
  737. *
  738. * 列出我自己的 reactions
  739. *
  740. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  741. * @param string|null $type 操作类型 (optional)
  742. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  743. * @param int|null $page 页码 (optional, default to 1)
  744. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  745. *
  746. * @throws \InvalidArgumentException
  747. * @return \GuzzleHttp\Promise\PromiseInterface
  748. */
  749. public function getApiV3MeReactionsAsyncWithHttpInfo($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  750. {
  751. $returnType = '\WikipaliApi\Model\GetApiV3MeReactions200Response';
  752. $request = $this->getApiV3MeReactionsRequest($per_page, $type, $target_type, $page, $contentType);
  753. return $this->client
  754. ->sendAsync($request, $this->createHttpClientOption())
  755. ->then(
  756. function ($response) use ($returnType) {
  757. if ($returnType === '\SplFileObject') {
  758. $content = $response->getBody(); //stream goes to serializer
  759. } else {
  760. $content = (string) $response->getBody();
  761. if ($returnType !== 'string') {
  762. $content = json_decode($content);
  763. }
  764. }
  765. return [
  766. ObjectSerializer::deserialize($content, $returnType, []),
  767. $response->getStatusCode(),
  768. $response->getHeaders()
  769. ];
  770. },
  771. function ($exception) {
  772. $response = $exception->getResponse();
  773. $statusCode = $response->getStatusCode();
  774. throw new ApiException(
  775. sprintf(
  776. '[%d] Error connecting to the API (%s)',
  777. $statusCode,
  778. $exception->getRequest()->getUri()
  779. ),
  780. $statusCode,
  781. $response->getHeaders(),
  782. (string) $response->getBody()
  783. );
  784. }
  785. );
  786. }
  787. /**
  788. * Create request for operation 'getApiV3MeReactions'
  789. *
  790. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  791. * @param string|null $type 操作类型 (optional)
  792. * @param string|null $target_type target 的类型(task 任务、collection 文集、progress_chapter 书·章节、article 文章、terms 术语) (optional)
  793. * @param int|null $page 页码 (optional, default to 1)
  794. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeReactions'] to see the possible values for this operation
  795. *
  796. * @throws \InvalidArgumentException
  797. * @return \GuzzleHttp\Psr7\Request
  798. */
  799. public function getApiV3MeReactionsRequest($per_page = 15, $type = null, $target_type = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeReactions'][0])
  800. {
  801. $resourcePath = '/v3/me/reactions';
  802. $formParams = [];
  803. $queryParams = [];
  804. $headerParams = [];
  805. $httpBody = '';
  806. $multipart = false;
  807. // query params
  808. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  809. $per_page,
  810. 'per_page', // param base name
  811. 'integer', // openApiType
  812. 'form', // style
  813. true, // explode
  814. false // required
  815. ) ?? []);
  816. // query params
  817. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  818. $type,
  819. 'type', // param base name
  820. 'string', // openApiType
  821. 'form', // style
  822. true, // explode
  823. false // required
  824. ) ?? []);
  825. // query params
  826. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  827. $target_type,
  828. 'target_type', // param base name
  829. 'string', // openApiType
  830. 'form', // style
  831. true, // explode
  832. false // required
  833. ) ?? []);
  834. // query params
  835. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  836. $page,
  837. 'page', // param base name
  838. 'integer', // openApiType
  839. 'form', // style
  840. true, // explode
  841. false // required
  842. ) ?? []);
  843. $headers = $this->headerSelector->selectHeaders(
  844. ['application/json', 'application/problem+json', ],
  845. $contentType,
  846. $multipart
  847. );
  848. // for model (json/xml)
  849. if (count($formParams) > 0) {
  850. if ($multipart) {
  851. $multipartContents = [];
  852. foreach ($formParams as $formParamName => $formParamValue) {
  853. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  854. foreach ($formParamValueItems as $formParamValueItem) {
  855. $multipartContents[] = [
  856. 'name' => $formParamName,
  857. 'contents' => $formParamValueItem
  858. ];
  859. }
  860. }
  861. // for HTTP post (form)
  862. $httpBody = new MultipartStream($multipartContents);
  863. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  864. # if Content-Type contains "application/json", json_encode the form parameters
  865. try {
  866. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  867. } catch (\JsonException $e) {
  868. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  869. }
  870. } else {
  871. // for HTTP post (form)
  872. $httpBody = ObjectSerializer::buildQuery($formParams);
  873. }
  874. }
  875. // this endpoint requires Bearer authentication (access token)
  876. if (!empty($this->config->getAccessToken())) {
  877. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  878. }
  879. $defaultHeaders = [];
  880. if ($this->config->getUserAgent()) {
  881. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  882. }
  883. $headers = array_merge(
  884. $defaultHeaders,
  885. $headerParams,
  886. $headers
  887. );
  888. $operationHost = $this->config->getHost();
  889. $query = ObjectSerializer::buildQuery($queryParams);
  890. return new Request(
  891. 'GET',
  892. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  893. $headers,
  894. $httpBody
  895. );
  896. }
  897. /**
  898. * Operation postApiV3MeReactions
  899. *
  900. * 添加一条我自己的 reaction(幂等)
  901. *
  902. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request post_api_v3_me_reactions_request (required)
  903. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  904. *
  905. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  906. * @throws \InvalidArgumentException
  907. * @return \WikipaliApi\Model\PostApiV3MeReactions200Response|\WikipaliApi\Model\PostApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  908. */
  909. public function postApiV3MeReactions($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  910. {
  911. list($response) = $this->postApiV3MeReactionsWithHttpInfo($post_api_v3_me_reactions_request, $contentType);
  912. return $response;
  913. }
  914. /**
  915. * Operation postApiV3MeReactionsWithHttpInfo
  916. *
  917. * 添加一条我自己的 reaction(幂等)
  918. *
  919. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request (required)
  920. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  921. *
  922. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  923. * @throws \InvalidArgumentException
  924. * @return array of \WikipaliApi\Model\PostApiV3MeReactions200Response|\WikipaliApi\Model\PostApiV3MeReactions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  925. */
  926. public function postApiV3MeReactionsWithHttpInfo($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  927. {
  928. $request = $this->postApiV3MeReactionsRequest($post_api_v3_me_reactions_request, $contentType);
  929. try {
  930. $options = $this->createHttpClientOption();
  931. try {
  932. $response = $this->client->send($request, $options);
  933. } catch (RequestException $e) {
  934. throw new ApiException(
  935. "[{$e->getCode()}] {$e->getMessage()}",
  936. (int) $e->getCode(),
  937. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  938. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  939. );
  940. } catch (ConnectException $e) {
  941. throw new ApiException(
  942. "[{$e->getCode()}] {$e->getMessage()}",
  943. (int) $e->getCode(),
  944. null,
  945. null
  946. );
  947. }
  948. $statusCode = $response->getStatusCode();
  949. switch($statusCode) {
  950. case 200:
  951. return $this->handleResponseWithDataType(
  952. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  953. $request,
  954. $response,
  955. );
  956. case 201:
  957. return $this->handleResponseWithDataType(
  958. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  959. $request,
  960. $response,
  961. );
  962. case 401:
  963. return $this->handleResponseWithDataType(
  964. '\WikipaliApi\Model\ProblemDetails',
  965. $request,
  966. $response,
  967. );
  968. case 422:
  969. return $this->handleResponseWithDataType(
  970. '\WikipaliApi\Model\ProblemDetails',
  971. $request,
  972. $response,
  973. );
  974. }
  975. if ($statusCode < 200 || $statusCode > 299) {
  976. throw new ApiException(
  977. sprintf(
  978. '[%d] Error connecting to the API (%s)',
  979. $statusCode,
  980. (string) $request->getUri()
  981. ),
  982. $statusCode,
  983. $response->getHeaders(),
  984. (string) $response->getBody()
  985. );
  986. }
  987. return $this->handleResponseWithDataType(
  988. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  989. $request,
  990. $response,
  991. );
  992. } catch (ApiException $e) {
  993. switch ($e->getCode()) {
  994. case 200:
  995. $data = ObjectSerializer::deserialize(
  996. $e->getResponseBody(),
  997. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  998. $e->getResponseHeaders()
  999. );
  1000. $e->setResponseObject($data);
  1001. throw $e;
  1002. case 201:
  1003. $data = ObjectSerializer::deserialize(
  1004. $e->getResponseBody(),
  1005. '\WikipaliApi\Model\PostApiV3MeReactions200Response',
  1006. $e->getResponseHeaders()
  1007. );
  1008. $e->setResponseObject($data);
  1009. throw $e;
  1010. case 401:
  1011. $data = ObjectSerializer::deserialize(
  1012. $e->getResponseBody(),
  1013. '\WikipaliApi\Model\ProblemDetails',
  1014. $e->getResponseHeaders()
  1015. );
  1016. $e->setResponseObject($data);
  1017. throw $e;
  1018. case 422:
  1019. $data = ObjectSerializer::deserialize(
  1020. $e->getResponseBody(),
  1021. '\WikipaliApi\Model\ProblemDetails',
  1022. $e->getResponseHeaders()
  1023. );
  1024. $e->setResponseObject($data);
  1025. throw $e;
  1026. }
  1027. throw $e;
  1028. }
  1029. }
  1030. /**
  1031. * Operation postApiV3MeReactionsAsync
  1032. *
  1033. * 添加一条我自己的 reaction(幂等)
  1034. *
  1035. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request (required)
  1036. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  1037. *
  1038. * @throws \InvalidArgumentException
  1039. * @return \GuzzleHttp\Promise\PromiseInterface
  1040. */
  1041. public function postApiV3MeReactionsAsync($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  1042. {
  1043. return $this->postApiV3MeReactionsAsyncWithHttpInfo($post_api_v3_me_reactions_request, $contentType)
  1044. ->then(
  1045. function ($response) {
  1046. return $response[0];
  1047. }
  1048. );
  1049. }
  1050. /**
  1051. * Operation postApiV3MeReactionsAsyncWithHttpInfo
  1052. *
  1053. * 添加一条我自己的 reaction(幂等)
  1054. *
  1055. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request (required)
  1056. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  1057. *
  1058. * @throws \InvalidArgumentException
  1059. * @return \GuzzleHttp\Promise\PromiseInterface
  1060. */
  1061. public function postApiV3MeReactionsAsyncWithHttpInfo($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  1062. {
  1063. $returnType = '\WikipaliApi\Model\PostApiV3MeReactions200Response';
  1064. $request = $this->postApiV3MeReactionsRequest($post_api_v3_me_reactions_request, $contentType);
  1065. return $this->client
  1066. ->sendAsync($request, $this->createHttpClientOption())
  1067. ->then(
  1068. function ($response) use ($returnType) {
  1069. if ($returnType === '\SplFileObject') {
  1070. $content = $response->getBody(); //stream goes to serializer
  1071. } else {
  1072. $content = (string) $response->getBody();
  1073. if ($returnType !== 'string') {
  1074. $content = json_decode($content);
  1075. }
  1076. }
  1077. return [
  1078. ObjectSerializer::deserialize($content, $returnType, []),
  1079. $response->getStatusCode(),
  1080. $response->getHeaders()
  1081. ];
  1082. },
  1083. function ($exception) {
  1084. $response = $exception->getResponse();
  1085. $statusCode = $response->getStatusCode();
  1086. throw new ApiException(
  1087. sprintf(
  1088. '[%d] Error connecting to the API (%s)',
  1089. $statusCode,
  1090. $exception->getRequest()->getUri()
  1091. ),
  1092. $statusCode,
  1093. $response->getHeaders(),
  1094. (string) $response->getBody()
  1095. );
  1096. }
  1097. );
  1098. }
  1099. /**
  1100. * Create request for operation 'postApiV3MeReactions'
  1101. *
  1102. * @param \WikipaliApi\Model\PostApiV3MeReactionsRequest $post_api_v3_me_reactions_request (required)
  1103. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3MeReactions'] to see the possible values for this operation
  1104. *
  1105. * @throws \InvalidArgumentException
  1106. * @return \GuzzleHttp\Psr7\Request
  1107. */
  1108. public function postApiV3MeReactionsRequest($post_api_v3_me_reactions_request, string $contentType = self::contentTypes['postApiV3MeReactions'][0])
  1109. {
  1110. // verify the required parameter 'post_api_v3_me_reactions_request' is set
  1111. if ($post_api_v3_me_reactions_request === null || (is_array($post_api_v3_me_reactions_request) && count($post_api_v3_me_reactions_request) === 0)) {
  1112. throw new \InvalidArgumentException(
  1113. 'Missing the required parameter $post_api_v3_me_reactions_request when calling postApiV3MeReactions'
  1114. );
  1115. }
  1116. $resourcePath = '/v3/me/reactions';
  1117. $formParams = [];
  1118. $queryParams = [];
  1119. $headerParams = [];
  1120. $httpBody = '';
  1121. $multipart = false;
  1122. $headers = $this->headerSelector->selectHeaders(
  1123. ['application/json', 'application/problem+json', ],
  1124. $contentType,
  1125. $multipart
  1126. );
  1127. // for model (json/xml)
  1128. if (isset($post_api_v3_me_reactions_request)) {
  1129. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  1130. # if Content-Type contains "application/json", json_encode the body
  1131. try {
  1132. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_me_reactions_request), JSON_THROW_ON_ERROR);
  1133. } catch (\JsonException $e) {
  1134. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1135. }
  1136. } else {
  1137. $httpBody = $post_api_v3_me_reactions_request;
  1138. }
  1139. } elseif (count($formParams) > 0) {
  1140. if ($multipart) {
  1141. $multipartContents = [];
  1142. foreach ($formParams as $formParamName => $formParamValue) {
  1143. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1144. foreach ($formParamValueItems as $formParamValueItem) {
  1145. $multipartContents[] = [
  1146. 'name' => $formParamName,
  1147. 'contents' => $formParamValueItem
  1148. ];
  1149. }
  1150. }
  1151. // for HTTP post (form)
  1152. $httpBody = new MultipartStream($multipartContents);
  1153. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1154. # if Content-Type contains "application/json", json_encode the form parameters
  1155. try {
  1156. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1157. } catch (\JsonException $e) {
  1158. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1159. }
  1160. } else {
  1161. // for HTTP post (form)
  1162. $httpBody = ObjectSerializer::buildQuery($formParams);
  1163. }
  1164. }
  1165. // this endpoint requires Bearer authentication (access token)
  1166. if (!empty($this->config->getAccessToken())) {
  1167. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1168. }
  1169. $defaultHeaders = [];
  1170. if ($this->config->getUserAgent()) {
  1171. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1172. }
  1173. $headers = array_merge(
  1174. $defaultHeaders,
  1175. $headerParams,
  1176. $headers
  1177. );
  1178. $operationHost = $this->config->getHost();
  1179. $query = ObjectSerializer::buildQuery($queryParams);
  1180. return new Request(
  1181. 'POST',
  1182. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1183. $headers,
  1184. $httpBody
  1185. );
  1186. }
  1187. /**
  1188. * Create http client option
  1189. *
  1190. * @throws \RuntimeException on file opening failure
  1191. * @return array of http client options
  1192. */
  1193. protected function createHttpClientOption()
  1194. {
  1195. $options = [];
  1196. if ($this->config->getDebug()) {
  1197. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  1198. if (!$options[RequestOptions::DEBUG]) {
  1199. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  1200. }
  1201. }
  1202. if ($this->config->getCertFile()) {
  1203. $options[RequestOptions::CERT] = $this->config->getCertFile();
  1204. }
  1205. if ($this->config->getKeyFile()) {
  1206. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  1207. }
  1208. return $options;
  1209. }
  1210. private function handleResponseWithDataType(
  1211. string $dataType,
  1212. RequestInterface $request,
  1213. ResponseInterface $response
  1214. ): array {
  1215. if ($dataType === '\SplFileObject') {
  1216. $content = $response->getBody(); //stream goes to serializer
  1217. } else {
  1218. $content = (string) $response->getBody();
  1219. if ($dataType !== 'string') {
  1220. try {
  1221. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  1222. } catch (\JsonException $exception) {
  1223. throw new ApiException(
  1224. sprintf(
  1225. 'Error JSON decoding server response (%s)',
  1226. $request->getUri()
  1227. ),
  1228. $response->getStatusCode(),
  1229. $response->getHeaders(),
  1230. $content
  1231. );
  1232. }
  1233. }
  1234. }
  1235. return [
  1236. ObjectSerializer::deserialize($content, $dataType, []),
  1237. $response->getStatusCode(),
  1238. $response->getHeaders()
  1239. ];
  1240. }
  1241. private function responseWithinRangeCode(
  1242. string $rangeCode,
  1243. int $statusCode
  1244. ): bool {
  1245. $left = (int) ($rangeCode[0].'00');
  1246. $right = (int) ($rangeCode[0].'99');
  1247. return $statusCode >= $left && $statusCode <= $right;
  1248. }
  1249. }