2
0

ProgressApi.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <?php
  2. /**
  3. * ProgressApi
  4. * PHP version 8.1
  5. *
  6. * @category Class
  7. * @package WikipaliApi
  8. * @author OpenAPI Generator team
  9. * @link https://openapi-generator.tech
  10. */
  11. /**
  12. * MINT API
  13. *
  14. * International Academy Of Pali Tipitaka(国际巴利三藏学院) 由 `php openapi/scripts/generate.php` 依据 api-v13 的路由与控制器源码生成。 响应统一封装为 `{ok, message, data}`;`ok=false` 时 `message` 为错误信息。
  15. *
  16. * The version of the OpenAPI document: 2026.9.28
  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. * ProgressApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class ProgressApi
  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. 'getApiV3Progress' => [
  69. 'application/json',
  70. ],
  71. ];
  72. /**
  73. * @param ClientInterface $client
  74. * @param Configuration $config
  75. * @param HeaderSelector $selector
  76. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  77. */
  78. public function __construct(
  79. ?ClientInterface $client = null,
  80. ?Configuration $config = null,
  81. ?HeaderSelector $selector = null,
  82. int $hostIndex = 0
  83. ) {
  84. $this->client = $client ?: new Client();
  85. $this->config = $config ?: Configuration::getDefaultConfiguration();
  86. $this->headerSelector = $selector ?: new HeaderSelector();
  87. $this->hostIndex = $hostIndex;
  88. }
  89. /**
  90. * Set the host index
  91. *
  92. * @param int $hostIndex Host index (required)
  93. */
  94. public function setHostIndex($hostIndex): void
  95. {
  96. $this->hostIndex = $hostIndex;
  97. }
  98. /**
  99. * Get the host index
  100. *
  101. * @return int Host index
  102. */
  103. public function getHostIndex()
  104. {
  105. return $this->hostIndex;
  106. }
  107. /**
  108. * @return Configuration
  109. */
  110. public function getConfig()
  111. {
  112. return $this->config;
  113. }
  114. /**
  115. * Operation getApiV3Progress
  116. *
  117. * 列出章节翻译进度
  118. *
  119. * @param string $channels channel uid 列表,**下划线分隔**(不是逗号) (required)
  120. * @param int|null $level 只返回该层级及以上的章节,需联查 pali_texts (optional)
  121. * @param string|null $lang 按译文语言过滤 (optional)
  122. * @param int|null $book 按典籍 id 过滤 (optional)
  123. * @param string|null $order 排序字段,白名单内 (optional, default to 'completed_at')
  124. * @param string|null $dir 排序方向 (optional, default to 'desc')
  125. * @param int|null $page 页码 (optional, default to 1)
  126. * @param int|null $per_page 每页数量,最大 200 (optional, default to 10)
  127. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Progress'] 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\GetApiV3Progress200Response|\WikipaliApi\Model\ProblemDetails
  132. */
  133. public function getApiV3Progress($channels, $level = null, $lang = null, $book = null, $order = 'completed_at', $dir = 'desc', $page = 1, $per_page = 10, string $contentType = self::contentTypes['getApiV3Progress'][0])
  134. {
  135. list($response) = $this->getApiV3ProgressWithHttpInfo($channels, $level, $lang, $book, $order, $dir, $page, $per_page, $contentType);
  136. return $response;
  137. }
  138. /**
  139. * Operation getApiV3ProgressWithHttpInfo
  140. *
  141. * 列出章节翻译进度
  142. *
  143. * @param string $channels channel uid 列表,**下划线分隔**(不是逗号) (required)
  144. * @param int|null $level 只返回该层级及以上的章节,需联查 pali_texts (optional)
  145. * @param string|null $lang 按译文语言过滤 (optional)
  146. * @param int|null $book 按典籍 id 过滤 (optional)
  147. * @param string|null $order 排序字段,白名单内 (optional, default to 'completed_at')
  148. * @param string|null $dir 排序方向 (optional, default to 'desc')
  149. * @param int|null $page 页码 (optional, default to 1)
  150. * @param int|null $per_page 每页数量,最大 200 (optional, default to 10)
  151. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Progress'] to see the possible values for this operation
  152. *
  153. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  154. * @throws \InvalidArgumentException
  155. * @return array of \WikipaliApi\Model\GetApiV3Progress200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  156. */
  157. public function getApiV3ProgressWithHttpInfo($channels, $level = null, $lang = null, $book = null, $order = 'completed_at', $dir = 'desc', $page = 1, $per_page = 10, string $contentType = self::contentTypes['getApiV3Progress'][0])
  158. {
  159. $request = $this->getApiV3ProgressRequest($channels, $level, $lang, $book, $order, $dir, $page, $per_page, $contentType);
  160. try {
  161. $options = $this->createHttpClientOption();
  162. try {
  163. $response = $this->client->send($request, $options);
  164. } catch (RequestException $e) {
  165. throw new ApiException(
  166. "[{$e->getCode()}] {$e->getMessage()}",
  167. (int) $e->getCode(),
  168. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  169. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  170. );
  171. } catch (ConnectException $e) {
  172. throw new ApiException(
  173. "[{$e->getCode()}] {$e->getMessage()}",
  174. (int) $e->getCode(),
  175. null,
  176. null
  177. );
  178. }
  179. $statusCode = $response->getStatusCode();
  180. switch($statusCode) {
  181. case 200:
  182. return $this->handleResponseWithDataType(
  183. '\WikipaliApi\Model\GetApiV3Progress200Response',
  184. $request,
  185. $response,
  186. );
  187. case 422:
  188. return $this->handleResponseWithDataType(
  189. '\WikipaliApi\Model\ProblemDetails',
  190. $request,
  191. $response,
  192. );
  193. }
  194. if ($statusCode < 200 || $statusCode > 299) {
  195. throw new ApiException(
  196. sprintf(
  197. '[%d] Error connecting to the API (%s)',
  198. $statusCode,
  199. (string) $request->getUri()
  200. ),
  201. $statusCode,
  202. $response->getHeaders(),
  203. (string) $response->getBody()
  204. );
  205. }
  206. return $this->handleResponseWithDataType(
  207. '\WikipaliApi\Model\GetApiV3Progress200Response',
  208. $request,
  209. $response,
  210. );
  211. } catch (ApiException $e) {
  212. switch ($e->getCode()) {
  213. case 200:
  214. $data = ObjectSerializer::deserialize(
  215. $e->getResponseBody(),
  216. '\WikipaliApi\Model\GetApiV3Progress200Response',
  217. $e->getResponseHeaders()
  218. );
  219. $e->setResponseObject($data);
  220. throw $e;
  221. case 422:
  222. $data = ObjectSerializer::deserialize(
  223. $e->getResponseBody(),
  224. '\WikipaliApi\Model\ProblemDetails',
  225. $e->getResponseHeaders()
  226. );
  227. $e->setResponseObject($data);
  228. throw $e;
  229. }
  230. throw $e;
  231. }
  232. }
  233. /**
  234. * Operation getApiV3ProgressAsync
  235. *
  236. * 列出章节翻译进度
  237. *
  238. * @param string $channels channel uid 列表,**下划线分隔**(不是逗号) (required)
  239. * @param int|null $level 只返回该层级及以上的章节,需联查 pali_texts (optional)
  240. * @param string|null $lang 按译文语言过滤 (optional)
  241. * @param int|null $book 按典籍 id 过滤 (optional)
  242. * @param string|null $order 排序字段,白名单内 (optional, default to 'completed_at')
  243. * @param string|null $dir 排序方向 (optional, default to 'desc')
  244. * @param int|null $page 页码 (optional, default to 1)
  245. * @param int|null $per_page 每页数量,最大 200 (optional, default to 10)
  246. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Progress'] to see the possible values for this operation
  247. *
  248. * @throws \InvalidArgumentException
  249. * @return \GuzzleHttp\Promise\PromiseInterface
  250. */
  251. public function getApiV3ProgressAsync($channels, $level = null, $lang = null, $book = null, $order = 'completed_at', $dir = 'desc', $page = 1, $per_page = 10, string $contentType = self::contentTypes['getApiV3Progress'][0])
  252. {
  253. return $this->getApiV3ProgressAsyncWithHttpInfo($channels, $level, $lang, $book, $order, $dir, $page, $per_page, $contentType)
  254. ->then(
  255. function ($response) {
  256. return $response[0];
  257. }
  258. );
  259. }
  260. /**
  261. * Operation getApiV3ProgressAsyncWithHttpInfo
  262. *
  263. * 列出章节翻译进度
  264. *
  265. * @param string $channels channel uid 列表,**下划线分隔**(不是逗号) (required)
  266. * @param int|null $level 只返回该层级及以上的章节,需联查 pali_texts (optional)
  267. * @param string|null $lang 按译文语言过滤 (optional)
  268. * @param int|null $book 按典籍 id 过滤 (optional)
  269. * @param string|null $order 排序字段,白名单内 (optional, default to 'completed_at')
  270. * @param string|null $dir 排序方向 (optional, default to 'desc')
  271. * @param int|null $page 页码 (optional, default to 1)
  272. * @param int|null $per_page 每页数量,最大 200 (optional, default to 10)
  273. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Progress'] to see the possible values for this operation
  274. *
  275. * @throws \InvalidArgumentException
  276. * @return \GuzzleHttp\Promise\PromiseInterface
  277. */
  278. public function getApiV3ProgressAsyncWithHttpInfo($channels, $level = null, $lang = null, $book = null, $order = 'completed_at', $dir = 'desc', $page = 1, $per_page = 10, string $contentType = self::contentTypes['getApiV3Progress'][0])
  279. {
  280. $returnType = '\WikipaliApi\Model\GetApiV3Progress200Response';
  281. $request = $this->getApiV3ProgressRequest($channels, $level, $lang, $book, $order, $dir, $page, $per_page, $contentType);
  282. return $this->client
  283. ->sendAsync($request, $this->createHttpClientOption())
  284. ->then(
  285. function ($response) use ($returnType) {
  286. if ($returnType === '\SplFileObject') {
  287. $content = $response->getBody(); //stream goes to serializer
  288. } else {
  289. $content = (string) $response->getBody();
  290. if ($returnType !== 'string') {
  291. $content = json_decode($content);
  292. }
  293. }
  294. return [
  295. ObjectSerializer::deserialize($content, $returnType, []),
  296. $response->getStatusCode(),
  297. $response->getHeaders()
  298. ];
  299. },
  300. function ($exception) {
  301. $response = $exception->getResponse();
  302. $statusCode = $response->getStatusCode();
  303. throw new ApiException(
  304. sprintf(
  305. '[%d] Error connecting to the API (%s)',
  306. $statusCode,
  307. $exception->getRequest()->getUri()
  308. ),
  309. $statusCode,
  310. $response->getHeaders(),
  311. (string) $response->getBody()
  312. );
  313. }
  314. );
  315. }
  316. /**
  317. * Create request for operation 'getApiV3Progress'
  318. *
  319. * @param string $channels channel uid 列表,**下划线分隔**(不是逗号) (required)
  320. * @param int|null $level 只返回该层级及以上的章节,需联查 pali_texts (optional)
  321. * @param string|null $lang 按译文语言过滤 (optional)
  322. * @param int|null $book 按典籍 id 过滤 (optional)
  323. * @param string|null $order 排序字段,白名单内 (optional, default to 'completed_at')
  324. * @param string|null $dir 排序方向 (optional, default to 'desc')
  325. * @param int|null $page 页码 (optional, default to 1)
  326. * @param int|null $per_page 每页数量,最大 200 (optional, default to 10)
  327. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Progress'] to see the possible values for this operation
  328. *
  329. * @throws \InvalidArgumentException
  330. * @return \GuzzleHttp\Psr7\Request
  331. */
  332. public function getApiV3ProgressRequest($channels, $level = null, $lang = null, $book = null, $order = 'completed_at', $dir = 'desc', $page = 1, $per_page = 10, string $contentType = self::contentTypes['getApiV3Progress'][0])
  333. {
  334. // verify the required parameter 'channels' is set
  335. if ($channels === null || (is_array($channels) && count($channels) === 0)) {
  336. throw new \InvalidArgumentException(
  337. 'Missing the required parameter $channels when calling getApiV3Progress'
  338. );
  339. }
  340. $resourcePath = '/v3/progress';
  341. $formParams = [];
  342. $queryParams = [];
  343. $headerParams = [];
  344. $httpBody = '';
  345. $multipart = false;
  346. // query params
  347. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  348. $channels,
  349. 'channels', // param base name
  350. 'string', // openApiType
  351. 'form', // style
  352. true, // explode
  353. true // required
  354. ) ?? []);
  355. // query params
  356. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  357. $level,
  358. 'level', // param base name
  359. 'integer', // openApiType
  360. 'form', // style
  361. true, // explode
  362. false // required
  363. ) ?? []);
  364. // query params
  365. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  366. $lang,
  367. 'lang', // param base name
  368. 'string', // openApiType
  369. 'form', // style
  370. true, // explode
  371. false // required
  372. ) ?? []);
  373. // query params
  374. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  375. $book,
  376. 'book', // param base name
  377. 'integer', // openApiType
  378. 'form', // style
  379. true, // explode
  380. false // required
  381. ) ?? []);
  382. // query params
  383. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  384. $order,
  385. 'order', // param base name
  386. 'string', // openApiType
  387. 'form', // style
  388. true, // explode
  389. false // required
  390. ) ?? []);
  391. // query params
  392. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  393. $dir,
  394. 'dir', // param base name
  395. 'string', // openApiType
  396. 'form', // style
  397. true, // explode
  398. false // required
  399. ) ?? []);
  400. // query params
  401. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  402. $page,
  403. 'page', // param base name
  404. 'integer', // openApiType
  405. 'form', // style
  406. true, // explode
  407. false // required
  408. ) ?? []);
  409. // query params
  410. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  411. $per_page,
  412. 'per_page', // param base name
  413. 'integer', // openApiType
  414. 'form', // style
  415. true, // explode
  416. false // required
  417. ) ?? []);
  418. $headers = $this->headerSelector->selectHeaders(
  419. ['application/json', 'application/problem+json', ],
  420. $contentType,
  421. $multipart
  422. );
  423. // for model (json/xml)
  424. if (count($formParams) > 0) {
  425. if ($multipart) {
  426. $multipartContents = [];
  427. foreach ($formParams as $formParamName => $formParamValue) {
  428. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  429. foreach ($formParamValueItems as $formParamValueItem) {
  430. $multipartContents[] = [
  431. 'name' => $formParamName,
  432. 'contents' => $formParamValueItem
  433. ];
  434. }
  435. }
  436. // for HTTP post (form)
  437. $httpBody = new MultipartStream($multipartContents);
  438. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  439. # if Content-Type contains "application/json", json_encode the form parameters
  440. try {
  441. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  442. } catch (\JsonException $e) {
  443. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  444. }
  445. } else {
  446. // for HTTP post (form)
  447. $httpBody = ObjectSerializer::buildQuery($formParams);
  448. }
  449. }
  450. $defaultHeaders = [];
  451. if ($this->config->getUserAgent()) {
  452. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  453. }
  454. $headers = array_merge(
  455. $defaultHeaders,
  456. $headerParams,
  457. $headers
  458. );
  459. $operationHost = $this->config->getHost();
  460. $query = ObjectSerializer::buildQuery($queryParams);
  461. return new Request(
  462. 'GET',
  463. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  464. $headers,
  465. $httpBody
  466. );
  467. }
  468. /**
  469. * Create http client option
  470. *
  471. * @throws \RuntimeException on file opening failure
  472. * @return array of http client options
  473. */
  474. protected function createHttpClientOption()
  475. {
  476. $options = [];
  477. if ($this->config->getDebug()) {
  478. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  479. if (!$options[RequestOptions::DEBUG]) {
  480. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  481. }
  482. }
  483. if ($this->config->getCertFile()) {
  484. $options[RequestOptions::CERT] = $this->config->getCertFile();
  485. }
  486. if ($this->config->getKeyFile()) {
  487. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  488. }
  489. return $options;
  490. }
  491. private function handleResponseWithDataType(
  492. string $dataType,
  493. RequestInterface $request,
  494. ResponseInterface $response
  495. ): array {
  496. if ($dataType === '\SplFileObject') {
  497. $content = $response->getBody(); //stream goes to serializer
  498. } else {
  499. $content = (string) $response->getBody();
  500. if ($dataType !== 'string') {
  501. try {
  502. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  503. } catch (\JsonException $exception) {
  504. throw new ApiException(
  505. sprintf(
  506. 'Error JSON decoding server response (%s)',
  507. $request->getUri()
  508. ),
  509. $response->getStatusCode(),
  510. $response->getHeaders(),
  511. $content
  512. );
  513. }
  514. }
  515. }
  516. return [
  517. ObjectSerializer::deserialize($content, $dataType, []),
  518. $response->getStatusCode(),
  519. $response->getHeaders()
  520. ];
  521. }
  522. private function responseWithinRangeCode(
  523. string $rangeCode,
  524. int $statusCode
  525. ): bool {
  526. $left = (int) ($rangeCode[0].'00');
  527. $right = (int) ($rangeCode[0].'99');
  528. return $statusCode >= $left && $statusCode <= $right;
  529. }
  530. }