SearchApi.php 50 KB

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