TipitakaExportsApi.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  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|\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|\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 302:
  449. return $this->handleResponseWithDataType(
  450. '\WikipaliApi\Model\ProblemDetails',
  451. $request,
  452. $response,
  453. );
  454. case 403:
  455. return $this->handleResponseWithDataType(
  456. '\WikipaliApi\Model\ProblemDetails',
  457. $request,
  458. $response,
  459. );
  460. case 404:
  461. return $this->handleResponseWithDataType(
  462. '\WikipaliApi\Model\ProblemDetails',
  463. $request,
  464. $response,
  465. );
  466. case 416:
  467. return $this->handleResponseWithDataType(
  468. '\WikipaliApi\Model\ProblemDetails',
  469. $request,
  470. $response,
  471. );
  472. case 422:
  473. return $this->handleResponseWithDataType(
  474. '\WikipaliApi\Model\ProblemDetails',
  475. $request,
  476. $response,
  477. );
  478. }
  479. if ($statusCode < 200 || $statusCode > 299) {
  480. throw new ApiException(
  481. sprintf(
  482. '[%d] Error connecting to the API (%s)',
  483. $statusCode,
  484. (string) $request->getUri()
  485. ),
  486. $statusCode,
  487. $response->getHeaders(),
  488. (string) $response->getBody()
  489. );
  490. }
  491. return $this->handleResponseWithDataType(
  492. '\SplFileObject',
  493. $request,
  494. $response,
  495. );
  496. } catch (ApiException $e) {
  497. switch ($e->getCode()) {
  498. case 200:
  499. $data = ObjectSerializer::deserialize(
  500. $e->getResponseBody(),
  501. '\SplFileObject',
  502. $e->getResponseHeaders()
  503. );
  504. $e->setResponseObject($data);
  505. throw $e;
  506. case 206:
  507. $data = ObjectSerializer::deserialize(
  508. $e->getResponseBody(),
  509. '\SplFileObject',
  510. $e->getResponseHeaders()
  511. );
  512. $e->setResponseObject($data);
  513. throw $e;
  514. case 302:
  515. $data = ObjectSerializer::deserialize(
  516. $e->getResponseBody(),
  517. '\WikipaliApi\Model\ProblemDetails',
  518. $e->getResponseHeaders()
  519. );
  520. $e->setResponseObject($data);
  521. throw $e;
  522. case 403:
  523. $data = ObjectSerializer::deserialize(
  524. $e->getResponseBody(),
  525. '\WikipaliApi\Model\ProblemDetails',
  526. $e->getResponseHeaders()
  527. );
  528. $e->setResponseObject($data);
  529. throw $e;
  530. case 404:
  531. $data = ObjectSerializer::deserialize(
  532. $e->getResponseBody(),
  533. '\WikipaliApi\Model\ProblemDetails',
  534. $e->getResponseHeaders()
  535. );
  536. $e->setResponseObject($data);
  537. throw $e;
  538. case 416:
  539. $data = ObjectSerializer::deserialize(
  540. $e->getResponseBody(),
  541. '\WikipaliApi\Model\ProblemDetails',
  542. $e->getResponseHeaders()
  543. );
  544. $e->setResponseObject($data);
  545. throw $e;
  546. case 422:
  547. $data = ObjectSerializer::deserialize(
  548. $e->getResponseBody(),
  549. '\WikipaliApi\Model\ProblemDetails',
  550. $e->getResponseHeaders()
  551. );
  552. $e->setResponseObject($data);
  553. throw $e;
  554. }
  555. throw $e;
  556. }
  557. }
  558. /**
  559. * Operation getApiV3TipitakaExportsExportFileAsync
  560. *
  561. * 下载文件
  562. *
  563. * @param string $export 导出 id (required)
  564. * @param int $expires 签名的过期时间(download_url 里自带) (required)
  565. * @param string $signature 签名(download_url 里自带) (required)
  566. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExportFile'] to see the possible values for this operation
  567. *
  568. * @throws \InvalidArgumentException
  569. * @return \GuzzleHttp\Promise\PromiseInterface
  570. */
  571. public function getApiV3TipitakaExportsExportFileAsync($export, $expires, $signature, string $contentType = self::contentTypes['getApiV3TipitakaExportsExportFile'][0])
  572. {
  573. return $this->getApiV3TipitakaExportsExportFileAsyncWithHttpInfo($export, $expires, $signature, $contentType)
  574. ->then(
  575. function ($response) {
  576. return $response[0];
  577. }
  578. );
  579. }
  580. /**
  581. * Operation getApiV3TipitakaExportsExportFileAsyncWithHttpInfo
  582. *
  583. * 下载文件
  584. *
  585. * @param string $export 导出 id (required)
  586. * @param int $expires 签名的过期时间(download_url 里自带) (required)
  587. * @param string $signature 签名(download_url 里自带) (required)
  588. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExportFile'] to see the possible values for this operation
  589. *
  590. * @throws \InvalidArgumentException
  591. * @return \GuzzleHttp\Promise\PromiseInterface
  592. */
  593. public function getApiV3TipitakaExportsExportFileAsyncWithHttpInfo($export, $expires, $signature, string $contentType = self::contentTypes['getApiV3TipitakaExportsExportFile'][0])
  594. {
  595. $returnType = '\SplFileObject';
  596. $request = $this->getApiV3TipitakaExportsExportFileRequest($export, $expires, $signature, $contentType);
  597. return $this->client
  598. ->sendAsync($request, $this->createHttpClientOption())
  599. ->then(
  600. function ($response) use ($returnType) {
  601. if ($returnType === '\SplFileObject') {
  602. $content = $response->getBody(); //stream goes to serializer
  603. } else {
  604. $content = (string) $response->getBody();
  605. if ($returnType !== 'string') {
  606. $content = json_decode($content);
  607. }
  608. }
  609. return [
  610. ObjectSerializer::deserialize($content, $returnType, []),
  611. $response->getStatusCode(),
  612. $response->getHeaders()
  613. ];
  614. },
  615. function ($exception) {
  616. $response = $exception->getResponse();
  617. $statusCode = $response->getStatusCode();
  618. throw new ApiException(
  619. sprintf(
  620. '[%d] Error connecting to the API (%s)',
  621. $statusCode,
  622. $exception->getRequest()->getUri()
  623. ),
  624. $statusCode,
  625. $response->getHeaders(),
  626. (string) $response->getBody()
  627. );
  628. }
  629. );
  630. }
  631. /**
  632. * Create request for operation 'getApiV3TipitakaExportsExportFile'
  633. *
  634. * @param string $export 导出 id (required)
  635. * @param int $expires 签名的过期时间(download_url 里自带) (required)
  636. * @param string $signature 签名(download_url 里自带) (required)
  637. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaExportsExportFile'] to see the possible values for this operation
  638. *
  639. * @throws \InvalidArgumentException
  640. * @return \GuzzleHttp\Psr7\Request
  641. */
  642. public function getApiV3TipitakaExportsExportFileRequest($export, $expires, $signature, string $contentType = self::contentTypes['getApiV3TipitakaExportsExportFile'][0])
  643. {
  644. // verify the required parameter 'export' is set
  645. if ($export === null || (is_array($export) && count($export) === 0)) {
  646. throw new \InvalidArgumentException(
  647. 'Missing the required parameter $export when calling getApiV3TipitakaExportsExportFile'
  648. );
  649. }
  650. // verify the required parameter 'expires' is set
  651. if ($expires === null || (is_array($expires) && count($expires) === 0)) {
  652. throw new \InvalidArgumentException(
  653. 'Missing the required parameter $expires when calling getApiV3TipitakaExportsExportFile'
  654. );
  655. }
  656. // verify the required parameter 'signature' is set
  657. if ($signature === null || (is_array($signature) && count($signature) === 0)) {
  658. throw new \InvalidArgumentException(
  659. 'Missing the required parameter $signature when calling getApiV3TipitakaExportsExportFile'
  660. );
  661. }
  662. $resourcePath = '/v3/tipitaka-exports/{export}/file';
  663. $formParams = [];
  664. $queryParams = [];
  665. $headerParams = [];
  666. $httpBody = '';
  667. $multipart = false;
  668. // query params
  669. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  670. $expires,
  671. 'expires', // param base name
  672. 'integer', // openApiType
  673. 'form', // style
  674. true, // explode
  675. true // required
  676. ) ?? []);
  677. // query params
  678. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  679. $signature,
  680. 'signature', // param base name
  681. 'string', // openApiType
  682. 'form', // style
  683. true, // explode
  684. true // required
  685. ) ?? []);
  686. // path params
  687. if ($export !== null) {
  688. $resourcePath = str_replace(
  689. '{export}',
  690. ObjectSerializer::toPathValue($export),
  691. $resourcePath
  692. );
  693. }
  694. $headers = $this->headerSelector->selectHeaders(
  695. ['application/zip', 'application/epub+zip', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/x-ndjson', 'application/problem+json', ],
  696. $contentType,
  697. $multipart
  698. );
  699. // for model (json/xml)
  700. if (count($formParams) > 0) {
  701. if ($multipart) {
  702. $multipartContents = [];
  703. foreach ($formParams as $formParamName => $formParamValue) {
  704. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  705. foreach ($formParamValueItems as $formParamValueItem) {
  706. $multipartContents[] = [
  707. 'name' => $formParamName,
  708. 'contents' => $formParamValueItem
  709. ];
  710. }
  711. }
  712. // for HTTP post (form)
  713. $httpBody = new MultipartStream($multipartContents);
  714. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  715. # if Content-Type contains "application/json", json_encode the form parameters
  716. try {
  717. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  718. } catch (\JsonException $e) {
  719. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  720. }
  721. } else {
  722. // for HTTP post (form)
  723. $httpBody = ObjectSerializer::buildQuery($formParams);
  724. }
  725. }
  726. // this endpoint requires Bearer authentication (access token)
  727. if (!empty($this->config->getAccessToken())) {
  728. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  729. }
  730. $defaultHeaders = [];
  731. if ($this->config->getUserAgent()) {
  732. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  733. }
  734. $headers = array_merge(
  735. $defaultHeaders,
  736. $headerParams,
  737. $headers
  738. );
  739. $operationHost = $this->config->getHost();
  740. $query = ObjectSerializer::buildQuery($queryParams);
  741. return new Request(
  742. 'GET',
  743. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  744. $headers,
  745. $httpBody
  746. );
  747. }
  748. /**
  749. * Operation postApiV3TipitakaExports
  750. *
  751. * 发起下载
  752. *
  753. * @param \WikipaliApi\Model\PostApiV3TipitakaExportsRequest $post_api_v3_tipitaka_exports_request post_api_v3_tipitaka_exports_request (required)
  754. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3TipitakaExports'] to see the possible values for this operation
  755. *
  756. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  757. * @throws \InvalidArgumentException
  758. * @return \WikipaliApi\Model\PostApiV3TipitakaExports200Response|\WikipaliApi\Model\PostApiV3TipitakaExports200Response|\WikipaliApi\Model\ProblemDetails
  759. */
  760. public function postApiV3TipitakaExports($post_api_v3_tipitaka_exports_request, string $contentType = self::contentTypes['postApiV3TipitakaExports'][0])
  761. {
  762. list($response) = $this->postApiV3TipitakaExportsWithHttpInfo($post_api_v3_tipitaka_exports_request, $contentType);
  763. return $response;
  764. }
  765. /**
  766. * Operation postApiV3TipitakaExportsWithHttpInfo
  767. *
  768. * 发起下载
  769. *
  770. * @param \WikipaliApi\Model\PostApiV3TipitakaExportsRequest $post_api_v3_tipitaka_exports_request (required)
  771. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3TipitakaExports'] to see the possible values for this operation
  772. *
  773. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  774. * @throws \InvalidArgumentException
  775. * @return array of \WikipaliApi\Model\PostApiV3TipitakaExports200Response|\WikipaliApi\Model\PostApiV3TipitakaExports200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  776. */
  777. public function postApiV3TipitakaExportsWithHttpInfo($post_api_v3_tipitaka_exports_request, string $contentType = self::contentTypes['postApiV3TipitakaExports'][0])
  778. {
  779. $request = $this->postApiV3TipitakaExportsRequest($post_api_v3_tipitaka_exports_request, $contentType);
  780. try {
  781. $options = $this->createHttpClientOption();
  782. try {
  783. $response = $this->client->send($request, $options);
  784. } catch (RequestException $e) {
  785. throw new ApiException(
  786. "[{$e->getCode()}] {$e->getMessage()}",
  787. (int) $e->getCode(),
  788. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  789. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  790. );
  791. } catch (ConnectException $e) {
  792. throw new ApiException(
  793. "[{$e->getCode()}] {$e->getMessage()}",
  794. (int) $e->getCode(),
  795. null,
  796. null
  797. );
  798. }
  799. $statusCode = $response->getStatusCode();
  800. switch($statusCode) {
  801. case 200:
  802. return $this->handleResponseWithDataType(
  803. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  804. $request,
  805. $response,
  806. );
  807. case 202:
  808. return $this->handleResponseWithDataType(
  809. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  810. $request,
  811. $response,
  812. );
  813. case 422:
  814. return $this->handleResponseWithDataType(
  815. '\WikipaliApi\Model\ProblemDetails',
  816. $request,
  817. $response,
  818. );
  819. }
  820. if ($statusCode < 200 || $statusCode > 299) {
  821. throw new ApiException(
  822. sprintf(
  823. '[%d] Error connecting to the API (%s)',
  824. $statusCode,
  825. (string) $request->getUri()
  826. ),
  827. $statusCode,
  828. $response->getHeaders(),
  829. (string) $response->getBody()
  830. );
  831. }
  832. return $this->handleResponseWithDataType(
  833. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  834. $request,
  835. $response,
  836. );
  837. } catch (ApiException $e) {
  838. switch ($e->getCode()) {
  839. case 200:
  840. $data = ObjectSerializer::deserialize(
  841. $e->getResponseBody(),
  842. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  843. $e->getResponseHeaders()
  844. );
  845. $e->setResponseObject($data);
  846. throw $e;
  847. case 202:
  848. $data = ObjectSerializer::deserialize(
  849. $e->getResponseBody(),
  850. '\WikipaliApi\Model\PostApiV3TipitakaExports200Response',
  851. $e->getResponseHeaders()
  852. );
  853. $e->setResponseObject($data);
  854. throw $e;
  855. case 422:
  856. $data = ObjectSerializer::deserialize(
  857. $e->getResponseBody(),
  858. '\WikipaliApi\Model\ProblemDetails',
  859. $e->getResponseHeaders()
  860. );
  861. $e->setResponseObject($data);
  862. throw $e;
  863. }
  864. throw $e;
  865. }
  866. }
  867. /**
  868. * Operation postApiV3TipitakaExportsAsync
  869. *
  870. * 发起下载
  871. *
  872. * @param \WikipaliApi\Model\PostApiV3TipitakaExportsRequest $post_api_v3_tipitaka_exports_request (required)
  873. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3TipitakaExports'] to see the possible values for this operation
  874. *
  875. * @throws \InvalidArgumentException
  876. * @return \GuzzleHttp\Promise\PromiseInterface
  877. */
  878. public function postApiV3TipitakaExportsAsync($post_api_v3_tipitaka_exports_request, string $contentType = self::contentTypes['postApiV3TipitakaExports'][0])
  879. {
  880. return $this->postApiV3TipitakaExportsAsyncWithHttpInfo($post_api_v3_tipitaka_exports_request, $contentType)
  881. ->then(
  882. function ($response) {
  883. return $response[0];
  884. }
  885. );
  886. }
  887. /**
  888. * Operation postApiV3TipitakaExportsAsyncWithHttpInfo
  889. *
  890. * 发起下载
  891. *
  892. * @param \WikipaliApi\Model\PostApiV3TipitakaExportsRequest $post_api_v3_tipitaka_exports_request (required)
  893. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3TipitakaExports'] to see the possible values for this operation
  894. *
  895. * @throws \InvalidArgumentException
  896. * @return \GuzzleHttp\Promise\PromiseInterface
  897. */
  898. public function postApiV3TipitakaExportsAsyncWithHttpInfo($post_api_v3_tipitaka_exports_request, string $contentType = self::contentTypes['postApiV3TipitakaExports'][0])
  899. {
  900. $returnType = '\WikipaliApi\Model\PostApiV3TipitakaExports200Response';
  901. $request = $this->postApiV3TipitakaExportsRequest($post_api_v3_tipitaka_exports_request, $contentType);
  902. return $this->client
  903. ->sendAsync($request, $this->createHttpClientOption())
  904. ->then(
  905. function ($response) use ($returnType) {
  906. if ($returnType === '\SplFileObject') {
  907. $content = $response->getBody(); //stream goes to serializer
  908. } else {
  909. $content = (string) $response->getBody();
  910. if ($returnType !== 'string') {
  911. $content = json_decode($content);
  912. }
  913. }
  914. return [
  915. ObjectSerializer::deserialize($content, $returnType, []),
  916. $response->getStatusCode(),
  917. $response->getHeaders()
  918. ];
  919. },
  920. function ($exception) {
  921. $response = $exception->getResponse();
  922. $statusCode = $response->getStatusCode();
  923. throw new ApiException(
  924. sprintf(
  925. '[%d] Error connecting to the API (%s)',
  926. $statusCode,
  927. $exception->getRequest()->getUri()
  928. ),
  929. $statusCode,
  930. $response->getHeaders(),
  931. (string) $response->getBody()
  932. );
  933. }
  934. );
  935. }
  936. /**
  937. * Create request for operation 'postApiV3TipitakaExports'
  938. *
  939. * @param \WikipaliApi\Model\PostApiV3TipitakaExportsRequest $post_api_v3_tipitaka_exports_request (required)
  940. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3TipitakaExports'] to see the possible values for this operation
  941. *
  942. * @throws \InvalidArgumentException
  943. * @return \GuzzleHttp\Psr7\Request
  944. */
  945. public function postApiV3TipitakaExportsRequest($post_api_v3_tipitaka_exports_request, string $contentType = self::contentTypes['postApiV3TipitakaExports'][0])
  946. {
  947. // verify the required parameter 'post_api_v3_tipitaka_exports_request' is set
  948. if ($post_api_v3_tipitaka_exports_request === null || (is_array($post_api_v3_tipitaka_exports_request) && count($post_api_v3_tipitaka_exports_request) === 0)) {
  949. throw new \InvalidArgumentException(
  950. 'Missing the required parameter $post_api_v3_tipitaka_exports_request when calling postApiV3TipitakaExports'
  951. );
  952. }
  953. $resourcePath = '/v3/tipitaka-exports';
  954. $formParams = [];
  955. $queryParams = [];
  956. $headerParams = [];
  957. $httpBody = '';
  958. $multipart = false;
  959. $headers = $this->headerSelector->selectHeaders(
  960. ['application/json', 'application/problem+json', ],
  961. $contentType,
  962. $multipart
  963. );
  964. // for model (json/xml)
  965. if (isset($post_api_v3_tipitaka_exports_request)) {
  966. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  967. # if Content-Type contains "application/json", json_encode the body
  968. try {
  969. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_tipitaka_exports_request), JSON_THROW_ON_ERROR);
  970. } catch (\JsonException $e) {
  971. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  972. }
  973. } else {
  974. $httpBody = $post_api_v3_tipitaka_exports_request;
  975. }
  976. } elseif (count($formParams) > 0) {
  977. if ($multipart) {
  978. $multipartContents = [];
  979. foreach ($formParams as $formParamName => $formParamValue) {
  980. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  981. foreach ($formParamValueItems as $formParamValueItem) {
  982. $multipartContents[] = [
  983. 'name' => $formParamName,
  984. 'contents' => $formParamValueItem
  985. ];
  986. }
  987. }
  988. // for HTTP post (form)
  989. $httpBody = new MultipartStream($multipartContents);
  990. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  991. # if Content-Type contains "application/json", json_encode the form parameters
  992. try {
  993. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  994. } catch (\JsonException $e) {
  995. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  996. }
  997. } else {
  998. // for HTTP post (form)
  999. $httpBody = ObjectSerializer::buildQuery($formParams);
  1000. }
  1001. }
  1002. // this endpoint requires Bearer authentication (access token)
  1003. if (!empty($this->config->getAccessToken())) {
  1004. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1005. }
  1006. $defaultHeaders = [];
  1007. if ($this->config->getUserAgent()) {
  1008. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1009. }
  1010. $headers = array_merge(
  1011. $defaultHeaders,
  1012. $headerParams,
  1013. $headers
  1014. );
  1015. $operationHost = $this->config->getHost();
  1016. $query = ObjectSerializer::buildQuery($queryParams);
  1017. return new Request(
  1018. 'POST',
  1019. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1020. $headers,
  1021. $httpBody
  1022. );
  1023. }
  1024. /**
  1025. * Create http client option
  1026. *
  1027. * @throws \RuntimeException on file opening failure
  1028. * @return array of http client options
  1029. */
  1030. protected function createHttpClientOption()
  1031. {
  1032. $options = [];
  1033. if ($this->config->getDebug()) {
  1034. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  1035. if (!$options[RequestOptions::DEBUG]) {
  1036. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  1037. }
  1038. }
  1039. if ($this->config->getCertFile()) {
  1040. $options[RequestOptions::CERT] = $this->config->getCertFile();
  1041. }
  1042. if ($this->config->getKeyFile()) {
  1043. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  1044. }
  1045. return $options;
  1046. }
  1047. private function handleResponseWithDataType(
  1048. string $dataType,
  1049. RequestInterface $request,
  1050. ResponseInterface $response
  1051. ): array {
  1052. if ($dataType === '\SplFileObject') {
  1053. $content = $response->getBody(); //stream goes to serializer
  1054. } else {
  1055. $content = (string) $response->getBody();
  1056. if ($dataType !== 'string') {
  1057. try {
  1058. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  1059. } catch (\JsonException $exception) {
  1060. throw new ApiException(
  1061. sprintf(
  1062. 'Error JSON decoding server response (%s)',
  1063. $request->getUri()
  1064. ),
  1065. $response->getStatusCode(),
  1066. $response->getHeaders(),
  1067. $content
  1068. );
  1069. }
  1070. }
  1071. }
  1072. return [
  1073. ObjectSerializer::deserialize($content, $dataType, []),
  1074. $response->getStatusCode(),
  1075. $response->getHeaders()
  1076. ];
  1077. }
  1078. private function responseWithinRangeCode(
  1079. string $rangeCode,
  1080. int $statusCode
  1081. ): bool {
  1082. $left = (int) ($rangeCode[0].'00');
  1083. $right = (int) ($rangeCode[0].'99');
  1084. return $statusCode >= $left && $statusCode <= $right;
  1085. }
  1086. }