ChannelsApi.php 93 KB

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