StudiosApi.php 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194
  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. 'getApiV3StudiosStudioTerms' => [
  72. 'application/json',
  73. ],
  74. 'postApiV3StudiosStudioChannels' => [
  75. 'application/json',
  76. ],
  77. 'postApiV3StudiosStudioTerms' => [
  78. 'application/json',
  79. ],
  80. 'postApiV3StudiosStudioTermsImports' => [
  81. 'multipart/form-data',
  82. ],
  83. ];
  84. /**
  85. * @param ClientInterface $client
  86. * @param Configuration $config
  87. * @param HeaderSelector $selector
  88. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  89. */
  90. public function __construct(
  91. ?ClientInterface $client = null,
  92. ?Configuration $config = null,
  93. ?HeaderSelector $selector = null,
  94. int $hostIndex = 0
  95. ) {
  96. $this->client = $client ?: new Client();
  97. $this->config = $config ?: Configuration::getDefaultConfiguration();
  98. $this->headerSelector = $selector ?: new HeaderSelector();
  99. $this->hostIndex = $hostIndex;
  100. }
  101. /**
  102. * Set the host index
  103. *
  104. * @param int $hostIndex Host index (required)
  105. */
  106. public function setHostIndex($hostIndex): void
  107. {
  108. $this->hostIndex = $hostIndex;
  109. }
  110. /**
  111. * Get the host index
  112. *
  113. * @return int Host index
  114. */
  115. public function getHostIndex()
  116. {
  117. return $this->hostIndex;
  118. }
  119. /**
  120. * @return Configuration
  121. */
  122. public function getConfig()
  123. {
  124. return $this->config;
  125. }
  126. /**
  127. * Operation getApiV3StudiosStudioChannels
  128. *
  129. * 列出 studio 的 channel
  130. *
  131. * @param string $studio 用户 uuid 或团队 uuid (required)
  132. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  133. * @param string|null $relation 关系 (optional, default to 'own')
  134. * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional)
  135. * @param string|null $search 按名字模糊匹配 (optional)
  136. * @param string|null $type channel 类型 (optional)
  137. * @param string|null $lang 语言 (optional)
  138. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  139. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  140. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  141. * @param string|null $dir 排序方向 (optional, default to 'desc')
  142. * @param int|null $page 页码 (optional, default to 1)
  143. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation
  144. *
  145. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  146. * @throws \InvalidArgumentException
  147. * @return \WikipaliApi\Model\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  148. */
  149. 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])
  150. {
  151. list($response) = $this->getApiV3StudiosStudioChannelsWithHttpInfo($studio, $per_page, $relation, $collaborator, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  152. return $response;
  153. }
  154. /**
  155. * Operation getApiV3StudiosStudioChannelsWithHttpInfo
  156. *
  157. * 列出 studio 的 channel
  158. *
  159. * @param string $studio 用户 uuid 或团队 uuid (required)
  160. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  161. * @param string|null $relation 关系 (optional, default to 'own')
  162. * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional)
  163. * @param string|null $search 按名字模糊匹配 (optional)
  164. * @param string|null $type channel 类型 (optional)
  165. * @param string|null $lang 语言 (optional)
  166. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  167. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  168. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  169. * @param string|null $dir 排序方向 (optional, default to 'desc')
  170. * @param int|null $page 页码 (optional, default to 1)
  171. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation
  172. *
  173. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  174. * @throws \InvalidArgumentException
  175. * @return array of \WikipaliApi\Model\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  176. */
  177. 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])
  178. {
  179. $request = $this->getApiV3StudiosStudioChannelsRequest($studio, $per_page, $relation, $collaborator, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  180. try {
  181. $options = $this->createHttpClientOption();
  182. try {
  183. $response = $this->client->send($request, $options);
  184. } catch (RequestException $e) {
  185. throw new ApiException(
  186. "[{$e->getCode()}] {$e->getMessage()}",
  187. (int) $e->getCode(),
  188. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  189. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  190. );
  191. } catch (ConnectException $e) {
  192. throw new ApiException(
  193. "[{$e->getCode()}] {$e->getMessage()}",
  194. (int) $e->getCode(),
  195. null,
  196. null
  197. );
  198. }
  199. $statusCode = $response->getStatusCode();
  200. switch($statusCode) {
  201. case 200:
  202. return $this->handleResponseWithDataType(
  203. '\WikipaliApi\Model\GetApiV3Channels200Response',
  204. $request,
  205. $response,
  206. );
  207. case 401:
  208. return $this->handleResponseWithDataType(
  209. '\WikipaliApi\Model\ProblemDetails',
  210. $request,
  211. $response,
  212. );
  213. case 403:
  214. return $this->handleResponseWithDataType(
  215. '\WikipaliApi\Model\ProblemDetails',
  216. $request,
  217. $response,
  218. );
  219. case 422:
  220. return $this->handleResponseWithDataType(
  221. '\WikipaliApi\Model\ProblemDetails',
  222. $request,
  223. $response,
  224. );
  225. }
  226. if ($statusCode < 200 || $statusCode > 299) {
  227. throw new ApiException(
  228. sprintf(
  229. '[%d] Error connecting to the API (%s)',
  230. $statusCode,
  231. (string) $request->getUri()
  232. ),
  233. $statusCode,
  234. $response->getHeaders(),
  235. (string) $response->getBody()
  236. );
  237. }
  238. return $this->handleResponseWithDataType(
  239. '\WikipaliApi\Model\GetApiV3Channels200Response',
  240. $request,
  241. $response,
  242. );
  243. } catch (ApiException $e) {
  244. switch ($e->getCode()) {
  245. case 200:
  246. $data = ObjectSerializer::deserialize(
  247. $e->getResponseBody(),
  248. '\WikipaliApi\Model\GetApiV3Channels200Response',
  249. $e->getResponseHeaders()
  250. );
  251. $e->setResponseObject($data);
  252. throw $e;
  253. case 401:
  254. $data = ObjectSerializer::deserialize(
  255. $e->getResponseBody(),
  256. '\WikipaliApi\Model\ProblemDetails',
  257. $e->getResponseHeaders()
  258. );
  259. $e->setResponseObject($data);
  260. throw $e;
  261. case 403:
  262. $data = ObjectSerializer::deserialize(
  263. $e->getResponseBody(),
  264. '\WikipaliApi\Model\ProblemDetails',
  265. $e->getResponseHeaders()
  266. );
  267. $e->setResponseObject($data);
  268. throw $e;
  269. case 422:
  270. $data = ObjectSerializer::deserialize(
  271. $e->getResponseBody(),
  272. '\WikipaliApi\Model\ProblemDetails',
  273. $e->getResponseHeaders()
  274. );
  275. $e->setResponseObject($data);
  276. throw $e;
  277. }
  278. throw $e;
  279. }
  280. }
  281. /**
  282. * Operation getApiV3StudiosStudioChannelsAsync
  283. *
  284. * 列出 studio 的 channel
  285. *
  286. * @param string $studio 用户 uuid 或团队 uuid (required)
  287. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  288. * @param string|null $relation 关系 (optional, default to 'own')
  289. * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional)
  290. * @param string|null $search 按名字模糊匹配 (optional)
  291. * @param string|null $type channel 类型 (optional)
  292. * @param string|null $lang 语言 (optional)
  293. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  294. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  295. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  296. * @param string|null $dir 排序方向 (optional, default to 'desc')
  297. * @param int|null $page 页码 (optional, default to 1)
  298. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation
  299. *
  300. * @throws \InvalidArgumentException
  301. * @return \GuzzleHttp\Promise\PromiseInterface
  302. */
  303. 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])
  304. {
  305. return $this->getApiV3StudiosStudioChannelsAsyncWithHttpInfo($studio, $per_page, $relation, $collaborator, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType)
  306. ->then(
  307. function ($response) {
  308. return $response[0];
  309. }
  310. );
  311. }
  312. /**
  313. * Operation getApiV3StudiosStudioChannelsAsyncWithHttpInfo
  314. *
  315. * 列出 studio 的 channel
  316. *
  317. * @param string $studio 用户 uuid 或团队 uuid (required)
  318. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  319. * @param string|null $relation 关系 (optional, default to 'own')
  320. * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional)
  321. * @param string|null $search 按名字模糊匹配 (optional)
  322. * @param string|null $type channel 类型 (optional)
  323. * @param string|null $lang 语言 (optional)
  324. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  325. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  326. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  327. * @param string|null $dir 排序方向 (optional, default to 'desc')
  328. * @param int|null $page 页码 (optional, default to 1)
  329. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation
  330. *
  331. * @throws \InvalidArgumentException
  332. * @return \GuzzleHttp\Promise\PromiseInterface
  333. */
  334. 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])
  335. {
  336. $returnType = '\WikipaliApi\Model\GetApiV3Channels200Response';
  337. $request = $this->getApiV3StudiosStudioChannelsRequest($studio, $per_page, $relation, $collaborator, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  338. return $this->client
  339. ->sendAsync($request, $this->createHttpClientOption())
  340. ->then(
  341. function ($response) use ($returnType) {
  342. if ($returnType === '\SplFileObject') {
  343. $content = $response->getBody(); //stream goes to serializer
  344. } else {
  345. $content = (string) $response->getBody();
  346. if ($returnType !== 'string') {
  347. $content = json_decode($content);
  348. }
  349. }
  350. return [
  351. ObjectSerializer::deserialize($content, $returnType, []),
  352. $response->getStatusCode(),
  353. $response->getHeaders()
  354. ];
  355. },
  356. function ($exception) {
  357. $response = $exception->getResponse();
  358. $statusCode = $response->getStatusCode();
  359. throw new ApiException(
  360. sprintf(
  361. '[%d] Error connecting to the API (%s)',
  362. $statusCode,
  363. $exception->getRequest()->getUri()
  364. ),
  365. $statusCode,
  366. $response->getHeaders(),
  367. (string) $response->getBody()
  368. );
  369. }
  370. );
  371. }
  372. /**
  373. * Create request for operation 'getApiV3StudiosStudioChannels'
  374. *
  375. * @param string $studio 用户 uuid 或团队 uuid (required)
  376. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  377. * @param string|null $relation 关系 (optional, default to 'own')
  378. * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional)
  379. * @param string|null $search 按名字模糊匹配 (optional)
  380. * @param string|null $type channel 类型 (optional)
  381. * @param string|null $lang 语言 (optional)
  382. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  383. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  384. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  385. * @param string|null $dir 排序方向 (optional, default to 'desc')
  386. * @param int|null $page 页码 (optional, default to 1)
  387. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation
  388. *
  389. * @throws \InvalidArgumentException
  390. * @return \GuzzleHttp\Psr7\Request
  391. */
  392. 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])
  393. {
  394. // verify the required parameter 'studio' is set
  395. if ($studio === null || (is_array($studio) && count($studio) === 0)) {
  396. throw new \InvalidArgumentException(
  397. 'Missing the required parameter $studio when calling getApiV3StudiosStudioChannels'
  398. );
  399. }
  400. $resourcePath = '/v3/studios/{studio}/channels';
  401. $formParams = [];
  402. $queryParams = [];
  403. $headerParams = [];
  404. $httpBody = '';
  405. $multipart = false;
  406. // query params
  407. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  408. $per_page,
  409. 'per_page', // param base name
  410. 'integer', // openApiType
  411. 'form', // style
  412. true, // explode
  413. false // required
  414. ) ?? []);
  415. // query params
  416. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  417. $relation,
  418. 'relation', // 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. $collaborator,
  427. 'collaborator', // 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. $search,
  436. 'search', // 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. $type,
  445. 'type', // 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. $lang,
  454. 'lang', // param base name
  455. 'string', // openApiType
  456. 'form', // style
  457. true, // explode
  458. false // required
  459. ) ?? []);
  460. // query params
  461. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  462. $book,
  463. 'book', // 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. $para,
  472. 'para', // param base name
  473. 'integer', // openApiType
  474. 'form', // style
  475. true, // explode
  476. false // required
  477. ) ?? []);
  478. // query params
  479. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  480. $order,
  481. 'order', // 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. $dir,
  490. 'dir', // param base name
  491. 'string', // openApiType
  492. 'form', // style
  493. true, // explode
  494. false // required
  495. ) ?? []);
  496. // query params
  497. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  498. $page,
  499. 'page', // param base name
  500. 'integer', // openApiType
  501. 'form', // style
  502. true, // explode
  503. false // required
  504. ) ?? []);
  505. // path params
  506. if ($studio !== null) {
  507. $resourcePath = str_replace(
  508. '{studio}',
  509. ObjectSerializer::toPathValue($studio),
  510. $resourcePath
  511. );
  512. }
  513. $headers = $this->headerSelector->selectHeaders(
  514. ['application/json', 'application/problem+json', ],
  515. $contentType,
  516. $multipart
  517. );
  518. // for model (json/xml)
  519. if (count($formParams) > 0) {
  520. if ($multipart) {
  521. $multipartContents = [];
  522. foreach ($formParams as $formParamName => $formParamValue) {
  523. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  524. foreach ($formParamValueItems as $formParamValueItem) {
  525. $multipartContents[] = [
  526. 'name' => $formParamName,
  527. 'contents' => $formParamValueItem
  528. ];
  529. }
  530. }
  531. // for HTTP post (form)
  532. $httpBody = new MultipartStream($multipartContents);
  533. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  534. # if Content-Type contains "application/json", json_encode the form parameters
  535. try {
  536. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  537. } catch (\JsonException $e) {
  538. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  539. }
  540. } else {
  541. // for HTTP post (form)
  542. $httpBody = ObjectSerializer::buildQuery($formParams);
  543. }
  544. }
  545. // this endpoint requires Bearer authentication (access token)
  546. if (!empty($this->config->getAccessToken())) {
  547. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  548. }
  549. $defaultHeaders = [];
  550. if ($this->config->getUserAgent()) {
  551. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  552. }
  553. $headers = array_merge(
  554. $defaultHeaders,
  555. $headerParams,
  556. $headers
  557. );
  558. $operationHost = $this->config->getHost();
  559. $query = ObjectSerializer::buildQuery($queryParams);
  560. return new Request(
  561. 'GET',
  562. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  563. $headers,
  564. $httpBody
  565. );
  566. }
  567. /**
  568. * Operation getApiV3StudiosStudioTerms
  569. *
  570. * studio 的术语列表
  571. *
  572. * @param string $studio 用户或团队的 uuid (required)
  573. * @param bool|null $general 只要 studio 级术语(不属于任何 channel) (optional)
  574. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  575. * @param string|null $search 按词、释义搜索 (optional)
  576. * @param string|null $quality 质量;pending 含未评级的 (optional)
  577. * @param string|null $category 百科分类 (optional)
  578. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  579. * @param string|null $dir 排序方向 (optional)
  580. * @param int|null $page 页码 (optional)
  581. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioTerms'] to see the possible values for this operation
  582. *
  583. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  584. * @throws \InvalidArgumentException
  585. * @return \WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  586. */
  587. public function getApiV3StudiosStudioTerms($studio, $general = null, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3StudiosStudioTerms'][0])
  588. {
  589. list($response) = $this->getApiV3StudiosStudioTermsWithHttpInfo($studio, $general, $per_page, $search, $quality, $category, $order, $dir, $page, $contentType);
  590. return $response;
  591. }
  592. /**
  593. * Operation getApiV3StudiosStudioTermsWithHttpInfo
  594. *
  595. * studio 的术语列表
  596. *
  597. * @param string $studio 用户或团队的 uuid (required)
  598. * @param bool|null $general 只要 studio 级术语(不属于任何 channel) (optional)
  599. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  600. * @param string|null $search 按词、释义搜索 (optional)
  601. * @param string|null $quality 质量;pending 含未评级的 (optional)
  602. * @param string|null $category 百科分类 (optional)
  603. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  604. * @param string|null $dir 排序方向 (optional)
  605. * @param int|null $page 页码 (optional)
  606. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioTerms'] to see the possible values for this operation
  607. *
  608. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  609. * @throws \InvalidArgumentException
  610. * @return array of \WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  611. */
  612. public function getApiV3StudiosStudioTermsWithHttpInfo($studio, $general = null, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3StudiosStudioTerms'][0])
  613. {
  614. $request = $this->getApiV3StudiosStudioTermsRequest($studio, $general, $per_page, $search, $quality, $category, $order, $dir, $page, $contentType);
  615. try {
  616. $options = $this->createHttpClientOption();
  617. try {
  618. $response = $this->client->send($request, $options);
  619. } catch (RequestException $e) {
  620. throw new ApiException(
  621. "[{$e->getCode()}] {$e->getMessage()}",
  622. (int) $e->getCode(),
  623. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  624. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  625. );
  626. } catch (ConnectException $e) {
  627. throw new ApiException(
  628. "[{$e->getCode()}] {$e->getMessage()}",
  629. (int) $e->getCode(),
  630. null,
  631. null
  632. );
  633. }
  634. $statusCode = $response->getStatusCode();
  635. switch($statusCode) {
  636. case 200:
  637. return $this->handleResponseWithDataType(
  638. '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response',
  639. $request,
  640. $response,
  641. );
  642. case 401:
  643. return $this->handleResponseWithDataType(
  644. '\WikipaliApi\Model\ProblemDetails',
  645. $request,
  646. $response,
  647. );
  648. case 403:
  649. return $this->handleResponseWithDataType(
  650. '\WikipaliApi\Model\ProblemDetails',
  651. $request,
  652. $response,
  653. );
  654. case 422:
  655. return $this->handleResponseWithDataType(
  656. '\WikipaliApi\Model\ProblemDetails',
  657. $request,
  658. $response,
  659. );
  660. }
  661. if ($statusCode < 200 || $statusCode > 299) {
  662. throw new ApiException(
  663. sprintf(
  664. '[%d] Error connecting to the API (%s)',
  665. $statusCode,
  666. (string) $request->getUri()
  667. ),
  668. $statusCode,
  669. $response->getHeaders(),
  670. (string) $response->getBody()
  671. );
  672. }
  673. return $this->handleResponseWithDataType(
  674. '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response',
  675. $request,
  676. $response,
  677. );
  678. } catch (ApiException $e) {
  679. switch ($e->getCode()) {
  680. case 200:
  681. $data = ObjectSerializer::deserialize(
  682. $e->getResponseBody(),
  683. '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response',
  684. $e->getResponseHeaders()
  685. );
  686. $e->setResponseObject($data);
  687. throw $e;
  688. case 401:
  689. $data = ObjectSerializer::deserialize(
  690. $e->getResponseBody(),
  691. '\WikipaliApi\Model\ProblemDetails',
  692. $e->getResponseHeaders()
  693. );
  694. $e->setResponseObject($data);
  695. throw $e;
  696. case 403:
  697. $data = ObjectSerializer::deserialize(
  698. $e->getResponseBody(),
  699. '\WikipaliApi\Model\ProblemDetails',
  700. $e->getResponseHeaders()
  701. );
  702. $e->setResponseObject($data);
  703. throw $e;
  704. case 422:
  705. $data = ObjectSerializer::deserialize(
  706. $e->getResponseBody(),
  707. '\WikipaliApi\Model\ProblemDetails',
  708. $e->getResponseHeaders()
  709. );
  710. $e->setResponseObject($data);
  711. throw $e;
  712. }
  713. throw $e;
  714. }
  715. }
  716. /**
  717. * Operation getApiV3StudiosStudioTermsAsync
  718. *
  719. * studio 的术语列表
  720. *
  721. * @param string $studio 用户或团队的 uuid (required)
  722. * @param bool|null $general 只要 studio 级术语(不属于任何 channel) (optional)
  723. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  724. * @param string|null $search 按词、释义搜索 (optional)
  725. * @param string|null $quality 质量;pending 含未评级的 (optional)
  726. * @param string|null $category 百科分类 (optional)
  727. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  728. * @param string|null $dir 排序方向 (optional)
  729. * @param int|null $page 页码 (optional)
  730. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioTerms'] to see the possible values for this operation
  731. *
  732. * @throws \InvalidArgumentException
  733. * @return \GuzzleHttp\Promise\PromiseInterface
  734. */
  735. public function getApiV3StudiosStudioTermsAsync($studio, $general = null, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3StudiosStudioTerms'][0])
  736. {
  737. return $this->getApiV3StudiosStudioTermsAsyncWithHttpInfo($studio, $general, $per_page, $search, $quality, $category, $order, $dir, $page, $contentType)
  738. ->then(
  739. function ($response) {
  740. return $response[0];
  741. }
  742. );
  743. }
  744. /**
  745. * Operation getApiV3StudiosStudioTermsAsyncWithHttpInfo
  746. *
  747. * studio 的术语列表
  748. *
  749. * @param string $studio 用户或团队的 uuid (required)
  750. * @param bool|null $general 只要 studio 级术语(不属于任何 channel) (optional)
  751. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  752. * @param string|null $search 按词、释义搜索 (optional)
  753. * @param string|null $quality 质量;pending 含未评级的 (optional)
  754. * @param string|null $category 百科分类 (optional)
  755. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  756. * @param string|null $dir 排序方向 (optional)
  757. * @param int|null $page 页码 (optional)
  758. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioTerms'] to see the possible values for this operation
  759. *
  760. * @throws \InvalidArgumentException
  761. * @return \GuzzleHttp\Promise\PromiseInterface
  762. */
  763. public function getApiV3StudiosStudioTermsAsyncWithHttpInfo($studio, $general = null, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3StudiosStudioTerms'][0])
  764. {
  765. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response';
  766. $request = $this->getApiV3StudiosStudioTermsRequest($studio, $general, $per_page, $search, $quality, $category, $order, $dir, $page, $contentType);
  767. return $this->client
  768. ->sendAsync($request, $this->createHttpClientOption())
  769. ->then(
  770. function ($response) use ($returnType) {
  771. if ($returnType === '\SplFileObject') {
  772. $content = $response->getBody(); //stream goes to serializer
  773. } else {
  774. $content = (string) $response->getBody();
  775. if ($returnType !== 'string') {
  776. $content = json_decode($content);
  777. }
  778. }
  779. return [
  780. ObjectSerializer::deserialize($content, $returnType, []),
  781. $response->getStatusCode(),
  782. $response->getHeaders()
  783. ];
  784. },
  785. function ($exception) {
  786. $response = $exception->getResponse();
  787. $statusCode = $response->getStatusCode();
  788. throw new ApiException(
  789. sprintf(
  790. '[%d] Error connecting to the API (%s)',
  791. $statusCode,
  792. $exception->getRequest()->getUri()
  793. ),
  794. $statusCode,
  795. $response->getHeaders(),
  796. (string) $response->getBody()
  797. );
  798. }
  799. );
  800. }
  801. /**
  802. * Create request for operation 'getApiV3StudiosStudioTerms'
  803. *
  804. * @param string $studio 用户或团队的 uuid (required)
  805. * @param bool|null $general 只要 studio 级术语(不属于任何 channel) (optional)
  806. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  807. * @param string|null $search 按词、释义搜索 (optional)
  808. * @param string|null $quality 质量;pending 含未评级的 (optional)
  809. * @param string|null $category 百科分类 (optional)
  810. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  811. * @param string|null $dir 排序方向 (optional)
  812. * @param int|null $page 页码 (optional)
  813. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioTerms'] to see the possible values for this operation
  814. *
  815. * @throws \InvalidArgumentException
  816. * @return \GuzzleHttp\Psr7\Request
  817. */
  818. public function getApiV3StudiosStudioTermsRequest($studio, $general = null, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3StudiosStudioTerms'][0])
  819. {
  820. // verify the required parameter 'studio' is set
  821. if ($studio === null || (is_array($studio) && count($studio) === 0)) {
  822. throw new \InvalidArgumentException(
  823. 'Missing the required parameter $studio when calling getApiV3StudiosStudioTerms'
  824. );
  825. }
  826. $resourcePath = '/v3/studios/{studio}/terms';
  827. $formParams = [];
  828. $queryParams = [];
  829. $headerParams = [];
  830. $httpBody = '';
  831. $multipart = false;
  832. // query params
  833. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  834. $general,
  835. 'general', // param base name
  836. 'boolean', // openApiType
  837. 'form', // style
  838. true, // explode
  839. false // required
  840. ) ?? []);
  841. // query params
  842. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  843. $per_page,
  844. 'per_page', // param base name
  845. 'integer', // openApiType
  846. 'form', // style
  847. true, // explode
  848. false // required
  849. ) ?? []);
  850. // query params
  851. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  852. $search,
  853. 'search', // param base name
  854. 'string', // openApiType
  855. 'form', // style
  856. true, // explode
  857. false // required
  858. ) ?? []);
  859. // query params
  860. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  861. $quality,
  862. 'quality', // param base name
  863. 'string', // openApiType
  864. 'form', // style
  865. true, // explode
  866. false // required
  867. ) ?? []);
  868. // query params
  869. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  870. $category,
  871. 'category', // param base name
  872. 'string', // openApiType
  873. 'form', // style
  874. true, // explode
  875. false // required
  876. ) ?? []);
  877. // query params
  878. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  879. $order,
  880. 'order', // param base name
  881. 'string', // openApiType
  882. 'form', // style
  883. true, // explode
  884. false // required
  885. ) ?? []);
  886. // query params
  887. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  888. $dir,
  889. 'dir', // param base name
  890. 'string', // openApiType
  891. 'form', // style
  892. true, // explode
  893. false // required
  894. ) ?? []);
  895. // query params
  896. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  897. $page,
  898. 'page', // param base name
  899. 'integer', // openApiType
  900. 'form', // style
  901. true, // explode
  902. false // required
  903. ) ?? []);
  904. // path params
  905. if ($studio !== null) {
  906. $resourcePath = str_replace(
  907. '{studio}',
  908. ObjectSerializer::toPathValue($studio),
  909. $resourcePath
  910. );
  911. }
  912. $headers = $this->headerSelector->selectHeaders(
  913. ['application/json', 'application/problem+json', ],
  914. $contentType,
  915. $multipart
  916. );
  917. // for model (json/xml)
  918. if (count($formParams) > 0) {
  919. if ($multipart) {
  920. $multipartContents = [];
  921. foreach ($formParams as $formParamName => $formParamValue) {
  922. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  923. foreach ($formParamValueItems as $formParamValueItem) {
  924. $multipartContents[] = [
  925. 'name' => $formParamName,
  926. 'contents' => $formParamValueItem
  927. ];
  928. }
  929. }
  930. // for HTTP post (form)
  931. $httpBody = new MultipartStream($multipartContents);
  932. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  933. # if Content-Type contains "application/json", json_encode the form parameters
  934. try {
  935. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  936. } catch (\JsonException $e) {
  937. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  938. }
  939. } else {
  940. // for HTTP post (form)
  941. $httpBody = ObjectSerializer::buildQuery($formParams);
  942. }
  943. }
  944. // this endpoint requires Bearer authentication (access token)
  945. if (!empty($this->config->getAccessToken())) {
  946. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  947. }
  948. $defaultHeaders = [];
  949. if ($this->config->getUserAgent()) {
  950. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  951. }
  952. $headers = array_merge(
  953. $defaultHeaders,
  954. $headerParams,
  955. $headers
  956. );
  957. $operationHost = $this->config->getHost();
  958. $query = ObjectSerializer::buildQuery($queryParams);
  959. return new Request(
  960. 'GET',
  961. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  962. $headers,
  963. $httpBody
  964. );
  965. }
  966. /**
  967. * Operation postApiV3StudiosStudioChannels
  968. *
  969. * 在 studio 名下建 channel
  970. *
  971. * @param string $studio 用户 uuid 或团队 uuid (required)
  972. * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request post_api_v3_studios_studio_channels_request (required)
  973. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation
  974. *
  975. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  976. * @throws \InvalidArgumentException
  977. * @return \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  978. */
  979. public function postApiV3StudiosStudioChannels($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0])
  980. {
  981. list($response) = $this->postApiV3StudiosStudioChannelsWithHttpInfo($studio, $post_api_v3_studios_studio_channels_request, $contentType);
  982. return $response;
  983. }
  984. /**
  985. * Operation postApiV3StudiosStudioChannelsWithHttpInfo
  986. *
  987. * 在 studio 名下建 channel
  988. *
  989. * @param string $studio 用户 uuid 或团队 uuid (required)
  990. * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request (required)
  991. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation
  992. *
  993. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  994. * @throws \InvalidArgumentException
  995. * @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)
  996. */
  997. public function postApiV3StudiosStudioChannelsWithHttpInfo($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0])
  998. {
  999. $request = $this->postApiV3StudiosStudioChannelsRequest($studio, $post_api_v3_studios_studio_channels_request, $contentType);
  1000. try {
  1001. $options = $this->createHttpClientOption();
  1002. try {
  1003. $response = $this->client->send($request, $options);
  1004. } catch (RequestException $e) {
  1005. throw new ApiException(
  1006. "[{$e->getCode()}] {$e->getMessage()}",
  1007. (int) $e->getCode(),
  1008. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1009. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1010. );
  1011. } catch (ConnectException $e) {
  1012. throw new ApiException(
  1013. "[{$e->getCode()}] {$e->getMessage()}",
  1014. (int) $e->getCode(),
  1015. null,
  1016. null
  1017. );
  1018. }
  1019. $statusCode = $response->getStatusCode();
  1020. switch($statusCode) {
  1021. case 200:
  1022. return $this->handleResponseWithDataType(
  1023. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  1024. $request,
  1025. $response,
  1026. );
  1027. case 201:
  1028. return $this->handleResponseWithDataType(
  1029. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  1030. $request,
  1031. $response,
  1032. );
  1033. case 401:
  1034. return $this->handleResponseWithDataType(
  1035. '\WikipaliApi\Model\ProblemDetails',
  1036. $request,
  1037. $response,
  1038. );
  1039. case 403:
  1040. return $this->handleResponseWithDataType(
  1041. '\WikipaliApi\Model\ProblemDetails',
  1042. $request,
  1043. $response,
  1044. );
  1045. case 422:
  1046. return $this->handleResponseWithDataType(
  1047. '\WikipaliApi\Model\ProblemDetails',
  1048. $request,
  1049. $response,
  1050. );
  1051. }
  1052. if ($statusCode < 200 || $statusCode > 299) {
  1053. throw new ApiException(
  1054. sprintf(
  1055. '[%d] Error connecting to the API (%s)',
  1056. $statusCode,
  1057. (string) $request->getUri()
  1058. ),
  1059. $statusCode,
  1060. $response->getHeaders(),
  1061. (string) $response->getBody()
  1062. );
  1063. }
  1064. return $this->handleResponseWithDataType(
  1065. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  1066. $request,
  1067. $response,
  1068. );
  1069. } catch (ApiException $e) {
  1070. switch ($e->getCode()) {
  1071. case 200:
  1072. $data = ObjectSerializer::deserialize(
  1073. $e->getResponseBody(),
  1074. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  1075. $e->getResponseHeaders()
  1076. );
  1077. $e->setResponseObject($data);
  1078. throw $e;
  1079. case 201:
  1080. $data = ObjectSerializer::deserialize(
  1081. $e->getResponseBody(),
  1082. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  1083. $e->getResponseHeaders()
  1084. );
  1085. $e->setResponseObject($data);
  1086. throw $e;
  1087. case 401:
  1088. $data = ObjectSerializer::deserialize(
  1089. $e->getResponseBody(),
  1090. '\WikipaliApi\Model\ProblemDetails',
  1091. $e->getResponseHeaders()
  1092. );
  1093. $e->setResponseObject($data);
  1094. throw $e;
  1095. case 403:
  1096. $data = ObjectSerializer::deserialize(
  1097. $e->getResponseBody(),
  1098. '\WikipaliApi\Model\ProblemDetails',
  1099. $e->getResponseHeaders()
  1100. );
  1101. $e->setResponseObject($data);
  1102. throw $e;
  1103. case 422:
  1104. $data = ObjectSerializer::deserialize(
  1105. $e->getResponseBody(),
  1106. '\WikipaliApi\Model\ProblemDetails',
  1107. $e->getResponseHeaders()
  1108. );
  1109. $e->setResponseObject($data);
  1110. throw $e;
  1111. }
  1112. throw $e;
  1113. }
  1114. }
  1115. /**
  1116. * Operation postApiV3StudiosStudioChannelsAsync
  1117. *
  1118. * 在 studio 名下建 channel
  1119. *
  1120. * @param string $studio 用户 uuid 或团队 uuid (required)
  1121. * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request (required)
  1122. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation
  1123. *
  1124. * @throws \InvalidArgumentException
  1125. * @return \GuzzleHttp\Promise\PromiseInterface
  1126. */
  1127. public function postApiV3StudiosStudioChannelsAsync($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0])
  1128. {
  1129. return $this->postApiV3StudiosStudioChannelsAsyncWithHttpInfo($studio, $post_api_v3_studios_studio_channels_request, $contentType)
  1130. ->then(
  1131. function ($response) {
  1132. return $response[0];
  1133. }
  1134. );
  1135. }
  1136. /**
  1137. * Operation postApiV3StudiosStudioChannelsAsyncWithHttpInfo
  1138. *
  1139. * 在 studio 名下建 channel
  1140. *
  1141. * @param string $studio 用户 uuid 或团队 uuid (required)
  1142. * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request (required)
  1143. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation
  1144. *
  1145. * @throws \InvalidArgumentException
  1146. * @return \GuzzleHttp\Promise\PromiseInterface
  1147. */
  1148. public function postApiV3StudiosStudioChannelsAsyncWithHttpInfo($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0])
  1149. {
  1150. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response';
  1151. $request = $this->postApiV3StudiosStudioChannelsRequest($studio, $post_api_v3_studios_studio_channels_request, $contentType);
  1152. return $this->client
  1153. ->sendAsync($request, $this->createHttpClientOption())
  1154. ->then(
  1155. function ($response) use ($returnType) {
  1156. if ($returnType === '\SplFileObject') {
  1157. $content = $response->getBody(); //stream goes to serializer
  1158. } else {
  1159. $content = (string) $response->getBody();
  1160. if ($returnType !== 'string') {
  1161. $content = json_decode($content);
  1162. }
  1163. }
  1164. return [
  1165. ObjectSerializer::deserialize($content, $returnType, []),
  1166. $response->getStatusCode(),
  1167. $response->getHeaders()
  1168. ];
  1169. },
  1170. function ($exception) {
  1171. $response = $exception->getResponse();
  1172. $statusCode = $response->getStatusCode();
  1173. throw new ApiException(
  1174. sprintf(
  1175. '[%d] Error connecting to the API (%s)',
  1176. $statusCode,
  1177. $exception->getRequest()->getUri()
  1178. ),
  1179. $statusCode,
  1180. $response->getHeaders(),
  1181. (string) $response->getBody()
  1182. );
  1183. }
  1184. );
  1185. }
  1186. /**
  1187. * Create request for operation 'postApiV3StudiosStudioChannels'
  1188. *
  1189. * @param string $studio 用户 uuid 或团队 uuid (required)
  1190. * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request (required)
  1191. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation
  1192. *
  1193. * @throws \InvalidArgumentException
  1194. * @return \GuzzleHttp\Psr7\Request
  1195. */
  1196. public function postApiV3StudiosStudioChannelsRequest($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0])
  1197. {
  1198. // verify the required parameter 'studio' is set
  1199. if ($studio === null || (is_array($studio) && count($studio) === 0)) {
  1200. throw new \InvalidArgumentException(
  1201. 'Missing the required parameter $studio when calling postApiV3StudiosStudioChannels'
  1202. );
  1203. }
  1204. // verify the required parameter 'post_api_v3_studios_studio_channels_request' is set
  1205. 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)) {
  1206. throw new \InvalidArgumentException(
  1207. 'Missing the required parameter $post_api_v3_studios_studio_channels_request when calling postApiV3StudiosStudioChannels'
  1208. );
  1209. }
  1210. $resourcePath = '/v3/studios/{studio}/channels';
  1211. $formParams = [];
  1212. $queryParams = [];
  1213. $headerParams = [];
  1214. $httpBody = '';
  1215. $multipart = false;
  1216. // path params
  1217. if ($studio !== null) {
  1218. $resourcePath = str_replace(
  1219. '{studio}',
  1220. ObjectSerializer::toPathValue($studio),
  1221. $resourcePath
  1222. );
  1223. }
  1224. $headers = $this->headerSelector->selectHeaders(
  1225. ['application/json', 'application/problem+json', ],
  1226. $contentType,
  1227. $multipart
  1228. );
  1229. // for model (json/xml)
  1230. if (isset($post_api_v3_studios_studio_channels_request)) {
  1231. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  1232. # if Content-Type contains "application/json", json_encode the body
  1233. try {
  1234. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_studios_studio_channels_request), JSON_THROW_ON_ERROR);
  1235. } catch (\JsonException $e) {
  1236. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1237. }
  1238. } else {
  1239. $httpBody = $post_api_v3_studios_studio_channels_request;
  1240. }
  1241. } elseif (count($formParams) > 0) {
  1242. if ($multipart) {
  1243. $multipartContents = [];
  1244. foreach ($formParams as $formParamName => $formParamValue) {
  1245. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1246. foreach ($formParamValueItems as $formParamValueItem) {
  1247. $multipartContents[] = [
  1248. 'name' => $formParamName,
  1249. 'contents' => $formParamValueItem
  1250. ];
  1251. }
  1252. }
  1253. // for HTTP post (form)
  1254. $httpBody = new MultipartStream($multipartContents);
  1255. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1256. # if Content-Type contains "application/json", json_encode the form parameters
  1257. try {
  1258. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1259. } catch (\JsonException $e) {
  1260. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1261. }
  1262. } else {
  1263. // for HTTP post (form)
  1264. $httpBody = ObjectSerializer::buildQuery($formParams);
  1265. }
  1266. }
  1267. // this endpoint requires Bearer authentication (access token)
  1268. if (!empty($this->config->getAccessToken())) {
  1269. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1270. }
  1271. $defaultHeaders = [];
  1272. if ($this->config->getUserAgent()) {
  1273. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1274. }
  1275. $headers = array_merge(
  1276. $defaultHeaders,
  1277. $headerParams,
  1278. $headers
  1279. );
  1280. $operationHost = $this->config->getHost();
  1281. $query = ObjectSerializer::buildQuery($queryParams);
  1282. return new Request(
  1283. 'POST',
  1284. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1285. $headers,
  1286. $httpBody
  1287. );
  1288. }
  1289. /**
  1290. * Operation postApiV3StudiosStudioTerms
  1291. *
  1292. * 新建 studio 级术语
  1293. *
  1294. * @param string $studio 用户或团队的 uuid (required)
  1295. * @param \WikipaliApi\Model\PostApiV3StudiosStudioTermsRequest $post_api_v3_studios_studio_terms_request post_api_v3_studios_studio_terms_request (required)
  1296. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTerms'] to see the possible values for this operation
  1297. *
  1298. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1299. * @throws \InvalidArgumentException
  1300. * @return \WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  1301. */
  1302. public function postApiV3StudiosStudioTerms($studio, $post_api_v3_studios_studio_terms_request, string $contentType = self::contentTypes['postApiV3StudiosStudioTerms'][0])
  1303. {
  1304. list($response) = $this->postApiV3StudiosStudioTermsWithHttpInfo($studio, $post_api_v3_studios_studio_terms_request, $contentType);
  1305. return $response;
  1306. }
  1307. /**
  1308. * Operation postApiV3StudiosStudioTermsWithHttpInfo
  1309. *
  1310. * 新建 studio 级术语
  1311. *
  1312. * @param string $studio 用户或团队的 uuid (required)
  1313. * @param \WikipaliApi\Model\PostApiV3StudiosStudioTermsRequest $post_api_v3_studios_studio_terms_request (required)
  1314. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTerms'] to see the possible values for this operation
  1315. *
  1316. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1317. * @throws \InvalidArgumentException
  1318. * @return array of \WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  1319. */
  1320. public function postApiV3StudiosStudioTermsWithHttpInfo($studio, $post_api_v3_studios_studio_terms_request, string $contentType = self::contentTypes['postApiV3StudiosStudioTerms'][0])
  1321. {
  1322. $request = $this->postApiV3StudiosStudioTermsRequest($studio, $post_api_v3_studios_studio_terms_request, $contentType);
  1323. try {
  1324. $options = $this->createHttpClientOption();
  1325. try {
  1326. $response = $this->client->send($request, $options);
  1327. } catch (RequestException $e) {
  1328. throw new ApiException(
  1329. "[{$e->getCode()}] {$e->getMessage()}",
  1330. (int) $e->getCode(),
  1331. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1332. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1333. );
  1334. } catch (ConnectException $e) {
  1335. throw new ApiException(
  1336. "[{$e->getCode()}] {$e->getMessage()}",
  1337. (int) $e->getCode(),
  1338. null,
  1339. null
  1340. );
  1341. }
  1342. $statusCode = $response->getStatusCode();
  1343. switch($statusCode) {
  1344. case 200:
  1345. return $this->handleResponseWithDataType(
  1346. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  1347. $request,
  1348. $response,
  1349. );
  1350. case 201:
  1351. return $this->handleResponseWithDataType(
  1352. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  1353. $request,
  1354. $response,
  1355. );
  1356. case 401:
  1357. return $this->handleResponseWithDataType(
  1358. '\WikipaliApi\Model\ProblemDetails',
  1359. $request,
  1360. $response,
  1361. );
  1362. case 403:
  1363. return $this->handleResponseWithDataType(
  1364. '\WikipaliApi\Model\ProblemDetails',
  1365. $request,
  1366. $response,
  1367. );
  1368. case 409:
  1369. return $this->handleResponseWithDataType(
  1370. '\WikipaliApi\Model\ProblemDetails',
  1371. $request,
  1372. $response,
  1373. );
  1374. case 422:
  1375. return $this->handleResponseWithDataType(
  1376. '\WikipaliApi\Model\ProblemDetails',
  1377. $request,
  1378. $response,
  1379. );
  1380. }
  1381. if ($statusCode < 200 || $statusCode > 299) {
  1382. throw new ApiException(
  1383. sprintf(
  1384. '[%d] Error connecting to the API (%s)',
  1385. $statusCode,
  1386. (string) $request->getUri()
  1387. ),
  1388. $statusCode,
  1389. $response->getHeaders(),
  1390. (string) $response->getBody()
  1391. );
  1392. }
  1393. return $this->handleResponseWithDataType(
  1394. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  1395. $request,
  1396. $response,
  1397. );
  1398. } catch (ApiException $e) {
  1399. switch ($e->getCode()) {
  1400. case 200:
  1401. $data = ObjectSerializer::deserialize(
  1402. $e->getResponseBody(),
  1403. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  1404. $e->getResponseHeaders()
  1405. );
  1406. $e->setResponseObject($data);
  1407. throw $e;
  1408. case 201:
  1409. $data = ObjectSerializer::deserialize(
  1410. $e->getResponseBody(),
  1411. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  1412. $e->getResponseHeaders()
  1413. );
  1414. $e->setResponseObject($data);
  1415. throw $e;
  1416. case 401:
  1417. $data = ObjectSerializer::deserialize(
  1418. $e->getResponseBody(),
  1419. '\WikipaliApi\Model\ProblemDetails',
  1420. $e->getResponseHeaders()
  1421. );
  1422. $e->setResponseObject($data);
  1423. throw $e;
  1424. case 403:
  1425. $data = ObjectSerializer::deserialize(
  1426. $e->getResponseBody(),
  1427. '\WikipaliApi\Model\ProblemDetails',
  1428. $e->getResponseHeaders()
  1429. );
  1430. $e->setResponseObject($data);
  1431. throw $e;
  1432. case 409:
  1433. $data = ObjectSerializer::deserialize(
  1434. $e->getResponseBody(),
  1435. '\WikipaliApi\Model\ProblemDetails',
  1436. $e->getResponseHeaders()
  1437. );
  1438. $e->setResponseObject($data);
  1439. throw $e;
  1440. case 422:
  1441. $data = ObjectSerializer::deserialize(
  1442. $e->getResponseBody(),
  1443. '\WikipaliApi\Model\ProblemDetails',
  1444. $e->getResponseHeaders()
  1445. );
  1446. $e->setResponseObject($data);
  1447. throw $e;
  1448. }
  1449. throw $e;
  1450. }
  1451. }
  1452. /**
  1453. * Operation postApiV3StudiosStudioTermsAsync
  1454. *
  1455. * 新建 studio 级术语
  1456. *
  1457. * @param string $studio 用户或团队的 uuid (required)
  1458. * @param \WikipaliApi\Model\PostApiV3StudiosStudioTermsRequest $post_api_v3_studios_studio_terms_request (required)
  1459. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTerms'] to see the possible values for this operation
  1460. *
  1461. * @throws \InvalidArgumentException
  1462. * @return \GuzzleHttp\Promise\PromiseInterface
  1463. */
  1464. public function postApiV3StudiosStudioTermsAsync($studio, $post_api_v3_studios_studio_terms_request, string $contentType = self::contentTypes['postApiV3StudiosStudioTerms'][0])
  1465. {
  1466. return $this->postApiV3StudiosStudioTermsAsyncWithHttpInfo($studio, $post_api_v3_studios_studio_terms_request, $contentType)
  1467. ->then(
  1468. function ($response) {
  1469. return $response[0];
  1470. }
  1471. );
  1472. }
  1473. /**
  1474. * Operation postApiV3StudiosStudioTermsAsyncWithHttpInfo
  1475. *
  1476. * 新建 studio 级术语
  1477. *
  1478. * @param string $studio 用户或团队的 uuid (required)
  1479. * @param \WikipaliApi\Model\PostApiV3StudiosStudioTermsRequest $post_api_v3_studios_studio_terms_request (required)
  1480. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTerms'] to see the possible values for this operation
  1481. *
  1482. * @throws \InvalidArgumentException
  1483. * @return \GuzzleHttp\Promise\PromiseInterface
  1484. */
  1485. public function postApiV3StudiosStudioTermsAsyncWithHttpInfo($studio, $post_api_v3_studios_studio_terms_request, string $contentType = self::contentTypes['postApiV3StudiosStudioTerms'][0])
  1486. {
  1487. $returnType = '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response';
  1488. $request = $this->postApiV3StudiosStudioTermsRequest($studio, $post_api_v3_studios_studio_terms_request, $contentType);
  1489. return $this->client
  1490. ->sendAsync($request, $this->createHttpClientOption())
  1491. ->then(
  1492. function ($response) use ($returnType) {
  1493. if ($returnType === '\SplFileObject') {
  1494. $content = $response->getBody(); //stream goes to serializer
  1495. } else {
  1496. $content = (string) $response->getBody();
  1497. if ($returnType !== 'string') {
  1498. $content = json_decode($content);
  1499. }
  1500. }
  1501. return [
  1502. ObjectSerializer::deserialize($content, $returnType, []),
  1503. $response->getStatusCode(),
  1504. $response->getHeaders()
  1505. ];
  1506. },
  1507. function ($exception) {
  1508. $response = $exception->getResponse();
  1509. $statusCode = $response->getStatusCode();
  1510. throw new ApiException(
  1511. sprintf(
  1512. '[%d] Error connecting to the API (%s)',
  1513. $statusCode,
  1514. $exception->getRequest()->getUri()
  1515. ),
  1516. $statusCode,
  1517. $response->getHeaders(),
  1518. (string) $response->getBody()
  1519. );
  1520. }
  1521. );
  1522. }
  1523. /**
  1524. * Create request for operation 'postApiV3StudiosStudioTerms'
  1525. *
  1526. * @param string $studio 用户或团队的 uuid (required)
  1527. * @param \WikipaliApi\Model\PostApiV3StudiosStudioTermsRequest $post_api_v3_studios_studio_terms_request (required)
  1528. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTerms'] to see the possible values for this operation
  1529. *
  1530. * @throws \InvalidArgumentException
  1531. * @return \GuzzleHttp\Psr7\Request
  1532. */
  1533. public function postApiV3StudiosStudioTermsRequest($studio, $post_api_v3_studios_studio_terms_request, string $contentType = self::contentTypes['postApiV3StudiosStudioTerms'][0])
  1534. {
  1535. // verify the required parameter 'studio' is set
  1536. if ($studio === null || (is_array($studio) && count($studio) === 0)) {
  1537. throw new \InvalidArgumentException(
  1538. 'Missing the required parameter $studio when calling postApiV3StudiosStudioTerms'
  1539. );
  1540. }
  1541. // verify the required parameter 'post_api_v3_studios_studio_terms_request' is set
  1542. if ($post_api_v3_studios_studio_terms_request === null || (is_array($post_api_v3_studios_studio_terms_request) && count($post_api_v3_studios_studio_terms_request) === 0)) {
  1543. throw new \InvalidArgumentException(
  1544. 'Missing the required parameter $post_api_v3_studios_studio_terms_request when calling postApiV3StudiosStudioTerms'
  1545. );
  1546. }
  1547. $resourcePath = '/v3/studios/{studio}/terms';
  1548. $formParams = [];
  1549. $queryParams = [];
  1550. $headerParams = [];
  1551. $httpBody = '';
  1552. $multipart = false;
  1553. // path params
  1554. if ($studio !== null) {
  1555. $resourcePath = str_replace(
  1556. '{studio}',
  1557. ObjectSerializer::toPathValue($studio),
  1558. $resourcePath
  1559. );
  1560. }
  1561. $headers = $this->headerSelector->selectHeaders(
  1562. ['application/json', 'application/problem+json', ],
  1563. $contentType,
  1564. $multipart
  1565. );
  1566. // for model (json/xml)
  1567. if (isset($post_api_v3_studios_studio_terms_request)) {
  1568. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  1569. # if Content-Type contains "application/json", json_encode the body
  1570. try {
  1571. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_studios_studio_terms_request), JSON_THROW_ON_ERROR);
  1572. } catch (\JsonException $e) {
  1573. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1574. }
  1575. } else {
  1576. $httpBody = $post_api_v3_studios_studio_terms_request;
  1577. }
  1578. } elseif (count($formParams) > 0) {
  1579. if ($multipart) {
  1580. $multipartContents = [];
  1581. foreach ($formParams as $formParamName => $formParamValue) {
  1582. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1583. foreach ($formParamValueItems as $formParamValueItem) {
  1584. $multipartContents[] = [
  1585. 'name' => $formParamName,
  1586. 'contents' => $formParamValueItem
  1587. ];
  1588. }
  1589. }
  1590. // for HTTP post (form)
  1591. $httpBody = new MultipartStream($multipartContents);
  1592. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1593. # if Content-Type contains "application/json", json_encode the form parameters
  1594. try {
  1595. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1596. } catch (\JsonException $e) {
  1597. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1598. }
  1599. } else {
  1600. // for HTTP post (form)
  1601. $httpBody = ObjectSerializer::buildQuery($formParams);
  1602. }
  1603. }
  1604. // this endpoint requires Bearer authentication (access token)
  1605. if (!empty($this->config->getAccessToken())) {
  1606. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1607. }
  1608. $defaultHeaders = [];
  1609. if ($this->config->getUserAgent()) {
  1610. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1611. }
  1612. $headers = array_merge(
  1613. $defaultHeaders,
  1614. $headerParams,
  1615. $headers
  1616. );
  1617. $operationHost = $this->config->getHost();
  1618. $query = ObjectSerializer::buildQuery($queryParams);
  1619. return new Request(
  1620. 'POST',
  1621. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1622. $headers,
  1623. $httpBody
  1624. );
  1625. }
  1626. /**
  1627. * Operation postApiV3StudiosStudioTermsImports
  1628. *
  1629. * 向 studio 导入术语
  1630. *
  1631. * @param string $studio 用户或团队的 uuid (required)
  1632. * @param \SplFileObject $file xlsx 表格,不超过 5MB (required)
  1633. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTermsImports'] to see the possible values for this operation
  1634. *
  1635. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1636. * @throws \InvalidArgumentException
  1637. * @return \WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  1638. */
  1639. public function postApiV3StudiosStudioTermsImports($studio, $file, string $contentType = self::contentTypes['postApiV3StudiosStudioTermsImports'][0])
  1640. {
  1641. list($response) = $this->postApiV3StudiosStudioTermsImportsWithHttpInfo($studio, $file, $contentType);
  1642. return $response;
  1643. }
  1644. /**
  1645. * Operation postApiV3StudiosStudioTermsImportsWithHttpInfo
  1646. *
  1647. * 向 studio 导入术语
  1648. *
  1649. * @param string $studio 用户或团队的 uuid (required)
  1650. * @param \SplFileObject $file xlsx 表格,不超过 5MB (required)
  1651. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTermsImports'] to see the possible values for this operation
  1652. *
  1653. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1654. * @throws \InvalidArgumentException
  1655. * @return array of \WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  1656. */
  1657. public function postApiV3StudiosStudioTermsImportsWithHttpInfo($studio, $file, string $contentType = self::contentTypes['postApiV3StudiosStudioTermsImports'][0])
  1658. {
  1659. $request = $this->postApiV3StudiosStudioTermsImportsRequest($studio, $file, $contentType);
  1660. try {
  1661. $options = $this->createHttpClientOption();
  1662. try {
  1663. $response = $this->client->send($request, $options);
  1664. } catch (RequestException $e) {
  1665. throw new ApiException(
  1666. "[{$e->getCode()}] {$e->getMessage()}",
  1667. (int) $e->getCode(),
  1668. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1669. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1670. );
  1671. } catch (ConnectException $e) {
  1672. throw new ApiException(
  1673. "[{$e->getCode()}] {$e->getMessage()}",
  1674. (int) $e->getCode(),
  1675. null,
  1676. null
  1677. );
  1678. }
  1679. $statusCode = $response->getStatusCode();
  1680. switch($statusCode) {
  1681. case 200:
  1682. return $this->handleResponseWithDataType(
  1683. '\WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response',
  1684. $request,
  1685. $response,
  1686. );
  1687. case 401:
  1688. return $this->handleResponseWithDataType(
  1689. '\WikipaliApi\Model\ProblemDetails',
  1690. $request,
  1691. $response,
  1692. );
  1693. case 403:
  1694. return $this->handleResponseWithDataType(
  1695. '\WikipaliApi\Model\ProblemDetails',
  1696. $request,
  1697. $response,
  1698. );
  1699. case 422:
  1700. return $this->handleResponseWithDataType(
  1701. '\WikipaliApi\Model\ProblemDetails',
  1702. $request,
  1703. $response,
  1704. );
  1705. }
  1706. if ($statusCode < 200 || $statusCode > 299) {
  1707. throw new ApiException(
  1708. sprintf(
  1709. '[%d] Error connecting to the API (%s)',
  1710. $statusCode,
  1711. (string) $request->getUri()
  1712. ),
  1713. $statusCode,
  1714. $response->getHeaders(),
  1715. (string) $response->getBody()
  1716. );
  1717. }
  1718. return $this->handleResponseWithDataType(
  1719. '\WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response',
  1720. $request,
  1721. $response,
  1722. );
  1723. } catch (ApiException $e) {
  1724. switch ($e->getCode()) {
  1725. case 200:
  1726. $data = ObjectSerializer::deserialize(
  1727. $e->getResponseBody(),
  1728. '\WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response',
  1729. $e->getResponseHeaders()
  1730. );
  1731. $e->setResponseObject($data);
  1732. throw $e;
  1733. case 401:
  1734. $data = ObjectSerializer::deserialize(
  1735. $e->getResponseBody(),
  1736. '\WikipaliApi\Model\ProblemDetails',
  1737. $e->getResponseHeaders()
  1738. );
  1739. $e->setResponseObject($data);
  1740. throw $e;
  1741. case 403:
  1742. $data = ObjectSerializer::deserialize(
  1743. $e->getResponseBody(),
  1744. '\WikipaliApi\Model\ProblemDetails',
  1745. $e->getResponseHeaders()
  1746. );
  1747. $e->setResponseObject($data);
  1748. throw $e;
  1749. case 422:
  1750. $data = ObjectSerializer::deserialize(
  1751. $e->getResponseBody(),
  1752. '\WikipaliApi\Model\ProblemDetails',
  1753. $e->getResponseHeaders()
  1754. );
  1755. $e->setResponseObject($data);
  1756. throw $e;
  1757. }
  1758. throw $e;
  1759. }
  1760. }
  1761. /**
  1762. * Operation postApiV3StudiosStudioTermsImportsAsync
  1763. *
  1764. * 向 studio 导入术语
  1765. *
  1766. * @param string $studio 用户或团队的 uuid (required)
  1767. * @param \SplFileObject $file xlsx 表格,不超过 5MB (required)
  1768. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTermsImports'] to see the possible values for this operation
  1769. *
  1770. * @throws \InvalidArgumentException
  1771. * @return \GuzzleHttp\Promise\PromiseInterface
  1772. */
  1773. public function postApiV3StudiosStudioTermsImportsAsync($studio, $file, string $contentType = self::contentTypes['postApiV3StudiosStudioTermsImports'][0])
  1774. {
  1775. return $this->postApiV3StudiosStudioTermsImportsAsyncWithHttpInfo($studio, $file, $contentType)
  1776. ->then(
  1777. function ($response) {
  1778. return $response[0];
  1779. }
  1780. );
  1781. }
  1782. /**
  1783. * Operation postApiV3StudiosStudioTermsImportsAsyncWithHttpInfo
  1784. *
  1785. * 向 studio 导入术语
  1786. *
  1787. * @param string $studio 用户或团队的 uuid (required)
  1788. * @param \SplFileObject $file xlsx 表格,不超过 5MB (required)
  1789. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTermsImports'] to see the possible values for this operation
  1790. *
  1791. * @throws \InvalidArgumentException
  1792. * @return \GuzzleHttp\Promise\PromiseInterface
  1793. */
  1794. public function postApiV3StudiosStudioTermsImportsAsyncWithHttpInfo($studio, $file, string $contentType = self::contentTypes['postApiV3StudiosStudioTermsImports'][0])
  1795. {
  1796. $returnType = '\WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response';
  1797. $request = $this->postApiV3StudiosStudioTermsImportsRequest($studio, $file, $contentType);
  1798. return $this->client
  1799. ->sendAsync($request, $this->createHttpClientOption())
  1800. ->then(
  1801. function ($response) use ($returnType) {
  1802. if ($returnType === '\SplFileObject') {
  1803. $content = $response->getBody(); //stream goes to serializer
  1804. } else {
  1805. $content = (string) $response->getBody();
  1806. if ($returnType !== 'string') {
  1807. $content = json_decode($content);
  1808. }
  1809. }
  1810. return [
  1811. ObjectSerializer::deserialize($content, $returnType, []),
  1812. $response->getStatusCode(),
  1813. $response->getHeaders()
  1814. ];
  1815. },
  1816. function ($exception) {
  1817. $response = $exception->getResponse();
  1818. $statusCode = $response->getStatusCode();
  1819. throw new ApiException(
  1820. sprintf(
  1821. '[%d] Error connecting to the API (%s)',
  1822. $statusCode,
  1823. $exception->getRequest()->getUri()
  1824. ),
  1825. $statusCode,
  1826. $response->getHeaders(),
  1827. (string) $response->getBody()
  1828. );
  1829. }
  1830. );
  1831. }
  1832. /**
  1833. * Create request for operation 'postApiV3StudiosStudioTermsImports'
  1834. *
  1835. * @param string $studio 用户或团队的 uuid (required)
  1836. * @param \SplFileObject $file xlsx 表格,不超过 5MB (required)
  1837. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTermsImports'] to see the possible values for this operation
  1838. *
  1839. * @throws \InvalidArgumentException
  1840. * @return \GuzzleHttp\Psr7\Request
  1841. */
  1842. public function postApiV3StudiosStudioTermsImportsRequest($studio, $file, string $contentType = self::contentTypes['postApiV3StudiosStudioTermsImports'][0])
  1843. {
  1844. // verify the required parameter 'studio' is set
  1845. if ($studio === null || (is_array($studio) && count($studio) === 0)) {
  1846. throw new \InvalidArgumentException(
  1847. 'Missing the required parameter $studio when calling postApiV3StudiosStudioTermsImports'
  1848. );
  1849. }
  1850. // verify the required parameter 'file' is set
  1851. if ($file === null || (is_array($file) && count($file) === 0)) {
  1852. throw new \InvalidArgumentException(
  1853. 'Missing the required parameter $file when calling postApiV3StudiosStudioTermsImports'
  1854. );
  1855. }
  1856. $resourcePath = '/v3/studios/{studio}/terms/imports';
  1857. $formParams = [];
  1858. $queryParams = [];
  1859. $headerParams = [];
  1860. $httpBody = '';
  1861. $multipart = false;
  1862. // path params
  1863. if ($studio !== null) {
  1864. $resourcePath = str_replace(
  1865. '{studio}',
  1866. ObjectSerializer::toPathValue($studio),
  1867. $resourcePath
  1868. );
  1869. }
  1870. // form params
  1871. $formDataProcessor = new FormDataProcessor();
  1872. $formData = $formDataProcessor->prepare([
  1873. 'file' => $file,
  1874. ]);
  1875. $formParams = $formDataProcessor->flatten($formData);
  1876. $multipart = $formDataProcessor->has_file;
  1877. $multipart = true;
  1878. $headers = $this->headerSelector->selectHeaders(
  1879. ['application/json', 'application/problem+json', ],
  1880. $contentType,
  1881. $multipart
  1882. );
  1883. // for model (json/xml)
  1884. if (count($formParams) > 0) {
  1885. if ($multipart) {
  1886. $multipartContents = [];
  1887. foreach ($formParams as $formParamName => $formParamValue) {
  1888. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1889. foreach ($formParamValueItems as $formParamValueItem) {
  1890. $multipartContents[] = [
  1891. 'name' => $formParamName,
  1892. 'contents' => $formParamValueItem
  1893. ];
  1894. }
  1895. }
  1896. // for HTTP post (form)
  1897. $httpBody = new MultipartStream($multipartContents);
  1898. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1899. # if Content-Type contains "application/json", json_encode the form parameters
  1900. try {
  1901. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1902. } catch (\JsonException $e) {
  1903. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1904. }
  1905. } else {
  1906. // for HTTP post (form)
  1907. $httpBody = ObjectSerializer::buildQuery($formParams);
  1908. }
  1909. }
  1910. // this endpoint requires Bearer authentication (access token)
  1911. if (!empty($this->config->getAccessToken())) {
  1912. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1913. }
  1914. $defaultHeaders = [];
  1915. if ($this->config->getUserAgent()) {
  1916. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1917. }
  1918. $headers = array_merge(
  1919. $defaultHeaders,
  1920. $headerParams,
  1921. $headers
  1922. );
  1923. $operationHost = $this->config->getHost();
  1924. $query = ObjectSerializer::buildQuery($queryParams);
  1925. return new Request(
  1926. 'POST',
  1927. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1928. $headers,
  1929. $httpBody
  1930. );
  1931. }
  1932. /**
  1933. * Create http client option
  1934. *
  1935. * @throws \RuntimeException on file opening failure
  1936. * @return array of http client options
  1937. */
  1938. protected function createHttpClientOption()
  1939. {
  1940. $options = [];
  1941. if ($this->config->getDebug()) {
  1942. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  1943. if (!$options[RequestOptions::DEBUG]) {
  1944. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  1945. }
  1946. }
  1947. if ($this->config->getCertFile()) {
  1948. $options[RequestOptions::CERT] = $this->config->getCertFile();
  1949. }
  1950. if ($this->config->getKeyFile()) {
  1951. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  1952. }
  1953. return $options;
  1954. }
  1955. private function handleResponseWithDataType(
  1956. string $dataType,
  1957. RequestInterface $request,
  1958. ResponseInterface $response
  1959. ): array {
  1960. if ($dataType === '\SplFileObject') {
  1961. $content = $response->getBody(); //stream goes to serializer
  1962. } else {
  1963. $content = (string) $response->getBody();
  1964. if ($dataType !== 'string') {
  1965. try {
  1966. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  1967. } catch (\JsonException $exception) {
  1968. throw new ApiException(
  1969. sprintf(
  1970. 'Error JSON decoding server response (%s)',
  1971. $request->getUri()
  1972. ),
  1973. $response->getStatusCode(),
  1974. $response->getHeaders(),
  1975. $content
  1976. );
  1977. }
  1978. }
  1979. }
  1980. return [
  1981. ObjectSerializer::deserialize($content, $dataType, []),
  1982. $response->getStatusCode(),
  1983. $response->getHeaders()
  1984. ];
  1985. }
  1986. private function responseWithinRangeCode(
  1987. string $rangeCode,
  1988. int $statusCode
  1989. ): bool {
  1990. $left = (int) ($rangeCode[0].'00');
  1991. $right = (int) ($rangeCode[0].'99');
  1992. return $statusCode >= $left && $statusCode <= $right;
  1993. }
  1994. }