StudiosApi.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. <?php
  2. /**
  3. * StudiosApi
  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. * StudiosApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class StudiosApi
  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. 'getApiV3StudiosStudioChannels' => [
  69. 'application/json',
  70. ],
  71. 'postApiV3StudiosStudioChannels' => [
  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 getApiV3StudiosStudioChannels
  119. *
  120. * 列出 studio 的 channel
  121. *
  122. * @param string $studio 用户 uuid 或团队 uuid (required)
  123. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  124. * @param string|null $relation 关系 (optional, default to 'own')
  125. * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional)
  126. * @param string|null $search 按名字模糊匹配 (optional)
  127. * @param string|null $type channel 类型 (optional)
  128. * @param string|null $lang 语言 (optional)
  129. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  130. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  131. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  132. * @param string|null $dir 排序方向 (optional, default to 'desc')
  133. * @param int|null $page 页码 (optional, default to 1)
  134. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation
  135. *
  136. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  137. * @throws \InvalidArgumentException
  138. * @return \WikipaliApi\Model\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  139. */
  140. public function getApiV3StudiosStudioChannels($studio, $per_page = 20, $relation = 'own', $collaborator = null, $search = null, $type = null, $lang = null, $book = null, $para = null, $order = 'updated_at', $dir = 'desc', $page = 1, string $contentType = self::contentTypes['getApiV3StudiosStudioChannels'][0])
  141. {
  142. list($response) = $this->getApiV3StudiosStudioChannelsWithHttpInfo($studio, $per_page, $relation, $collaborator, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  143. return $response;
  144. }
  145. /**
  146. * Operation getApiV3StudiosStudioChannelsWithHttpInfo
  147. *
  148. * 列出 studio 的 channel
  149. *
  150. * @param string $studio 用户 uuid 或团队 uuid (required)
  151. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  152. * @param string|null $relation 关系 (optional, default to 'own')
  153. * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional)
  154. * @param string|null $search 按名字模糊匹配 (optional)
  155. * @param string|null $type channel 类型 (optional)
  156. * @param string|null $lang 语言 (optional)
  157. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  158. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  159. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  160. * @param string|null $dir 排序方向 (optional, default to 'desc')
  161. * @param int|null $page 页码 (optional, default to 1)
  162. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation
  163. *
  164. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  165. * @throws \InvalidArgumentException
  166. * @return array of \WikipaliApi\Model\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  167. */
  168. public function getApiV3StudiosStudioChannelsWithHttpInfo($studio, $per_page = 20, $relation = 'own', $collaborator = null, $search = null, $type = null, $lang = null, $book = null, $para = null, $order = 'updated_at', $dir = 'desc', $page = 1, string $contentType = self::contentTypes['getApiV3StudiosStudioChannels'][0])
  169. {
  170. $request = $this->getApiV3StudiosStudioChannelsRequest($studio, $per_page, $relation, $collaborator, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  171. try {
  172. $options = $this->createHttpClientOption();
  173. try {
  174. $response = $this->client->send($request, $options);
  175. } catch (RequestException $e) {
  176. throw new ApiException(
  177. "[{$e->getCode()}] {$e->getMessage()}",
  178. (int) $e->getCode(),
  179. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  180. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  181. );
  182. } catch (ConnectException $e) {
  183. throw new ApiException(
  184. "[{$e->getCode()}] {$e->getMessage()}",
  185. (int) $e->getCode(),
  186. null,
  187. null
  188. );
  189. }
  190. $statusCode = $response->getStatusCode();
  191. switch($statusCode) {
  192. case 200:
  193. return $this->handleResponseWithDataType(
  194. '\WikipaliApi\Model\GetApiV3Channels200Response',
  195. $request,
  196. $response,
  197. );
  198. case 401:
  199. return $this->handleResponseWithDataType(
  200. '\WikipaliApi\Model\ProblemDetails',
  201. $request,
  202. $response,
  203. );
  204. case 403:
  205. return $this->handleResponseWithDataType(
  206. '\WikipaliApi\Model\ProblemDetails',
  207. $request,
  208. $response,
  209. );
  210. case 422:
  211. return $this->handleResponseWithDataType(
  212. '\WikipaliApi\Model\ProblemDetails',
  213. $request,
  214. $response,
  215. );
  216. }
  217. if ($statusCode < 200 || $statusCode > 299) {
  218. throw new ApiException(
  219. sprintf(
  220. '[%d] Error connecting to the API (%s)',
  221. $statusCode,
  222. (string) $request->getUri()
  223. ),
  224. $statusCode,
  225. $response->getHeaders(),
  226. (string) $response->getBody()
  227. );
  228. }
  229. return $this->handleResponseWithDataType(
  230. '\WikipaliApi\Model\GetApiV3Channels200Response',
  231. $request,
  232. $response,
  233. );
  234. } catch (ApiException $e) {
  235. switch ($e->getCode()) {
  236. case 200:
  237. $data = ObjectSerializer::deserialize(
  238. $e->getResponseBody(),
  239. '\WikipaliApi\Model\GetApiV3Channels200Response',
  240. $e->getResponseHeaders()
  241. );
  242. $e->setResponseObject($data);
  243. throw $e;
  244. case 401:
  245. $data = ObjectSerializer::deserialize(
  246. $e->getResponseBody(),
  247. '\WikipaliApi\Model\ProblemDetails',
  248. $e->getResponseHeaders()
  249. );
  250. $e->setResponseObject($data);
  251. throw $e;
  252. case 403:
  253. $data = ObjectSerializer::deserialize(
  254. $e->getResponseBody(),
  255. '\WikipaliApi\Model\ProblemDetails',
  256. $e->getResponseHeaders()
  257. );
  258. $e->setResponseObject($data);
  259. throw $e;
  260. case 422:
  261. $data = ObjectSerializer::deserialize(
  262. $e->getResponseBody(),
  263. '\WikipaliApi\Model\ProblemDetails',
  264. $e->getResponseHeaders()
  265. );
  266. $e->setResponseObject($data);
  267. throw $e;
  268. }
  269. throw $e;
  270. }
  271. }
  272. /**
  273. * Operation getApiV3StudiosStudioChannelsAsync
  274. *
  275. * 列出 studio 的 channel
  276. *
  277. * @param string $studio 用户 uuid 或团队 uuid (required)
  278. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  279. * @param string|null $relation 关系 (optional, default to 'own')
  280. * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional)
  281. * @param string|null $search 按名字模糊匹配 (optional)
  282. * @param string|null $type channel 类型 (optional)
  283. * @param string|null $lang 语言 (optional)
  284. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  285. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  286. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  287. * @param string|null $dir 排序方向 (optional, default to 'desc')
  288. * @param int|null $page 页码 (optional, default to 1)
  289. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation
  290. *
  291. * @throws \InvalidArgumentException
  292. * @return \GuzzleHttp\Promise\PromiseInterface
  293. */
  294. public function getApiV3StudiosStudioChannelsAsync($studio, $per_page = 20, $relation = 'own', $collaborator = null, $search = null, $type = null, $lang = null, $book = null, $para = null, $order = 'updated_at', $dir = 'desc', $page = 1, string $contentType = self::contentTypes['getApiV3StudiosStudioChannels'][0])
  295. {
  296. return $this->getApiV3StudiosStudioChannelsAsyncWithHttpInfo($studio, $per_page, $relation, $collaborator, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType)
  297. ->then(
  298. function ($response) {
  299. return $response[0];
  300. }
  301. );
  302. }
  303. /**
  304. * Operation getApiV3StudiosStudioChannelsAsyncWithHttpInfo
  305. *
  306. * 列出 studio 的 channel
  307. *
  308. * @param string $studio 用户 uuid 或团队 uuid (required)
  309. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  310. * @param string|null $relation 关系 (optional, default to 'own')
  311. * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional)
  312. * @param string|null $search 按名字模糊匹配 (optional)
  313. * @param string|null $type channel 类型 (optional)
  314. * @param string|null $lang 语言 (optional)
  315. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  316. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  317. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  318. * @param string|null $dir 排序方向 (optional, default to 'desc')
  319. * @param int|null $page 页码 (optional, default to 1)
  320. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation
  321. *
  322. * @throws \InvalidArgumentException
  323. * @return \GuzzleHttp\Promise\PromiseInterface
  324. */
  325. public function getApiV3StudiosStudioChannelsAsyncWithHttpInfo($studio, $per_page = 20, $relation = 'own', $collaborator = null, $search = null, $type = null, $lang = null, $book = null, $para = null, $order = 'updated_at', $dir = 'desc', $page = 1, string $contentType = self::contentTypes['getApiV3StudiosStudioChannels'][0])
  326. {
  327. $returnType = '\WikipaliApi\Model\GetApiV3Channels200Response';
  328. $request = $this->getApiV3StudiosStudioChannelsRequest($studio, $per_page, $relation, $collaborator, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  329. return $this->client
  330. ->sendAsync($request, $this->createHttpClientOption())
  331. ->then(
  332. function ($response) use ($returnType) {
  333. if ($returnType === '\SplFileObject') {
  334. $content = $response->getBody(); //stream goes to serializer
  335. } else {
  336. $content = (string) $response->getBody();
  337. if ($returnType !== 'string') {
  338. $content = json_decode($content);
  339. }
  340. }
  341. return [
  342. ObjectSerializer::deserialize($content, $returnType, []),
  343. $response->getStatusCode(),
  344. $response->getHeaders()
  345. ];
  346. },
  347. function ($exception) {
  348. $response = $exception->getResponse();
  349. $statusCode = $response->getStatusCode();
  350. throw new ApiException(
  351. sprintf(
  352. '[%d] Error connecting to the API (%s)',
  353. $statusCode,
  354. $exception->getRequest()->getUri()
  355. ),
  356. $statusCode,
  357. $response->getHeaders(),
  358. (string) $response->getBody()
  359. );
  360. }
  361. );
  362. }
  363. /**
  364. * Create request for operation 'getApiV3StudiosStudioChannels'
  365. *
  366. * @param string $studio 用户 uuid 或团队 uuid (required)
  367. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  368. * @param string|null $relation 关系 (optional, default to 'own')
  369. * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional)
  370. * @param string|null $search 按名字模糊匹配 (optional)
  371. * @param string|null $type channel 类型 (optional)
  372. * @param string|null $lang 语言 (optional)
  373. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  374. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  375. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  376. * @param string|null $dir 排序方向 (optional, default to 'desc')
  377. * @param int|null $page 页码 (optional, default to 1)
  378. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation
  379. *
  380. * @throws \InvalidArgumentException
  381. * @return \GuzzleHttp\Psr7\Request
  382. */
  383. public function getApiV3StudiosStudioChannelsRequest($studio, $per_page = 20, $relation = 'own', $collaborator = null, $search = null, $type = null, $lang = null, $book = null, $para = null, $order = 'updated_at', $dir = 'desc', $page = 1, string $contentType = self::contentTypes['getApiV3StudiosStudioChannels'][0])
  384. {
  385. // verify the required parameter 'studio' is set
  386. if ($studio === null || (is_array($studio) && count($studio) === 0)) {
  387. throw new \InvalidArgumentException(
  388. 'Missing the required parameter $studio when calling getApiV3StudiosStudioChannels'
  389. );
  390. }
  391. $resourcePath = '/v3/studios/{studio}/channels';
  392. $formParams = [];
  393. $queryParams = [];
  394. $headerParams = [];
  395. $httpBody = '';
  396. $multipart = false;
  397. // query params
  398. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  399. $per_page,
  400. 'per_page', // param base name
  401. 'integer', // openApiType
  402. 'form', // style
  403. true, // explode
  404. false // required
  405. ) ?? []);
  406. // query params
  407. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  408. $relation,
  409. 'relation', // param base name
  410. 'string', // openApiType
  411. 'form', // style
  412. true, // explode
  413. false // required
  414. ) ?? []);
  415. // query params
  416. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  417. $collaborator,
  418. 'collaborator', // param base name
  419. 'string', // openApiType
  420. 'form', // style
  421. true, // explode
  422. false // required
  423. ) ?? []);
  424. // query params
  425. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  426. $search,
  427. 'search', // param base name
  428. 'string', // openApiType
  429. 'form', // style
  430. true, // explode
  431. false // required
  432. ) ?? []);
  433. // query params
  434. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  435. $type,
  436. 'type', // param base name
  437. 'string', // openApiType
  438. 'form', // style
  439. true, // explode
  440. false // required
  441. ) ?? []);
  442. // query params
  443. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  444. $lang,
  445. 'lang', // param base name
  446. 'string', // openApiType
  447. 'form', // style
  448. true, // explode
  449. false // required
  450. ) ?? []);
  451. // query params
  452. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  453. $book,
  454. 'book', // param base name
  455. 'integer', // openApiType
  456. 'form', // style
  457. true, // explode
  458. false // required
  459. ) ?? []);
  460. // query params
  461. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  462. $para,
  463. 'para', // param base name
  464. 'integer', // openApiType
  465. 'form', // style
  466. true, // explode
  467. false // required
  468. ) ?? []);
  469. // query params
  470. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  471. $order,
  472. 'order', // param base name
  473. 'string', // openApiType
  474. 'form', // style
  475. true, // explode
  476. false // required
  477. ) ?? []);
  478. // query params
  479. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  480. $dir,
  481. 'dir', // param base name
  482. 'string', // openApiType
  483. 'form', // style
  484. true, // explode
  485. false // required
  486. ) ?? []);
  487. // query params
  488. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  489. $page,
  490. 'page', // param base name
  491. 'integer', // openApiType
  492. 'form', // style
  493. true, // explode
  494. false // required
  495. ) ?? []);
  496. // path params
  497. if ($studio !== null) {
  498. $resourcePath = str_replace(
  499. '{studio}',
  500. ObjectSerializer::toPathValue($studio),
  501. $resourcePath
  502. );
  503. }
  504. $headers = $this->headerSelector->selectHeaders(
  505. ['application/json', 'application/problem+json', ],
  506. $contentType,
  507. $multipart
  508. );
  509. // for model (json/xml)
  510. if (count($formParams) > 0) {
  511. if ($multipart) {
  512. $multipartContents = [];
  513. foreach ($formParams as $formParamName => $formParamValue) {
  514. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  515. foreach ($formParamValueItems as $formParamValueItem) {
  516. $multipartContents[] = [
  517. 'name' => $formParamName,
  518. 'contents' => $formParamValueItem
  519. ];
  520. }
  521. }
  522. // for HTTP post (form)
  523. $httpBody = new MultipartStream($multipartContents);
  524. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  525. # if Content-Type contains "application/json", json_encode the form parameters
  526. try {
  527. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  528. } catch (\JsonException $e) {
  529. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  530. }
  531. } else {
  532. // for HTTP post (form)
  533. $httpBody = ObjectSerializer::buildQuery($formParams);
  534. }
  535. }
  536. // this endpoint requires Bearer authentication (access token)
  537. if (!empty($this->config->getAccessToken())) {
  538. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  539. }
  540. $defaultHeaders = [];
  541. if ($this->config->getUserAgent()) {
  542. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  543. }
  544. $headers = array_merge(
  545. $defaultHeaders,
  546. $headerParams,
  547. $headers
  548. );
  549. $operationHost = $this->config->getHost();
  550. $query = ObjectSerializer::buildQuery($queryParams);
  551. return new Request(
  552. 'GET',
  553. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  554. $headers,
  555. $httpBody
  556. );
  557. }
  558. /**
  559. * Operation postApiV3StudiosStudioChannels
  560. *
  561. * 在 studio 名下建 channel
  562. *
  563. * @param string $studio 用户 uuid 或团队 uuid (required)
  564. * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request post_api_v3_studios_studio_channels_request (required)
  565. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation
  566. *
  567. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  568. * @throws \InvalidArgumentException
  569. * @return \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  570. */
  571. public function postApiV3StudiosStudioChannels($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0])
  572. {
  573. list($response) = $this->postApiV3StudiosStudioChannelsWithHttpInfo($studio, $post_api_v3_studios_studio_channels_request, $contentType);
  574. return $response;
  575. }
  576. /**
  577. * Operation postApiV3StudiosStudioChannelsWithHttpInfo
  578. *
  579. * 在 studio 名下建 channel
  580. *
  581. * @param string $studio 用户 uuid 或团队 uuid (required)
  582. * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request (required)
  583. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation
  584. *
  585. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  586. * @throws \InvalidArgumentException
  587. * @return array of \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  588. */
  589. public function postApiV3StudiosStudioChannelsWithHttpInfo($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0])
  590. {
  591. $request = $this->postApiV3StudiosStudioChannelsRequest($studio, $post_api_v3_studios_studio_channels_request, $contentType);
  592. try {
  593. $options = $this->createHttpClientOption();
  594. try {
  595. $response = $this->client->send($request, $options);
  596. } catch (RequestException $e) {
  597. throw new ApiException(
  598. "[{$e->getCode()}] {$e->getMessage()}",
  599. (int) $e->getCode(),
  600. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  601. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  602. );
  603. } catch (ConnectException $e) {
  604. throw new ApiException(
  605. "[{$e->getCode()}] {$e->getMessage()}",
  606. (int) $e->getCode(),
  607. null,
  608. null
  609. );
  610. }
  611. $statusCode = $response->getStatusCode();
  612. switch($statusCode) {
  613. case 200:
  614. return $this->handleResponseWithDataType(
  615. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  616. $request,
  617. $response,
  618. );
  619. case 201:
  620. return $this->handleResponseWithDataType(
  621. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  622. $request,
  623. $response,
  624. );
  625. case 401:
  626. return $this->handleResponseWithDataType(
  627. '\WikipaliApi\Model\ProblemDetails',
  628. $request,
  629. $response,
  630. );
  631. case 403:
  632. return $this->handleResponseWithDataType(
  633. '\WikipaliApi\Model\ProblemDetails',
  634. $request,
  635. $response,
  636. );
  637. case 422:
  638. return $this->handleResponseWithDataType(
  639. '\WikipaliApi\Model\ProblemDetails',
  640. $request,
  641. $response,
  642. );
  643. }
  644. if ($statusCode < 200 || $statusCode > 299) {
  645. throw new ApiException(
  646. sprintf(
  647. '[%d] Error connecting to the API (%s)',
  648. $statusCode,
  649. (string) $request->getUri()
  650. ),
  651. $statusCode,
  652. $response->getHeaders(),
  653. (string) $response->getBody()
  654. );
  655. }
  656. return $this->handleResponseWithDataType(
  657. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  658. $request,
  659. $response,
  660. );
  661. } catch (ApiException $e) {
  662. switch ($e->getCode()) {
  663. case 200:
  664. $data = ObjectSerializer::deserialize(
  665. $e->getResponseBody(),
  666. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  667. $e->getResponseHeaders()
  668. );
  669. $e->setResponseObject($data);
  670. throw $e;
  671. case 201:
  672. $data = ObjectSerializer::deserialize(
  673. $e->getResponseBody(),
  674. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  675. $e->getResponseHeaders()
  676. );
  677. $e->setResponseObject($data);
  678. throw $e;
  679. case 401:
  680. $data = ObjectSerializer::deserialize(
  681. $e->getResponseBody(),
  682. '\WikipaliApi\Model\ProblemDetails',
  683. $e->getResponseHeaders()
  684. );
  685. $e->setResponseObject($data);
  686. throw $e;
  687. case 403:
  688. $data = ObjectSerializer::deserialize(
  689. $e->getResponseBody(),
  690. '\WikipaliApi\Model\ProblemDetails',
  691. $e->getResponseHeaders()
  692. );
  693. $e->setResponseObject($data);
  694. throw $e;
  695. case 422:
  696. $data = ObjectSerializer::deserialize(
  697. $e->getResponseBody(),
  698. '\WikipaliApi\Model\ProblemDetails',
  699. $e->getResponseHeaders()
  700. );
  701. $e->setResponseObject($data);
  702. throw $e;
  703. }
  704. throw $e;
  705. }
  706. }
  707. /**
  708. * Operation postApiV3StudiosStudioChannelsAsync
  709. *
  710. * 在 studio 名下建 channel
  711. *
  712. * @param string $studio 用户 uuid 或团队 uuid (required)
  713. * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request (required)
  714. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation
  715. *
  716. * @throws \InvalidArgumentException
  717. * @return \GuzzleHttp\Promise\PromiseInterface
  718. */
  719. public function postApiV3StudiosStudioChannelsAsync($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0])
  720. {
  721. return $this->postApiV3StudiosStudioChannelsAsyncWithHttpInfo($studio, $post_api_v3_studios_studio_channels_request, $contentType)
  722. ->then(
  723. function ($response) {
  724. return $response[0];
  725. }
  726. );
  727. }
  728. /**
  729. * Operation postApiV3StudiosStudioChannelsAsyncWithHttpInfo
  730. *
  731. * 在 studio 名下建 channel
  732. *
  733. * @param string $studio 用户 uuid 或团队 uuid (required)
  734. * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request (required)
  735. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation
  736. *
  737. * @throws \InvalidArgumentException
  738. * @return \GuzzleHttp\Promise\PromiseInterface
  739. */
  740. public function postApiV3StudiosStudioChannelsAsyncWithHttpInfo($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0])
  741. {
  742. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response';
  743. $request = $this->postApiV3StudiosStudioChannelsRequest($studio, $post_api_v3_studios_studio_channels_request, $contentType);
  744. return $this->client
  745. ->sendAsync($request, $this->createHttpClientOption())
  746. ->then(
  747. function ($response) use ($returnType) {
  748. if ($returnType === '\SplFileObject') {
  749. $content = $response->getBody(); //stream goes to serializer
  750. } else {
  751. $content = (string) $response->getBody();
  752. if ($returnType !== 'string') {
  753. $content = json_decode($content);
  754. }
  755. }
  756. return [
  757. ObjectSerializer::deserialize($content, $returnType, []),
  758. $response->getStatusCode(),
  759. $response->getHeaders()
  760. ];
  761. },
  762. function ($exception) {
  763. $response = $exception->getResponse();
  764. $statusCode = $response->getStatusCode();
  765. throw new ApiException(
  766. sprintf(
  767. '[%d] Error connecting to the API (%s)',
  768. $statusCode,
  769. $exception->getRequest()->getUri()
  770. ),
  771. $statusCode,
  772. $response->getHeaders(),
  773. (string) $response->getBody()
  774. );
  775. }
  776. );
  777. }
  778. /**
  779. * Create request for operation 'postApiV3StudiosStudioChannels'
  780. *
  781. * @param string $studio 用户 uuid 或团队 uuid (required)
  782. * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request (required)
  783. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation
  784. *
  785. * @throws \InvalidArgumentException
  786. * @return \GuzzleHttp\Psr7\Request
  787. */
  788. public function postApiV3StudiosStudioChannelsRequest($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0])
  789. {
  790. // verify the required parameter 'studio' is set
  791. if ($studio === null || (is_array($studio) && count($studio) === 0)) {
  792. throw new \InvalidArgumentException(
  793. 'Missing the required parameter $studio when calling postApiV3StudiosStudioChannels'
  794. );
  795. }
  796. // verify the required parameter 'post_api_v3_studios_studio_channels_request' is set
  797. if ($post_api_v3_studios_studio_channels_request === null || (is_array($post_api_v3_studios_studio_channels_request) && count($post_api_v3_studios_studio_channels_request) === 0)) {
  798. throw new \InvalidArgumentException(
  799. 'Missing the required parameter $post_api_v3_studios_studio_channels_request when calling postApiV3StudiosStudioChannels'
  800. );
  801. }
  802. $resourcePath = '/v3/studios/{studio}/channels';
  803. $formParams = [];
  804. $queryParams = [];
  805. $headerParams = [];
  806. $httpBody = '';
  807. $multipart = false;
  808. // path params
  809. if ($studio !== null) {
  810. $resourcePath = str_replace(
  811. '{studio}',
  812. ObjectSerializer::toPathValue($studio),
  813. $resourcePath
  814. );
  815. }
  816. $headers = $this->headerSelector->selectHeaders(
  817. ['application/json', 'application/problem+json', ],
  818. $contentType,
  819. $multipart
  820. );
  821. // for model (json/xml)
  822. if (isset($post_api_v3_studios_studio_channels_request)) {
  823. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  824. # if Content-Type contains "application/json", json_encode the body
  825. try {
  826. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_studios_studio_channels_request), JSON_THROW_ON_ERROR);
  827. } catch (\JsonException $e) {
  828. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  829. }
  830. } else {
  831. $httpBody = $post_api_v3_studios_studio_channels_request;
  832. }
  833. } elseif (count($formParams) > 0) {
  834. if ($multipart) {
  835. $multipartContents = [];
  836. foreach ($formParams as $formParamName => $formParamValue) {
  837. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  838. foreach ($formParamValueItems as $formParamValueItem) {
  839. $multipartContents[] = [
  840. 'name' => $formParamName,
  841. 'contents' => $formParamValueItem
  842. ];
  843. }
  844. }
  845. // for HTTP post (form)
  846. $httpBody = new MultipartStream($multipartContents);
  847. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  848. # if Content-Type contains "application/json", json_encode the form parameters
  849. try {
  850. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  851. } catch (\JsonException $e) {
  852. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  853. }
  854. } else {
  855. // for HTTP post (form)
  856. $httpBody = ObjectSerializer::buildQuery($formParams);
  857. }
  858. }
  859. // this endpoint requires Bearer authentication (access token)
  860. if (!empty($this->config->getAccessToken())) {
  861. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  862. }
  863. $defaultHeaders = [];
  864. if ($this->config->getUserAgent()) {
  865. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  866. }
  867. $headers = array_merge(
  868. $defaultHeaders,
  869. $headerParams,
  870. $headers
  871. );
  872. $operationHost = $this->config->getHost();
  873. $query = ObjectSerializer::buildQuery($queryParams);
  874. return new Request(
  875. 'POST',
  876. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  877. $headers,
  878. $httpBody
  879. );
  880. }
  881. /**
  882. * Create http client option
  883. *
  884. * @throws \RuntimeException on file opening failure
  885. * @return array of http client options
  886. */
  887. protected function createHttpClientOption()
  888. {
  889. $options = [];
  890. if ($this->config->getDebug()) {
  891. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  892. if (!$options[RequestOptions::DEBUG]) {
  893. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  894. }
  895. }
  896. if ($this->config->getCertFile()) {
  897. $options[RequestOptions::CERT] = $this->config->getCertFile();
  898. }
  899. if ($this->config->getKeyFile()) {
  900. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  901. }
  902. return $options;
  903. }
  904. private function handleResponseWithDataType(
  905. string $dataType,
  906. RequestInterface $request,
  907. ResponseInterface $response
  908. ): array {
  909. if ($dataType === '\SplFileObject') {
  910. $content = $response->getBody(); //stream goes to serializer
  911. } else {
  912. $content = (string) $response->getBody();
  913. if ($dataType !== 'string') {
  914. try {
  915. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  916. } catch (\JsonException $exception) {
  917. throw new ApiException(
  918. sprintf(
  919. 'Error JSON decoding server response (%s)',
  920. $request->getUri()
  921. ),
  922. $response->getStatusCode(),
  923. $response->getHeaders(),
  924. $content
  925. );
  926. }
  927. }
  928. }
  929. return [
  930. ObjectSerializer::deserialize($content, $dataType, []),
  931. $response->getStatusCode(),
  932. $response->getHeaders()
  933. ];
  934. }
  935. private function responseWithinRangeCode(
  936. string $rangeCode,
  937. int $statusCode
  938. ): bool {
  939. $left = (int) ($rangeCode[0].'00');
  940. $right = (int) ($rangeCode[0].'99');
  941. return $statusCode >= $left && $statusCode <= $right;
  942. }
  943. }