TipitakaExportsApi.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. <?php
  2. /**
  3. * TipitakaExportsApi
  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. * TipitakaExportsApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class TipitakaExportsApi
  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. 'getApiV3TipitakaExportsExport' => [
  69. 'application/json',
  70. ],
  71. 'getApiV3TipitakaExportsExportFile' => [
  72. 'application/json',
  73. ],
  74. 'postApiV3TipitakaExports' => [
  75. 'application/json',
  76. ],
  77. ];
  78. /**
  79. * @param ClientInterface $client
  80. * @param Configuration $config
  81. * @param HeaderSelector $selector
  82. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  83. */
  84. public function __construct(
  85. ?ClientInterface $client = null,
  86. ?Configuration $config = null,
  87. ?HeaderSelector $selector = null,
  88. int $hostIndex = 0
  89. ) {
  90. $this->client = $client ?: new Client();
  91. $this->config = $config ?: Configuration::getDefaultConfiguration();
  92. $this->headerSelector = $selector ?: new HeaderSelector();
  93. $this->hostIndex = $hostIndex;
  94. }
  95. /**
  96. * Set the host index
  97. *
  98. * @param int $hostIndex Host index (required)
  99. */
  100. public function setHostIndex($hostIndex): void
  101. {
  102. $this->hostIndex = $hostIndex;
  103. }
  104. /**
  105. * Get the host index
  106. *
  107. * @return int Host index
  108. */
  109. public function getHostIndex()
  110. {
  111. return $this->hostIndex;
  112. }
  113. /**
  114. * @return Configuration
  115. */
  116. public function getConfig()
  117. {
  118. return $this->config;
  119. }
  120. /**
  121. * Operation getApiV3TipitakaExportsExport
  122. *
  123. * 查看下载状态
  124. *
  125. * @param string $export 导出 id(POST 返回的 id) (required)
  126. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExport'] to see the possible values for this operation
  127. *
  128. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  129. * @throws \InvalidArgumentException
  130. * @return \WikipaliApi\Model\PostApiV3TipitakaExports200Response|\WikipaliApi\Model\ProblemDetails
  131. */
  132. public function getApiV3TipitakaExportsExport($export, string $contentType = self::contentTypes['getApiV3TipitakaExportsExport'][0])
  133. {
  134. list($response) = $this->getApiV3TipitakaExportsExportWithHttpInfo($export, $contentType);
  135. return $response;
  136. }
  137. /**
  138. * Operation getApiV3TipitakaExportsExportWithHttpInfo
  139. *
  140. * 查看下载状态
  141. *
  142. * @param string $export 导出 id(POST 返回的 id) (required)
  143. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExport'] to see the possible values for this operation
  144. *
  145. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  146. * @throws \InvalidArgumentException
  147. * @return array of \WikipaliApi\Model\PostApiV3TipitakaExports200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  148. */
  149. public function getApiV3TipitakaExportsExportWithHttpInfo($export, string $contentType = self::contentTypes['getApiV3TipitakaExportsExport'][0])
  150. {
  151. $request = $this->getApiV3TipitakaExportsExportRequest($export, $contentType);
  152. try {
  153. $options = $this->createHttpClientOption();
  154. try {
  155. $response = $this->client->send($request, $options);
  156. } catch (RequestException $e) {
  157. throw new ApiException(
  158. "[{$e->getCode()}] {$e->getMessage()}",
  159. (int) $e->getCode(),
  160. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  161. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  162. );
  163. } catch (ConnectException $e) {
  164. throw new ApiException(
  165. "[{$e->getCode()}] {$e->getMessage()}",
  166. (int) $e->getCode(),
  167. null,
  168. null
  169. );
  170. }
  171. $statusCode = $response->getStatusCode();
  172. switch($statusCode) {
  173. case 200:
  174. return $this->handleResponseWithDataType(
  175. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  176. $request,
  177. $response,
  178. );
  179. case 422:
  180. return $this->handleResponseWithDataType(
  181. '\WikipaliApi\Model\ProblemDetails',
  182. $request,
  183. $response,
  184. );
  185. }
  186. if ($statusCode < 200 || $statusCode > 299) {
  187. throw new ApiException(
  188. sprintf(
  189. '[%d] Error connecting to the API (%s)',
  190. $statusCode,
  191. (string) $request->getUri()
  192. ),
  193. $statusCode,
  194. $response->getHeaders(),
  195. (string) $response->getBody()
  196. );
  197. }
  198. return $this->handleResponseWithDataType(
  199. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  200. $request,
  201. $response,
  202. );
  203. } catch (ApiException $e) {
  204. switch ($e->getCode()) {
  205. case 200:
  206. $data = ObjectSerializer::deserialize(
  207. $e->getResponseBody(),
  208. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  209. $e->getResponseHeaders()
  210. );
  211. $e->setResponseObject($data);
  212. throw $e;
  213. case 422:
  214. $data = ObjectSerializer::deserialize(
  215. $e->getResponseBody(),
  216. '\WikipaliApi\Model\ProblemDetails',
  217. $e->getResponseHeaders()
  218. );
  219. $e->setResponseObject($data);
  220. throw $e;
  221. }
  222. throw $e;
  223. }
  224. }
  225. /**
  226. * Operation getApiV3TipitakaExportsExportAsync
  227. *
  228. * 查看下载状态
  229. *
  230. * @param string $export 导出 id(POST 返回的 id) (required)
  231. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExport'] to see the possible values for this operation
  232. *
  233. * @throws \InvalidArgumentException
  234. * @return \GuzzleHttp\Promise\PromiseInterface
  235. */
  236. public function getApiV3TipitakaExportsExportAsync($export, string $contentType = self::contentTypes['getApiV3TipitakaExportsExport'][0])
  237. {
  238. return $this->getApiV3TipitakaExportsExportAsyncWithHttpInfo($export, $contentType)
  239. ->then(
  240. function ($response) {
  241. return $response[0];
  242. }
  243. );
  244. }
  245. /**
  246. * Operation getApiV3TipitakaExportsExportAsyncWithHttpInfo
  247. *
  248. * 查看下载状态
  249. *
  250. * @param string $export 导出 id(POST 返回的 id) (required)
  251. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExport'] to see the possible values for this operation
  252. *
  253. * @throws \InvalidArgumentException
  254. * @return \GuzzleHttp\Promise\PromiseInterface
  255. */
  256. public function getApiV3TipitakaExportsExportAsyncWithHttpInfo($export, string $contentType = self::contentTypes['getApiV3TipitakaExportsExport'][0])
  257. {
  258. $returnType = '\WikipaliApi\Model\PostApiV3TipitakaExports200Response';
  259. $request = $this->getApiV3TipitakaExportsExportRequest($export, $contentType);
  260. return $this->client
  261. ->sendAsync($request, $this->createHttpClientOption())
  262. ->then(
  263. function ($response) use ($returnType) {
  264. if ($returnType === '\SplFileObject') {
  265. $content = $response->getBody(); //stream goes to serializer
  266. } else {
  267. $content = (string) $response->getBody();
  268. if ($returnType !== 'string') {
  269. $content = json_decode($content);
  270. }
  271. }
  272. return [
  273. ObjectSerializer::deserialize($content, $returnType, []),
  274. $response->getStatusCode(),
  275. $response->getHeaders()
  276. ];
  277. },
  278. function ($exception) {
  279. $response = $exception->getResponse();
  280. $statusCode = $response->getStatusCode();
  281. throw new ApiException(
  282. sprintf(
  283. '[%d] Error connecting to the API (%s)',
  284. $statusCode,
  285. $exception->getRequest()->getUri()
  286. ),
  287. $statusCode,
  288. $response->getHeaders(),
  289. (string) $response->getBody()
  290. );
  291. }
  292. );
  293. }
  294. /**
  295. * Create request for operation 'getApiV3TipitakaExportsExport'
  296. *
  297. * @param string $export 导出 id(POST 返回的 id) (required)
  298. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExport'] to see the possible values for this operation
  299. *
  300. * @throws \InvalidArgumentException
  301. * @return \GuzzleHttp\Psr7\Request
  302. */
  303. public function getApiV3TipitakaExportsExportRequest($export, string $contentType = self::contentTypes['getApiV3TipitakaExportsExport'][0])
  304. {
  305. // verify the required parameter 'export' is set
  306. if ($export === null || (is_array($export) && count($export) === 0)) {
  307. throw new \InvalidArgumentException(
  308. 'Missing the required parameter $export when calling getApiV3TipitakaExportsExport'
  309. );
  310. }
  311. $resourcePath = '/v3/tipitaka-exports/{export}';
  312. $formParams = [];
  313. $queryParams = [];
  314. $headerParams = [];
  315. $httpBody = '';
  316. $multipart = false;
  317. // path params
  318. if ($export !== null) {
  319. $resourcePath = str_replace(
  320. '{export}',
  321. ObjectSerializer::toPathValue($export),
  322. $resourcePath
  323. );
  324. }
  325. $headers = $this->headerSelector->selectHeaders(
  326. ['application/json', 'application/problem+json', ],
  327. $contentType,
  328. $multipart
  329. );
  330. // for model (json/xml)
  331. if (count($formParams) > 0) {
  332. if ($multipart) {
  333. $multipartContents = [];
  334. foreach ($formParams as $formParamName => $formParamValue) {
  335. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  336. foreach ($formParamValueItems as $formParamValueItem) {
  337. $multipartContents[] = [
  338. 'name' => $formParamName,
  339. 'contents' => $formParamValueItem
  340. ];
  341. }
  342. }
  343. // for HTTP post (form)
  344. $httpBody = new MultipartStream($multipartContents);
  345. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  346. # if Content-Type contains "application/json", json_encode the form parameters
  347. try {
  348. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  349. } catch (\JsonException $e) {
  350. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  351. }
  352. } else {
  353. // for HTTP post (form)
  354. $httpBody = ObjectSerializer::buildQuery($formParams);
  355. }
  356. }
  357. // this endpoint requires Bearer authentication (access token)
  358. if (!empty($this->config->getAccessToken())) {
  359. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  360. }
  361. $defaultHeaders = [];
  362. if ($this->config->getUserAgent()) {
  363. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  364. }
  365. $headers = array_merge(
  366. $defaultHeaders,
  367. $headerParams,
  368. $headers
  369. );
  370. $operationHost = $this->config->getHost();
  371. $query = ObjectSerializer::buildQuery($queryParams);
  372. return new Request(
  373. 'GET',
  374. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  375. $headers,
  376. $httpBody
  377. );
  378. }
  379. /**
  380. * Operation getApiV3TipitakaExportsExportFile
  381. *
  382. * 下载文件
  383. *
  384. * @param string $export 导出 id (required)
  385. * @param int $expires 签名的过期时间(download_url 里自带) (required)
  386. * @param string $signature 签名(download_url 里自带) (required)
  387. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExportFile'] to see the possible values for this operation
  388. *
  389. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  390. * @throws \InvalidArgumentException
  391. * @return \SplFileObject|\SplFileObject|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  392. */
  393. public function getApiV3TipitakaExportsExportFile($export, $expires, $signature, string $contentType = self::contentTypes['getApiV3TipitakaExportsExportFile'][0])
  394. {
  395. list($response) = $this->getApiV3TipitakaExportsExportFileWithHttpInfo($export, $expires, $signature, $contentType);
  396. return $response;
  397. }
  398. /**
  399. * Operation getApiV3TipitakaExportsExportFileWithHttpInfo
  400. *
  401. * 下载文件
  402. *
  403. * @param string $export 导出 id (required)
  404. * @param int $expires 签名的过期时间(download_url 里自带) (required)
  405. * @param string $signature 签名(download_url 里自带) (required)
  406. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExportFile'] to see the possible values for this operation
  407. *
  408. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  409. * @throws \InvalidArgumentException
  410. * @return array of \SplFileObject|\SplFileObject|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  411. */
  412. public function getApiV3TipitakaExportsExportFileWithHttpInfo($export, $expires, $signature, string $contentType = self::contentTypes['getApiV3TipitakaExportsExportFile'][0])
  413. {
  414. $request = $this->getApiV3TipitakaExportsExportFileRequest($export, $expires, $signature, $contentType);
  415. try {
  416. $options = $this->createHttpClientOption();
  417. try {
  418. $response = $this->client->send($request, $options);
  419. } catch (RequestException $e) {
  420. throw new ApiException(
  421. "[{$e->getCode()}] {$e->getMessage()}",
  422. (int) $e->getCode(),
  423. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  424. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  425. );
  426. } catch (ConnectException $e) {
  427. throw new ApiException(
  428. "[{$e->getCode()}] {$e->getMessage()}",
  429. (int) $e->getCode(),
  430. null,
  431. null
  432. );
  433. }
  434. $statusCode = $response->getStatusCode();
  435. switch($statusCode) {
  436. case 200:
  437. return $this->handleResponseWithDataType(
  438. '\SplFileObject',
  439. $request,
  440. $response,
  441. );
  442. case 206:
  443. return $this->handleResponseWithDataType(
  444. '\SplFileObject',
  445. $request,
  446. $response,
  447. );
  448. case 403:
  449. return $this->handleResponseWithDataType(
  450. '\WikipaliApi\Model\ProblemDetails',
  451. $request,
  452. $response,
  453. );
  454. case 404:
  455. return $this->handleResponseWithDataType(
  456. '\WikipaliApi\Model\ProblemDetails',
  457. $request,
  458. $response,
  459. );
  460. case 416:
  461. return $this->handleResponseWithDataType(
  462. '\WikipaliApi\Model\ProblemDetails',
  463. $request,
  464. $response,
  465. );
  466. case 422:
  467. return $this->handleResponseWithDataType(
  468. '\WikipaliApi\Model\ProblemDetails',
  469. $request,
  470. $response,
  471. );
  472. }
  473. if ($statusCode < 200 || $statusCode > 299) {
  474. throw new ApiException(
  475. sprintf(
  476. '[%d] Error connecting to the API (%s)',
  477. $statusCode,
  478. (string) $request->getUri()
  479. ),
  480. $statusCode,
  481. $response->getHeaders(),
  482. (string) $response->getBody()
  483. );
  484. }
  485. return $this->handleResponseWithDataType(
  486. '\SplFileObject',
  487. $request,
  488. $response,
  489. );
  490. } catch (ApiException $e) {
  491. switch ($e->getCode()) {
  492. case 200:
  493. $data = ObjectSerializer::deserialize(
  494. $e->getResponseBody(),
  495. '\SplFileObject',
  496. $e->getResponseHeaders()
  497. );
  498. $e->setResponseObject($data);
  499. throw $e;
  500. case 206:
  501. $data = ObjectSerializer::deserialize(
  502. $e->getResponseBody(),
  503. '\SplFileObject',
  504. $e->getResponseHeaders()
  505. );
  506. $e->setResponseObject($data);
  507. throw $e;
  508. case 403:
  509. $data = ObjectSerializer::deserialize(
  510. $e->getResponseBody(),
  511. '\WikipaliApi\Model\ProblemDetails',
  512. $e->getResponseHeaders()
  513. );
  514. $e->setResponseObject($data);
  515. throw $e;
  516. case 404:
  517. $data = ObjectSerializer::deserialize(
  518. $e->getResponseBody(),
  519. '\WikipaliApi\Model\ProblemDetails',
  520. $e->getResponseHeaders()
  521. );
  522. $e->setResponseObject($data);
  523. throw $e;
  524. case 416:
  525. $data = ObjectSerializer::deserialize(
  526. $e->getResponseBody(),
  527. '\WikipaliApi\Model\ProblemDetails',
  528. $e->getResponseHeaders()
  529. );
  530. $e->setResponseObject($data);
  531. throw $e;
  532. case 422:
  533. $data = ObjectSerializer::deserialize(
  534. $e->getResponseBody(),
  535. '\WikipaliApi\Model\ProblemDetails',
  536. $e->getResponseHeaders()
  537. );
  538. $e->setResponseObject($data);
  539. throw $e;
  540. }
  541. throw $e;
  542. }
  543. }
  544. /**
  545. * Operation getApiV3TipitakaExportsExportFileAsync
  546. *
  547. * 下载文件
  548. *
  549. * @param string $export 导出 id (required)
  550. * @param int $expires 签名的过期时间(download_url 里自带) (required)
  551. * @param string $signature 签名(download_url 里自带) (required)
  552. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExportFile'] to see the possible values for this operation
  553. *
  554. * @throws \InvalidArgumentException
  555. * @return \GuzzleHttp\Promise\PromiseInterface
  556. */
  557. public function getApiV3TipitakaExportsExportFileAsync($export, $expires, $signature, string $contentType = self::contentTypes['getApiV3TipitakaExportsExportFile'][0])
  558. {
  559. return $this->getApiV3TipitakaExportsExportFileAsyncWithHttpInfo($export, $expires, $signature, $contentType)
  560. ->then(
  561. function ($response) {
  562. return $response[0];
  563. }
  564. );
  565. }
  566. /**
  567. * Operation getApiV3TipitakaExportsExportFileAsyncWithHttpInfo
  568. *
  569. * 下载文件
  570. *
  571. * @param string $export 导出 id (required)
  572. * @param int $expires 签名的过期时间(download_url 里自带) (required)
  573. * @param string $signature 签名(download_url 里自带) (required)
  574. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExportFile'] to see the possible values for this operation
  575. *
  576. * @throws \InvalidArgumentException
  577. * @return \GuzzleHttp\Promise\PromiseInterface
  578. */
  579. public function getApiV3TipitakaExportsExportFileAsyncWithHttpInfo($export, $expires, $signature, string $contentType = self::contentTypes['getApiV3TipitakaExportsExportFile'][0])
  580. {
  581. $returnType = '\SplFileObject';
  582. $request = $this->getApiV3TipitakaExportsExportFileRequest($export, $expires, $signature, $contentType);
  583. return $this->client
  584. ->sendAsync($request, $this->createHttpClientOption())
  585. ->then(
  586. function ($response) use ($returnType) {
  587. if ($returnType === '\SplFileObject') {
  588. $content = $response->getBody(); //stream goes to serializer
  589. } else {
  590. $content = (string) $response->getBody();
  591. if ($returnType !== 'string') {
  592. $content = json_decode($content);
  593. }
  594. }
  595. return [
  596. ObjectSerializer::deserialize($content, $returnType, []),
  597. $response->getStatusCode(),
  598. $response->getHeaders()
  599. ];
  600. },
  601. function ($exception) {
  602. $response = $exception->getResponse();
  603. $statusCode = $response->getStatusCode();
  604. throw new ApiException(
  605. sprintf(
  606. '[%d] Error connecting to the API (%s)',
  607. $statusCode,
  608. $exception->getRequest()->getUri()
  609. ),
  610. $statusCode,
  611. $response->getHeaders(),
  612. (string) $response->getBody()
  613. );
  614. }
  615. );
  616. }
  617. /**
  618. * Create request for operation 'getApiV3TipitakaExportsExportFile'
  619. *
  620. * @param string $export 导出 id (required)
  621. * @param int $expires 签名的过期时间(download_url 里自带) (required)
  622. * @param string $signature 签名(download_url 里自带) (required)
  623. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExportFile'] to see the possible values for this operation
  624. *
  625. * @throws \InvalidArgumentException
  626. * @return \GuzzleHttp\Psr7\Request
  627. */
  628. public function getApiV3TipitakaExportsExportFileRequest($export, $expires, $signature, string $contentType = self::contentTypes['getApiV3TipitakaExportsExportFile'][0])
  629. {
  630. // verify the required parameter 'export' is set
  631. if ($export === null || (is_array($export) && count($export) === 0)) {
  632. throw new \InvalidArgumentException(
  633. 'Missing the required parameter $export when calling getApiV3TipitakaExportsExportFile'
  634. );
  635. }
  636. // verify the required parameter 'expires' is set
  637. if ($expires === null || (is_array($expires) && count($expires) === 0)) {
  638. throw new \InvalidArgumentException(
  639. 'Missing the required parameter $expires when calling getApiV3TipitakaExportsExportFile'
  640. );
  641. }
  642. // verify the required parameter 'signature' is set
  643. if ($signature === null || (is_array($signature) && count($signature) === 0)) {
  644. throw new \InvalidArgumentException(
  645. 'Missing the required parameter $signature when calling getApiV3TipitakaExportsExportFile'
  646. );
  647. }
  648. $resourcePath = '/v3/tipitaka-exports/{export}/file';
  649. $formParams = [];
  650. $queryParams = [];
  651. $headerParams = [];
  652. $httpBody = '';
  653. $multipart = false;
  654. // query params
  655. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  656. $expires,
  657. 'expires', // param base name
  658. 'integer', // openApiType
  659. 'form', // style
  660. true, // explode
  661. true // required
  662. ) ?? []);
  663. // query params
  664. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  665. $signature,
  666. 'signature', // param base name
  667. 'string', // openApiType
  668. 'form', // style
  669. true, // explode
  670. true // required
  671. ) ?? []);
  672. // path params
  673. if ($export !== null) {
  674. $resourcePath = str_replace(
  675. '{export}',
  676. ObjectSerializer::toPathValue($export),
  677. $resourcePath
  678. );
  679. }
  680. $headers = $this->headerSelector->selectHeaders(
  681. ['application/zip', 'application/epub+zip', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/x-ndjson', 'application/problem+json', ],
  682. $contentType,
  683. $multipart
  684. );
  685. // for model (json/xml)
  686. if (count($formParams) > 0) {
  687. if ($multipart) {
  688. $multipartContents = [];
  689. foreach ($formParams as $formParamName => $formParamValue) {
  690. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  691. foreach ($formParamValueItems as $formParamValueItem) {
  692. $multipartContents[] = [
  693. 'name' => $formParamName,
  694. 'contents' => $formParamValueItem
  695. ];
  696. }
  697. }
  698. // for HTTP post (form)
  699. $httpBody = new MultipartStream($multipartContents);
  700. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  701. # if Content-Type contains "application/json", json_encode the form parameters
  702. try {
  703. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  704. } catch (\JsonException $e) {
  705. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  706. }
  707. } else {
  708. // for HTTP post (form)
  709. $httpBody = ObjectSerializer::buildQuery($formParams);
  710. }
  711. }
  712. // this endpoint requires Bearer authentication (access token)
  713. if (!empty($this->config->getAccessToken())) {
  714. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  715. }
  716. $defaultHeaders = [];
  717. if ($this->config->getUserAgent()) {
  718. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  719. }
  720. $headers = array_merge(
  721. $defaultHeaders,
  722. $headerParams,
  723. $headers
  724. );
  725. $operationHost = $this->config->getHost();
  726. $query = ObjectSerializer::buildQuery($queryParams);
  727. return new Request(
  728. 'GET',
  729. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  730. $headers,
  731. $httpBody
  732. );
  733. }
  734. /**
  735. * Operation postApiV3TipitakaExports
  736. *
  737. * 发起下载
  738. *
  739. * @param \WikipaliApi\Model\PostApiV3TipitakaExportsRequest $post_api_v3_tipitaka_exports_request post_api_v3_tipitaka_exports_request (required)
  740. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3TipitakaExports'] to see the possible values for this operation
  741. *
  742. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  743. * @throws \InvalidArgumentException
  744. * @return \WikipaliApi\Model\PostApiV3TipitakaExports200Response|\WikipaliApi\Model\PostApiV3TipitakaExports200Response|\WikipaliApi\Model\ProblemDetails
  745. */
  746. public function postApiV3TipitakaExports($post_api_v3_tipitaka_exports_request, string $contentType = self::contentTypes['postApiV3TipitakaExports'][0])
  747. {
  748. list($response) = $this->postApiV3TipitakaExportsWithHttpInfo($post_api_v3_tipitaka_exports_request, $contentType);
  749. return $response;
  750. }
  751. /**
  752. * Operation postApiV3TipitakaExportsWithHttpInfo
  753. *
  754. * 发起下载
  755. *
  756. * @param \WikipaliApi\Model\PostApiV3TipitakaExportsRequest $post_api_v3_tipitaka_exports_request (required)
  757. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3TipitakaExports'] to see the possible values for this operation
  758. *
  759. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  760. * @throws \InvalidArgumentException
  761. * @return array of \WikipaliApi\Model\PostApiV3TipitakaExports200Response|\WikipaliApi\Model\PostApiV3TipitakaExports200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  762. */
  763. public function postApiV3TipitakaExportsWithHttpInfo($post_api_v3_tipitaka_exports_request, string $contentType = self::contentTypes['postApiV3TipitakaExports'][0])
  764. {
  765. $request = $this->postApiV3TipitakaExportsRequest($post_api_v3_tipitaka_exports_request, $contentType);
  766. try {
  767. $options = $this->createHttpClientOption();
  768. try {
  769. $response = $this->client->send($request, $options);
  770. } catch (RequestException $e) {
  771. throw new ApiException(
  772. "[{$e->getCode()}] {$e->getMessage()}",
  773. (int) $e->getCode(),
  774. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  775. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  776. );
  777. } catch (ConnectException $e) {
  778. throw new ApiException(
  779. "[{$e->getCode()}] {$e->getMessage()}",
  780. (int) $e->getCode(),
  781. null,
  782. null
  783. );
  784. }
  785. $statusCode = $response->getStatusCode();
  786. switch($statusCode) {
  787. case 200:
  788. return $this->handleResponseWithDataType(
  789. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  790. $request,
  791. $response,
  792. );
  793. case 202:
  794. return $this->handleResponseWithDataType(
  795. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  796. $request,
  797. $response,
  798. );
  799. case 422:
  800. return $this->handleResponseWithDataType(
  801. '\WikipaliApi\Model\ProblemDetails',
  802. $request,
  803. $response,
  804. );
  805. }
  806. if ($statusCode < 200 || $statusCode > 299) {
  807. throw new ApiException(
  808. sprintf(
  809. '[%d] Error connecting to the API (%s)',
  810. $statusCode,
  811. (string) $request->getUri()
  812. ),
  813. $statusCode,
  814. $response->getHeaders(),
  815. (string) $response->getBody()
  816. );
  817. }
  818. return $this->handleResponseWithDataType(
  819. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  820. $request,
  821. $response,
  822. );
  823. } catch (ApiException $e) {
  824. switch ($e->getCode()) {
  825. case 200:
  826. $data = ObjectSerializer::deserialize(
  827. $e->getResponseBody(),
  828. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  829. $e->getResponseHeaders()
  830. );
  831. $e->setResponseObject($data);
  832. throw $e;
  833. case 202:
  834. $data = ObjectSerializer::deserialize(
  835. $e->getResponseBody(),
  836. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  837. $e->getResponseHeaders()
  838. );
  839. $e->setResponseObject($data);
  840. throw $e;
  841. case 422:
  842. $data = ObjectSerializer::deserialize(
  843. $e->getResponseBody(),
  844. '\WikipaliApi\Model\ProblemDetails',
  845. $e->getResponseHeaders()
  846. );
  847. $e->setResponseObject($data);
  848. throw $e;
  849. }
  850. throw $e;
  851. }
  852. }
  853. /**
  854. * Operation postApiV3TipitakaExportsAsync
  855. *
  856. * 发起下载
  857. *
  858. * @param \WikipaliApi\Model\PostApiV3TipitakaExportsRequest $post_api_v3_tipitaka_exports_request (required)
  859. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3TipitakaExports'] to see the possible values for this operation
  860. *
  861. * @throws \InvalidArgumentException
  862. * @return \GuzzleHttp\Promise\PromiseInterface
  863. */
  864. public function postApiV3TipitakaExportsAsync($post_api_v3_tipitaka_exports_request, string $contentType = self::contentTypes['postApiV3TipitakaExports'][0])
  865. {
  866. return $this->postApiV3TipitakaExportsAsyncWithHttpInfo($post_api_v3_tipitaka_exports_request, $contentType)
  867. ->then(
  868. function ($response) {
  869. return $response[0];
  870. }
  871. );
  872. }
  873. /**
  874. * Operation postApiV3TipitakaExportsAsyncWithHttpInfo
  875. *
  876. * 发起下载
  877. *
  878. * @param \WikipaliApi\Model\PostApiV3TipitakaExportsRequest $post_api_v3_tipitaka_exports_request (required)
  879. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3TipitakaExports'] to see the possible values for this operation
  880. *
  881. * @throws \InvalidArgumentException
  882. * @return \GuzzleHttp\Promise\PromiseInterface
  883. */
  884. public function postApiV3TipitakaExportsAsyncWithHttpInfo($post_api_v3_tipitaka_exports_request, string $contentType = self::contentTypes['postApiV3TipitakaExports'][0])
  885. {
  886. $returnType = '\WikipaliApi\Model\PostApiV3TipitakaExports200Response';
  887. $request = $this->postApiV3TipitakaExportsRequest($post_api_v3_tipitaka_exports_request, $contentType);
  888. return $this->client
  889. ->sendAsync($request, $this->createHttpClientOption())
  890. ->then(
  891. function ($response) use ($returnType) {
  892. if ($returnType === '\SplFileObject') {
  893. $content = $response->getBody(); //stream goes to serializer
  894. } else {
  895. $content = (string) $response->getBody();
  896. if ($returnType !== 'string') {
  897. $content = json_decode($content);
  898. }
  899. }
  900. return [
  901. ObjectSerializer::deserialize($content, $returnType, []),
  902. $response->getStatusCode(),
  903. $response->getHeaders()
  904. ];
  905. },
  906. function ($exception) {
  907. $response = $exception->getResponse();
  908. $statusCode = $response->getStatusCode();
  909. throw new ApiException(
  910. sprintf(
  911. '[%d] Error connecting to the API (%s)',
  912. $statusCode,
  913. $exception->getRequest()->getUri()
  914. ),
  915. $statusCode,
  916. $response->getHeaders(),
  917. (string) $response->getBody()
  918. );
  919. }
  920. );
  921. }
  922. /**
  923. * Create request for operation 'postApiV3TipitakaExports'
  924. *
  925. * @param \WikipaliApi\Model\PostApiV3TipitakaExportsRequest $post_api_v3_tipitaka_exports_request (required)
  926. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3TipitakaExports'] to see the possible values for this operation
  927. *
  928. * @throws \InvalidArgumentException
  929. * @return \GuzzleHttp\Psr7\Request
  930. */
  931. public function postApiV3TipitakaExportsRequest($post_api_v3_tipitaka_exports_request, string $contentType = self::contentTypes['postApiV3TipitakaExports'][0])
  932. {
  933. // verify the required parameter 'post_api_v3_tipitaka_exports_request' is set
  934. if ($post_api_v3_tipitaka_exports_request === null || (is_array($post_api_v3_tipitaka_exports_request) && count($post_api_v3_tipitaka_exports_request) === 0)) {
  935. throw new \InvalidArgumentException(
  936. 'Missing the required parameter $post_api_v3_tipitaka_exports_request when calling postApiV3TipitakaExports'
  937. );
  938. }
  939. $resourcePath = '/v3/tipitaka-exports';
  940. $formParams = [];
  941. $queryParams = [];
  942. $headerParams = [];
  943. $httpBody = '';
  944. $multipart = false;
  945. $headers = $this->headerSelector->selectHeaders(
  946. ['application/json', 'application/problem+json', ],
  947. $contentType,
  948. $multipart
  949. );
  950. // for model (json/xml)
  951. if (isset($post_api_v3_tipitaka_exports_request)) {
  952. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  953. # if Content-Type contains "application/json", json_encode the body
  954. try {
  955. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_tipitaka_exports_request), JSON_THROW_ON_ERROR);
  956. } catch (\JsonException $e) {
  957. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  958. }
  959. } else {
  960. $httpBody = $post_api_v3_tipitaka_exports_request;
  961. }
  962. } elseif (count($formParams) > 0) {
  963. if ($multipart) {
  964. $multipartContents = [];
  965. foreach ($formParams as $formParamName => $formParamValue) {
  966. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  967. foreach ($formParamValueItems as $formParamValueItem) {
  968. $multipartContents[] = [
  969. 'name' => $formParamName,
  970. 'contents' => $formParamValueItem
  971. ];
  972. }
  973. }
  974. // for HTTP post (form)
  975. $httpBody = new MultipartStream($multipartContents);
  976. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  977. # if Content-Type contains "application/json", json_encode the form parameters
  978. try {
  979. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  980. } catch (\JsonException $e) {
  981. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  982. }
  983. } else {
  984. // for HTTP post (form)
  985. $httpBody = ObjectSerializer::buildQuery($formParams);
  986. }
  987. }
  988. // this endpoint requires Bearer authentication (access token)
  989. if (!empty($this->config->getAccessToken())) {
  990. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  991. }
  992. $defaultHeaders = [];
  993. if ($this->config->getUserAgent()) {
  994. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  995. }
  996. $headers = array_merge(
  997. $defaultHeaders,
  998. $headerParams,
  999. $headers
  1000. );
  1001. $operationHost = $this->config->getHost();
  1002. $query = ObjectSerializer::buildQuery($queryParams);
  1003. return new Request(
  1004. 'POST',
  1005. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1006. $headers,
  1007. $httpBody
  1008. );
  1009. }
  1010. /**
  1011. * Create http client option
  1012. *
  1013. * @throws \RuntimeException on file opening failure
  1014. * @return array of http client options
  1015. */
  1016. protected function createHttpClientOption()
  1017. {
  1018. $options = [];
  1019. if ($this->config->getDebug()) {
  1020. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  1021. if (!$options[RequestOptions::DEBUG]) {
  1022. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  1023. }
  1024. }
  1025. if ($this->config->getCertFile()) {
  1026. $options[RequestOptions::CERT] = $this->config->getCertFile();
  1027. }
  1028. if ($this->config->getKeyFile()) {
  1029. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  1030. }
  1031. return $options;
  1032. }
  1033. private function handleResponseWithDataType(
  1034. string $dataType,
  1035. RequestInterface $request,
  1036. ResponseInterface $response
  1037. ): array {
  1038. if ($dataType === '\SplFileObject') {
  1039. $content = $response->getBody(); //stream goes to serializer
  1040. } else {
  1041. $content = (string) $response->getBody();
  1042. if ($dataType !== 'string') {
  1043. try {
  1044. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  1045. } catch (\JsonException $exception) {
  1046. throw new ApiException(
  1047. sprintf(
  1048. 'Error JSON decoding server response (%s)',
  1049. $request->getUri()
  1050. ),
  1051. $response->getStatusCode(),
  1052. $response->getHeaders(),
  1053. $content
  1054. );
  1055. }
  1056. }
  1057. }
  1058. return [
  1059. ObjectSerializer::deserialize($content, $dataType, []),
  1060. $response->getStatusCode(),
  1061. $response->getHeaders()
  1062. ];
  1063. }
  1064. private function responseWithinRangeCode(
  1065. string $rangeCode,
  1066. int $statusCode
  1067. ): bool {
  1068. $left = (int) ($rangeCode[0].'00');
  1069. $right = (int) ($rangeCode[0].'99');
  1070. return $statusCode >= $left && $statusCode <= $right;
  1071. }
  1072. }