AgentGrantsApi.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <?php
  2. /**
  3. * AgentGrantsApi
  4. * PHP version 8.1
  5. *
  6. * @category Class
  7. * @package WikipaliApi
  8. * @author OpenAPI Generator team
  9. * @link https://openapi-generator.tech
  10. */
  11. /**
  12. * MINT API
  13. *
  14. * International Academy Of Pali Tipitaka(国际巴利三藏学院) 由 `php openapi/scripts/generate.php` 依据 api-v13 的路由与控制器源码生成。 响应统一封装为 `{ok, message, data}`;`ok=false` 时 `message` 为错误信息。
  15. *
  16. * The version of the OpenAPI document: 2026.10.15
  17. * Generated by: https://openapi-generator.tech
  18. * Generator version: 7.25.0
  19. */
  20. /**
  21. * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
  22. * https://openapi-generator.tech
  23. * Do not edit the class manually.
  24. */
  25. namespace WikipaliApi\Api;
  26. use GuzzleHttp\Client;
  27. use GuzzleHttp\ClientInterface;
  28. use GuzzleHttp\Exception\ConnectException;
  29. use GuzzleHttp\Exception\RequestException;
  30. use GuzzleHttp\Psr7\MultipartStream;
  31. use GuzzleHttp\Psr7\Request;
  32. use GuzzleHttp\RequestOptions;
  33. use Psr\Http\Message\RequestInterface;
  34. use Psr\Http\Message\ResponseInterface;
  35. use WikipaliApi\ApiException;
  36. use WikipaliApi\Configuration;
  37. use WikipaliApi\FormDataProcessor;
  38. use WikipaliApi\HeaderSelector;
  39. use WikipaliApi\ObjectSerializer;
  40. /**
  41. * AgentGrantsApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class AgentGrantsApi
  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. 'postApiV3AgentGrants' => [
  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 postApiV3AgentGrants
  116. *
  117. * 签发 agent 写入授权
  118. *
  119. * @param \WikipaliApi\Model\PostApiV3AgentGrantsRequest $post_api_v3_agent_grants_request post_api_v3_agent_grants_request (required)
  120. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentGrants'] 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\PostApiV3AgentGrants200Response|\WikipaliApi\Model\PostApiV3AgentGrants200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  125. */
  126. public function postApiV3AgentGrants($post_api_v3_agent_grants_request, string $contentType = self::contentTypes['postApiV3AgentGrants'][0])
  127. {
  128. list($response) = $this->postApiV3AgentGrantsWithHttpInfo($post_api_v3_agent_grants_request, $contentType);
  129. return $response;
  130. }
  131. /**
  132. * Operation postApiV3AgentGrantsWithHttpInfo
  133. *
  134. * 签发 agent 写入授权
  135. *
  136. * @param \WikipaliApi\Model\PostApiV3AgentGrantsRequest $post_api_v3_agent_grants_request (required)
  137. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentGrants'] 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\PostApiV3AgentGrants200Response|\WikipaliApi\Model\PostApiV3AgentGrants200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  142. */
  143. public function postApiV3AgentGrantsWithHttpInfo($post_api_v3_agent_grants_request, string $contentType = self::contentTypes['postApiV3AgentGrants'][0])
  144. {
  145. $request = $this->postApiV3AgentGrantsRequest($post_api_v3_agent_grants_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\PostApiV3AgentGrants200Response',
  170. $request,
  171. $response,
  172. );
  173. case 201:
  174. return $this->handleResponseWithDataType(
  175. '\WikipaliApi\Model\PostApiV3AgentGrants200Response',
  176. $request,
  177. $response,
  178. );
  179. case 401:
  180. return $this->handleResponseWithDataType(
  181. '\WikipaliApi\Model\ProblemDetails',
  182. $request,
  183. $response,
  184. );
  185. case 403:
  186. return $this->handleResponseWithDataType(
  187. '\WikipaliApi\Model\ProblemDetails',
  188. $request,
  189. $response,
  190. );
  191. case 422:
  192. return $this->handleResponseWithDataType(
  193. '\WikipaliApi\Model\ProblemDetails',
  194. $request,
  195. $response,
  196. );
  197. }
  198. if ($statusCode < 200 || $statusCode > 299) {
  199. throw new ApiException(
  200. sprintf(
  201. '[%d] Error connecting to the API (%s)',
  202. $statusCode,
  203. (string) $request->getUri()
  204. ),
  205. $statusCode,
  206. $response->getHeaders(),
  207. (string) $response->getBody()
  208. );
  209. }
  210. return $this->handleResponseWithDataType(
  211. '\WikipaliApi\Model\PostApiV3AgentGrants200Response',
  212. $request,
  213. $response,
  214. );
  215. } catch (ApiException $e) {
  216. switch ($e->getCode()) {
  217. case 200:
  218. $data = ObjectSerializer::deserialize(
  219. $e->getResponseBody(),
  220. '\WikipaliApi\Model\PostApiV3AgentGrants200Response',
  221. $e->getResponseHeaders()
  222. );
  223. $e->setResponseObject($data);
  224. throw $e;
  225. case 201:
  226. $data = ObjectSerializer::deserialize(
  227. $e->getResponseBody(),
  228. '\WikipaliApi\Model\PostApiV3AgentGrants200Response',
  229. $e->getResponseHeaders()
  230. );
  231. $e->setResponseObject($data);
  232. throw $e;
  233. case 401:
  234. $data = ObjectSerializer::deserialize(
  235. $e->getResponseBody(),
  236. '\WikipaliApi\Model\ProblemDetails',
  237. $e->getResponseHeaders()
  238. );
  239. $e->setResponseObject($data);
  240. throw $e;
  241. case 403:
  242. $data = ObjectSerializer::deserialize(
  243. $e->getResponseBody(),
  244. '\WikipaliApi\Model\ProblemDetails',
  245. $e->getResponseHeaders()
  246. );
  247. $e->setResponseObject($data);
  248. throw $e;
  249. case 422:
  250. $data = ObjectSerializer::deserialize(
  251. $e->getResponseBody(),
  252. '\WikipaliApi\Model\ProblemDetails',
  253. $e->getResponseHeaders()
  254. );
  255. $e->setResponseObject($data);
  256. throw $e;
  257. }
  258. throw $e;
  259. }
  260. }
  261. /**
  262. * Operation postApiV3AgentGrantsAsync
  263. *
  264. * 签发 agent 写入授权
  265. *
  266. * @param \WikipaliApi\Model\PostApiV3AgentGrantsRequest $post_api_v3_agent_grants_request (required)
  267. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentGrants'] to see the possible values for this operation
  268. *
  269. * @throws \InvalidArgumentException
  270. * @return \GuzzleHttp\Promise\PromiseInterface
  271. */
  272. public function postApiV3AgentGrantsAsync($post_api_v3_agent_grants_request, string $contentType = self::contentTypes['postApiV3AgentGrants'][0])
  273. {
  274. return $this->postApiV3AgentGrantsAsyncWithHttpInfo($post_api_v3_agent_grants_request, $contentType)
  275. ->then(
  276. function ($response) {
  277. return $response[0];
  278. }
  279. );
  280. }
  281. /**
  282. * Operation postApiV3AgentGrantsAsyncWithHttpInfo
  283. *
  284. * 签发 agent 写入授权
  285. *
  286. * @param \WikipaliApi\Model\PostApiV3AgentGrantsRequest $post_api_v3_agent_grants_request (required)
  287. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentGrants'] to see the possible values for this operation
  288. *
  289. * @throws \InvalidArgumentException
  290. * @return \GuzzleHttp\Promise\PromiseInterface
  291. */
  292. public function postApiV3AgentGrantsAsyncWithHttpInfo($post_api_v3_agent_grants_request, string $contentType = self::contentTypes['postApiV3AgentGrants'][0])
  293. {
  294. $returnType = '\WikipaliApi\Model\PostApiV3AgentGrants200Response';
  295. $request = $this->postApiV3AgentGrantsRequest($post_api_v3_agent_grants_request, $contentType);
  296. return $this->client
  297. ->sendAsync($request, $this->createHttpClientOption())
  298. ->then(
  299. function ($response) use ($returnType) {
  300. if ($returnType === '\SplFileObject') {
  301. $content = $response->getBody(); //stream goes to serializer
  302. } else {
  303. $content = (string) $response->getBody();
  304. if ($returnType !== 'string') {
  305. $content = json_decode($content);
  306. }
  307. }
  308. return [
  309. ObjectSerializer::deserialize($content, $returnType, []),
  310. $response->getStatusCode(),
  311. $response->getHeaders()
  312. ];
  313. },
  314. function ($exception) {
  315. $response = $exception->getResponse();
  316. $statusCode = $response->getStatusCode();
  317. throw new ApiException(
  318. sprintf(
  319. '[%d] Error connecting to the API (%s)',
  320. $statusCode,
  321. $exception->getRequest()->getUri()
  322. ),
  323. $statusCode,
  324. $response->getHeaders(),
  325. (string) $response->getBody()
  326. );
  327. }
  328. );
  329. }
  330. /**
  331. * Create request for operation 'postApiV3AgentGrants'
  332. *
  333. * @param \WikipaliApi\Model\PostApiV3AgentGrantsRequest $post_api_v3_agent_grants_request (required)
  334. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3AgentGrants'] to see the possible values for this operation
  335. *
  336. * @throws \InvalidArgumentException
  337. * @return \GuzzleHttp\Psr7\Request
  338. */
  339. public function postApiV3AgentGrantsRequest($post_api_v3_agent_grants_request, string $contentType = self::contentTypes['postApiV3AgentGrants'][0])
  340. {
  341. // verify the required parameter 'post_api_v3_agent_grants_request' is set
  342. if ($post_api_v3_agent_grants_request === null || (is_array($post_api_v3_agent_grants_request) && count($post_api_v3_agent_grants_request) === 0)) {
  343. throw new \InvalidArgumentException(
  344. 'Missing the required parameter $post_api_v3_agent_grants_request when calling postApiV3AgentGrants'
  345. );
  346. }
  347. $resourcePath = '/v3/agent-grants';
  348. $formParams = [];
  349. $queryParams = [];
  350. $headerParams = [];
  351. $httpBody = '';
  352. $multipart = false;
  353. $headers = $this->headerSelector->selectHeaders(
  354. ['application/json', 'application/problem+json', ],
  355. $contentType,
  356. $multipart
  357. );
  358. // for model (json/xml)
  359. if (isset($post_api_v3_agent_grants_request)) {
  360. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  361. # if Content-Type contains "application/json", json_encode the body
  362. try {
  363. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_agent_grants_request), JSON_THROW_ON_ERROR);
  364. } catch (\JsonException $e) {
  365. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  366. }
  367. } else {
  368. $httpBody = $post_api_v3_agent_grants_request;
  369. }
  370. } elseif (count($formParams) > 0) {
  371. if ($multipart) {
  372. $multipartContents = [];
  373. foreach ($formParams as $formParamName => $formParamValue) {
  374. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  375. foreach ($formParamValueItems as $formParamValueItem) {
  376. $multipartContents[] = [
  377. 'name' => $formParamName,
  378. 'contents' => $formParamValueItem
  379. ];
  380. }
  381. }
  382. // for HTTP post (form)
  383. $httpBody = new MultipartStream($multipartContents);
  384. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  385. # if Content-Type contains "application/json", json_encode the form parameters
  386. try {
  387. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  388. } catch (\JsonException $e) {
  389. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  390. }
  391. } else {
  392. // for HTTP post (form)
  393. $httpBody = ObjectSerializer::buildQuery($formParams);
  394. }
  395. }
  396. // this endpoint requires Bearer authentication (access token)
  397. if (!empty($this->config->getAccessToken())) {
  398. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  399. }
  400. $defaultHeaders = [];
  401. if ($this->config->getUserAgent()) {
  402. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  403. }
  404. $headers = array_merge(
  405. $defaultHeaders,
  406. $headerParams,
  407. $headers
  408. );
  409. $operationHost = $this->config->getHost();
  410. $query = ObjectSerializer::buildQuery($queryParams);
  411. return new Request(
  412. 'POST',
  413. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  414. $headers,
  415. $httpBody
  416. );
  417. }
  418. /**
  419. * Create http client option
  420. *
  421. * @throws \RuntimeException on file opening failure
  422. * @return array of http client options
  423. */
  424. protected function createHttpClientOption()
  425. {
  426. $options = [];
  427. if ($this->config->getDebug()) {
  428. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  429. if (!$options[RequestOptions::DEBUG]) {
  430. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  431. }
  432. }
  433. if ($this->config->getCertFile()) {
  434. $options[RequestOptions::CERT] = $this->config->getCertFile();
  435. }
  436. if ($this->config->getKeyFile()) {
  437. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  438. }
  439. return $options;
  440. }
  441. private function handleResponseWithDataType(
  442. string $dataType,
  443. RequestInterface $request,
  444. ResponseInterface $response
  445. ): array {
  446. if ($dataType === '\SplFileObject') {
  447. $content = $response->getBody(); //stream goes to serializer
  448. } else {
  449. $content = (string) $response->getBody();
  450. if ($dataType !== 'string') {
  451. try {
  452. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  453. } catch (\JsonException $exception) {
  454. throw new ApiException(
  455. sprintf(
  456. 'Error JSON decoding server response (%s)',
  457. $request->getUri()
  458. ),
  459. $response->getStatusCode(),
  460. $response->getHeaders(),
  461. $content
  462. );
  463. }
  464. }
  465. }
  466. return [
  467. ObjectSerializer::deserialize($content, $dataType, []),
  468. $response->getStatusCode(),
  469. $response->getHeaders()
  470. ];
  471. }
  472. private function responseWithinRangeCode(
  473. string $rangeCode,
  474. int $statusCode
  475. ): bool {
  476. $left = (int) ($rangeCode[0].'00');
  477. $right = (int) ($rangeCode[0].'99');
  478. return $statusCode >= $left && $statusCode <= $right;
  479. }
  480. }