TermsApi.php 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  1. <?php
  2. /**
  3. * TermsApi
  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: 1.0.0
  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. * TermsApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class TermsApi
  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. 'deleteApiV3TermsTerm' => [
  69. 'application/json',
  70. ],
  71. 'getApiV3Terms' => [
  72. 'application/json',
  73. ],
  74. 'getApiV3TermsTerm' => [
  75. 'application/json',
  76. ],
  77. 'patchApiV3TermsTerm' => [
  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 deleteApiV3TermsTerm
  125. *
  126. * 删术语
  127. *
  128. * @param string $term 术语 id(guid) (required)
  129. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3TermsTerm'] 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 \WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  134. */
  135. public function deleteApiV3TermsTerm($term, string $contentType = self::contentTypes['deleteApiV3TermsTerm'][0])
  136. {
  137. list($response) = $this->deleteApiV3TermsTermWithHttpInfo($term, $contentType);
  138. return $response;
  139. }
  140. /**
  141. * Operation deleteApiV3TermsTermWithHttpInfo
  142. *
  143. * 删术语
  144. *
  145. * @param string $term 术语 id(guid) (required)
  146. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3TermsTerm'] 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\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  151. */
  152. public function deleteApiV3TermsTermWithHttpInfo($term, string $contentType = self::contentTypes['deleteApiV3TermsTerm'][0])
  153. {
  154. $request = $this->deleteApiV3TermsTermRequest($term, $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\PostApiV3ChannelsChannelTerms200Response',
  179. $request,
  180. $response,
  181. );
  182. case 401:
  183. return $this->handleResponseWithDataType(
  184. '\WikipaliApi\Model\ProblemDetails',
  185. $request,
  186. $response,
  187. );
  188. case 403:
  189. return $this->handleResponseWithDataType(
  190. '\WikipaliApi\Model\ProblemDetails',
  191. $request,
  192. $response,
  193. );
  194. case 422:
  195. return $this->handleResponseWithDataType(
  196. '\WikipaliApi\Model\ProblemDetails',
  197. $request,
  198. $response,
  199. );
  200. }
  201. if ($statusCode < 200 || $statusCode > 299) {
  202. throw new ApiException(
  203. sprintf(
  204. '[%d] Error connecting to the API (%s)',
  205. $statusCode,
  206. (string) $request->getUri()
  207. ),
  208. $statusCode,
  209. $response->getHeaders(),
  210. (string) $response->getBody()
  211. );
  212. }
  213. return $this->handleResponseWithDataType(
  214. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  215. $request,
  216. $response,
  217. );
  218. } catch (ApiException $e) {
  219. switch ($e->getCode()) {
  220. case 200:
  221. $data = ObjectSerializer::deserialize(
  222. $e->getResponseBody(),
  223. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  224. $e->getResponseHeaders()
  225. );
  226. $e->setResponseObject($data);
  227. throw $e;
  228. case 401:
  229. $data = ObjectSerializer::deserialize(
  230. $e->getResponseBody(),
  231. '\WikipaliApi\Model\ProblemDetails',
  232. $e->getResponseHeaders()
  233. );
  234. $e->setResponseObject($data);
  235. throw $e;
  236. case 403:
  237. $data = ObjectSerializer::deserialize(
  238. $e->getResponseBody(),
  239. '\WikipaliApi\Model\ProblemDetails',
  240. $e->getResponseHeaders()
  241. );
  242. $e->setResponseObject($data);
  243. throw $e;
  244. case 422:
  245. $data = ObjectSerializer::deserialize(
  246. $e->getResponseBody(),
  247. '\WikipaliApi\Model\ProblemDetails',
  248. $e->getResponseHeaders()
  249. );
  250. $e->setResponseObject($data);
  251. throw $e;
  252. }
  253. throw $e;
  254. }
  255. }
  256. /**
  257. * Operation deleteApiV3TermsTermAsync
  258. *
  259. * 删术语
  260. *
  261. * @param string $term 术语 id(guid) (required)
  262. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3TermsTerm'] to see the possible values for this operation
  263. *
  264. * @throws \InvalidArgumentException
  265. * @return \GuzzleHttp\Promise\PromiseInterface
  266. */
  267. public function deleteApiV3TermsTermAsync($term, string $contentType = self::contentTypes['deleteApiV3TermsTerm'][0])
  268. {
  269. return $this->deleteApiV3TermsTermAsyncWithHttpInfo($term, $contentType)
  270. ->then(
  271. function ($response) {
  272. return $response[0];
  273. }
  274. );
  275. }
  276. /**
  277. * Operation deleteApiV3TermsTermAsyncWithHttpInfo
  278. *
  279. * 删术语
  280. *
  281. * @param string $term 术语 id(guid) (required)
  282. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3TermsTerm'] to see the possible values for this operation
  283. *
  284. * @throws \InvalidArgumentException
  285. * @return \GuzzleHttp\Promise\PromiseInterface
  286. */
  287. public function deleteApiV3TermsTermAsyncWithHttpInfo($term, string $contentType = self::contentTypes['deleteApiV3TermsTerm'][0])
  288. {
  289. $returnType = '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response';
  290. $request = $this->deleteApiV3TermsTermRequest($term, $contentType);
  291. return $this->client
  292. ->sendAsync($request, $this->createHttpClientOption())
  293. ->then(
  294. function ($response) use ($returnType) {
  295. if ($returnType === '\SplFileObject') {
  296. $content = $response->getBody(); //stream goes to serializer
  297. } else {
  298. $content = (string) $response->getBody();
  299. if ($returnType !== 'string') {
  300. $content = json_decode($content);
  301. }
  302. }
  303. return [
  304. ObjectSerializer::deserialize($content, $returnType, []),
  305. $response->getStatusCode(),
  306. $response->getHeaders()
  307. ];
  308. },
  309. function ($exception) {
  310. $response = $exception->getResponse();
  311. $statusCode = $response->getStatusCode();
  312. throw new ApiException(
  313. sprintf(
  314. '[%d] Error connecting to the API (%s)',
  315. $statusCode,
  316. $exception->getRequest()->getUri()
  317. ),
  318. $statusCode,
  319. $response->getHeaders(),
  320. (string) $response->getBody()
  321. );
  322. }
  323. );
  324. }
  325. /**
  326. * Create request for operation 'deleteApiV3TermsTerm'
  327. *
  328. * @param string $term 术语 id(guid) (required)
  329. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3TermsTerm'] to see the possible values for this operation
  330. *
  331. * @throws \InvalidArgumentException
  332. * @return \GuzzleHttp\Psr7\Request
  333. */
  334. public function deleteApiV3TermsTermRequest($term, string $contentType = self::contentTypes['deleteApiV3TermsTerm'][0])
  335. {
  336. // verify the required parameter 'term' is set
  337. if ($term === null || (is_array($term) && count($term) === 0)) {
  338. throw new \InvalidArgumentException(
  339. 'Missing the required parameter $term when calling deleteApiV3TermsTerm'
  340. );
  341. }
  342. $resourcePath = '/v3/terms/{term}';
  343. $formParams = [];
  344. $queryParams = [];
  345. $headerParams = [];
  346. $httpBody = '';
  347. $multipart = false;
  348. // path params
  349. if ($term !== null) {
  350. $resourcePath = str_replace(
  351. '{term}',
  352. ObjectSerializer::toPathValue($term),
  353. $resourcePath
  354. );
  355. }
  356. $headers = $this->headerSelector->selectHeaders(
  357. ['application/json', 'application/problem+json', ],
  358. $contentType,
  359. $multipart
  360. );
  361. // for model (json/xml)
  362. if (count($formParams) > 0) {
  363. if ($multipart) {
  364. $multipartContents = [];
  365. foreach ($formParams as $formParamName => $formParamValue) {
  366. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  367. foreach ($formParamValueItems as $formParamValueItem) {
  368. $multipartContents[] = [
  369. 'name' => $formParamName,
  370. 'contents' => $formParamValueItem
  371. ];
  372. }
  373. }
  374. // for HTTP post (form)
  375. $httpBody = new MultipartStream($multipartContents);
  376. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  377. # if Content-Type contains "application/json", json_encode the form parameters
  378. try {
  379. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  380. } catch (\JsonException $e) {
  381. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  382. }
  383. } else {
  384. // for HTTP post (form)
  385. $httpBody = ObjectSerializer::buildQuery($formParams);
  386. }
  387. }
  388. // this endpoint requires Bearer authentication (access token)
  389. if (!empty($this->config->getAccessToken())) {
  390. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  391. }
  392. $defaultHeaders = [];
  393. if ($this->config->getUserAgent()) {
  394. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  395. }
  396. $headers = array_merge(
  397. $defaultHeaders,
  398. $headerParams,
  399. $headers
  400. );
  401. $operationHost = $this->config->getHost();
  402. $query = ObjectSerializer::buildQuery($queryParams);
  403. return new Request(
  404. 'DELETE',
  405. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  406. $headers,
  407. $httpBody
  408. );
  409. }
  410. /**
  411. * Operation getApiV3Terms
  412. *
  413. * 按词查术语
  414. *
  415. * @param string $word 巴利词,逗号分隔,最多 50 个 (required)
  416. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  417. * @param string|null $tag 义项;传空串只要没有义项的 (optional)
  418. * @param string|null $channel 只要这个 channel 的 (optional)
  419. * @param string|null $language 只要这个语言的 (optional)
  420. * @param bool|null $with_body 每条都带渲染后的正文 &#x60;body&#x60; (optional)
  421. * @param int|null $page 页码 (optional)
  422. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Terms'] to see the possible values for this operation
  423. *
  424. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  425. * @throws \InvalidArgumentException
  426. * @return \WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails
  427. */
  428. public function getApiV3Terms($word, $per_page = 20, $tag = null, $channel = null, $language = null, $with_body = null, $page = null, string $contentType = self::contentTypes['getApiV3Terms'][0])
  429. {
  430. list($response) = $this->getApiV3TermsWithHttpInfo($word, $per_page, $tag, $channel, $language, $with_body, $page, $contentType);
  431. return $response;
  432. }
  433. /**
  434. * Operation getApiV3TermsWithHttpInfo
  435. *
  436. * 按词查术语
  437. *
  438. * @param string $word 巴利词,逗号分隔,最多 50 个 (required)
  439. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  440. * @param string|null $tag 义项;传空串只要没有义项的 (optional)
  441. * @param string|null $channel 只要这个 channel 的 (optional)
  442. * @param string|null $language 只要这个语言的 (optional)
  443. * @param bool|null $with_body 每条都带渲染后的正文 &#x60;body&#x60; (optional)
  444. * @param int|null $page 页码 (optional)
  445. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Terms'] to see the possible values for this operation
  446. *
  447. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  448. * @throws \InvalidArgumentException
  449. * @return array of \WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  450. */
  451. public function getApiV3TermsWithHttpInfo($word, $per_page = 20, $tag = null, $channel = null, $language = null, $with_body = null, $page = null, string $contentType = self::contentTypes['getApiV3Terms'][0])
  452. {
  453. $request = $this->getApiV3TermsRequest($word, $per_page, $tag, $channel, $language, $with_body, $page, $contentType);
  454. try {
  455. $options = $this->createHttpClientOption();
  456. try {
  457. $response = $this->client->send($request, $options);
  458. } catch (RequestException $e) {
  459. throw new ApiException(
  460. "[{$e->getCode()}] {$e->getMessage()}",
  461. (int) $e->getCode(),
  462. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  463. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  464. );
  465. } catch (ConnectException $e) {
  466. throw new ApiException(
  467. "[{$e->getCode()}] {$e->getMessage()}",
  468. (int) $e->getCode(),
  469. null,
  470. null
  471. );
  472. }
  473. $statusCode = $response->getStatusCode();
  474. switch($statusCode) {
  475. case 200:
  476. return $this->handleResponseWithDataType(
  477. '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response',
  478. $request,
  479. $response,
  480. );
  481. case 422:
  482. return $this->handleResponseWithDataType(
  483. '\WikipaliApi\Model\ProblemDetails',
  484. $request,
  485. $response,
  486. );
  487. }
  488. if ($statusCode < 200 || $statusCode > 299) {
  489. throw new ApiException(
  490. sprintf(
  491. '[%d] Error connecting to the API (%s)',
  492. $statusCode,
  493. (string) $request->getUri()
  494. ),
  495. $statusCode,
  496. $response->getHeaders(),
  497. (string) $response->getBody()
  498. );
  499. }
  500. return $this->handleResponseWithDataType(
  501. '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response',
  502. $request,
  503. $response,
  504. );
  505. } catch (ApiException $e) {
  506. switch ($e->getCode()) {
  507. case 200:
  508. $data = ObjectSerializer::deserialize(
  509. $e->getResponseBody(),
  510. '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response',
  511. $e->getResponseHeaders()
  512. );
  513. $e->setResponseObject($data);
  514. throw $e;
  515. case 422:
  516. $data = ObjectSerializer::deserialize(
  517. $e->getResponseBody(),
  518. '\WikipaliApi\Model\ProblemDetails',
  519. $e->getResponseHeaders()
  520. );
  521. $e->setResponseObject($data);
  522. throw $e;
  523. }
  524. throw $e;
  525. }
  526. }
  527. /**
  528. * Operation getApiV3TermsAsync
  529. *
  530. * 按词查术语
  531. *
  532. * @param string $word 巴利词,逗号分隔,最多 50 个 (required)
  533. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  534. * @param string|null $tag 义项;传空串只要没有义项的 (optional)
  535. * @param string|null $channel 只要这个 channel 的 (optional)
  536. * @param string|null $language 只要这个语言的 (optional)
  537. * @param bool|null $with_body 每条都带渲染后的正文 &#x60;body&#x60; (optional)
  538. * @param int|null $page 页码 (optional)
  539. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Terms'] to see the possible values for this operation
  540. *
  541. * @throws \InvalidArgumentException
  542. * @return \GuzzleHttp\Promise\PromiseInterface
  543. */
  544. public function getApiV3TermsAsync($word, $per_page = 20, $tag = null, $channel = null, $language = null, $with_body = null, $page = null, string $contentType = self::contentTypes['getApiV3Terms'][0])
  545. {
  546. return $this->getApiV3TermsAsyncWithHttpInfo($word, $per_page, $tag, $channel, $language, $with_body, $page, $contentType)
  547. ->then(
  548. function ($response) {
  549. return $response[0];
  550. }
  551. );
  552. }
  553. /**
  554. * Operation getApiV3TermsAsyncWithHttpInfo
  555. *
  556. * 按词查术语
  557. *
  558. * @param string $word 巴利词,逗号分隔,最多 50 个 (required)
  559. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  560. * @param string|null $tag 义项;传空串只要没有义项的 (optional)
  561. * @param string|null $channel 只要这个 channel 的 (optional)
  562. * @param string|null $language 只要这个语言的 (optional)
  563. * @param bool|null $with_body 每条都带渲染后的正文 &#x60;body&#x60; (optional)
  564. * @param int|null $page 页码 (optional)
  565. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Terms'] to see the possible values for this operation
  566. *
  567. * @throws \InvalidArgumentException
  568. * @return \GuzzleHttp\Promise\PromiseInterface
  569. */
  570. public function getApiV3TermsAsyncWithHttpInfo($word, $per_page = 20, $tag = null, $channel = null, $language = null, $with_body = null, $page = null, string $contentType = self::contentTypes['getApiV3Terms'][0])
  571. {
  572. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response';
  573. $request = $this->getApiV3TermsRequest($word, $per_page, $tag, $channel, $language, $with_body, $page, $contentType);
  574. return $this->client
  575. ->sendAsync($request, $this->createHttpClientOption())
  576. ->then(
  577. function ($response) use ($returnType) {
  578. if ($returnType === '\SplFileObject') {
  579. $content = $response->getBody(); //stream goes to serializer
  580. } else {
  581. $content = (string) $response->getBody();
  582. if ($returnType !== 'string') {
  583. $content = json_decode($content);
  584. }
  585. }
  586. return [
  587. ObjectSerializer::deserialize($content, $returnType, []),
  588. $response->getStatusCode(),
  589. $response->getHeaders()
  590. ];
  591. },
  592. function ($exception) {
  593. $response = $exception->getResponse();
  594. $statusCode = $response->getStatusCode();
  595. throw new ApiException(
  596. sprintf(
  597. '[%d] Error connecting to the API (%s)',
  598. $statusCode,
  599. $exception->getRequest()->getUri()
  600. ),
  601. $statusCode,
  602. $response->getHeaders(),
  603. (string) $response->getBody()
  604. );
  605. }
  606. );
  607. }
  608. /**
  609. * Create request for operation 'getApiV3Terms'
  610. *
  611. * @param string $word 巴利词,逗号分隔,最多 50 个 (required)
  612. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  613. * @param string|null $tag 义项;传空串只要没有义项的 (optional)
  614. * @param string|null $channel 只要这个 channel 的 (optional)
  615. * @param string|null $language 只要这个语言的 (optional)
  616. * @param bool|null $with_body 每条都带渲染后的正文 &#x60;body&#x60; (optional)
  617. * @param int|null $page 页码 (optional)
  618. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Terms'] to see the possible values for this operation
  619. *
  620. * @throws \InvalidArgumentException
  621. * @return \GuzzleHttp\Psr7\Request
  622. */
  623. public function getApiV3TermsRequest($word, $per_page = 20, $tag = null, $channel = null, $language = null, $with_body = null, $page = null, string $contentType = self::contentTypes['getApiV3Terms'][0])
  624. {
  625. // verify the required parameter 'word' is set
  626. if ($word === null || (is_array($word) && count($word) === 0)) {
  627. throw new \InvalidArgumentException(
  628. 'Missing the required parameter $word when calling getApiV3Terms'
  629. );
  630. }
  631. $resourcePath = '/v3/terms';
  632. $formParams = [];
  633. $queryParams = [];
  634. $headerParams = [];
  635. $httpBody = '';
  636. $multipart = false;
  637. // query params
  638. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  639. $per_page,
  640. 'per_page', // param base name
  641. 'integer', // openApiType
  642. 'form', // style
  643. true, // explode
  644. false // required
  645. ) ?? []);
  646. // query params
  647. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  648. $word,
  649. 'word', // param base name
  650. 'string', // openApiType
  651. 'form', // style
  652. true, // explode
  653. true // required
  654. ) ?? []);
  655. // query params
  656. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  657. $tag,
  658. 'tag', // param base name
  659. 'string', // openApiType
  660. 'form', // style
  661. true, // explode
  662. false // required
  663. ) ?? []);
  664. // query params
  665. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  666. $channel,
  667. 'channel', // param base name
  668. 'string', // openApiType
  669. 'form', // style
  670. true, // explode
  671. false // required
  672. ) ?? []);
  673. // query params
  674. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  675. $language,
  676. 'language', // param base name
  677. 'string', // openApiType
  678. 'form', // style
  679. true, // explode
  680. false // required
  681. ) ?? []);
  682. // query params
  683. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  684. $with_body,
  685. 'with_body', // param base name
  686. 'boolean', // openApiType
  687. 'form', // style
  688. true, // explode
  689. false // required
  690. ) ?? []);
  691. // query params
  692. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  693. $page,
  694. 'page', // param base name
  695. 'integer', // openApiType
  696. 'form', // style
  697. true, // explode
  698. false // required
  699. ) ?? []);
  700. $headers = $this->headerSelector->selectHeaders(
  701. ['application/json', 'application/problem+json', ],
  702. $contentType,
  703. $multipart
  704. );
  705. // for model (json/xml)
  706. if (count($formParams) > 0) {
  707. if ($multipart) {
  708. $multipartContents = [];
  709. foreach ($formParams as $formParamName => $formParamValue) {
  710. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  711. foreach ($formParamValueItems as $formParamValueItem) {
  712. $multipartContents[] = [
  713. 'name' => $formParamName,
  714. 'contents' => $formParamValueItem
  715. ];
  716. }
  717. }
  718. // for HTTP post (form)
  719. $httpBody = new MultipartStream($multipartContents);
  720. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  721. # if Content-Type contains "application/json", json_encode the form parameters
  722. try {
  723. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  724. } catch (\JsonException $e) {
  725. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  726. }
  727. } else {
  728. // for HTTP post (form)
  729. $httpBody = ObjectSerializer::buildQuery($formParams);
  730. }
  731. }
  732. // this endpoint requires Bearer authentication (access token)
  733. if (!empty($this->config->getAccessToken())) {
  734. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  735. }
  736. $defaultHeaders = [];
  737. if ($this->config->getUserAgent()) {
  738. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  739. }
  740. $headers = array_merge(
  741. $defaultHeaders,
  742. $headerParams,
  743. $headers
  744. );
  745. $operationHost = $this->config->getHost();
  746. $query = ObjectSerializer::buildQuery($queryParams);
  747. return new Request(
  748. 'GET',
  749. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  750. $headers,
  751. $httpBody
  752. );
  753. }
  754. /**
  755. * Operation getApiV3TermsTerm
  756. *
  757. * 术语详情
  758. *
  759. * @param string $term 术语 id(guid) (required)
  760. * @param string|null $channels 正文按这些 channel 解析(句子、术语),逗号分隔,最多 20 个;只认你看得见的,不给就用术语所在 channel (optional)
  761. * @param string|null $mode 正文模式 (optional, default to 'read')
  762. * @param string|null $format 正文格式:tree 给节点树 &#x60;body&#x60;,html 给 HTML 字符串 &#x60;html&#x60;(WebView 显示用) (optional, default to 'tree')
  763. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TermsTerm'] to see the possible values for this operation
  764. *
  765. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  766. * @throws \InvalidArgumentException
  767. * @return \WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  768. */
  769. public function getApiV3TermsTerm($term, $channels = null, $mode = 'read', $format = 'tree', string $contentType = self::contentTypes['getApiV3TermsTerm'][0])
  770. {
  771. list($response) = $this->getApiV3TermsTermWithHttpInfo($term, $channels, $mode, $format, $contentType);
  772. return $response;
  773. }
  774. /**
  775. * Operation getApiV3TermsTermWithHttpInfo
  776. *
  777. * 术语详情
  778. *
  779. * @param string $term 术语 id(guid) (required)
  780. * @param string|null $channels 正文按这些 channel 解析(句子、术语),逗号分隔,最多 20 个;只认你看得见的,不给就用术语所在 channel (optional)
  781. * @param string|null $mode 正文模式 (optional, default to 'read')
  782. * @param string|null $format 正文格式:tree 给节点树 &#x60;body&#x60;,html 给 HTML 字符串 &#x60;html&#x60;(WebView 显示用) (optional, default to 'tree')
  783. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TermsTerm'] to see the possible values for this operation
  784. *
  785. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  786. * @throws \InvalidArgumentException
  787. * @return array of \WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  788. */
  789. public function getApiV3TermsTermWithHttpInfo($term, $channels = null, $mode = 'read', $format = 'tree', string $contentType = self::contentTypes['getApiV3TermsTerm'][0])
  790. {
  791. $request = $this->getApiV3TermsTermRequest($term, $channels, $mode, $format, $contentType);
  792. try {
  793. $options = $this->createHttpClientOption();
  794. try {
  795. $response = $this->client->send($request, $options);
  796. } catch (RequestException $e) {
  797. throw new ApiException(
  798. "[{$e->getCode()}] {$e->getMessage()}",
  799. (int) $e->getCode(),
  800. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  801. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  802. );
  803. } catch (ConnectException $e) {
  804. throw new ApiException(
  805. "[{$e->getCode()}] {$e->getMessage()}",
  806. (int) $e->getCode(),
  807. null,
  808. null
  809. );
  810. }
  811. $statusCode = $response->getStatusCode();
  812. switch($statusCode) {
  813. case 200:
  814. return $this->handleResponseWithDataType(
  815. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  816. $request,
  817. $response,
  818. );
  819. case 403:
  820. return $this->handleResponseWithDataType(
  821. '\WikipaliApi\Model\ProblemDetails',
  822. $request,
  823. $response,
  824. );
  825. case 422:
  826. return $this->handleResponseWithDataType(
  827. '\WikipaliApi\Model\ProblemDetails',
  828. $request,
  829. $response,
  830. );
  831. }
  832. if ($statusCode < 200 || $statusCode > 299) {
  833. throw new ApiException(
  834. sprintf(
  835. '[%d] Error connecting to the API (%s)',
  836. $statusCode,
  837. (string) $request->getUri()
  838. ),
  839. $statusCode,
  840. $response->getHeaders(),
  841. (string) $response->getBody()
  842. );
  843. }
  844. return $this->handleResponseWithDataType(
  845. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  846. $request,
  847. $response,
  848. );
  849. } catch (ApiException $e) {
  850. switch ($e->getCode()) {
  851. case 200:
  852. $data = ObjectSerializer::deserialize(
  853. $e->getResponseBody(),
  854. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  855. $e->getResponseHeaders()
  856. );
  857. $e->setResponseObject($data);
  858. throw $e;
  859. case 403:
  860. $data = ObjectSerializer::deserialize(
  861. $e->getResponseBody(),
  862. '\WikipaliApi\Model\ProblemDetails',
  863. $e->getResponseHeaders()
  864. );
  865. $e->setResponseObject($data);
  866. throw $e;
  867. case 422:
  868. $data = ObjectSerializer::deserialize(
  869. $e->getResponseBody(),
  870. '\WikipaliApi\Model\ProblemDetails',
  871. $e->getResponseHeaders()
  872. );
  873. $e->setResponseObject($data);
  874. throw $e;
  875. }
  876. throw $e;
  877. }
  878. }
  879. /**
  880. * Operation getApiV3TermsTermAsync
  881. *
  882. * 术语详情
  883. *
  884. * @param string $term 术语 id(guid) (required)
  885. * @param string|null $channels 正文按这些 channel 解析(句子、术语),逗号分隔,最多 20 个;只认你看得见的,不给就用术语所在 channel (optional)
  886. * @param string|null $mode 正文模式 (optional, default to 'read')
  887. * @param string|null $format 正文格式:tree 给节点树 &#x60;body&#x60;,html 给 HTML 字符串 &#x60;html&#x60;(WebView 显示用) (optional, default to 'tree')
  888. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TermsTerm'] to see the possible values for this operation
  889. *
  890. * @throws \InvalidArgumentException
  891. * @return \GuzzleHttp\Promise\PromiseInterface
  892. */
  893. public function getApiV3TermsTermAsync($term, $channels = null, $mode = 'read', $format = 'tree', string $contentType = self::contentTypes['getApiV3TermsTerm'][0])
  894. {
  895. return $this->getApiV3TermsTermAsyncWithHttpInfo($term, $channels, $mode, $format, $contentType)
  896. ->then(
  897. function ($response) {
  898. return $response[0];
  899. }
  900. );
  901. }
  902. /**
  903. * Operation getApiV3TermsTermAsyncWithHttpInfo
  904. *
  905. * 术语详情
  906. *
  907. * @param string $term 术语 id(guid) (required)
  908. * @param string|null $channels 正文按这些 channel 解析(句子、术语),逗号分隔,最多 20 个;只认你看得见的,不给就用术语所在 channel (optional)
  909. * @param string|null $mode 正文模式 (optional, default to 'read')
  910. * @param string|null $format 正文格式:tree 给节点树 &#x60;body&#x60;,html 给 HTML 字符串 &#x60;html&#x60;(WebView 显示用) (optional, default to 'tree')
  911. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TermsTerm'] to see the possible values for this operation
  912. *
  913. * @throws \InvalidArgumentException
  914. * @return \GuzzleHttp\Promise\PromiseInterface
  915. */
  916. public function getApiV3TermsTermAsyncWithHttpInfo($term, $channels = null, $mode = 'read', $format = 'tree', string $contentType = self::contentTypes['getApiV3TermsTerm'][0])
  917. {
  918. $returnType = '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response';
  919. $request = $this->getApiV3TermsTermRequest($term, $channels, $mode, $format, $contentType);
  920. return $this->client
  921. ->sendAsync($request, $this->createHttpClientOption())
  922. ->then(
  923. function ($response) use ($returnType) {
  924. if ($returnType === '\SplFileObject') {
  925. $content = $response->getBody(); //stream goes to serializer
  926. } else {
  927. $content = (string) $response->getBody();
  928. if ($returnType !== 'string') {
  929. $content = json_decode($content);
  930. }
  931. }
  932. return [
  933. ObjectSerializer::deserialize($content, $returnType, []),
  934. $response->getStatusCode(),
  935. $response->getHeaders()
  936. ];
  937. },
  938. function ($exception) {
  939. $response = $exception->getResponse();
  940. $statusCode = $response->getStatusCode();
  941. throw new ApiException(
  942. sprintf(
  943. '[%d] Error connecting to the API (%s)',
  944. $statusCode,
  945. $exception->getRequest()->getUri()
  946. ),
  947. $statusCode,
  948. $response->getHeaders(),
  949. (string) $response->getBody()
  950. );
  951. }
  952. );
  953. }
  954. /**
  955. * Create request for operation 'getApiV3TermsTerm'
  956. *
  957. * @param string $term 术语 id(guid) (required)
  958. * @param string|null $channels 正文按这些 channel 解析(句子、术语),逗号分隔,最多 20 个;只认你看得见的,不给就用术语所在 channel (optional)
  959. * @param string|null $mode 正文模式 (optional, default to 'read')
  960. * @param string|null $format 正文格式:tree 给节点树 &#x60;body&#x60;,html 给 HTML 字符串 &#x60;html&#x60;(WebView 显示用) (optional, default to 'tree')
  961. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TermsTerm'] to see the possible values for this operation
  962. *
  963. * @throws \InvalidArgumentException
  964. * @return \GuzzleHttp\Psr7\Request
  965. */
  966. public function getApiV3TermsTermRequest($term, $channels = null, $mode = 'read', $format = 'tree', string $contentType = self::contentTypes['getApiV3TermsTerm'][0])
  967. {
  968. // verify the required parameter 'term' is set
  969. if ($term === null || (is_array($term) && count($term) === 0)) {
  970. throw new \InvalidArgumentException(
  971. 'Missing the required parameter $term when calling getApiV3TermsTerm'
  972. );
  973. }
  974. $resourcePath = '/v3/terms/{term}';
  975. $formParams = [];
  976. $queryParams = [];
  977. $headerParams = [];
  978. $httpBody = '';
  979. $multipart = false;
  980. // query params
  981. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  982. $channels,
  983. 'channels', // param base name
  984. 'string', // openApiType
  985. 'form', // style
  986. true, // explode
  987. false // required
  988. ) ?? []);
  989. // query params
  990. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  991. $mode,
  992. 'mode', // param base name
  993. 'string', // openApiType
  994. 'form', // style
  995. true, // explode
  996. false // required
  997. ) ?? []);
  998. // query params
  999. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1000. $format,
  1001. 'format', // param base name
  1002. 'string', // openApiType
  1003. 'form', // style
  1004. true, // explode
  1005. false // required
  1006. ) ?? []);
  1007. // path params
  1008. if ($term !== null) {
  1009. $resourcePath = str_replace(
  1010. '{term}',
  1011. ObjectSerializer::toPathValue($term),
  1012. $resourcePath
  1013. );
  1014. }
  1015. $headers = $this->headerSelector->selectHeaders(
  1016. ['application/json', 'application/problem+json', ],
  1017. $contentType,
  1018. $multipart
  1019. );
  1020. // for model (json/xml)
  1021. if (count($formParams) > 0) {
  1022. if ($multipart) {
  1023. $multipartContents = [];
  1024. foreach ($formParams as $formParamName => $formParamValue) {
  1025. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1026. foreach ($formParamValueItems as $formParamValueItem) {
  1027. $multipartContents[] = [
  1028. 'name' => $formParamName,
  1029. 'contents' => $formParamValueItem
  1030. ];
  1031. }
  1032. }
  1033. // for HTTP post (form)
  1034. $httpBody = new MultipartStream($multipartContents);
  1035. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1036. # if Content-Type contains "application/json", json_encode the form parameters
  1037. try {
  1038. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1039. } catch (\JsonException $e) {
  1040. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1041. }
  1042. } else {
  1043. // for HTTP post (form)
  1044. $httpBody = ObjectSerializer::buildQuery($formParams);
  1045. }
  1046. }
  1047. // this endpoint requires Bearer authentication (access token)
  1048. if (!empty($this->config->getAccessToken())) {
  1049. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1050. }
  1051. $defaultHeaders = [];
  1052. if ($this->config->getUserAgent()) {
  1053. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1054. }
  1055. $headers = array_merge(
  1056. $defaultHeaders,
  1057. $headerParams,
  1058. $headers
  1059. );
  1060. $operationHost = $this->config->getHost();
  1061. $query = ObjectSerializer::buildQuery($queryParams);
  1062. return new Request(
  1063. 'GET',
  1064. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1065. $headers,
  1066. $httpBody
  1067. );
  1068. }
  1069. /**
  1070. * Operation patchApiV3TermsTerm
  1071. *
  1072. * 改术语
  1073. *
  1074. * @param string $term 术语 id(guid) (required)
  1075. * @param \WikipaliApi\Model\PatchApiV3TermsTermRequest|null $patch_api_v3_terms_term_request patch_api_v3_terms_term_request (optional)
  1076. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3TermsTerm'] to see the possible values for this operation
  1077. *
  1078. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1079. * @throws \InvalidArgumentException
  1080. * @return \WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  1081. */
  1082. public function patchApiV3TermsTerm($term, $patch_api_v3_terms_term_request = null, string $contentType = self::contentTypes['patchApiV3TermsTerm'][0])
  1083. {
  1084. list($response) = $this->patchApiV3TermsTermWithHttpInfo($term, $patch_api_v3_terms_term_request, $contentType);
  1085. return $response;
  1086. }
  1087. /**
  1088. * Operation patchApiV3TermsTermWithHttpInfo
  1089. *
  1090. * 改术语
  1091. *
  1092. * @param string $term 术语 id(guid) (required)
  1093. * @param \WikipaliApi\Model\PatchApiV3TermsTermRequest|null $patch_api_v3_terms_term_request (optional)
  1094. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3TermsTerm'] to see the possible values for this operation
  1095. *
  1096. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1097. * @throws \InvalidArgumentException
  1098. * @return array of \WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  1099. */
  1100. public function patchApiV3TermsTermWithHttpInfo($term, $patch_api_v3_terms_term_request = null, string $contentType = self::contentTypes['patchApiV3TermsTerm'][0])
  1101. {
  1102. $request = $this->patchApiV3TermsTermRequest($term, $patch_api_v3_terms_term_request, $contentType);
  1103. try {
  1104. $options = $this->createHttpClientOption();
  1105. try {
  1106. $response = $this->client->send($request, $options);
  1107. } catch (RequestException $e) {
  1108. throw new ApiException(
  1109. "[{$e->getCode()}] {$e->getMessage()}",
  1110. (int) $e->getCode(),
  1111. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1112. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1113. );
  1114. } catch (ConnectException $e) {
  1115. throw new ApiException(
  1116. "[{$e->getCode()}] {$e->getMessage()}",
  1117. (int) $e->getCode(),
  1118. null,
  1119. null
  1120. );
  1121. }
  1122. $statusCode = $response->getStatusCode();
  1123. switch($statusCode) {
  1124. case 200:
  1125. return $this->handleResponseWithDataType(
  1126. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  1127. $request,
  1128. $response,
  1129. );
  1130. case 401:
  1131. return $this->handleResponseWithDataType(
  1132. '\WikipaliApi\Model\ProblemDetails',
  1133. $request,
  1134. $response,
  1135. );
  1136. case 403:
  1137. return $this->handleResponseWithDataType(
  1138. '\WikipaliApi\Model\ProblemDetails',
  1139. $request,
  1140. $response,
  1141. );
  1142. case 412:
  1143. return $this->handleResponseWithDataType(
  1144. '\WikipaliApi\Model\ProblemDetails',
  1145. $request,
  1146. $response,
  1147. );
  1148. case 422:
  1149. return $this->handleResponseWithDataType(
  1150. '\WikipaliApi\Model\ProblemDetails',
  1151. $request,
  1152. $response,
  1153. );
  1154. case 428:
  1155. return $this->handleResponseWithDataType(
  1156. '\WikipaliApi\Model\ProblemDetails',
  1157. $request,
  1158. $response,
  1159. );
  1160. }
  1161. if ($statusCode < 200 || $statusCode > 299) {
  1162. throw new ApiException(
  1163. sprintf(
  1164. '[%d] Error connecting to the API (%s)',
  1165. $statusCode,
  1166. (string) $request->getUri()
  1167. ),
  1168. $statusCode,
  1169. $response->getHeaders(),
  1170. (string) $response->getBody()
  1171. );
  1172. }
  1173. return $this->handleResponseWithDataType(
  1174. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  1175. $request,
  1176. $response,
  1177. );
  1178. } catch (ApiException $e) {
  1179. switch ($e->getCode()) {
  1180. case 200:
  1181. $data = ObjectSerializer::deserialize(
  1182. $e->getResponseBody(),
  1183. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  1184. $e->getResponseHeaders()
  1185. );
  1186. $e->setResponseObject($data);
  1187. throw $e;
  1188. case 401:
  1189. $data = ObjectSerializer::deserialize(
  1190. $e->getResponseBody(),
  1191. '\WikipaliApi\Model\ProblemDetails',
  1192. $e->getResponseHeaders()
  1193. );
  1194. $e->setResponseObject($data);
  1195. throw $e;
  1196. case 403:
  1197. $data = ObjectSerializer::deserialize(
  1198. $e->getResponseBody(),
  1199. '\WikipaliApi\Model\ProblemDetails',
  1200. $e->getResponseHeaders()
  1201. );
  1202. $e->setResponseObject($data);
  1203. throw $e;
  1204. case 412:
  1205. $data = ObjectSerializer::deserialize(
  1206. $e->getResponseBody(),
  1207. '\WikipaliApi\Model\ProblemDetails',
  1208. $e->getResponseHeaders()
  1209. );
  1210. $e->setResponseObject($data);
  1211. throw $e;
  1212. case 422:
  1213. $data = ObjectSerializer::deserialize(
  1214. $e->getResponseBody(),
  1215. '\WikipaliApi\Model\ProblemDetails',
  1216. $e->getResponseHeaders()
  1217. );
  1218. $e->setResponseObject($data);
  1219. throw $e;
  1220. case 428:
  1221. $data = ObjectSerializer::deserialize(
  1222. $e->getResponseBody(),
  1223. '\WikipaliApi\Model\ProblemDetails',
  1224. $e->getResponseHeaders()
  1225. );
  1226. $e->setResponseObject($data);
  1227. throw $e;
  1228. }
  1229. throw $e;
  1230. }
  1231. }
  1232. /**
  1233. * Operation patchApiV3TermsTermAsync
  1234. *
  1235. * 改术语
  1236. *
  1237. * @param string $term 术语 id(guid) (required)
  1238. * @param \WikipaliApi\Model\PatchApiV3TermsTermRequest|null $patch_api_v3_terms_term_request (optional)
  1239. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3TermsTerm'] to see the possible values for this operation
  1240. *
  1241. * @throws \InvalidArgumentException
  1242. * @return \GuzzleHttp\Promise\PromiseInterface
  1243. */
  1244. public function patchApiV3TermsTermAsync($term, $patch_api_v3_terms_term_request = null, string $contentType = self::contentTypes['patchApiV3TermsTerm'][0])
  1245. {
  1246. return $this->patchApiV3TermsTermAsyncWithHttpInfo($term, $patch_api_v3_terms_term_request, $contentType)
  1247. ->then(
  1248. function ($response) {
  1249. return $response[0];
  1250. }
  1251. );
  1252. }
  1253. /**
  1254. * Operation patchApiV3TermsTermAsyncWithHttpInfo
  1255. *
  1256. * 改术语
  1257. *
  1258. * @param string $term 术语 id(guid) (required)
  1259. * @param \WikipaliApi\Model\PatchApiV3TermsTermRequest|null $patch_api_v3_terms_term_request (optional)
  1260. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3TermsTerm'] to see the possible values for this operation
  1261. *
  1262. * @throws \InvalidArgumentException
  1263. * @return \GuzzleHttp\Promise\PromiseInterface
  1264. */
  1265. public function patchApiV3TermsTermAsyncWithHttpInfo($term, $patch_api_v3_terms_term_request = null, string $contentType = self::contentTypes['patchApiV3TermsTerm'][0])
  1266. {
  1267. $returnType = '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response';
  1268. $request = $this->patchApiV3TermsTermRequest($term, $patch_api_v3_terms_term_request, $contentType);
  1269. return $this->client
  1270. ->sendAsync($request, $this->createHttpClientOption())
  1271. ->then(
  1272. function ($response) use ($returnType) {
  1273. if ($returnType === '\SplFileObject') {
  1274. $content = $response->getBody(); //stream goes to serializer
  1275. } else {
  1276. $content = (string) $response->getBody();
  1277. if ($returnType !== 'string') {
  1278. $content = json_decode($content);
  1279. }
  1280. }
  1281. return [
  1282. ObjectSerializer::deserialize($content, $returnType, []),
  1283. $response->getStatusCode(),
  1284. $response->getHeaders()
  1285. ];
  1286. },
  1287. function ($exception) {
  1288. $response = $exception->getResponse();
  1289. $statusCode = $response->getStatusCode();
  1290. throw new ApiException(
  1291. sprintf(
  1292. '[%d] Error connecting to the API (%s)',
  1293. $statusCode,
  1294. $exception->getRequest()->getUri()
  1295. ),
  1296. $statusCode,
  1297. $response->getHeaders(),
  1298. (string) $response->getBody()
  1299. );
  1300. }
  1301. );
  1302. }
  1303. /**
  1304. * Create request for operation 'patchApiV3TermsTerm'
  1305. *
  1306. * @param string $term 术语 id(guid) (required)
  1307. * @param \WikipaliApi\Model\PatchApiV3TermsTermRequest|null $patch_api_v3_terms_term_request (optional)
  1308. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3TermsTerm'] to see the possible values for this operation
  1309. *
  1310. * @throws \InvalidArgumentException
  1311. * @return \GuzzleHttp\Psr7\Request
  1312. */
  1313. public function patchApiV3TermsTermRequest($term, $patch_api_v3_terms_term_request = null, string $contentType = self::contentTypes['patchApiV3TermsTerm'][0])
  1314. {
  1315. // verify the required parameter 'term' is set
  1316. if ($term === null || (is_array($term) && count($term) === 0)) {
  1317. throw new \InvalidArgumentException(
  1318. 'Missing the required parameter $term when calling patchApiV3TermsTerm'
  1319. );
  1320. }
  1321. $resourcePath = '/v3/terms/{term}';
  1322. $formParams = [];
  1323. $queryParams = [];
  1324. $headerParams = [];
  1325. $httpBody = '';
  1326. $multipart = false;
  1327. // path params
  1328. if ($term !== null) {
  1329. $resourcePath = str_replace(
  1330. '{term}',
  1331. ObjectSerializer::toPathValue($term),
  1332. $resourcePath
  1333. );
  1334. }
  1335. $headers = $this->headerSelector->selectHeaders(
  1336. ['application/json', 'application/problem+json', ],
  1337. $contentType,
  1338. $multipart
  1339. );
  1340. // for model (json/xml)
  1341. if (isset($patch_api_v3_terms_term_request)) {
  1342. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  1343. # if Content-Type contains "application/json", json_encode the body
  1344. try {
  1345. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($patch_api_v3_terms_term_request), JSON_THROW_ON_ERROR);
  1346. } catch (\JsonException $e) {
  1347. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1348. }
  1349. } else {
  1350. $httpBody = $patch_api_v3_terms_term_request;
  1351. }
  1352. } elseif (count($formParams) > 0) {
  1353. if ($multipart) {
  1354. $multipartContents = [];
  1355. foreach ($formParams as $formParamName => $formParamValue) {
  1356. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1357. foreach ($formParamValueItems as $formParamValueItem) {
  1358. $multipartContents[] = [
  1359. 'name' => $formParamName,
  1360. 'contents' => $formParamValueItem
  1361. ];
  1362. }
  1363. }
  1364. // for HTTP post (form)
  1365. $httpBody = new MultipartStream($multipartContents);
  1366. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1367. # if Content-Type contains "application/json", json_encode the form parameters
  1368. try {
  1369. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1370. } catch (\JsonException $e) {
  1371. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1372. }
  1373. } else {
  1374. // for HTTP post (form)
  1375. $httpBody = ObjectSerializer::buildQuery($formParams);
  1376. }
  1377. }
  1378. // this endpoint requires Bearer authentication (access token)
  1379. if (!empty($this->config->getAccessToken())) {
  1380. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1381. }
  1382. $defaultHeaders = [];
  1383. if ($this->config->getUserAgent()) {
  1384. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1385. }
  1386. $headers = array_merge(
  1387. $defaultHeaders,
  1388. $headerParams,
  1389. $headers
  1390. );
  1391. $operationHost = $this->config->getHost();
  1392. $query = ObjectSerializer::buildQuery($queryParams);
  1393. return new Request(
  1394. 'PATCH',
  1395. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1396. $headers,
  1397. $httpBody
  1398. );
  1399. }
  1400. /**
  1401. * Create http client option
  1402. *
  1403. * @throws \RuntimeException on file opening failure
  1404. * @return array of http client options
  1405. */
  1406. protected function createHttpClientOption()
  1407. {
  1408. $options = [];
  1409. if ($this->config->getDebug()) {
  1410. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  1411. if (!$options[RequestOptions::DEBUG]) {
  1412. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  1413. }
  1414. }
  1415. if ($this->config->getCertFile()) {
  1416. $options[RequestOptions::CERT] = $this->config->getCertFile();
  1417. }
  1418. if ($this->config->getKeyFile()) {
  1419. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  1420. }
  1421. return $options;
  1422. }
  1423. private function handleResponseWithDataType(
  1424. string $dataType,
  1425. RequestInterface $request,
  1426. ResponseInterface $response
  1427. ): array {
  1428. if ($dataType === '\SplFileObject') {
  1429. $content = $response->getBody(); //stream goes to serializer
  1430. } else {
  1431. $content = (string) $response->getBody();
  1432. if ($dataType !== 'string') {
  1433. try {
  1434. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  1435. } catch (\JsonException $exception) {
  1436. throw new ApiException(
  1437. sprintf(
  1438. 'Error JSON decoding server response (%s)',
  1439. $request->getUri()
  1440. ),
  1441. $response->getStatusCode(),
  1442. $response->getHeaders(),
  1443. $content
  1444. );
  1445. }
  1446. }
  1447. }
  1448. return [
  1449. ObjectSerializer::deserialize($content, $dataType, []),
  1450. $response->getStatusCode(),
  1451. $response->getHeaders()
  1452. ];
  1453. }
  1454. private function responseWithinRangeCode(
  1455. string $rangeCode,
  1456. int $statusCode
  1457. ): bool {
  1458. $left = (int) ($rangeCode[0].'00');
  1459. $right = (int) ($rangeCode[0].'99');
  1460. return $statusCode >= $left && $statusCode <= $right;
  1461. }
  1462. }