AgentFeedbackApi.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. <?php
  2. /**
  3. * AgentFeedbackApi
  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. * AgentFeedbackApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class AgentFeedbackApi
  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. 'deleteApiV3AgentFeedbackMessage' => [
  69. 'application/json',
  70. ],
  71. 'postApiV3AgentFeedback' => [
  72. 'application/json',
  73. ],
  74. ];
  75. /**
  76. * @param ClientInterface $client
  77. * @param Configuration $config
  78. * @param HeaderSelector $selector
  79. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  80. */
  81. public function __construct(
  82. ?ClientInterface $client = null,
  83. ?Configuration $config = null,
  84. ?HeaderSelector $selector = null,
  85. int $hostIndex = 0
  86. ) {
  87. $this->client = $client ?: new Client();
  88. $this->config = $config ?: Configuration::getDefaultConfiguration();
  89. $this->headerSelector = $selector ?: new HeaderSelector();
  90. $this->hostIndex = $hostIndex;
  91. }
  92. /**
  93. * Set the host index
  94. *
  95. * @param int $hostIndex Host index (required)
  96. */
  97. public function setHostIndex($hostIndex): void
  98. {
  99. $this->hostIndex = $hostIndex;
  100. }
  101. /**
  102. * Get the host index
  103. *
  104. * @return int Host index
  105. */
  106. public function getHostIndex()
  107. {
  108. return $this->hostIndex;
  109. }
  110. /**
  111. * @return Configuration
  112. */
  113. public function getConfig()
  114. {
  115. return $this->config;
  116. }
  117. /**
  118. * Operation deleteApiV3AgentFeedbackMessage
  119. *
  120. * 撤回评价
  121. *
  122. * @param string $message AG-UI 回答消息 id (required)
  123. * @param string|null $device_id 设备匿名 id(uuid)。未登录时必填 (optional)
  124. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3AgentFeedbackMessage'] to see the possible values for this operation
  125. *
  126. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  127. * @throws \InvalidArgumentException
  128. * @return void
  129. */
  130. public function deleteApiV3AgentFeedbackMessage($message, $device_id = null, string $contentType = self::contentTypes['deleteApiV3AgentFeedbackMessage'][0])
  131. {
  132. $this->deleteApiV3AgentFeedbackMessageWithHttpInfo($message, $device_id, $contentType);
  133. }
  134. /**
  135. * Operation deleteApiV3AgentFeedbackMessageWithHttpInfo
  136. *
  137. * 撤回评价
  138. *
  139. * @param string $message AG-UI 回答消息 id (required)
  140. * @param string|null $device_id 设备匿名 id(uuid)。未登录时必填 (optional)
  141. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3AgentFeedbackMessage'] to see the possible values for this operation
  142. *
  143. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  144. * @throws \InvalidArgumentException
  145. * @return array of null, HTTP status code, HTTP response headers (array of strings)
  146. */
  147. public function deleteApiV3AgentFeedbackMessageWithHttpInfo($message, $device_id = null, string $contentType = self::contentTypes['deleteApiV3AgentFeedbackMessage'][0])
  148. {
  149. $request = $this->deleteApiV3AgentFeedbackMessageRequest($message, $device_id, $contentType);
  150. try {
  151. $options = $this->createHttpClientOption();
  152. try {
  153. $response = $this->client->send($request, $options);
  154. } catch (RequestException $e) {
  155. throw new ApiException(
  156. "[{$e->getCode()}] {$e->getMessage()}",
  157. (int) $e->getCode(),
  158. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  159. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  160. );
  161. } catch (ConnectException $e) {
  162. throw new ApiException(
  163. "[{$e->getCode()}] {$e->getMessage()}",
  164. (int) $e->getCode(),
  165. null,
  166. null
  167. );
  168. }
  169. $statusCode = $response->getStatusCode();
  170. return [null, $statusCode, $response->getHeaders()];
  171. } catch (ApiException $e) {
  172. switch ($e->getCode()) {
  173. case 422:
  174. $data = ObjectSerializer::deserialize(
  175. $e->getResponseBody(),
  176. '\WikipaliApi\Model\ProblemDetails',
  177. $e->getResponseHeaders()
  178. );
  179. $e->setResponseObject($data);
  180. throw $e;
  181. }
  182. throw $e;
  183. }
  184. }
  185. /**
  186. * Operation deleteApiV3AgentFeedbackMessageAsync
  187. *
  188. * 撤回评价
  189. *
  190. * @param string $message AG-UI 回答消息 id (required)
  191. * @param string|null $device_id 设备匿名 id(uuid)。未登录时必填 (optional)
  192. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3AgentFeedbackMessage'] to see the possible values for this operation
  193. *
  194. * @throws \InvalidArgumentException
  195. * @return \GuzzleHttp\Promise\PromiseInterface
  196. */
  197. public function deleteApiV3AgentFeedbackMessageAsync($message, $device_id = null, string $contentType = self::contentTypes['deleteApiV3AgentFeedbackMessage'][0])
  198. {
  199. return $this->deleteApiV3AgentFeedbackMessageAsyncWithHttpInfo($message, $device_id, $contentType)
  200. ->then(
  201. function ($response) {
  202. return $response[0];
  203. }
  204. );
  205. }
  206. /**
  207. * Operation deleteApiV3AgentFeedbackMessageAsyncWithHttpInfo
  208. *
  209. * 撤回评价
  210. *
  211. * @param string $message AG-UI 回答消息 id (required)
  212. * @param string|null $device_id 设备匿名 id(uuid)。未登录时必填 (optional)
  213. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3AgentFeedbackMessage'] to see the possible values for this operation
  214. *
  215. * @throws \InvalidArgumentException
  216. * @return \GuzzleHttp\Promise\PromiseInterface
  217. */
  218. public function deleteApiV3AgentFeedbackMessageAsyncWithHttpInfo($message, $device_id = null, string $contentType = self::contentTypes['deleteApiV3AgentFeedbackMessage'][0])
  219. {
  220. $returnType = '';
  221. $request = $this->deleteApiV3AgentFeedbackMessageRequest($message, $device_id, $contentType);
  222. return $this->client
  223. ->sendAsync($request, $this->createHttpClientOption())
  224. ->then(
  225. function ($response) use ($returnType) {
  226. return [null, $response->getStatusCode(), $response->getHeaders()];
  227. },
  228. function ($exception) {
  229. $response = $exception->getResponse();
  230. $statusCode = $response->getStatusCode();
  231. throw new ApiException(
  232. sprintf(
  233. '[%d] Error connecting to the API (%s)',
  234. $statusCode,
  235. $exception->getRequest()->getUri()
  236. ),
  237. $statusCode,
  238. $response->getHeaders(),
  239. (string) $response->getBody()
  240. );
  241. }
  242. );
  243. }
  244. /**
  245. * Create request for operation 'deleteApiV3AgentFeedbackMessage'
  246. *
  247. * @param string $message AG-UI 回答消息 id (required)
  248. * @param string|null $device_id 设备匿名 id(uuid)。未登录时必填 (optional)
  249. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3AgentFeedbackMessage'] to see the possible values for this operation
  250. *
  251. * @throws \InvalidArgumentException
  252. * @return \GuzzleHttp\Psr7\Request
  253. */
  254. public function deleteApiV3AgentFeedbackMessageRequest($message, $device_id = null, string $contentType = self::contentTypes['deleteApiV3AgentFeedbackMessage'][0])
  255. {
  256. // verify the required parameter 'message' is set
  257. if ($message === null || (is_array($message) && count($message) === 0)) {
  258. throw new \InvalidArgumentException(
  259. 'Missing the required parameter $message when calling deleteApiV3AgentFeedbackMessage'
  260. );
  261. }
  262. $resourcePath = '/v3/agent-feedback/{message}';
  263. $formParams = [];
  264. $queryParams = [];
  265. $headerParams = [];
  266. $httpBody = '';
  267. $multipart = false;
  268. // query params
  269. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  270. $device_id,
  271. 'device_id', // param base name
  272. 'string', // openApiType
  273. 'form', // style
  274. true, // explode
  275. false // required
  276. ) ?? []);
  277. // path params
  278. if ($message !== null) {
  279. $resourcePath = str_replace(
  280. '{message}',
  281. ObjectSerializer::toPathValue($message),
  282. $resourcePath
  283. );
  284. }
  285. $headers = $this->headerSelector->selectHeaders(
  286. ['application/problem+json', ],
  287. $contentType,
  288. $multipart
  289. );
  290. // for model (json/xml)
  291. if (count($formParams) > 0) {
  292. if ($multipart) {
  293. $multipartContents = [];
  294. foreach ($formParams as $formParamName => $formParamValue) {
  295. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  296. foreach ($formParamValueItems as $formParamValueItem) {
  297. $multipartContents[] = [
  298. 'name' => $formParamName,
  299. 'contents' => $formParamValueItem
  300. ];
  301. }
  302. }
  303. // for HTTP post (form)
  304. $httpBody = new MultipartStream($multipartContents);
  305. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  306. # if Content-Type contains "application/json", json_encode the form parameters
  307. try {
  308. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  309. } catch (\JsonException $e) {
  310. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  311. }
  312. } else {
  313. // for HTTP post (form)
  314. $httpBody = ObjectSerializer::buildQuery($formParams);
  315. }
  316. }
  317. // this endpoint requires Bearer authentication (access token)
  318. if (!empty($this->config->getAccessToken())) {
  319. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  320. }
  321. $defaultHeaders = [];
  322. if ($this->config->getUserAgent()) {
  323. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  324. }
  325. $headers = array_merge(
  326. $defaultHeaders,
  327. $headerParams,
  328. $headers
  329. );
  330. $operationHost = $this->config->getHost();
  331. $query = ObjectSerializer::buildQuery($queryParams);
  332. return new Request(
  333. 'DELETE',
  334. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  335. $headers,
  336. $httpBody
  337. );
  338. }
  339. /**
  340. * Operation postApiV3AgentFeedback
  341. *
  342. * 评价一条回答(再次提交即更新)
  343. *
  344. * @param \WikipaliApi\Model\PostApiV3AgentFeedbackRequest $post_api_v3_agent_feedback_request post_api_v3_agent_feedback_request (required)
  345. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentFeedback'] to see the possible values for this operation
  346. *
  347. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  348. * @throws \InvalidArgumentException
  349. * @return \WikipaliApi\Model\PostApiV3AgentFeedback200Response|\WikipaliApi\Model\PostApiV3AgentFeedback200Response|\WikipaliApi\Model\ProblemDetails
  350. */
  351. public function postApiV3AgentFeedback($post_api_v3_agent_feedback_request, string $contentType = self::contentTypes['postApiV3AgentFeedback'][0])
  352. {
  353. list($response) = $this->postApiV3AgentFeedbackWithHttpInfo($post_api_v3_agent_feedback_request, $contentType);
  354. return $response;
  355. }
  356. /**
  357. * Operation postApiV3AgentFeedbackWithHttpInfo
  358. *
  359. * 评价一条回答(再次提交即更新)
  360. *
  361. * @param \WikipaliApi\Model\PostApiV3AgentFeedbackRequest $post_api_v3_agent_feedback_request (required)
  362. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentFeedback'] to see the possible values for this operation
  363. *
  364. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  365. * @throws \InvalidArgumentException
  366. * @return array of \WikipaliApi\Model\PostApiV3AgentFeedback200Response|\WikipaliApi\Model\PostApiV3AgentFeedback200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  367. */
  368. public function postApiV3AgentFeedbackWithHttpInfo($post_api_v3_agent_feedback_request, string $contentType = self::contentTypes['postApiV3AgentFeedback'][0])
  369. {
  370. $request = $this->postApiV3AgentFeedbackRequest($post_api_v3_agent_feedback_request, $contentType);
  371. try {
  372. $options = $this->createHttpClientOption();
  373. try {
  374. $response = $this->client->send($request, $options);
  375. } catch (RequestException $e) {
  376. throw new ApiException(
  377. "[{$e->getCode()}] {$e->getMessage()}",
  378. (int) $e->getCode(),
  379. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  380. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  381. );
  382. } catch (ConnectException $e) {
  383. throw new ApiException(
  384. "[{$e->getCode()}] {$e->getMessage()}",
  385. (int) $e->getCode(),
  386. null,
  387. null
  388. );
  389. }
  390. $statusCode = $response->getStatusCode();
  391. switch($statusCode) {
  392. case 200:
  393. return $this->handleResponseWithDataType(
  394. '\WikipaliApi\Model\PostApiV3AgentFeedback200Response',
  395. $request,
  396. $response,
  397. );
  398. case 201:
  399. return $this->handleResponseWithDataType(
  400. '\WikipaliApi\Model\PostApiV3AgentFeedback200Response',
  401. $request,
  402. $response,
  403. );
  404. case 422:
  405. return $this->handleResponseWithDataType(
  406. '\WikipaliApi\Model\ProblemDetails',
  407. $request,
  408. $response,
  409. );
  410. }
  411. if ($statusCode < 200 || $statusCode > 299) {
  412. throw new ApiException(
  413. sprintf(
  414. '[%d] Error connecting to the API (%s)',
  415. $statusCode,
  416. (string) $request->getUri()
  417. ),
  418. $statusCode,
  419. $response->getHeaders(),
  420. (string) $response->getBody()
  421. );
  422. }
  423. return $this->handleResponseWithDataType(
  424. '\WikipaliApi\Model\PostApiV3AgentFeedback200Response',
  425. $request,
  426. $response,
  427. );
  428. } catch (ApiException $e) {
  429. switch ($e->getCode()) {
  430. case 200:
  431. $data = ObjectSerializer::deserialize(
  432. $e->getResponseBody(),
  433. '\WikipaliApi\Model\PostApiV3AgentFeedback200Response',
  434. $e->getResponseHeaders()
  435. );
  436. $e->setResponseObject($data);
  437. throw $e;
  438. case 201:
  439. $data = ObjectSerializer::deserialize(
  440. $e->getResponseBody(),
  441. '\WikipaliApi\Model\PostApiV3AgentFeedback200Response',
  442. $e->getResponseHeaders()
  443. );
  444. $e->setResponseObject($data);
  445. throw $e;
  446. case 422:
  447. $data = ObjectSerializer::deserialize(
  448. $e->getResponseBody(),
  449. '\WikipaliApi\Model\ProblemDetails',
  450. $e->getResponseHeaders()
  451. );
  452. $e->setResponseObject($data);
  453. throw $e;
  454. }
  455. throw $e;
  456. }
  457. }
  458. /**
  459. * Operation postApiV3AgentFeedbackAsync
  460. *
  461. * 评价一条回答(再次提交即更新)
  462. *
  463. * @param \WikipaliApi\Model\PostApiV3AgentFeedbackRequest $post_api_v3_agent_feedback_request (required)
  464. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentFeedback'] to see the possible values for this operation
  465. *
  466. * @throws \InvalidArgumentException
  467. * @return \GuzzleHttp\Promise\PromiseInterface
  468. */
  469. public function postApiV3AgentFeedbackAsync($post_api_v3_agent_feedback_request, string $contentType = self::contentTypes['postApiV3AgentFeedback'][0])
  470. {
  471. return $this->postApiV3AgentFeedbackAsyncWithHttpInfo($post_api_v3_agent_feedback_request, $contentType)
  472. ->then(
  473. function ($response) {
  474. return $response[0];
  475. }
  476. );
  477. }
  478. /**
  479. * Operation postApiV3AgentFeedbackAsyncWithHttpInfo
  480. *
  481. * 评价一条回答(再次提交即更新)
  482. *
  483. * @param \WikipaliApi\Model\PostApiV3AgentFeedbackRequest $post_api_v3_agent_feedback_request (required)
  484. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentFeedback'] to see the possible values for this operation
  485. *
  486. * @throws \InvalidArgumentException
  487. * @return \GuzzleHttp\Promise\PromiseInterface
  488. */
  489. public function postApiV3AgentFeedbackAsyncWithHttpInfo($post_api_v3_agent_feedback_request, string $contentType = self::contentTypes['postApiV3AgentFeedback'][0])
  490. {
  491. $returnType = '\WikipaliApi\Model\PostApiV3AgentFeedback200Response';
  492. $request = $this->postApiV3AgentFeedbackRequest($post_api_v3_agent_feedback_request, $contentType);
  493. return $this->client
  494. ->sendAsync($request, $this->createHttpClientOption())
  495. ->then(
  496. function ($response) use ($returnType) {
  497. if ($returnType === '\SplFileObject') {
  498. $content = $response->getBody(); //stream goes to serializer
  499. } else {
  500. $content = (string) $response->getBody();
  501. if ($returnType !== 'string') {
  502. $content = json_decode($content);
  503. }
  504. }
  505. return [
  506. ObjectSerializer::deserialize($content, $returnType, []),
  507. $response->getStatusCode(),
  508. $response->getHeaders()
  509. ];
  510. },
  511. function ($exception) {
  512. $response = $exception->getResponse();
  513. $statusCode = $response->getStatusCode();
  514. throw new ApiException(
  515. sprintf(
  516. '[%d] Error connecting to the API (%s)',
  517. $statusCode,
  518. $exception->getRequest()->getUri()
  519. ),
  520. $statusCode,
  521. $response->getHeaders(),
  522. (string) $response->getBody()
  523. );
  524. }
  525. );
  526. }
  527. /**
  528. * Create request for operation 'postApiV3AgentFeedback'
  529. *
  530. * @param \WikipaliApi\Model\PostApiV3AgentFeedbackRequest $post_api_v3_agent_feedback_request (required)
  531. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentFeedback'] to see the possible values for this operation
  532. *
  533. * @throws \InvalidArgumentException
  534. * @return \GuzzleHttp\Psr7\Request
  535. */
  536. public function postApiV3AgentFeedbackRequest($post_api_v3_agent_feedback_request, string $contentType = self::contentTypes['postApiV3AgentFeedback'][0])
  537. {
  538. // verify the required parameter 'post_api_v3_agent_feedback_request' is set
  539. if ($post_api_v3_agent_feedback_request === null || (is_array($post_api_v3_agent_feedback_request) && count($post_api_v3_agent_feedback_request) === 0)) {
  540. throw new \InvalidArgumentException(
  541. 'Missing the required parameter $post_api_v3_agent_feedback_request when calling postApiV3AgentFeedback'
  542. );
  543. }
  544. $resourcePath = '/v3/agent-feedback';
  545. $formParams = [];
  546. $queryParams = [];
  547. $headerParams = [];
  548. $httpBody = '';
  549. $multipart = false;
  550. $headers = $this->headerSelector->selectHeaders(
  551. ['application/json', 'application/problem+json', ],
  552. $contentType,
  553. $multipart
  554. );
  555. // for model (json/xml)
  556. if (isset($post_api_v3_agent_feedback_request)) {
  557. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  558. # if Content-Type contains "application/json", json_encode the body
  559. try {
  560. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_agent_feedback_request), JSON_THROW_ON_ERROR);
  561. } catch (\JsonException $e) {
  562. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  563. }
  564. } else {
  565. $httpBody = $post_api_v3_agent_feedback_request;
  566. }
  567. } elseif (count($formParams) > 0) {
  568. if ($multipart) {
  569. $multipartContents = [];
  570. foreach ($formParams as $formParamName => $formParamValue) {
  571. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  572. foreach ($formParamValueItems as $formParamValueItem) {
  573. $multipartContents[] = [
  574. 'name' => $formParamName,
  575. 'contents' => $formParamValueItem
  576. ];
  577. }
  578. }
  579. // for HTTP post (form)
  580. $httpBody = new MultipartStream($multipartContents);
  581. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  582. # if Content-Type contains "application/json", json_encode the form parameters
  583. try {
  584. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  585. } catch (\JsonException $e) {
  586. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  587. }
  588. } else {
  589. // for HTTP post (form)
  590. $httpBody = ObjectSerializer::buildQuery($formParams);
  591. }
  592. }
  593. // this endpoint requires Bearer authentication (access token)
  594. if (!empty($this->config->getAccessToken())) {
  595. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  596. }
  597. $defaultHeaders = [];
  598. if ($this->config->getUserAgent()) {
  599. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  600. }
  601. $headers = array_merge(
  602. $defaultHeaders,
  603. $headerParams,
  604. $headers
  605. );
  606. $operationHost = $this->config->getHost();
  607. $query = ObjectSerializer::buildQuery($queryParams);
  608. return new Request(
  609. 'POST',
  610. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  611. $headers,
  612. $httpBody
  613. );
  614. }
  615. /**
  616. * Create http client option
  617. *
  618. * @throws \RuntimeException on file opening failure
  619. * @return array of http client options
  620. */
  621. protected function createHttpClientOption()
  622. {
  623. $options = [];
  624. if ($this->config->getDebug()) {
  625. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  626. if (!$options[RequestOptions::DEBUG]) {
  627. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  628. }
  629. }
  630. if ($this->config->getCertFile()) {
  631. $options[RequestOptions::CERT] = $this->config->getCertFile();
  632. }
  633. if ($this->config->getKeyFile()) {
  634. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  635. }
  636. return $options;
  637. }
  638. private function handleResponseWithDataType(
  639. string $dataType,
  640. RequestInterface $request,
  641. ResponseInterface $response
  642. ): array {
  643. if ($dataType === '\SplFileObject') {
  644. $content = $response->getBody(); //stream goes to serializer
  645. } else {
  646. $content = (string) $response->getBody();
  647. if ($dataType !== 'string') {
  648. try {
  649. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  650. } catch (\JsonException $exception) {
  651. throw new ApiException(
  652. sprintf(
  653. 'Error JSON decoding server response (%s)',
  654. $request->getUri()
  655. ),
  656. $response->getStatusCode(),
  657. $response->getHeaders(),
  658. $content
  659. );
  660. }
  661. }
  662. }
  663. return [
  664. ObjectSerializer::deserialize($content, $dataType, []),
  665. $response->getStatusCode(),
  666. $response->getHeaders()
  667. ];
  668. }
  669. private function responseWithinRangeCode(
  670. string $rangeCode,
  671. int $statusCode
  672. ): bool {
  673. $left = (int) ($rangeCode[0].'00');
  674. $right = (int) ($rangeCode[0].'99');
  675. return $statusCode >= $left && $statusCode <= $right;
  676. }
  677. }