AgentEventsApi.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <?php
  2. /**
  3. * AgentEventsApi
  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. * AgentEventsApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class AgentEventsApi
  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. 'postApiV3AgentEvents' => [
  69. 'application/json',
  70. ],
  71. ];
  72. /**
  73. * @param ClientInterface $client
  74. * @param Configuration $config
  75. * @param HeaderSelector $selector
  76. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  77. */
  78. public function __construct(
  79. ?ClientInterface $client = null,
  80. ?Configuration $config = null,
  81. ?HeaderSelector $selector = null,
  82. int $hostIndex = 0
  83. ) {
  84. $this->client = $client ?: new Client();
  85. $this->config = $config ?: Configuration::getDefaultConfiguration();
  86. $this->headerSelector = $selector ?: new HeaderSelector();
  87. $this->hostIndex = $hostIndex;
  88. }
  89. /**
  90. * Set the host index
  91. *
  92. * @param int $hostIndex Host index (required)
  93. */
  94. public function setHostIndex($hostIndex): void
  95. {
  96. $this->hostIndex = $hostIndex;
  97. }
  98. /**
  99. * Get the host index
  100. *
  101. * @return int Host index
  102. */
  103. public function getHostIndex()
  104. {
  105. return $this->hostIndex;
  106. }
  107. /**
  108. * @return Configuration
  109. */
  110. public function getConfig()
  111. {
  112. return $this->config;
  113. }
  114. /**
  115. * Operation postApiV3AgentEvents
  116. *
  117. * 上报一条隐式信号
  118. *
  119. * @param \WikipaliApi\Model\PostApiV3AgentEventsRequest $post_api_v3_agent_events_request post_api_v3_agent_events_request (required)
  120. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentEvents'] to see the possible values for this operation
  121. *
  122. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  123. * @throws \InvalidArgumentException
  124. * @return \WikipaliApi\Model\PostApiV3AgentEvents200Response|\WikipaliApi\Model\ProblemDetails
  125. */
  126. public function postApiV3AgentEvents($post_api_v3_agent_events_request, string $contentType = self::contentTypes['postApiV3AgentEvents'][0])
  127. {
  128. list($response) = $this->postApiV3AgentEventsWithHttpInfo($post_api_v3_agent_events_request, $contentType);
  129. return $response;
  130. }
  131. /**
  132. * Operation postApiV3AgentEventsWithHttpInfo
  133. *
  134. * 上报一条隐式信号
  135. *
  136. * @param \WikipaliApi\Model\PostApiV3AgentEventsRequest $post_api_v3_agent_events_request (required)
  137. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentEvents'] to see the possible values for this operation
  138. *
  139. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  140. * @throws \InvalidArgumentException
  141. * @return array of \WikipaliApi\Model\PostApiV3AgentEvents200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  142. */
  143. public function postApiV3AgentEventsWithHttpInfo($post_api_v3_agent_events_request, string $contentType = self::contentTypes['postApiV3AgentEvents'][0])
  144. {
  145. $request = $this->postApiV3AgentEventsRequest($post_api_v3_agent_events_request, $contentType);
  146. try {
  147. $options = $this->createHttpClientOption();
  148. try {
  149. $response = $this->client->send($request, $options);
  150. } catch (RequestException $e) {
  151. throw new ApiException(
  152. "[{$e->getCode()}] {$e->getMessage()}",
  153. (int) $e->getCode(),
  154. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  155. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  156. );
  157. } catch (ConnectException $e) {
  158. throw new ApiException(
  159. "[{$e->getCode()}] {$e->getMessage()}",
  160. (int) $e->getCode(),
  161. null,
  162. null
  163. );
  164. }
  165. $statusCode = $response->getStatusCode();
  166. switch($statusCode) {
  167. case 200:
  168. return $this->handleResponseWithDataType(
  169. '\WikipaliApi\Model\PostApiV3AgentEvents200Response',
  170. $request,
  171. $response,
  172. );
  173. case 422:
  174. return $this->handleResponseWithDataType(
  175. '\WikipaliApi\Model\ProblemDetails',
  176. $request,
  177. $response,
  178. );
  179. }
  180. if ($statusCode < 200 || $statusCode > 299) {
  181. throw new ApiException(
  182. sprintf(
  183. '[%d] Error connecting to the API (%s)',
  184. $statusCode,
  185. (string) $request->getUri()
  186. ),
  187. $statusCode,
  188. $response->getHeaders(),
  189. (string) $response->getBody()
  190. );
  191. }
  192. return $this->handleResponseWithDataType(
  193. '\WikipaliApi\Model\PostApiV3AgentEvents200Response',
  194. $request,
  195. $response,
  196. );
  197. } catch (ApiException $e) {
  198. switch ($e->getCode()) {
  199. case 200:
  200. $data = ObjectSerializer::deserialize(
  201. $e->getResponseBody(),
  202. '\WikipaliApi\Model\PostApiV3AgentEvents200Response',
  203. $e->getResponseHeaders()
  204. );
  205. $e->setResponseObject($data);
  206. throw $e;
  207. case 422:
  208. $data = ObjectSerializer::deserialize(
  209. $e->getResponseBody(),
  210. '\WikipaliApi\Model\ProblemDetails',
  211. $e->getResponseHeaders()
  212. );
  213. $e->setResponseObject($data);
  214. throw $e;
  215. }
  216. throw $e;
  217. }
  218. }
  219. /**
  220. * Operation postApiV3AgentEventsAsync
  221. *
  222. * 上报一条隐式信号
  223. *
  224. * @param \WikipaliApi\Model\PostApiV3AgentEventsRequest $post_api_v3_agent_events_request (required)
  225. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentEvents'] to see the possible values for this operation
  226. *
  227. * @throws \InvalidArgumentException
  228. * @return \GuzzleHttp\Promise\PromiseInterface
  229. */
  230. public function postApiV3AgentEventsAsync($post_api_v3_agent_events_request, string $contentType = self::contentTypes['postApiV3AgentEvents'][0])
  231. {
  232. return $this->postApiV3AgentEventsAsyncWithHttpInfo($post_api_v3_agent_events_request, $contentType)
  233. ->then(
  234. function ($response) {
  235. return $response[0];
  236. }
  237. );
  238. }
  239. /**
  240. * Operation postApiV3AgentEventsAsyncWithHttpInfo
  241. *
  242. * 上报一条隐式信号
  243. *
  244. * @param \WikipaliApi\Model\PostApiV3AgentEventsRequest $post_api_v3_agent_events_request (required)
  245. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentEvents'] to see the possible values for this operation
  246. *
  247. * @throws \InvalidArgumentException
  248. * @return \GuzzleHttp\Promise\PromiseInterface
  249. */
  250. public function postApiV3AgentEventsAsyncWithHttpInfo($post_api_v3_agent_events_request, string $contentType = self::contentTypes['postApiV3AgentEvents'][0])
  251. {
  252. $returnType = '\WikipaliApi\Model\PostApiV3AgentEvents200Response';
  253. $request = $this->postApiV3AgentEventsRequest($post_api_v3_agent_events_request, $contentType);
  254. return $this->client
  255. ->sendAsync($request, $this->createHttpClientOption())
  256. ->then(
  257. function ($response) use ($returnType) {
  258. if ($returnType === '\SplFileObject') {
  259. $content = $response->getBody(); //stream goes to serializer
  260. } else {
  261. $content = (string) $response->getBody();
  262. if ($returnType !== 'string') {
  263. $content = json_decode($content);
  264. }
  265. }
  266. return [
  267. ObjectSerializer::deserialize($content, $returnType, []),
  268. $response->getStatusCode(),
  269. $response->getHeaders()
  270. ];
  271. },
  272. function ($exception) {
  273. $response = $exception->getResponse();
  274. $statusCode = $response->getStatusCode();
  275. throw new ApiException(
  276. sprintf(
  277. '[%d] Error connecting to the API (%s)',
  278. $statusCode,
  279. $exception->getRequest()->getUri()
  280. ),
  281. $statusCode,
  282. $response->getHeaders(),
  283. (string) $response->getBody()
  284. );
  285. }
  286. );
  287. }
  288. /**
  289. * Create request for operation 'postApiV3AgentEvents'
  290. *
  291. * @param \WikipaliApi\Model\PostApiV3AgentEventsRequest $post_api_v3_agent_events_request (required)
  292. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentEvents'] to see the possible values for this operation
  293. *
  294. * @throws \InvalidArgumentException
  295. * @return \GuzzleHttp\Psr7\Request
  296. */
  297. public function postApiV3AgentEventsRequest($post_api_v3_agent_events_request, string $contentType = self::contentTypes['postApiV3AgentEvents'][0])
  298. {
  299. // verify the required parameter 'post_api_v3_agent_events_request' is set
  300. if ($post_api_v3_agent_events_request === null || (is_array($post_api_v3_agent_events_request) && count($post_api_v3_agent_events_request) === 0)) {
  301. throw new \InvalidArgumentException(
  302. 'Missing the required parameter $post_api_v3_agent_events_request when calling postApiV3AgentEvents'
  303. );
  304. }
  305. $resourcePath = '/v3/agent-events';
  306. $formParams = [];
  307. $queryParams = [];
  308. $headerParams = [];
  309. $httpBody = '';
  310. $multipart = false;
  311. $headers = $this->headerSelector->selectHeaders(
  312. ['application/json', 'application/problem+json', ],
  313. $contentType,
  314. $multipart
  315. );
  316. // for model (json/xml)
  317. if (isset($post_api_v3_agent_events_request)) {
  318. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  319. # if Content-Type contains "application/json", json_encode the body
  320. try {
  321. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_agent_events_request), JSON_THROW_ON_ERROR);
  322. } catch (\JsonException $e) {
  323. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  324. }
  325. } else {
  326. $httpBody = $post_api_v3_agent_events_request;
  327. }
  328. } elseif (count($formParams) > 0) {
  329. if ($multipart) {
  330. $multipartContents = [];
  331. foreach ($formParams as $formParamName => $formParamValue) {
  332. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  333. foreach ($formParamValueItems as $formParamValueItem) {
  334. $multipartContents[] = [
  335. 'name' => $formParamName,
  336. 'contents' => $formParamValueItem
  337. ];
  338. }
  339. }
  340. // for HTTP post (form)
  341. $httpBody = new MultipartStream($multipartContents);
  342. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  343. # if Content-Type contains "application/json", json_encode the form parameters
  344. try {
  345. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  346. } catch (\JsonException $e) {
  347. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  348. }
  349. } else {
  350. // for HTTP post (form)
  351. $httpBody = ObjectSerializer::buildQuery($formParams);
  352. }
  353. }
  354. // this endpoint requires Bearer authentication (access token)
  355. if (!empty($this->config->getAccessToken())) {
  356. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  357. }
  358. $defaultHeaders = [];
  359. if ($this->config->getUserAgent()) {
  360. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  361. }
  362. $headers = array_merge(
  363. $defaultHeaders,
  364. $headerParams,
  365. $headers
  366. );
  367. $operationHost = $this->config->getHost();
  368. $query = ObjectSerializer::buildQuery($queryParams);
  369. return new Request(
  370. 'POST',
  371. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  372. $headers,
  373. $httpBody
  374. );
  375. }
  376. /**
  377. * Create http client option
  378. *
  379. * @throws \RuntimeException on file opening failure
  380. * @return array of http client options
  381. */
  382. protected function createHttpClientOption()
  383. {
  384. $options = [];
  385. if ($this->config->getDebug()) {
  386. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  387. if (!$options[RequestOptions::DEBUG]) {
  388. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  389. }
  390. }
  391. if ($this->config->getCertFile()) {
  392. $options[RequestOptions::CERT] = $this->config->getCertFile();
  393. }
  394. if ($this->config->getKeyFile()) {
  395. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  396. }
  397. return $options;
  398. }
  399. private function handleResponseWithDataType(
  400. string $dataType,
  401. RequestInterface $request,
  402. ResponseInterface $response
  403. ): array {
  404. if ($dataType === '\SplFileObject') {
  405. $content = $response->getBody(); //stream goes to serializer
  406. } else {
  407. $content = (string) $response->getBody();
  408. if ($dataType !== 'string') {
  409. try {
  410. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  411. } catch (\JsonException $exception) {
  412. throw new ApiException(
  413. sprintf(
  414. 'Error JSON decoding server response (%s)',
  415. $request->getUri()
  416. ),
  417. $response->getStatusCode(),
  418. $response->getHeaders(),
  419. $content
  420. );
  421. }
  422. }
  423. }
  424. return [
  425. ObjectSerializer::deserialize($content, $dataType, []),
  426. $response->getStatusCode(),
  427. $response->getHeaders()
  428. ];
  429. }
  430. private function responseWithinRangeCode(
  431. string $rangeCode,
  432. int $statusCode
  433. ): bool {
  434. $left = (int) ($rangeCode[0].'00');
  435. $right = (int) ($rangeCode[0].'99');
  436. return $statusCode >= $left && $statusCode <= $right;
  437. }
  438. }