TipitakaWordParagraphsApi.php 33 KB

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