TipitakaRelatedParagraphsApi.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. <?php
  2. /**
  3. * TipitakaRelatedParagraphsApi
  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.10.15
  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. * TipitakaRelatedParagraphsApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class TipitakaRelatedParagraphsApi
  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. 'getApiV3TipitakaRelatedParagraphs' => [
  69. 'application/json',
  70. ],
  71. 'getApiV3TipitakaRelatedParagraphsAggregate' => [
  72. 'application/json',
  73. ],
  74. 'getApiV3TipitakaRelatedParagraphsAggregateBookName' => [
  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 getApiV3TipitakaRelatedParagraphs
  122. *
  123. * 列出一个段落的关联段落
  124. *
  125. * @param int|null $book 典籍文件号(1-217)。与 para 一起用,prohibits 下面那组 (optional)
  126. * @param int|null $para 段落号。与 book 一起用 (optional)
  127. * @param string|null $book_name SC 风格书名缩写(如 dn1、an2)。与 cs_para 一起用,prohibits 上面那组 (optional)
  128. * @param int|null $cs_para 书内段落号。与 book_name 一起用 (optional)
  129. * @param int|null $book_id 真书号(book_titles.sn),可选收窄 (optional)
  130. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphs'] to see the possible values for this operation
  131. *
  132. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  133. * @throws \InvalidArgumentException
  134. * @return \WikipaliApi\Model\GetApiV3TipitakaRelatedParagraphs200Response|\WikipaliApi\Model\ProblemDetails
  135. */
  136. public function getApiV3TipitakaRelatedParagraphs($book = null, $para = null, $book_name = null, $cs_para = null, $book_id = null, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphs'][0])
  137. {
  138. list($response) = $this->getApiV3TipitakaRelatedParagraphsWithHttpInfo($book, $para, $book_name, $cs_para, $book_id, $contentType);
  139. return $response;
  140. }
  141. /**
  142. * Operation getApiV3TipitakaRelatedParagraphsWithHttpInfo
  143. *
  144. * 列出一个段落的关联段落
  145. *
  146. * @param int|null $book 典籍文件号(1-217)。与 para 一起用,prohibits 下面那组 (optional)
  147. * @param int|null $para 段落号。与 book 一起用 (optional)
  148. * @param string|null $book_name SC 风格书名缩写(如 dn1、an2)。与 cs_para 一起用,prohibits 上面那组 (optional)
  149. * @param int|null $cs_para 书内段落号。与 book_name 一起用 (optional)
  150. * @param int|null $book_id 真书号(book_titles.sn),可选收窄 (optional)
  151. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphs'] 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\GetApiV3TipitakaRelatedParagraphs200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  156. */
  157. public function getApiV3TipitakaRelatedParagraphsWithHttpInfo($book = null, $para = null, $book_name = null, $cs_para = null, $book_id = null, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphs'][0])
  158. {
  159. $request = $this->getApiV3TipitakaRelatedParagraphsRequest($book, $para, $book_name, $cs_para, $book_id, $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\GetApiV3TipitakaRelatedParagraphs200Response',
  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\GetApiV3TipitakaRelatedParagraphs200Response',
  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\GetApiV3TipitakaRelatedParagraphs200Response',
  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 getApiV3TipitakaRelatedParagraphsAsync
  235. *
  236. * 列出一个段落的关联段落
  237. *
  238. * @param int|null $book 典籍文件号(1-217)。与 para 一起用,prohibits 下面那组 (optional)
  239. * @param int|null $para 段落号。与 book 一起用 (optional)
  240. * @param string|null $book_name SC 风格书名缩写(如 dn1、an2)。与 cs_para 一起用,prohibits 上面那组 (optional)
  241. * @param int|null $cs_para 书内段落号。与 book_name 一起用 (optional)
  242. * @param int|null $book_id 真书号(book_titles.sn),可选收窄 (optional)
  243. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphs'] to see the possible values for this operation
  244. *
  245. * @throws \InvalidArgumentException
  246. * @return \GuzzleHttp\Promise\PromiseInterface
  247. */
  248. public function getApiV3TipitakaRelatedParagraphsAsync($book = null, $para = null, $book_name = null, $cs_para = null, $book_id = null, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphs'][0])
  249. {
  250. return $this->getApiV3TipitakaRelatedParagraphsAsyncWithHttpInfo($book, $para, $book_name, $cs_para, $book_id, $contentType)
  251. ->then(
  252. function ($response) {
  253. return $response[0];
  254. }
  255. );
  256. }
  257. /**
  258. * Operation getApiV3TipitakaRelatedParagraphsAsyncWithHttpInfo
  259. *
  260. * 列出一个段落的关联段落
  261. *
  262. * @param int|null $book 典籍文件号(1-217)。与 para 一起用,prohibits 下面那组 (optional)
  263. * @param int|null $para 段落号。与 book 一起用 (optional)
  264. * @param string|null $book_name SC 风格书名缩写(如 dn1、an2)。与 cs_para 一起用,prohibits 上面那组 (optional)
  265. * @param int|null $cs_para 书内段落号。与 book_name 一起用 (optional)
  266. * @param int|null $book_id 真书号(book_titles.sn),可选收窄 (optional)
  267. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphs'] to see the possible values for this operation
  268. *
  269. * @throws \InvalidArgumentException
  270. * @return \GuzzleHttp\Promise\PromiseInterface
  271. */
  272. public function getApiV3TipitakaRelatedParagraphsAsyncWithHttpInfo($book = null, $para = null, $book_name = null, $cs_para = null, $book_id = null, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphs'][0])
  273. {
  274. $returnType = '\WikipaliApi\Model\GetApiV3TipitakaRelatedParagraphs200Response';
  275. $request = $this->getApiV3TipitakaRelatedParagraphsRequest($book, $para, $book_name, $cs_para, $book_id, $contentType);
  276. return $this->client
  277. ->sendAsync($request, $this->createHttpClientOption())
  278. ->then(
  279. function ($response) use ($returnType) {
  280. if ($returnType === '\SplFileObject') {
  281. $content = $response->getBody(); //stream goes to serializer
  282. } else {
  283. $content = (string) $response->getBody();
  284. if ($returnType !== 'string') {
  285. $content = json_decode($content);
  286. }
  287. }
  288. return [
  289. ObjectSerializer::deserialize($content, $returnType, []),
  290. $response->getStatusCode(),
  291. $response->getHeaders()
  292. ];
  293. },
  294. function ($exception) {
  295. $response = $exception->getResponse();
  296. $statusCode = $response->getStatusCode();
  297. throw new ApiException(
  298. sprintf(
  299. '[%d] Error connecting to the API (%s)',
  300. $statusCode,
  301. $exception->getRequest()->getUri()
  302. ),
  303. $statusCode,
  304. $response->getHeaders(),
  305. (string) $response->getBody()
  306. );
  307. }
  308. );
  309. }
  310. /**
  311. * Create request for operation 'getApiV3TipitakaRelatedParagraphs'
  312. *
  313. * @param int|null $book 典籍文件号(1-217)。与 para 一起用,prohibits 下面那组 (optional)
  314. * @param int|null $para 段落号。与 book 一起用 (optional)
  315. * @param string|null $book_name SC 风格书名缩写(如 dn1、an2)。与 cs_para 一起用,prohibits 上面那组 (optional)
  316. * @param int|null $cs_para 书内段落号。与 book_name 一起用 (optional)
  317. * @param int|null $book_id 真书号(book_titles.sn),可选收窄 (optional)
  318. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphs'] to see the possible values for this operation
  319. *
  320. * @throws \InvalidArgumentException
  321. * @return \GuzzleHttp\Psr7\Request
  322. */
  323. public function getApiV3TipitakaRelatedParagraphsRequest($book = null, $para = null, $book_name = null, $cs_para = null, $book_id = null, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphs'][0])
  324. {
  325. $resourcePath = '/v3/tipitaka-related-paragraphs';
  326. $formParams = [];
  327. $queryParams = [];
  328. $headerParams = [];
  329. $httpBody = '';
  330. $multipart = false;
  331. // query params
  332. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  333. $book,
  334. 'book', // param base name
  335. 'integer', // openApiType
  336. 'form', // style
  337. true, // explode
  338. false // required
  339. ) ?? []);
  340. // query params
  341. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  342. $para,
  343. 'para', // param base name
  344. 'integer', // openApiType
  345. 'form', // style
  346. true, // explode
  347. false // required
  348. ) ?? []);
  349. // query params
  350. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  351. $book_name,
  352. 'book_name', // param base name
  353. 'string', // openApiType
  354. 'form', // style
  355. true, // explode
  356. false // required
  357. ) ?? []);
  358. // query params
  359. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  360. $cs_para,
  361. 'cs_para', // param base name
  362. 'integer', // openApiType
  363. 'form', // style
  364. true, // explode
  365. false // required
  366. ) ?? []);
  367. // query params
  368. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  369. $book_id,
  370. 'book_id', // param base name
  371. 'integer', // openApiType
  372. 'form', // style
  373. true, // explode
  374. false // required
  375. ) ?? []);
  376. $headers = $this->headerSelector->selectHeaders(
  377. ['application/json', 'application/problem+json', ],
  378. $contentType,
  379. $multipart
  380. );
  381. // for model (json/xml)
  382. if (count($formParams) > 0) {
  383. if ($multipart) {
  384. $multipartContents = [];
  385. foreach ($formParams as $formParamName => $formParamValue) {
  386. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  387. foreach ($formParamValueItems as $formParamValueItem) {
  388. $multipartContents[] = [
  389. 'name' => $formParamName,
  390. 'contents' => $formParamValueItem
  391. ];
  392. }
  393. }
  394. // for HTTP post (form)
  395. $httpBody = new MultipartStream($multipartContents);
  396. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  397. # if Content-Type contains "application/json", json_encode the form parameters
  398. try {
  399. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  400. } catch (\JsonException $e) {
  401. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  402. }
  403. } else {
  404. // for HTTP post (form)
  405. $httpBody = ObjectSerializer::buildQuery($formParams);
  406. }
  407. }
  408. // this endpoint requires Bearer authentication (access token)
  409. if (!empty($this->config->getAccessToken())) {
  410. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  411. }
  412. $defaultHeaders = [];
  413. if ($this->config->getUserAgent()) {
  414. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  415. }
  416. $headers = array_merge(
  417. $defaultHeaders,
  418. $headerParams,
  419. $headers
  420. );
  421. $operationHost = $this->config->getHost();
  422. $query = ObjectSerializer::buildQuery($queryParams);
  423. return new Request(
  424. 'GET',
  425. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  426. $headers,
  427. $httpBody
  428. );
  429. }
  430. /**
  431. * Operation getApiV3TipitakaRelatedParagraphsAggregate
  432. *
  433. * 列出所有 SC 缩写
  434. *
  435. * @param int|null $file 典籍文件号过滤(对应表里的 book 列) (optional)
  436. * @param int|null $book 真书号过滤(对应表里的 book_id 列) (optional)
  437. * @param int|null $page 页码 (optional, default to 1)
  438. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  439. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregate'] to see the possible values for this operation
  440. *
  441. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  442. * @throws \InvalidArgumentException
  443. * @return \WikipaliApi\Model\GetApiV3TipitakaRelatedParagraphsAggregate200Response|\WikipaliApi\Model\ProblemDetails
  444. */
  445. public function getApiV3TipitakaRelatedParagraphsAggregate($file = null, $book = null, $page = 1, $per_page = 15, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregate'][0])
  446. {
  447. list($response) = $this->getApiV3TipitakaRelatedParagraphsAggregateWithHttpInfo($file, $book, $page, $per_page, $contentType);
  448. return $response;
  449. }
  450. /**
  451. * Operation getApiV3TipitakaRelatedParagraphsAggregateWithHttpInfo
  452. *
  453. * 列出所有 SC 缩写
  454. *
  455. * @param int|null $file 典籍文件号过滤(对应表里的 book 列) (optional)
  456. * @param int|null $book 真书号过滤(对应表里的 book_id 列) (optional)
  457. * @param int|null $page 页码 (optional, default to 1)
  458. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  459. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregate'] to see the possible values for this operation
  460. *
  461. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  462. * @throws \InvalidArgumentException
  463. * @return array of \WikipaliApi\Model\GetApiV3TipitakaRelatedParagraphsAggregate200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  464. */
  465. public function getApiV3TipitakaRelatedParagraphsAggregateWithHttpInfo($file = null, $book = null, $page = 1, $per_page = 15, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregate'][0])
  466. {
  467. $request = $this->getApiV3TipitakaRelatedParagraphsAggregateRequest($file, $book, $page, $per_page, $contentType);
  468. try {
  469. $options = $this->createHttpClientOption();
  470. try {
  471. $response = $this->client->send($request, $options);
  472. } catch (RequestException $e) {
  473. throw new ApiException(
  474. "[{$e->getCode()}] {$e->getMessage()}",
  475. (int) $e->getCode(),
  476. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  477. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  478. );
  479. } catch (ConnectException $e) {
  480. throw new ApiException(
  481. "[{$e->getCode()}] {$e->getMessage()}",
  482. (int) $e->getCode(),
  483. null,
  484. null
  485. );
  486. }
  487. $statusCode = $response->getStatusCode();
  488. switch($statusCode) {
  489. case 200:
  490. return $this->handleResponseWithDataType(
  491. '\WikipaliApi\Model\GetApiV3TipitakaRelatedParagraphsAggregate200Response',
  492. $request,
  493. $response,
  494. );
  495. case 422:
  496. return $this->handleResponseWithDataType(
  497. '\WikipaliApi\Model\ProblemDetails',
  498. $request,
  499. $response,
  500. );
  501. }
  502. if ($statusCode < 200 || $statusCode > 299) {
  503. throw new ApiException(
  504. sprintf(
  505. '[%d] Error connecting to the API (%s)',
  506. $statusCode,
  507. (string) $request->getUri()
  508. ),
  509. $statusCode,
  510. $response->getHeaders(),
  511. (string) $response->getBody()
  512. );
  513. }
  514. return $this->handleResponseWithDataType(
  515. '\WikipaliApi\Model\GetApiV3TipitakaRelatedParagraphsAggregate200Response',
  516. $request,
  517. $response,
  518. );
  519. } catch (ApiException $e) {
  520. switch ($e->getCode()) {
  521. case 200:
  522. $data = ObjectSerializer::deserialize(
  523. $e->getResponseBody(),
  524. '\WikipaliApi\Model\GetApiV3TipitakaRelatedParagraphsAggregate200Response',
  525. $e->getResponseHeaders()
  526. );
  527. $e->setResponseObject($data);
  528. throw $e;
  529. case 422:
  530. $data = ObjectSerializer::deserialize(
  531. $e->getResponseBody(),
  532. '\WikipaliApi\Model\ProblemDetails',
  533. $e->getResponseHeaders()
  534. );
  535. $e->setResponseObject($data);
  536. throw $e;
  537. }
  538. throw $e;
  539. }
  540. }
  541. /**
  542. * Operation getApiV3TipitakaRelatedParagraphsAggregateAsync
  543. *
  544. * 列出所有 SC 缩写
  545. *
  546. * @param int|null $file 典籍文件号过滤(对应表里的 book 列) (optional)
  547. * @param int|null $book 真书号过滤(对应表里的 book_id 列) (optional)
  548. * @param int|null $page 页码 (optional, default to 1)
  549. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  550. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregate'] to see the possible values for this operation
  551. *
  552. * @throws \InvalidArgumentException
  553. * @return \GuzzleHttp\Promise\PromiseInterface
  554. */
  555. public function getApiV3TipitakaRelatedParagraphsAggregateAsync($file = null, $book = null, $page = 1, $per_page = 15, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregate'][0])
  556. {
  557. return $this->getApiV3TipitakaRelatedParagraphsAggregateAsyncWithHttpInfo($file, $book, $page, $per_page, $contentType)
  558. ->then(
  559. function ($response) {
  560. return $response[0];
  561. }
  562. );
  563. }
  564. /**
  565. * Operation getApiV3TipitakaRelatedParagraphsAggregateAsyncWithHttpInfo
  566. *
  567. * 列出所有 SC 缩写
  568. *
  569. * @param int|null $file 典籍文件号过滤(对应表里的 book 列) (optional)
  570. * @param int|null $book 真书号过滤(对应表里的 book_id 列) (optional)
  571. * @param int|null $page 页码 (optional, default to 1)
  572. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  573. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregate'] to see the possible values for this operation
  574. *
  575. * @throws \InvalidArgumentException
  576. * @return \GuzzleHttp\Promise\PromiseInterface
  577. */
  578. public function getApiV3TipitakaRelatedParagraphsAggregateAsyncWithHttpInfo($file = null, $book = null, $page = 1, $per_page = 15, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregate'][0])
  579. {
  580. $returnType = '\WikipaliApi\Model\GetApiV3TipitakaRelatedParagraphsAggregate200Response';
  581. $request = $this->getApiV3TipitakaRelatedParagraphsAggregateRequest($file, $book, $page, $per_page, $contentType);
  582. return $this->client
  583. ->sendAsync($request, $this->createHttpClientOption())
  584. ->then(
  585. function ($response) use ($returnType) {
  586. if ($returnType === '\SplFileObject') {
  587. $content = $response->getBody(); //stream goes to serializer
  588. } else {
  589. $content = (string) $response->getBody();
  590. if ($returnType !== 'string') {
  591. $content = json_decode($content);
  592. }
  593. }
  594. return [
  595. ObjectSerializer::deserialize($content, $returnType, []),
  596. $response->getStatusCode(),
  597. $response->getHeaders()
  598. ];
  599. },
  600. function ($exception) {
  601. $response = $exception->getResponse();
  602. $statusCode = $response->getStatusCode();
  603. throw new ApiException(
  604. sprintf(
  605. '[%d] Error connecting to the API (%s)',
  606. $statusCode,
  607. $exception->getRequest()->getUri()
  608. ),
  609. $statusCode,
  610. $response->getHeaders(),
  611. (string) $response->getBody()
  612. );
  613. }
  614. );
  615. }
  616. /**
  617. * Create request for operation 'getApiV3TipitakaRelatedParagraphsAggregate'
  618. *
  619. * @param int|null $file 典籍文件号过滤(对应表里的 book 列) (optional)
  620. * @param int|null $book 真书号过滤(对应表里的 book_id 列) (optional)
  621. * @param int|null $page 页码 (optional, default to 1)
  622. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  623. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregate'] to see the possible values for this operation
  624. *
  625. * @throws \InvalidArgumentException
  626. * @return \GuzzleHttp\Psr7\Request
  627. */
  628. public function getApiV3TipitakaRelatedParagraphsAggregateRequest($file = null, $book = null, $page = 1, $per_page = 15, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregate'][0])
  629. {
  630. $resourcePath = '/v3/tipitaka-related-paragraphs/aggregate';
  631. $formParams = [];
  632. $queryParams = [];
  633. $headerParams = [];
  634. $httpBody = '';
  635. $multipart = false;
  636. // query params
  637. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  638. $file,
  639. 'file', // param base name
  640. 'integer', // openApiType
  641. 'form', // style
  642. true, // explode
  643. false // required
  644. ) ?? []);
  645. // query params
  646. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  647. $book,
  648. 'book', // param base name
  649. 'integer', // openApiType
  650. 'form', // style
  651. true, // explode
  652. false // required
  653. ) ?? []);
  654. // query params
  655. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  656. $page,
  657. 'page', // param base name
  658. 'integer', // openApiType
  659. 'form', // style
  660. true, // explode
  661. false // required
  662. ) ?? []);
  663. // query params
  664. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  665. $per_page,
  666. 'per_page', // param base name
  667. 'integer', // openApiType
  668. 'form', // style
  669. true, // explode
  670. false // required
  671. ) ?? []);
  672. $headers = $this->headerSelector->selectHeaders(
  673. ['application/json', 'application/problem+json', ],
  674. $contentType,
  675. $multipart
  676. );
  677. // for model (json/xml)
  678. if (count($formParams) > 0) {
  679. if ($multipart) {
  680. $multipartContents = [];
  681. foreach ($formParams as $formParamName => $formParamValue) {
  682. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  683. foreach ($formParamValueItems as $formParamValueItem) {
  684. $multipartContents[] = [
  685. 'name' => $formParamName,
  686. 'contents' => $formParamValueItem
  687. ];
  688. }
  689. }
  690. // for HTTP post (form)
  691. $httpBody = new MultipartStream($multipartContents);
  692. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  693. # if Content-Type contains "application/json", json_encode the form parameters
  694. try {
  695. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  696. } catch (\JsonException $e) {
  697. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  698. }
  699. } else {
  700. // for HTTP post (form)
  701. $httpBody = ObjectSerializer::buildQuery($formParams);
  702. }
  703. }
  704. // this endpoint requires Bearer authentication (access token)
  705. if (!empty($this->config->getAccessToken())) {
  706. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  707. }
  708. $defaultHeaders = [];
  709. if ($this->config->getUserAgent()) {
  710. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  711. }
  712. $headers = array_merge(
  713. $defaultHeaders,
  714. $headerParams,
  715. $headers
  716. );
  717. $operationHost = $this->config->getHost();
  718. $query = ObjectSerializer::buildQuery($queryParams);
  719. return new Request(
  720. 'GET',
  721. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  722. $headers,
  723. $httpBody
  724. );
  725. }
  726. /**
  727. * Operation getApiV3TipitakaRelatedParagraphsAggregateBookName
  728. *
  729. * 列出某个 SC 缩写下的 cs_para
  730. *
  731. * @param string $book_name SC 风格书名缩写(如 dn1、an2) (required)
  732. * @param int|null $file 典籍文件号过滤(对应表里的 book 列) (optional)
  733. * @param int|null $book 真书号过滤(对应表里的 book_id 列) (optional)
  734. * @param int|null $page 页码 (optional, default to 1)
  735. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  736. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregateBookName'] to see the possible values for this operation
  737. *
  738. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  739. * @throws \InvalidArgumentException
  740. * @return \WikipaliApi\Model\GetApiV3TipitakaRelatedParagraphsAggregateBookName200Response|\WikipaliApi\Model\ProblemDetails
  741. */
  742. public function getApiV3TipitakaRelatedParagraphsAggregateBookName($book_name, $file = null, $book = null, $page = 1, $per_page = 15, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregateBookName'][0])
  743. {
  744. list($response) = $this->getApiV3TipitakaRelatedParagraphsAggregateBookNameWithHttpInfo($book_name, $file, $book, $page, $per_page, $contentType);
  745. return $response;
  746. }
  747. /**
  748. * Operation getApiV3TipitakaRelatedParagraphsAggregateBookNameWithHttpInfo
  749. *
  750. * 列出某个 SC 缩写下的 cs_para
  751. *
  752. * @param string $book_name SC 风格书名缩写(如 dn1、an2) (required)
  753. * @param int|null $file 典籍文件号过滤(对应表里的 book 列) (optional)
  754. * @param int|null $book 真书号过滤(对应表里的 book_id 列) (optional)
  755. * @param int|null $page 页码 (optional, default to 1)
  756. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  757. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregateBookName'] 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\GetApiV3TipitakaRelatedParagraphsAggregateBookName200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  762. */
  763. public function getApiV3TipitakaRelatedParagraphsAggregateBookNameWithHttpInfo($book_name, $file = null, $book = null, $page = 1, $per_page = 15, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregateBookName'][0])
  764. {
  765. $request = $this->getApiV3TipitakaRelatedParagraphsAggregateBookNameRequest($book_name, $file, $book, $page, $per_page, $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\GetApiV3TipitakaRelatedParagraphsAggregateBookName200Response',
  790. $request,
  791. $response,
  792. );
  793. case 422:
  794. return $this->handleResponseWithDataType(
  795. '\WikipaliApi\Model\ProblemDetails',
  796. $request,
  797. $response,
  798. );
  799. }
  800. if ($statusCode < 200 || $statusCode > 299) {
  801. throw new ApiException(
  802. sprintf(
  803. '[%d] Error connecting to the API (%s)',
  804. $statusCode,
  805. (string) $request->getUri()
  806. ),
  807. $statusCode,
  808. $response->getHeaders(),
  809. (string) $response->getBody()
  810. );
  811. }
  812. return $this->handleResponseWithDataType(
  813. '\WikipaliApi\Model\GetApiV3TipitakaRelatedParagraphsAggregateBookName200Response',
  814. $request,
  815. $response,
  816. );
  817. } catch (ApiException $e) {
  818. switch ($e->getCode()) {
  819. case 200:
  820. $data = ObjectSerializer::deserialize(
  821. $e->getResponseBody(),
  822. '\WikipaliApi\Model\GetApiV3TipitakaRelatedParagraphsAggregateBookName200Response',
  823. $e->getResponseHeaders()
  824. );
  825. $e->setResponseObject($data);
  826. throw $e;
  827. case 422:
  828. $data = ObjectSerializer::deserialize(
  829. $e->getResponseBody(),
  830. '\WikipaliApi\Model\ProblemDetails',
  831. $e->getResponseHeaders()
  832. );
  833. $e->setResponseObject($data);
  834. throw $e;
  835. }
  836. throw $e;
  837. }
  838. }
  839. /**
  840. * Operation getApiV3TipitakaRelatedParagraphsAggregateBookNameAsync
  841. *
  842. * 列出某个 SC 缩写下的 cs_para
  843. *
  844. * @param string $book_name SC 风格书名缩写(如 dn1、an2) (required)
  845. * @param int|null $file 典籍文件号过滤(对应表里的 book 列) (optional)
  846. * @param int|null $book 真书号过滤(对应表里的 book_id 列) (optional)
  847. * @param int|null $page 页码 (optional, default to 1)
  848. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  849. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregateBookName'] to see the possible values for this operation
  850. *
  851. * @throws \InvalidArgumentException
  852. * @return \GuzzleHttp\Promise\PromiseInterface
  853. */
  854. public function getApiV3TipitakaRelatedParagraphsAggregateBookNameAsync($book_name, $file = null, $book = null, $page = 1, $per_page = 15, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregateBookName'][0])
  855. {
  856. return $this->getApiV3TipitakaRelatedParagraphsAggregateBookNameAsyncWithHttpInfo($book_name, $file, $book, $page, $per_page, $contentType)
  857. ->then(
  858. function ($response) {
  859. return $response[0];
  860. }
  861. );
  862. }
  863. /**
  864. * Operation getApiV3TipitakaRelatedParagraphsAggregateBookNameAsyncWithHttpInfo
  865. *
  866. * 列出某个 SC 缩写下的 cs_para
  867. *
  868. * @param string $book_name SC 风格书名缩写(如 dn1、an2) (required)
  869. * @param int|null $file 典籍文件号过滤(对应表里的 book 列) (optional)
  870. * @param int|null $book 真书号过滤(对应表里的 book_id 列) (optional)
  871. * @param int|null $page 页码 (optional, default to 1)
  872. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  873. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregateBookName'] to see the possible values for this operation
  874. *
  875. * @throws \InvalidArgumentException
  876. * @return \GuzzleHttp\Promise\PromiseInterface
  877. */
  878. public function getApiV3TipitakaRelatedParagraphsAggregateBookNameAsyncWithHttpInfo($book_name, $file = null, $book = null, $page = 1, $per_page = 15, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregateBookName'][0])
  879. {
  880. $returnType = '\WikipaliApi\Model\GetApiV3TipitakaRelatedParagraphsAggregateBookName200Response';
  881. $request = $this->getApiV3TipitakaRelatedParagraphsAggregateBookNameRequest($book_name, $file, $book, $page, $per_page, $contentType);
  882. return $this->client
  883. ->sendAsync($request, $this->createHttpClientOption())
  884. ->then(
  885. function ($response) use ($returnType) {
  886. if ($returnType === '\SplFileObject') {
  887. $content = $response->getBody(); //stream goes to serializer
  888. } else {
  889. $content = (string) $response->getBody();
  890. if ($returnType !== 'string') {
  891. $content = json_decode($content);
  892. }
  893. }
  894. return [
  895. ObjectSerializer::deserialize($content, $returnType, []),
  896. $response->getStatusCode(),
  897. $response->getHeaders()
  898. ];
  899. },
  900. function ($exception) {
  901. $response = $exception->getResponse();
  902. $statusCode = $response->getStatusCode();
  903. throw new ApiException(
  904. sprintf(
  905. '[%d] Error connecting to the API (%s)',
  906. $statusCode,
  907. $exception->getRequest()->getUri()
  908. ),
  909. $statusCode,
  910. $response->getHeaders(),
  911. (string) $response->getBody()
  912. );
  913. }
  914. );
  915. }
  916. /**
  917. * Create request for operation 'getApiV3TipitakaRelatedParagraphsAggregateBookName'
  918. *
  919. * @param string $book_name SC 风格书名缩写(如 dn1、an2) (required)
  920. * @param int|null $file 典籍文件号过滤(对应表里的 book 列) (optional)
  921. * @param int|null $book 真书号过滤(对应表里的 book_id 列) (optional)
  922. * @param int|null $page 页码 (optional, default to 1)
  923. * @param int|null $per_page 每页数量,最大 200 (optional, default to 15)
  924. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregateBookName'] to see the possible values for this operation
  925. *
  926. * @throws \InvalidArgumentException
  927. * @return \GuzzleHttp\Psr7\Request
  928. */
  929. public function getApiV3TipitakaRelatedParagraphsAggregateBookNameRequest($book_name, $file = null, $book = null, $page = 1, $per_page = 15, string $contentType = self::contentTypes['getApiV3TipitakaRelatedParagraphsAggregateBookName'][0])
  930. {
  931. // verify the required parameter 'book_name' is set
  932. if ($book_name === null || (is_array($book_name) && count($book_name) === 0)) {
  933. throw new \InvalidArgumentException(
  934. 'Missing the required parameter $book_name when calling getApiV3TipitakaRelatedParagraphsAggregateBookName'
  935. );
  936. }
  937. $resourcePath = '/v3/tipitaka-related-paragraphs/aggregate/{book_name}';
  938. $formParams = [];
  939. $queryParams = [];
  940. $headerParams = [];
  941. $httpBody = '';
  942. $multipart = false;
  943. // query params
  944. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  945. $file,
  946. 'file', // param base name
  947. 'integer', // openApiType
  948. 'form', // style
  949. true, // explode
  950. false // required
  951. ) ?? []);
  952. // query params
  953. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  954. $book,
  955. 'book', // param base name
  956. 'integer', // openApiType
  957. 'form', // style
  958. true, // explode
  959. false // required
  960. ) ?? []);
  961. // query params
  962. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  963. $page,
  964. 'page', // param base name
  965. 'integer', // openApiType
  966. 'form', // style
  967. true, // explode
  968. false // required
  969. ) ?? []);
  970. // query params
  971. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  972. $per_page,
  973. 'per_page', // param base name
  974. 'integer', // openApiType
  975. 'form', // style
  976. true, // explode
  977. false // required
  978. ) ?? []);
  979. // path params
  980. if ($book_name !== null) {
  981. $resourcePath = str_replace(
  982. '{book_name}',
  983. ObjectSerializer::toPathValue($book_name),
  984. $resourcePath
  985. );
  986. }
  987. $headers = $this->headerSelector->selectHeaders(
  988. ['application/json', 'application/problem+json', ],
  989. $contentType,
  990. $multipart
  991. );
  992. // for model (json/xml)
  993. if (count($formParams) > 0) {
  994. if ($multipart) {
  995. $multipartContents = [];
  996. foreach ($formParams as $formParamName => $formParamValue) {
  997. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  998. foreach ($formParamValueItems as $formParamValueItem) {
  999. $multipartContents[] = [
  1000. 'name' => $formParamName,
  1001. 'contents' => $formParamValueItem
  1002. ];
  1003. }
  1004. }
  1005. // for HTTP post (form)
  1006. $httpBody = new MultipartStream($multipartContents);
  1007. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1008. # if Content-Type contains "application/json", json_encode the form parameters
  1009. try {
  1010. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1011. } catch (\JsonException $e) {
  1012. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1013. }
  1014. } else {
  1015. // for HTTP post (form)
  1016. $httpBody = ObjectSerializer::buildQuery($formParams);
  1017. }
  1018. }
  1019. // this endpoint requires Bearer authentication (access token)
  1020. if (!empty($this->config->getAccessToken())) {
  1021. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1022. }
  1023. $defaultHeaders = [];
  1024. if ($this->config->getUserAgent()) {
  1025. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1026. }
  1027. $headers = array_merge(
  1028. $defaultHeaders,
  1029. $headerParams,
  1030. $headers
  1031. );
  1032. $operationHost = $this->config->getHost();
  1033. $query = ObjectSerializer::buildQuery($queryParams);
  1034. return new Request(
  1035. 'GET',
  1036. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1037. $headers,
  1038. $httpBody
  1039. );
  1040. }
  1041. /**
  1042. * Create http client option
  1043. *
  1044. * @throws \RuntimeException on file opening failure
  1045. * @return array of http client options
  1046. */
  1047. protected function createHttpClientOption()
  1048. {
  1049. $options = [];
  1050. if ($this->config->getDebug()) {
  1051. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  1052. if (!$options[RequestOptions::DEBUG]) {
  1053. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  1054. }
  1055. }
  1056. if ($this->config->getCertFile()) {
  1057. $options[RequestOptions::CERT] = $this->config->getCertFile();
  1058. }
  1059. if ($this->config->getKeyFile()) {
  1060. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  1061. }
  1062. return $options;
  1063. }
  1064. private function handleResponseWithDataType(
  1065. string $dataType,
  1066. RequestInterface $request,
  1067. ResponseInterface $response
  1068. ): array {
  1069. if ($dataType === '\SplFileObject') {
  1070. $content = $response->getBody(); //stream goes to serializer
  1071. } else {
  1072. $content = (string) $response->getBody();
  1073. if ($dataType !== 'string') {
  1074. try {
  1075. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  1076. } catch (\JsonException $exception) {
  1077. throw new ApiException(
  1078. sprintf(
  1079. 'Error JSON decoding server response (%s)',
  1080. $request->getUri()
  1081. ),
  1082. $response->getStatusCode(),
  1083. $response->getHeaders(),
  1084. $content
  1085. );
  1086. }
  1087. }
  1088. }
  1089. return [
  1090. ObjectSerializer::deserialize($content, $dataType, []),
  1091. $response->getStatusCode(),
  1092. $response->getHeaders()
  1093. ];
  1094. }
  1095. private function responseWithinRangeCode(
  1096. string $rangeCode,
  1097. int $statusCode
  1098. ): bool {
  1099. $left = (int) ($rangeCode[0].'00');
  1100. $right = (int) ($rangeCode[0].'99');
  1101. return $statusCode >= $left && $statusCode <= $right;
  1102. }
  1103. }