SearchApi.php 54 KB

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