ChannelsApi.php 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974
  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. 'getApiV3ChannelsChannelLinks' => [
  78. 'application/json',
  79. ],
  80. 'getApiV3ChannelsEditable' => [
  81. 'application/json',
  82. ],
  83. 'patchApiV3ChannelsChannel' => [
  84. 'application/json',
  85. ],
  86. 'patchApiV3ChannelsChannelLinks' => [
  87. 'application/json',
  88. ],
  89. 'postApiV3ChannelsBatchProgress' => [
  90. 'application/json',
  91. ],
  92. ];
  93. /**
  94. * @param ClientInterface $client
  95. * @param Configuration $config
  96. * @param HeaderSelector $selector
  97. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  98. */
  99. public function __construct(
  100. ?ClientInterface $client = null,
  101. ?Configuration $config = null,
  102. ?HeaderSelector $selector = null,
  103. int $hostIndex = 0
  104. ) {
  105. $this->client = $client ?: new Client();
  106. $this->config = $config ?: Configuration::getDefaultConfiguration();
  107. $this->headerSelector = $selector ?: new HeaderSelector();
  108. $this->hostIndex = $hostIndex;
  109. }
  110. /**
  111. * Set the host index
  112. *
  113. * @param int $hostIndex Host index (required)
  114. */
  115. public function setHostIndex($hostIndex): void
  116. {
  117. $this->hostIndex = $hostIndex;
  118. }
  119. /**
  120. * Get the host index
  121. *
  122. * @return int Host index
  123. */
  124. public function getHostIndex()
  125. {
  126. return $this->hostIndex;
  127. }
  128. /**
  129. * @return Configuration
  130. */
  131. public function getConfig()
  132. {
  133. return $this->config;
  134. }
  135. /**
  136. * Operation deleteApiV3ChannelsChannel
  137. *
  138. * 删除 channel
  139. *
  140. * @param string $channel channel uid (required)
  141. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3ChannelsChannel'] to see the possible values for this operation
  142. *
  143. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  144. * @throws \InvalidArgumentException
  145. * @return \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  146. */
  147. public function deleteApiV3ChannelsChannel($channel, string $contentType = self::contentTypes['deleteApiV3ChannelsChannel'][0])
  148. {
  149. list($response) = $this->deleteApiV3ChannelsChannelWithHttpInfo($channel, $contentType);
  150. return $response;
  151. }
  152. /**
  153. * Operation deleteApiV3ChannelsChannelWithHttpInfo
  154. *
  155. * 删除 channel
  156. *
  157. * @param string $channel channel uid (required)
  158. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3ChannelsChannel'] to see the possible values for this operation
  159. *
  160. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  161. * @throws \InvalidArgumentException
  162. * @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)
  163. */
  164. public function deleteApiV3ChannelsChannelWithHttpInfo($channel, string $contentType = self::contentTypes['deleteApiV3ChannelsChannel'][0])
  165. {
  166. $request = $this->deleteApiV3ChannelsChannelRequest($channel, $contentType);
  167. try {
  168. $options = $this->createHttpClientOption();
  169. try {
  170. $response = $this->client->send($request, $options);
  171. } catch (RequestException $e) {
  172. throw new ApiException(
  173. "[{$e->getCode()}] {$e->getMessage()}",
  174. (int) $e->getCode(),
  175. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  176. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  177. );
  178. } catch (ConnectException $e) {
  179. throw new ApiException(
  180. "[{$e->getCode()}] {$e->getMessage()}",
  181. (int) $e->getCode(),
  182. null,
  183. null
  184. );
  185. }
  186. $statusCode = $response->getStatusCode();
  187. switch($statusCode) {
  188. case 200:
  189. return $this->handleResponseWithDataType(
  190. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  191. $request,
  192. $response,
  193. );
  194. case 401:
  195. return $this->handleResponseWithDataType(
  196. '\WikipaliApi\Model\ProblemDetails',
  197. $request,
  198. $response,
  199. );
  200. case 403:
  201. return $this->handleResponseWithDataType(
  202. '\WikipaliApi\Model\ProblemDetails',
  203. $request,
  204. $response,
  205. );
  206. case 409:
  207. return $this->handleResponseWithDataType(
  208. '\WikipaliApi\Model\ProblemDetails',
  209. $request,
  210. $response,
  211. );
  212. case 422:
  213. return $this->handleResponseWithDataType(
  214. '\WikipaliApi\Model\ProblemDetails',
  215. $request,
  216. $response,
  217. );
  218. }
  219. if ($statusCode < 200 || $statusCode > 299) {
  220. throw new ApiException(
  221. sprintf(
  222. '[%d] Error connecting to the API (%s)',
  223. $statusCode,
  224. (string) $request->getUri()
  225. ),
  226. $statusCode,
  227. $response->getHeaders(),
  228. (string) $response->getBody()
  229. );
  230. }
  231. return $this->handleResponseWithDataType(
  232. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  233. $request,
  234. $response,
  235. );
  236. } catch (ApiException $e) {
  237. switch ($e->getCode()) {
  238. case 200:
  239. $data = ObjectSerializer::deserialize(
  240. $e->getResponseBody(),
  241. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  242. $e->getResponseHeaders()
  243. );
  244. $e->setResponseObject($data);
  245. throw $e;
  246. case 401:
  247. $data = ObjectSerializer::deserialize(
  248. $e->getResponseBody(),
  249. '\WikipaliApi\Model\ProblemDetails',
  250. $e->getResponseHeaders()
  251. );
  252. $e->setResponseObject($data);
  253. throw $e;
  254. case 403:
  255. $data = ObjectSerializer::deserialize(
  256. $e->getResponseBody(),
  257. '\WikipaliApi\Model\ProblemDetails',
  258. $e->getResponseHeaders()
  259. );
  260. $e->setResponseObject($data);
  261. throw $e;
  262. case 409:
  263. $data = ObjectSerializer::deserialize(
  264. $e->getResponseBody(),
  265. '\WikipaliApi\Model\ProblemDetails',
  266. $e->getResponseHeaders()
  267. );
  268. $e->setResponseObject($data);
  269. throw $e;
  270. case 422:
  271. $data = ObjectSerializer::deserialize(
  272. $e->getResponseBody(),
  273. '\WikipaliApi\Model\ProblemDetails',
  274. $e->getResponseHeaders()
  275. );
  276. $e->setResponseObject($data);
  277. throw $e;
  278. }
  279. throw $e;
  280. }
  281. }
  282. /**
  283. * Operation deleteApiV3ChannelsChannelAsync
  284. *
  285. * 删除 channel
  286. *
  287. * @param string $channel channel uid (required)
  288. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3ChannelsChannel'] to see the possible values for this operation
  289. *
  290. * @throws \InvalidArgumentException
  291. * @return \GuzzleHttp\Promise\PromiseInterface
  292. */
  293. public function deleteApiV3ChannelsChannelAsync($channel, string $contentType = self::contentTypes['deleteApiV3ChannelsChannel'][0])
  294. {
  295. return $this->deleteApiV3ChannelsChannelAsyncWithHttpInfo($channel, $contentType)
  296. ->then(
  297. function ($response) {
  298. return $response[0];
  299. }
  300. );
  301. }
  302. /**
  303. * Operation deleteApiV3ChannelsChannelAsyncWithHttpInfo
  304. *
  305. * 删除 channel
  306. *
  307. * @param string $channel channel uid (required)
  308. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3ChannelsChannel'] to see the possible values for this operation
  309. *
  310. * @throws \InvalidArgumentException
  311. * @return \GuzzleHttp\Promise\PromiseInterface
  312. */
  313. public function deleteApiV3ChannelsChannelAsyncWithHttpInfo($channel, string $contentType = self::contentTypes['deleteApiV3ChannelsChannel'][0])
  314. {
  315. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response';
  316. $request = $this->deleteApiV3ChannelsChannelRequest($channel, $contentType);
  317. return $this->client
  318. ->sendAsync($request, $this->createHttpClientOption())
  319. ->then(
  320. function ($response) use ($returnType) {
  321. if ($returnType === '\SplFileObject') {
  322. $content = $response->getBody(); //stream goes to serializer
  323. } else {
  324. $content = (string) $response->getBody();
  325. if ($returnType !== 'string') {
  326. $content = json_decode($content);
  327. }
  328. }
  329. return [
  330. ObjectSerializer::deserialize($content, $returnType, []),
  331. $response->getStatusCode(),
  332. $response->getHeaders()
  333. ];
  334. },
  335. function ($exception) {
  336. $response = $exception->getResponse();
  337. $statusCode = $response->getStatusCode();
  338. throw new ApiException(
  339. sprintf(
  340. '[%d] Error connecting to the API (%s)',
  341. $statusCode,
  342. $exception->getRequest()->getUri()
  343. ),
  344. $statusCode,
  345. $response->getHeaders(),
  346. (string) $response->getBody()
  347. );
  348. }
  349. );
  350. }
  351. /**
  352. * Create request for operation 'deleteApiV3ChannelsChannel'
  353. *
  354. * @param string $channel channel uid (required)
  355. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3ChannelsChannel'] to see the possible values for this operation
  356. *
  357. * @throws \InvalidArgumentException
  358. * @return \GuzzleHttp\Psr7\Request
  359. */
  360. public function deleteApiV3ChannelsChannelRequest($channel, string $contentType = self::contentTypes['deleteApiV3ChannelsChannel'][0])
  361. {
  362. // verify the required parameter 'channel' is set
  363. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  364. throw new \InvalidArgumentException(
  365. 'Missing the required parameter $channel when calling deleteApiV3ChannelsChannel'
  366. );
  367. }
  368. $resourcePath = '/v3/channels/{channel}';
  369. $formParams = [];
  370. $queryParams = [];
  371. $headerParams = [];
  372. $httpBody = '';
  373. $multipart = false;
  374. // path params
  375. if ($channel !== null) {
  376. $resourcePath = str_replace(
  377. '{channel}',
  378. ObjectSerializer::toPathValue($channel),
  379. $resourcePath
  380. );
  381. }
  382. $headers = $this->headerSelector->selectHeaders(
  383. ['application/json', 'application/problem+json', ],
  384. $contentType,
  385. $multipart
  386. );
  387. // for model (json/xml)
  388. if (count($formParams) > 0) {
  389. if ($multipart) {
  390. $multipartContents = [];
  391. foreach ($formParams as $formParamName => $formParamValue) {
  392. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  393. foreach ($formParamValueItems as $formParamValueItem) {
  394. $multipartContents[] = [
  395. 'name' => $formParamName,
  396. 'contents' => $formParamValueItem
  397. ];
  398. }
  399. }
  400. // for HTTP post (form)
  401. $httpBody = new MultipartStream($multipartContents);
  402. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  403. # if Content-Type contains "application/json", json_encode the form parameters
  404. try {
  405. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  406. } catch (\JsonException $e) {
  407. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  408. }
  409. } else {
  410. // for HTTP post (form)
  411. $httpBody = ObjectSerializer::buildQuery($formParams);
  412. }
  413. }
  414. // this endpoint requires Bearer authentication (access token)
  415. if (!empty($this->config->getAccessToken())) {
  416. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  417. }
  418. $defaultHeaders = [];
  419. if ($this->config->getUserAgent()) {
  420. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  421. }
  422. $headers = array_merge(
  423. $defaultHeaders,
  424. $headerParams,
  425. $headers
  426. );
  427. $operationHost = $this->config->getHost();
  428. $query = ObjectSerializer::buildQuery($queryParams);
  429. return new Request(
  430. 'DELETE',
  431. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  432. $headers,
  433. $httpBody
  434. );
  435. }
  436. /**
  437. * Operation getApiV3Channels
  438. *
  439. * 公开 channel 目录
  440. *
  441. * @param bool|null $system 只列系统 channel (optional)
  442. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  443. * @param string|null $search 按名字模糊匹配 (optional)
  444. * @param string|null $type channel 类型 (optional)
  445. * @param string|null $lang 语言 (optional)
  446. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  447. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  448. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  449. * @param string|null $dir 排序方向 (optional, default to 'desc')
  450. * @param int|null $page 页码 (optional, default to 1)
  451. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Channels'] to see the possible values for this operation
  452. *
  453. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  454. * @throws \InvalidArgumentException
  455. * @return \WikipaliApi\Model\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails
  456. */
  457. 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])
  458. {
  459. list($response) = $this->getApiV3ChannelsWithHttpInfo($system, $per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  460. return $response;
  461. }
  462. /**
  463. * Operation getApiV3ChannelsWithHttpInfo
  464. *
  465. * 公开 channel 目录
  466. *
  467. * @param bool|null $system 只列系统 channel (optional)
  468. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  469. * @param string|null $search 按名字模糊匹配 (optional)
  470. * @param string|null $type channel 类型 (optional)
  471. * @param string|null $lang 语言 (optional)
  472. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  473. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  474. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  475. * @param string|null $dir 排序方向 (optional, default to 'desc')
  476. * @param int|null $page 页码 (optional, default to 1)
  477. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Channels'] to see the possible values for this operation
  478. *
  479. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  480. * @throws \InvalidArgumentException
  481. * @return array of \WikipaliApi\Model\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  482. */
  483. 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])
  484. {
  485. $request = $this->getApiV3ChannelsRequest($system, $per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  486. try {
  487. $options = $this->createHttpClientOption();
  488. try {
  489. $response = $this->client->send($request, $options);
  490. } catch (RequestException $e) {
  491. throw new ApiException(
  492. "[{$e->getCode()}] {$e->getMessage()}",
  493. (int) $e->getCode(),
  494. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  495. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  496. );
  497. } catch (ConnectException $e) {
  498. throw new ApiException(
  499. "[{$e->getCode()}] {$e->getMessage()}",
  500. (int) $e->getCode(),
  501. null,
  502. null
  503. );
  504. }
  505. $statusCode = $response->getStatusCode();
  506. switch($statusCode) {
  507. case 200:
  508. return $this->handleResponseWithDataType(
  509. '\WikipaliApi\Model\GetApiV3Channels200Response',
  510. $request,
  511. $response,
  512. );
  513. case 422:
  514. return $this->handleResponseWithDataType(
  515. '\WikipaliApi\Model\ProblemDetails',
  516. $request,
  517. $response,
  518. );
  519. }
  520. if ($statusCode < 200 || $statusCode > 299) {
  521. throw new ApiException(
  522. sprintf(
  523. '[%d] Error connecting to the API (%s)',
  524. $statusCode,
  525. (string) $request->getUri()
  526. ),
  527. $statusCode,
  528. $response->getHeaders(),
  529. (string) $response->getBody()
  530. );
  531. }
  532. return $this->handleResponseWithDataType(
  533. '\WikipaliApi\Model\GetApiV3Channels200Response',
  534. $request,
  535. $response,
  536. );
  537. } catch (ApiException $e) {
  538. switch ($e->getCode()) {
  539. case 200:
  540. $data = ObjectSerializer::deserialize(
  541. $e->getResponseBody(),
  542. '\WikipaliApi\Model\GetApiV3Channels200Response',
  543. $e->getResponseHeaders()
  544. );
  545. $e->setResponseObject($data);
  546. throw $e;
  547. case 422:
  548. $data = ObjectSerializer::deserialize(
  549. $e->getResponseBody(),
  550. '\WikipaliApi\Model\ProblemDetails',
  551. $e->getResponseHeaders()
  552. );
  553. $e->setResponseObject($data);
  554. throw $e;
  555. }
  556. throw $e;
  557. }
  558. }
  559. /**
  560. * Operation getApiV3ChannelsAsync
  561. *
  562. * 公开 channel 目录
  563. *
  564. * @param bool|null $system 只列系统 channel (optional)
  565. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  566. * @param string|null $search 按名字模糊匹配 (optional)
  567. * @param string|null $type channel 类型 (optional)
  568. * @param string|null $lang 语言 (optional)
  569. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  570. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  571. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  572. * @param string|null $dir 排序方向 (optional, default to 'desc')
  573. * @param int|null $page 页码 (optional, default to 1)
  574. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Channels'] to see the possible values for this operation
  575. *
  576. * @throws \InvalidArgumentException
  577. * @return \GuzzleHttp\Promise\PromiseInterface
  578. */
  579. 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])
  580. {
  581. return $this->getApiV3ChannelsAsyncWithHttpInfo($system, $per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType)
  582. ->then(
  583. function ($response) {
  584. return $response[0];
  585. }
  586. );
  587. }
  588. /**
  589. * Operation getApiV3ChannelsAsyncWithHttpInfo
  590. *
  591. * 公开 channel 目录
  592. *
  593. * @param bool|null $system 只列系统 channel (optional)
  594. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  595. * @param string|null $search 按名字模糊匹配 (optional)
  596. * @param string|null $type channel 类型 (optional)
  597. * @param string|null $lang 语言 (optional)
  598. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  599. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  600. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  601. * @param string|null $dir 排序方向 (optional, default to 'desc')
  602. * @param int|null $page 页码 (optional, default to 1)
  603. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Channels'] to see the possible values for this operation
  604. *
  605. * @throws \InvalidArgumentException
  606. * @return \GuzzleHttp\Promise\PromiseInterface
  607. */
  608. 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])
  609. {
  610. $returnType = '\WikipaliApi\Model\GetApiV3Channels200Response';
  611. $request = $this->getApiV3ChannelsRequest($system, $per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  612. return $this->client
  613. ->sendAsync($request, $this->createHttpClientOption())
  614. ->then(
  615. function ($response) use ($returnType) {
  616. if ($returnType === '\SplFileObject') {
  617. $content = $response->getBody(); //stream goes to serializer
  618. } else {
  619. $content = (string) $response->getBody();
  620. if ($returnType !== 'string') {
  621. $content = json_decode($content);
  622. }
  623. }
  624. return [
  625. ObjectSerializer::deserialize($content, $returnType, []),
  626. $response->getStatusCode(),
  627. $response->getHeaders()
  628. ];
  629. },
  630. function ($exception) {
  631. $response = $exception->getResponse();
  632. $statusCode = $response->getStatusCode();
  633. throw new ApiException(
  634. sprintf(
  635. '[%d] Error connecting to the API (%s)',
  636. $statusCode,
  637. $exception->getRequest()->getUri()
  638. ),
  639. $statusCode,
  640. $response->getHeaders(),
  641. (string) $response->getBody()
  642. );
  643. }
  644. );
  645. }
  646. /**
  647. * Create request for operation 'getApiV3Channels'
  648. *
  649. * @param bool|null $system 只列系统 channel (optional)
  650. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  651. * @param string|null $search 按名字模糊匹配 (optional)
  652. * @param string|null $type channel 类型 (optional)
  653. * @param string|null $lang 语言 (optional)
  654. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  655. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  656. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  657. * @param string|null $dir 排序方向 (optional, default to 'desc')
  658. * @param int|null $page 页码 (optional, default to 1)
  659. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Channels'] to see the possible values for this operation
  660. *
  661. * @throws \InvalidArgumentException
  662. * @return \GuzzleHttp\Psr7\Request
  663. */
  664. 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])
  665. {
  666. $resourcePath = '/v3/channels';
  667. $formParams = [];
  668. $queryParams = [];
  669. $headerParams = [];
  670. $httpBody = '';
  671. $multipart = false;
  672. // query params
  673. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  674. $system,
  675. 'system', // param base name
  676. 'boolean', // openApiType
  677. 'form', // style
  678. true, // explode
  679. false // required
  680. ) ?? []);
  681. // query params
  682. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  683. $per_page,
  684. 'per_page', // param base name
  685. 'integer', // openApiType
  686. 'form', // style
  687. true, // explode
  688. false // required
  689. ) ?? []);
  690. // query params
  691. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  692. $search,
  693. 'search', // param base name
  694. 'string', // openApiType
  695. 'form', // style
  696. true, // explode
  697. false // required
  698. ) ?? []);
  699. // query params
  700. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  701. $type,
  702. 'type', // param base name
  703. 'string', // openApiType
  704. 'form', // style
  705. true, // explode
  706. false // required
  707. ) ?? []);
  708. // query params
  709. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  710. $lang,
  711. 'lang', // param base name
  712. 'string', // openApiType
  713. 'form', // style
  714. true, // explode
  715. false // required
  716. ) ?? []);
  717. // query params
  718. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  719. $book,
  720. 'book', // param base name
  721. 'integer', // openApiType
  722. 'form', // style
  723. true, // explode
  724. false // required
  725. ) ?? []);
  726. // query params
  727. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  728. $para,
  729. 'para', // param base name
  730. 'integer', // openApiType
  731. 'form', // style
  732. true, // explode
  733. false // required
  734. ) ?? []);
  735. // query params
  736. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  737. $order,
  738. 'order', // param base name
  739. 'string', // openApiType
  740. 'form', // style
  741. true, // explode
  742. false // required
  743. ) ?? []);
  744. // query params
  745. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  746. $dir,
  747. 'dir', // param base name
  748. 'string', // openApiType
  749. 'form', // style
  750. true, // explode
  751. false // required
  752. ) ?? []);
  753. // query params
  754. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  755. $page,
  756. 'page', // param base name
  757. 'integer', // openApiType
  758. 'form', // style
  759. true, // explode
  760. false // required
  761. ) ?? []);
  762. $headers = $this->headerSelector->selectHeaders(
  763. ['application/json', 'application/problem+json', ],
  764. $contentType,
  765. $multipart
  766. );
  767. // for model (json/xml)
  768. if (count($formParams) > 0) {
  769. if ($multipart) {
  770. $multipartContents = [];
  771. foreach ($formParams as $formParamName => $formParamValue) {
  772. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  773. foreach ($formParamValueItems as $formParamValueItem) {
  774. $multipartContents[] = [
  775. 'name' => $formParamName,
  776. 'contents' => $formParamValueItem
  777. ];
  778. }
  779. }
  780. // for HTTP post (form)
  781. $httpBody = new MultipartStream($multipartContents);
  782. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  783. # if Content-Type contains "application/json", json_encode the form parameters
  784. try {
  785. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  786. } catch (\JsonException $e) {
  787. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  788. }
  789. } else {
  790. // for HTTP post (form)
  791. $httpBody = ObjectSerializer::buildQuery($formParams);
  792. }
  793. }
  794. // this endpoint requires Bearer authentication (access token)
  795. if (!empty($this->config->getAccessToken())) {
  796. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  797. }
  798. $defaultHeaders = [];
  799. if ($this->config->getUserAgent()) {
  800. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  801. }
  802. $headers = array_merge(
  803. $defaultHeaders,
  804. $headerParams,
  805. $headers
  806. );
  807. $operationHost = $this->config->getHost();
  808. $query = ObjectSerializer::buildQuery($queryParams);
  809. return new Request(
  810. 'GET',
  811. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  812. $headers,
  813. $httpBody
  814. );
  815. }
  816. /**
  817. * Operation getApiV3ChannelsChannel
  818. *
  819. * channel 详情
  820. *
  821. * @param string $channel channel uid (required)
  822. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannel'] to see the possible values for this operation
  823. *
  824. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  825. * @throws \InvalidArgumentException
  826. * @return \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  827. */
  828. public function getApiV3ChannelsChannel($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannel'][0])
  829. {
  830. list($response) = $this->getApiV3ChannelsChannelWithHttpInfo($channel, $contentType);
  831. return $response;
  832. }
  833. /**
  834. * Operation getApiV3ChannelsChannelWithHttpInfo
  835. *
  836. * channel 详情
  837. *
  838. * @param string $channel channel uid (required)
  839. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannel'] to see the possible values for this operation
  840. *
  841. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  842. * @throws \InvalidArgumentException
  843. * @return array of \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  844. */
  845. public function getApiV3ChannelsChannelWithHttpInfo($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannel'][0])
  846. {
  847. $request = $this->getApiV3ChannelsChannelRequest($channel, $contentType);
  848. try {
  849. $options = $this->createHttpClientOption();
  850. try {
  851. $response = $this->client->send($request, $options);
  852. } catch (RequestException $e) {
  853. throw new ApiException(
  854. "[{$e->getCode()}] {$e->getMessage()}",
  855. (int) $e->getCode(),
  856. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  857. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  858. );
  859. } catch (ConnectException $e) {
  860. throw new ApiException(
  861. "[{$e->getCode()}] {$e->getMessage()}",
  862. (int) $e->getCode(),
  863. null,
  864. null
  865. );
  866. }
  867. $statusCode = $response->getStatusCode();
  868. switch($statusCode) {
  869. case 200:
  870. return $this->handleResponseWithDataType(
  871. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  872. $request,
  873. $response,
  874. );
  875. case 403:
  876. return $this->handleResponseWithDataType(
  877. '\WikipaliApi\Model\ProblemDetails',
  878. $request,
  879. $response,
  880. );
  881. case 422:
  882. return $this->handleResponseWithDataType(
  883. '\WikipaliApi\Model\ProblemDetails',
  884. $request,
  885. $response,
  886. );
  887. }
  888. if ($statusCode < 200 || $statusCode > 299) {
  889. throw new ApiException(
  890. sprintf(
  891. '[%d] Error connecting to the API (%s)',
  892. $statusCode,
  893. (string) $request->getUri()
  894. ),
  895. $statusCode,
  896. $response->getHeaders(),
  897. (string) $response->getBody()
  898. );
  899. }
  900. return $this->handleResponseWithDataType(
  901. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  902. $request,
  903. $response,
  904. );
  905. } catch (ApiException $e) {
  906. switch ($e->getCode()) {
  907. case 200:
  908. $data = ObjectSerializer::deserialize(
  909. $e->getResponseBody(),
  910. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  911. $e->getResponseHeaders()
  912. );
  913. $e->setResponseObject($data);
  914. throw $e;
  915. case 403:
  916. $data = ObjectSerializer::deserialize(
  917. $e->getResponseBody(),
  918. '\WikipaliApi\Model\ProblemDetails',
  919. $e->getResponseHeaders()
  920. );
  921. $e->setResponseObject($data);
  922. throw $e;
  923. case 422:
  924. $data = ObjectSerializer::deserialize(
  925. $e->getResponseBody(),
  926. '\WikipaliApi\Model\ProblemDetails',
  927. $e->getResponseHeaders()
  928. );
  929. $e->setResponseObject($data);
  930. throw $e;
  931. }
  932. throw $e;
  933. }
  934. }
  935. /**
  936. * Operation getApiV3ChannelsChannelAsync
  937. *
  938. * channel 详情
  939. *
  940. * @param string $channel channel uid (required)
  941. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannel'] to see the possible values for this operation
  942. *
  943. * @throws \InvalidArgumentException
  944. * @return \GuzzleHttp\Promise\PromiseInterface
  945. */
  946. public function getApiV3ChannelsChannelAsync($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannel'][0])
  947. {
  948. return $this->getApiV3ChannelsChannelAsyncWithHttpInfo($channel, $contentType)
  949. ->then(
  950. function ($response) {
  951. return $response[0];
  952. }
  953. );
  954. }
  955. /**
  956. * Operation getApiV3ChannelsChannelAsyncWithHttpInfo
  957. *
  958. * channel 详情
  959. *
  960. * @param string $channel channel uid (required)
  961. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannel'] to see the possible values for this operation
  962. *
  963. * @throws \InvalidArgumentException
  964. * @return \GuzzleHttp\Promise\PromiseInterface
  965. */
  966. public function getApiV3ChannelsChannelAsyncWithHttpInfo($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannel'][0])
  967. {
  968. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response';
  969. $request = $this->getApiV3ChannelsChannelRequest($channel, $contentType);
  970. return $this->client
  971. ->sendAsync($request, $this->createHttpClientOption())
  972. ->then(
  973. function ($response) use ($returnType) {
  974. if ($returnType === '\SplFileObject') {
  975. $content = $response->getBody(); //stream goes to serializer
  976. } else {
  977. $content = (string) $response->getBody();
  978. if ($returnType !== 'string') {
  979. $content = json_decode($content);
  980. }
  981. }
  982. return [
  983. ObjectSerializer::deserialize($content, $returnType, []),
  984. $response->getStatusCode(),
  985. $response->getHeaders()
  986. ];
  987. },
  988. function ($exception) {
  989. $response = $exception->getResponse();
  990. $statusCode = $response->getStatusCode();
  991. throw new ApiException(
  992. sprintf(
  993. '[%d] Error connecting to the API (%s)',
  994. $statusCode,
  995. $exception->getRequest()->getUri()
  996. ),
  997. $statusCode,
  998. $response->getHeaders(),
  999. (string) $response->getBody()
  1000. );
  1001. }
  1002. );
  1003. }
  1004. /**
  1005. * Create request for operation 'getApiV3ChannelsChannel'
  1006. *
  1007. * @param string $channel channel uid (required)
  1008. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannel'] to see the possible values for this operation
  1009. *
  1010. * @throws \InvalidArgumentException
  1011. * @return \GuzzleHttp\Psr7\Request
  1012. */
  1013. public function getApiV3ChannelsChannelRequest($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannel'][0])
  1014. {
  1015. // verify the required parameter 'channel' is set
  1016. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  1017. throw new \InvalidArgumentException(
  1018. 'Missing the required parameter $channel when calling getApiV3ChannelsChannel'
  1019. );
  1020. }
  1021. $resourcePath = '/v3/channels/{channel}';
  1022. $formParams = [];
  1023. $queryParams = [];
  1024. $headerParams = [];
  1025. $httpBody = '';
  1026. $multipart = false;
  1027. // path params
  1028. if ($channel !== null) {
  1029. $resourcePath = str_replace(
  1030. '{channel}',
  1031. ObjectSerializer::toPathValue($channel),
  1032. $resourcePath
  1033. );
  1034. }
  1035. $headers = $this->headerSelector->selectHeaders(
  1036. ['application/json', 'application/problem+json', ],
  1037. $contentType,
  1038. $multipart
  1039. );
  1040. // for model (json/xml)
  1041. if (count($formParams) > 0) {
  1042. if ($multipart) {
  1043. $multipartContents = [];
  1044. foreach ($formParams as $formParamName => $formParamValue) {
  1045. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1046. foreach ($formParamValueItems as $formParamValueItem) {
  1047. $multipartContents[] = [
  1048. 'name' => $formParamName,
  1049. 'contents' => $formParamValueItem
  1050. ];
  1051. }
  1052. }
  1053. // for HTTP post (form)
  1054. $httpBody = new MultipartStream($multipartContents);
  1055. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1056. # if Content-Type contains "application/json", json_encode the form parameters
  1057. try {
  1058. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1059. } catch (\JsonException $e) {
  1060. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1061. }
  1062. } else {
  1063. // for HTTP post (form)
  1064. $httpBody = ObjectSerializer::buildQuery($formParams);
  1065. }
  1066. }
  1067. // this endpoint requires Bearer authentication (access token)
  1068. if (!empty($this->config->getAccessToken())) {
  1069. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1070. }
  1071. $defaultHeaders = [];
  1072. if ($this->config->getUserAgent()) {
  1073. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1074. }
  1075. $headers = array_merge(
  1076. $defaultHeaders,
  1077. $headerParams,
  1078. $headers
  1079. );
  1080. $operationHost = $this->config->getHost();
  1081. $query = ObjectSerializer::buildQuery($queryParams);
  1082. return new Request(
  1083. 'GET',
  1084. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1085. $headers,
  1086. $httpBody
  1087. );
  1088. }
  1089. /**
  1090. * Operation getApiV3ChannelsChannelLinks
  1091. *
  1092. * channel 的关系设置
  1093. *
  1094. * @param string $channel channel uid (required)
  1095. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelLinks'] to see the possible values for this operation
  1096. *
  1097. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1098. * @throws \InvalidArgumentException
  1099. * @return \WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  1100. */
  1101. public function getApiV3ChannelsChannelLinks($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannelLinks'][0])
  1102. {
  1103. list($response) = $this->getApiV3ChannelsChannelLinksWithHttpInfo($channel, $contentType);
  1104. return $response;
  1105. }
  1106. /**
  1107. * Operation getApiV3ChannelsChannelLinksWithHttpInfo
  1108. *
  1109. * channel 的关系设置
  1110. *
  1111. * @param string $channel channel uid (required)
  1112. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelLinks'] to see the possible values for this operation
  1113. *
  1114. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1115. * @throws \InvalidArgumentException
  1116. * @return array of \WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  1117. */
  1118. public function getApiV3ChannelsChannelLinksWithHttpInfo($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannelLinks'][0])
  1119. {
  1120. $request = $this->getApiV3ChannelsChannelLinksRequest($channel, $contentType);
  1121. try {
  1122. $options = $this->createHttpClientOption();
  1123. try {
  1124. $response = $this->client->send($request, $options);
  1125. } catch (RequestException $e) {
  1126. throw new ApiException(
  1127. "[{$e->getCode()}] {$e->getMessage()}",
  1128. (int) $e->getCode(),
  1129. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1130. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1131. );
  1132. } catch (ConnectException $e) {
  1133. throw new ApiException(
  1134. "[{$e->getCode()}] {$e->getMessage()}",
  1135. (int) $e->getCode(),
  1136. null,
  1137. null
  1138. );
  1139. }
  1140. $statusCode = $response->getStatusCode();
  1141. switch($statusCode) {
  1142. case 200:
  1143. return $this->handleResponseWithDataType(
  1144. '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response',
  1145. $request,
  1146. $response,
  1147. );
  1148. case 403:
  1149. return $this->handleResponseWithDataType(
  1150. '\WikipaliApi\Model\ProblemDetails',
  1151. $request,
  1152. $response,
  1153. );
  1154. case 422:
  1155. return $this->handleResponseWithDataType(
  1156. '\WikipaliApi\Model\ProblemDetails',
  1157. $request,
  1158. $response,
  1159. );
  1160. }
  1161. if ($statusCode < 200 || $statusCode > 299) {
  1162. throw new ApiException(
  1163. sprintf(
  1164. '[%d] Error connecting to the API (%s)',
  1165. $statusCode,
  1166. (string) $request->getUri()
  1167. ),
  1168. $statusCode,
  1169. $response->getHeaders(),
  1170. (string) $response->getBody()
  1171. );
  1172. }
  1173. return $this->handleResponseWithDataType(
  1174. '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response',
  1175. $request,
  1176. $response,
  1177. );
  1178. } catch (ApiException $e) {
  1179. switch ($e->getCode()) {
  1180. case 200:
  1181. $data = ObjectSerializer::deserialize(
  1182. $e->getResponseBody(),
  1183. '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response',
  1184. $e->getResponseHeaders()
  1185. );
  1186. $e->setResponseObject($data);
  1187. throw $e;
  1188. case 403:
  1189. $data = ObjectSerializer::deserialize(
  1190. $e->getResponseBody(),
  1191. '\WikipaliApi\Model\ProblemDetails',
  1192. $e->getResponseHeaders()
  1193. );
  1194. $e->setResponseObject($data);
  1195. throw $e;
  1196. case 422:
  1197. $data = ObjectSerializer::deserialize(
  1198. $e->getResponseBody(),
  1199. '\WikipaliApi\Model\ProblemDetails',
  1200. $e->getResponseHeaders()
  1201. );
  1202. $e->setResponseObject($data);
  1203. throw $e;
  1204. }
  1205. throw $e;
  1206. }
  1207. }
  1208. /**
  1209. * Operation getApiV3ChannelsChannelLinksAsync
  1210. *
  1211. * channel 的关系设置
  1212. *
  1213. * @param string $channel channel uid (required)
  1214. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelLinks'] to see the possible values for this operation
  1215. *
  1216. * @throws \InvalidArgumentException
  1217. * @return \GuzzleHttp\Promise\PromiseInterface
  1218. */
  1219. public function getApiV3ChannelsChannelLinksAsync($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannelLinks'][0])
  1220. {
  1221. return $this->getApiV3ChannelsChannelLinksAsyncWithHttpInfo($channel, $contentType)
  1222. ->then(
  1223. function ($response) {
  1224. return $response[0];
  1225. }
  1226. );
  1227. }
  1228. /**
  1229. * Operation getApiV3ChannelsChannelLinksAsyncWithHttpInfo
  1230. *
  1231. * channel 的关系设置
  1232. *
  1233. * @param string $channel channel uid (required)
  1234. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelLinks'] to see the possible values for this operation
  1235. *
  1236. * @throws \InvalidArgumentException
  1237. * @return \GuzzleHttp\Promise\PromiseInterface
  1238. */
  1239. public function getApiV3ChannelsChannelLinksAsyncWithHttpInfo($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannelLinks'][0])
  1240. {
  1241. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response';
  1242. $request = $this->getApiV3ChannelsChannelLinksRequest($channel, $contentType);
  1243. return $this->client
  1244. ->sendAsync($request, $this->createHttpClientOption())
  1245. ->then(
  1246. function ($response) use ($returnType) {
  1247. if ($returnType === '\SplFileObject') {
  1248. $content = $response->getBody(); //stream goes to serializer
  1249. } else {
  1250. $content = (string) $response->getBody();
  1251. if ($returnType !== 'string') {
  1252. $content = json_decode($content);
  1253. }
  1254. }
  1255. return [
  1256. ObjectSerializer::deserialize($content, $returnType, []),
  1257. $response->getStatusCode(),
  1258. $response->getHeaders()
  1259. ];
  1260. },
  1261. function ($exception) {
  1262. $response = $exception->getResponse();
  1263. $statusCode = $response->getStatusCode();
  1264. throw new ApiException(
  1265. sprintf(
  1266. '[%d] Error connecting to the API (%s)',
  1267. $statusCode,
  1268. $exception->getRequest()->getUri()
  1269. ),
  1270. $statusCode,
  1271. $response->getHeaders(),
  1272. (string) $response->getBody()
  1273. );
  1274. }
  1275. );
  1276. }
  1277. /**
  1278. * Create request for operation 'getApiV3ChannelsChannelLinks'
  1279. *
  1280. * @param string $channel channel uid (required)
  1281. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelLinks'] to see the possible values for this operation
  1282. *
  1283. * @throws \InvalidArgumentException
  1284. * @return \GuzzleHttp\Psr7\Request
  1285. */
  1286. public function getApiV3ChannelsChannelLinksRequest($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannelLinks'][0])
  1287. {
  1288. // verify the required parameter 'channel' is set
  1289. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  1290. throw new \InvalidArgumentException(
  1291. 'Missing the required parameter $channel when calling getApiV3ChannelsChannelLinks'
  1292. );
  1293. }
  1294. $resourcePath = '/v3/channels/{channel}/links';
  1295. $formParams = [];
  1296. $queryParams = [];
  1297. $headerParams = [];
  1298. $httpBody = '';
  1299. $multipart = false;
  1300. // path params
  1301. if ($channel !== null) {
  1302. $resourcePath = str_replace(
  1303. '{channel}',
  1304. ObjectSerializer::toPathValue($channel),
  1305. $resourcePath
  1306. );
  1307. }
  1308. $headers = $this->headerSelector->selectHeaders(
  1309. ['application/json', 'application/problem+json', ],
  1310. $contentType,
  1311. $multipart
  1312. );
  1313. // for model (json/xml)
  1314. if (count($formParams) > 0) {
  1315. if ($multipart) {
  1316. $multipartContents = [];
  1317. foreach ($formParams as $formParamName => $formParamValue) {
  1318. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1319. foreach ($formParamValueItems as $formParamValueItem) {
  1320. $multipartContents[] = [
  1321. 'name' => $formParamName,
  1322. 'contents' => $formParamValueItem
  1323. ];
  1324. }
  1325. }
  1326. // for HTTP post (form)
  1327. $httpBody = new MultipartStream($multipartContents);
  1328. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1329. # if Content-Type contains "application/json", json_encode the form parameters
  1330. try {
  1331. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1332. } catch (\JsonException $e) {
  1333. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1334. }
  1335. } else {
  1336. // for HTTP post (form)
  1337. $httpBody = ObjectSerializer::buildQuery($formParams);
  1338. }
  1339. }
  1340. // this endpoint requires Bearer authentication (access token)
  1341. if (!empty($this->config->getAccessToken())) {
  1342. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1343. }
  1344. $defaultHeaders = [];
  1345. if ($this->config->getUserAgent()) {
  1346. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1347. }
  1348. $headers = array_merge(
  1349. $defaultHeaders,
  1350. $headerParams,
  1351. $headers
  1352. );
  1353. $operationHost = $this->config->getHost();
  1354. $query = ObjectSerializer::buildQuery($queryParams);
  1355. return new Request(
  1356. 'GET',
  1357. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1358. $headers,
  1359. $httpBody
  1360. );
  1361. }
  1362. /**
  1363. * Operation getApiV3ChannelsEditable
  1364. *
  1365. * 列出我能写的 channel
  1366. *
  1367. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  1368. * @param string|null $search 按名字模糊匹配 (optional)
  1369. * @param string|null $type channel 类型 (optional)
  1370. * @param string|null $lang 语言 (optional)
  1371. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  1372. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  1373. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1374. * @param string|null $dir 排序方向 (optional, default to 'desc')
  1375. * @param int|null $page 页码 (optional, default to 1)
  1376. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsEditable'] to see the possible values for this operation
  1377. *
  1378. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1379. * @throws \InvalidArgumentException
  1380. * @return \WikipaliApi\Model\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  1381. */
  1382. 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])
  1383. {
  1384. list($response) = $this->getApiV3ChannelsEditableWithHttpInfo($per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  1385. return $response;
  1386. }
  1387. /**
  1388. * Operation getApiV3ChannelsEditableWithHttpInfo
  1389. *
  1390. * 列出我能写的 channel
  1391. *
  1392. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  1393. * @param string|null $search 按名字模糊匹配 (optional)
  1394. * @param string|null $type channel 类型 (optional)
  1395. * @param string|null $lang 语言 (optional)
  1396. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  1397. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  1398. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1399. * @param string|null $dir 排序方向 (optional, default to 'desc')
  1400. * @param int|null $page 页码 (optional, default to 1)
  1401. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsEditable'] to see the possible values for this operation
  1402. *
  1403. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1404. * @throws \InvalidArgumentException
  1405. * @return array of \WikipaliApi\Model\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  1406. */
  1407. 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])
  1408. {
  1409. $request = $this->getApiV3ChannelsEditableRequest($per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  1410. try {
  1411. $options = $this->createHttpClientOption();
  1412. try {
  1413. $response = $this->client->send($request, $options);
  1414. } catch (RequestException $e) {
  1415. throw new ApiException(
  1416. "[{$e->getCode()}] {$e->getMessage()}",
  1417. (int) $e->getCode(),
  1418. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1419. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1420. );
  1421. } catch (ConnectException $e) {
  1422. throw new ApiException(
  1423. "[{$e->getCode()}] {$e->getMessage()}",
  1424. (int) $e->getCode(),
  1425. null,
  1426. null
  1427. );
  1428. }
  1429. $statusCode = $response->getStatusCode();
  1430. switch($statusCode) {
  1431. case 200:
  1432. return $this->handleResponseWithDataType(
  1433. '\WikipaliApi\Model\GetApiV3Channels200Response',
  1434. $request,
  1435. $response,
  1436. );
  1437. case 401:
  1438. return $this->handleResponseWithDataType(
  1439. '\WikipaliApi\Model\ProblemDetails',
  1440. $request,
  1441. $response,
  1442. );
  1443. case 422:
  1444. return $this->handleResponseWithDataType(
  1445. '\WikipaliApi\Model\ProblemDetails',
  1446. $request,
  1447. $response,
  1448. );
  1449. }
  1450. if ($statusCode < 200 || $statusCode > 299) {
  1451. throw new ApiException(
  1452. sprintf(
  1453. '[%d] Error connecting to the API (%s)',
  1454. $statusCode,
  1455. (string) $request->getUri()
  1456. ),
  1457. $statusCode,
  1458. $response->getHeaders(),
  1459. (string) $response->getBody()
  1460. );
  1461. }
  1462. return $this->handleResponseWithDataType(
  1463. '\WikipaliApi\Model\GetApiV3Channels200Response',
  1464. $request,
  1465. $response,
  1466. );
  1467. } catch (ApiException $e) {
  1468. switch ($e->getCode()) {
  1469. case 200:
  1470. $data = ObjectSerializer::deserialize(
  1471. $e->getResponseBody(),
  1472. '\WikipaliApi\Model\GetApiV3Channels200Response',
  1473. $e->getResponseHeaders()
  1474. );
  1475. $e->setResponseObject($data);
  1476. throw $e;
  1477. case 401:
  1478. $data = ObjectSerializer::deserialize(
  1479. $e->getResponseBody(),
  1480. '\WikipaliApi\Model\ProblemDetails',
  1481. $e->getResponseHeaders()
  1482. );
  1483. $e->setResponseObject($data);
  1484. throw $e;
  1485. case 422:
  1486. $data = ObjectSerializer::deserialize(
  1487. $e->getResponseBody(),
  1488. '\WikipaliApi\Model\ProblemDetails',
  1489. $e->getResponseHeaders()
  1490. );
  1491. $e->setResponseObject($data);
  1492. throw $e;
  1493. }
  1494. throw $e;
  1495. }
  1496. }
  1497. /**
  1498. * Operation getApiV3ChannelsEditableAsync
  1499. *
  1500. * 列出我能写的 channel
  1501. *
  1502. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  1503. * @param string|null $search 按名字模糊匹配 (optional)
  1504. * @param string|null $type channel 类型 (optional)
  1505. * @param string|null $lang 语言 (optional)
  1506. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  1507. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  1508. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1509. * @param string|null $dir 排序方向 (optional, default to 'desc')
  1510. * @param int|null $page 页码 (optional, default to 1)
  1511. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsEditable'] to see the possible values for this operation
  1512. *
  1513. * @throws \InvalidArgumentException
  1514. * @return \GuzzleHttp\Promise\PromiseInterface
  1515. */
  1516. 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])
  1517. {
  1518. return $this->getApiV3ChannelsEditableAsyncWithHttpInfo($per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType)
  1519. ->then(
  1520. function ($response) {
  1521. return $response[0];
  1522. }
  1523. );
  1524. }
  1525. /**
  1526. * Operation getApiV3ChannelsEditableAsyncWithHttpInfo
  1527. *
  1528. * 列出我能写的 channel
  1529. *
  1530. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  1531. * @param string|null $search 按名字模糊匹配 (optional)
  1532. * @param string|null $type channel 类型 (optional)
  1533. * @param string|null $lang 语言 (optional)
  1534. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  1535. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  1536. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1537. * @param string|null $dir 排序方向 (optional, default to 'desc')
  1538. * @param int|null $page 页码 (optional, default to 1)
  1539. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsEditable'] to see the possible values for this operation
  1540. *
  1541. * @throws \InvalidArgumentException
  1542. * @return \GuzzleHttp\Promise\PromiseInterface
  1543. */
  1544. 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])
  1545. {
  1546. $returnType = '\WikipaliApi\Model\GetApiV3Channels200Response';
  1547. $request = $this->getApiV3ChannelsEditableRequest($per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  1548. return $this->client
  1549. ->sendAsync($request, $this->createHttpClientOption())
  1550. ->then(
  1551. function ($response) use ($returnType) {
  1552. if ($returnType === '\SplFileObject') {
  1553. $content = $response->getBody(); //stream goes to serializer
  1554. } else {
  1555. $content = (string) $response->getBody();
  1556. if ($returnType !== 'string') {
  1557. $content = json_decode($content);
  1558. }
  1559. }
  1560. return [
  1561. ObjectSerializer::deserialize($content, $returnType, []),
  1562. $response->getStatusCode(),
  1563. $response->getHeaders()
  1564. ];
  1565. },
  1566. function ($exception) {
  1567. $response = $exception->getResponse();
  1568. $statusCode = $response->getStatusCode();
  1569. throw new ApiException(
  1570. sprintf(
  1571. '[%d] Error connecting to the API (%s)',
  1572. $statusCode,
  1573. $exception->getRequest()->getUri()
  1574. ),
  1575. $statusCode,
  1576. $response->getHeaders(),
  1577. (string) $response->getBody()
  1578. );
  1579. }
  1580. );
  1581. }
  1582. /**
  1583. * Create request for operation 'getApiV3ChannelsEditable'
  1584. *
  1585. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  1586. * @param string|null $search 按名字模糊匹配 (optional)
  1587. * @param string|null $type channel 类型 (optional)
  1588. * @param string|null $lang 语言 (optional)
  1589. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  1590. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  1591. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1592. * @param string|null $dir 排序方向 (optional, default to 'desc')
  1593. * @param int|null $page 页码 (optional, default to 1)
  1594. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsEditable'] to see the possible values for this operation
  1595. *
  1596. * @throws \InvalidArgumentException
  1597. * @return \GuzzleHttp\Psr7\Request
  1598. */
  1599. 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])
  1600. {
  1601. $resourcePath = '/v3/channels/editable';
  1602. $formParams = [];
  1603. $queryParams = [];
  1604. $headerParams = [];
  1605. $httpBody = '';
  1606. $multipart = false;
  1607. // query params
  1608. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1609. $per_page,
  1610. 'per_page', // param base name
  1611. 'integer', // openApiType
  1612. 'form', // style
  1613. true, // explode
  1614. false // required
  1615. ) ?? []);
  1616. // query params
  1617. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1618. $search,
  1619. 'search', // param base name
  1620. 'string', // openApiType
  1621. 'form', // style
  1622. true, // explode
  1623. false // required
  1624. ) ?? []);
  1625. // query params
  1626. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1627. $type,
  1628. 'type', // param base name
  1629. 'string', // openApiType
  1630. 'form', // style
  1631. true, // explode
  1632. false // required
  1633. ) ?? []);
  1634. // query params
  1635. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1636. $lang,
  1637. 'lang', // param base name
  1638. 'string', // openApiType
  1639. 'form', // style
  1640. true, // explode
  1641. false // required
  1642. ) ?? []);
  1643. // query params
  1644. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1645. $book,
  1646. 'book', // param base name
  1647. 'integer', // openApiType
  1648. 'form', // style
  1649. true, // explode
  1650. false // required
  1651. ) ?? []);
  1652. // query params
  1653. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1654. $para,
  1655. 'para', // param base name
  1656. 'integer', // openApiType
  1657. 'form', // style
  1658. true, // explode
  1659. false // required
  1660. ) ?? []);
  1661. // query params
  1662. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1663. $order,
  1664. 'order', // param base name
  1665. 'string', // openApiType
  1666. 'form', // style
  1667. true, // explode
  1668. false // required
  1669. ) ?? []);
  1670. // query params
  1671. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1672. $dir,
  1673. 'dir', // param base name
  1674. 'string', // openApiType
  1675. 'form', // style
  1676. true, // explode
  1677. false // required
  1678. ) ?? []);
  1679. // query params
  1680. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1681. $page,
  1682. 'page', // param base name
  1683. 'integer', // openApiType
  1684. 'form', // style
  1685. true, // explode
  1686. false // required
  1687. ) ?? []);
  1688. $headers = $this->headerSelector->selectHeaders(
  1689. ['application/json', 'application/problem+json', ],
  1690. $contentType,
  1691. $multipart
  1692. );
  1693. // for model (json/xml)
  1694. if (count($formParams) > 0) {
  1695. if ($multipart) {
  1696. $multipartContents = [];
  1697. foreach ($formParams as $formParamName => $formParamValue) {
  1698. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1699. foreach ($formParamValueItems as $formParamValueItem) {
  1700. $multipartContents[] = [
  1701. 'name' => $formParamName,
  1702. 'contents' => $formParamValueItem
  1703. ];
  1704. }
  1705. }
  1706. // for HTTP post (form)
  1707. $httpBody = new MultipartStream($multipartContents);
  1708. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1709. # if Content-Type contains "application/json", json_encode the form parameters
  1710. try {
  1711. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1712. } catch (\JsonException $e) {
  1713. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1714. }
  1715. } else {
  1716. // for HTTP post (form)
  1717. $httpBody = ObjectSerializer::buildQuery($formParams);
  1718. }
  1719. }
  1720. // this endpoint requires Bearer authentication (access token)
  1721. if (!empty($this->config->getAccessToken())) {
  1722. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1723. }
  1724. $defaultHeaders = [];
  1725. if ($this->config->getUserAgent()) {
  1726. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1727. }
  1728. $headers = array_merge(
  1729. $defaultHeaders,
  1730. $headerParams,
  1731. $headers
  1732. );
  1733. $operationHost = $this->config->getHost();
  1734. $query = ObjectSerializer::buildQuery($queryParams);
  1735. return new Request(
  1736. 'GET',
  1737. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1738. $headers,
  1739. $httpBody
  1740. );
  1741. }
  1742. /**
  1743. * Operation patchApiV3ChannelsChannel
  1744. *
  1745. * 改 channel 信息
  1746. *
  1747. * @param string $channel channel uid (required)
  1748. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelRequest|null $patch_api_v3_channels_channel_request patch_api_v3_channels_channel_request (optional)
  1749. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannel'] to see the possible values for this operation
  1750. *
  1751. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1752. * @throws \InvalidArgumentException
  1753. * @return \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  1754. */
  1755. public function patchApiV3ChannelsChannel($channel, $patch_api_v3_channels_channel_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannel'][0])
  1756. {
  1757. list($response) = $this->patchApiV3ChannelsChannelWithHttpInfo($channel, $patch_api_v3_channels_channel_request, $contentType);
  1758. return $response;
  1759. }
  1760. /**
  1761. * Operation patchApiV3ChannelsChannelWithHttpInfo
  1762. *
  1763. * 改 channel 信息
  1764. *
  1765. * @param string $channel channel uid (required)
  1766. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelRequest|null $patch_api_v3_channels_channel_request (optional)
  1767. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannel'] to see the possible values for this operation
  1768. *
  1769. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1770. * @throws \InvalidArgumentException
  1771. * @return array of \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  1772. */
  1773. public function patchApiV3ChannelsChannelWithHttpInfo($channel, $patch_api_v3_channels_channel_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannel'][0])
  1774. {
  1775. $request = $this->patchApiV3ChannelsChannelRequest($channel, $patch_api_v3_channels_channel_request, $contentType);
  1776. try {
  1777. $options = $this->createHttpClientOption();
  1778. try {
  1779. $response = $this->client->send($request, $options);
  1780. } catch (RequestException $e) {
  1781. throw new ApiException(
  1782. "[{$e->getCode()}] {$e->getMessage()}",
  1783. (int) $e->getCode(),
  1784. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1785. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1786. );
  1787. } catch (ConnectException $e) {
  1788. throw new ApiException(
  1789. "[{$e->getCode()}] {$e->getMessage()}",
  1790. (int) $e->getCode(),
  1791. null,
  1792. null
  1793. );
  1794. }
  1795. $statusCode = $response->getStatusCode();
  1796. switch($statusCode) {
  1797. case 200:
  1798. return $this->handleResponseWithDataType(
  1799. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  1800. $request,
  1801. $response,
  1802. );
  1803. case 401:
  1804. return $this->handleResponseWithDataType(
  1805. '\WikipaliApi\Model\ProblemDetails',
  1806. $request,
  1807. $response,
  1808. );
  1809. case 403:
  1810. return $this->handleResponseWithDataType(
  1811. '\WikipaliApi\Model\ProblemDetails',
  1812. $request,
  1813. $response,
  1814. );
  1815. case 422:
  1816. return $this->handleResponseWithDataType(
  1817. '\WikipaliApi\Model\ProblemDetails',
  1818. $request,
  1819. $response,
  1820. );
  1821. }
  1822. if ($statusCode < 200 || $statusCode > 299) {
  1823. throw new ApiException(
  1824. sprintf(
  1825. '[%d] Error connecting to the API (%s)',
  1826. $statusCode,
  1827. (string) $request->getUri()
  1828. ),
  1829. $statusCode,
  1830. $response->getHeaders(),
  1831. (string) $response->getBody()
  1832. );
  1833. }
  1834. return $this->handleResponseWithDataType(
  1835. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  1836. $request,
  1837. $response,
  1838. );
  1839. } catch (ApiException $e) {
  1840. switch ($e->getCode()) {
  1841. case 200:
  1842. $data = ObjectSerializer::deserialize(
  1843. $e->getResponseBody(),
  1844. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  1845. $e->getResponseHeaders()
  1846. );
  1847. $e->setResponseObject($data);
  1848. throw $e;
  1849. case 401:
  1850. $data = ObjectSerializer::deserialize(
  1851. $e->getResponseBody(),
  1852. '\WikipaliApi\Model\ProblemDetails',
  1853. $e->getResponseHeaders()
  1854. );
  1855. $e->setResponseObject($data);
  1856. throw $e;
  1857. case 403:
  1858. $data = ObjectSerializer::deserialize(
  1859. $e->getResponseBody(),
  1860. '\WikipaliApi\Model\ProblemDetails',
  1861. $e->getResponseHeaders()
  1862. );
  1863. $e->setResponseObject($data);
  1864. throw $e;
  1865. case 422:
  1866. $data = ObjectSerializer::deserialize(
  1867. $e->getResponseBody(),
  1868. '\WikipaliApi\Model\ProblemDetails',
  1869. $e->getResponseHeaders()
  1870. );
  1871. $e->setResponseObject($data);
  1872. throw $e;
  1873. }
  1874. throw $e;
  1875. }
  1876. }
  1877. /**
  1878. * Operation patchApiV3ChannelsChannelAsync
  1879. *
  1880. * 改 channel 信息
  1881. *
  1882. * @param string $channel channel uid (required)
  1883. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelRequest|null $patch_api_v3_channels_channel_request (optional)
  1884. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannel'] to see the possible values for this operation
  1885. *
  1886. * @throws \InvalidArgumentException
  1887. * @return \GuzzleHttp\Promise\PromiseInterface
  1888. */
  1889. public function patchApiV3ChannelsChannelAsync($channel, $patch_api_v3_channels_channel_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannel'][0])
  1890. {
  1891. return $this->patchApiV3ChannelsChannelAsyncWithHttpInfo($channel, $patch_api_v3_channels_channel_request, $contentType)
  1892. ->then(
  1893. function ($response) {
  1894. return $response[0];
  1895. }
  1896. );
  1897. }
  1898. /**
  1899. * Operation patchApiV3ChannelsChannelAsyncWithHttpInfo
  1900. *
  1901. * 改 channel 信息
  1902. *
  1903. * @param string $channel channel uid (required)
  1904. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelRequest|null $patch_api_v3_channels_channel_request (optional)
  1905. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannel'] to see the possible values for this operation
  1906. *
  1907. * @throws \InvalidArgumentException
  1908. * @return \GuzzleHttp\Promise\PromiseInterface
  1909. */
  1910. public function patchApiV3ChannelsChannelAsyncWithHttpInfo($channel, $patch_api_v3_channels_channel_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannel'][0])
  1911. {
  1912. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response';
  1913. $request = $this->patchApiV3ChannelsChannelRequest($channel, $patch_api_v3_channels_channel_request, $contentType);
  1914. return $this->client
  1915. ->sendAsync($request, $this->createHttpClientOption())
  1916. ->then(
  1917. function ($response) use ($returnType) {
  1918. if ($returnType === '\SplFileObject') {
  1919. $content = $response->getBody(); //stream goes to serializer
  1920. } else {
  1921. $content = (string) $response->getBody();
  1922. if ($returnType !== 'string') {
  1923. $content = json_decode($content);
  1924. }
  1925. }
  1926. return [
  1927. ObjectSerializer::deserialize($content, $returnType, []),
  1928. $response->getStatusCode(),
  1929. $response->getHeaders()
  1930. ];
  1931. },
  1932. function ($exception) {
  1933. $response = $exception->getResponse();
  1934. $statusCode = $response->getStatusCode();
  1935. throw new ApiException(
  1936. sprintf(
  1937. '[%d] Error connecting to the API (%s)',
  1938. $statusCode,
  1939. $exception->getRequest()->getUri()
  1940. ),
  1941. $statusCode,
  1942. $response->getHeaders(),
  1943. (string) $response->getBody()
  1944. );
  1945. }
  1946. );
  1947. }
  1948. /**
  1949. * Create request for operation 'patchApiV3ChannelsChannel'
  1950. *
  1951. * @param string $channel channel uid (required)
  1952. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelRequest|null $patch_api_v3_channels_channel_request (optional)
  1953. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannel'] to see the possible values for this operation
  1954. *
  1955. * @throws \InvalidArgumentException
  1956. * @return \GuzzleHttp\Psr7\Request
  1957. */
  1958. public function patchApiV3ChannelsChannelRequest($channel, $patch_api_v3_channels_channel_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannel'][0])
  1959. {
  1960. // verify the required parameter 'channel' is set
  1961. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  1962. throw new \InvalidArgumentException(
  1963. 'Missing the required parameter $channel when calling patchApiV3ChannelsChannel'
  1964. );
  1965. }
  1966. $resourcePath = '/v3/channels/{channel}';
  1967. $formParams = [];
  1968. $queryParams = [];
  1969. $headerParams = [];
  1970. $httpBody = '';
  1971. $multipart = false;
  1972. // path params
  1973. if ($channel !== null) {
  1974. $resourcePath = str_replace(
  1975. '{channel}',
  1976. ObjectSerializer::toPathValue($channel),
  1977. $resourcePath
  1978. );
  1979. }
  1980. $headers = $this->headerSelector->selectHeaders(
  1981. ['application/json', 'application/problem+json', ],
  1982. $contentType,
  1983. $multipart
  1984. );
  1985. // for model (json/xml)
  1986. if (isset($patch_api_v3_channels_channel_request)) {
  1987. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  1988. # if Content-Type contains "application/json", json_encode the body
  1989. try {
  1990. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($patch_api_v3_channels_channel_request), JSON_THROW_ON_ERROR);
  1991. } catch (\JsonException $e) {
  1992. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1993. }
  1994. } else {
  1995. $httpBody = $patch_api_v3_channels_channel_request;
  1996. }
  1997. } elseif (count($formParams) > 0) {
  1998. if ($multipart) {
  1999. $multipartContents = [];
  2000. foreach ($formParams as $formParamName => $formParamValue) {
  2001. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  2002. foreach ($formParamValueItems as $formParamValueItem) {
  2003. $multipartContents[] = [
  2004. 'name' => $formParamName,
  2005. 'contents' => $formParamValueItem
  2006. ];
  2007. }
  2008. }
  2009. // for HTTP post (form)
  2010. $httpBody = new MultipartStream($multipartContents);
  2011. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  2012. # if Content-Type contains "application/json", json_encode the form parameters
  2013. try {
  2014. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  2015. } catch (\JsonException $e) {
  2016. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  2017. }
  2018. } else {
  2019. // for HTTP post (form)
  2020. $httpBody = ObjectSerializer::buildQuery($formParams);
  2021. }
  2022. }
  2023. // this endpoint requires Bearer authentication (access token)
  2024. if (!empty($this->config->getAccessToken())) {
  2025. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  2026. }
  2027. $defaultHeaders = [];
  2028. if ($this->config->getUserAgent()) {
  2029. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  2030. }
  2031. $headers = array_merge(
  2032. $defaultHeaders,
  2033. $headerParams,
  2034. $headers
  2035. );
  2036. $operationHost = $this->config->getHost();
  2037. $query = ObjectSerializer::buildQuery($queryParams);
  2038. return new Request(
  2039. 'PATCH',
  2040. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  2041. $headers,
  2042. $httpBody
  2043. );
  2044. }
  2045. /**
  2046. * Operation patchApiV3ChannelsChannelLinks
  2047. *
  2048. * 改 channel 的关系设置
  2049. *
  2050. * @param string $channel channel uid (required)
  2051. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelLinksRequest|null $patch_api_v3_channels_channel_links_request patch_api_v3_channels_channel_links_request (optional)
  2052. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannelLinks'] to see the possible values for this operation
  2053. *
  2054. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  2055. * @throws \InvalidArgumentException
  2056. * @return \WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  2057. */
  2058. public function patchApiV3ChannelsChannelLinks($channel, $patch_api_v3_channels_channel_links_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannelLinks'][0])
  2059. {
  2060. list($response) = $this->patchApiV3ChannelsChannelLinksWithHttpInfo($channel, $patch_api_v3_channels_channel_links_request, $contentType);
  2061. return $response;
  2062. }
  2063. /**
  2064. * Operation patchApiV3ChannelsChannelLinksWithHttpInfo
  2065. *
  2066. * 改 channel 的关系设置
  2067. *
  2068. * @param string $channel channel uid (required)
  2069. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelLinksRequest|null $patch_api_v3_channels_channel_links_request (optional)
  2070. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannelLinks'] to see the possible values for this operation
  2071. *
  2072. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  2073. * @throws \InvalidArgumentException
  2074. * @return array of \WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  2075. */
  2076. public function patchApiV3ChannelsChannelLinksWithHttpInfo($channel, $patch_api_v3_channels_channel_links_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannelLinks'][0])
  2077. {
  2078. $request = $this->patchApiV3ChannelsChannelLinksRequest($channel, $patch_api_v3_channels_channel_links_request, $contentType);
  2079. try {
  2080. $options = $this->createHttpClientOption();
  2081. try {
  2082. $response = $this->client->send($request, $options);
  2083. } catch (RequestException $e) {
  2084. throw new ApiException(
  2085. "[{$e->getCode()}] {$e->getMessage()}",
  2086. (int) $e->getCode(),
  2087. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  2088. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  2089. );
  2090. } catch (ConnectException $e) {
  2091. throw new ApiException(
  2092. "[{$e->getCode()}] {$e->getMessage()}",
  2093. (int) $e->getCode(),
  2094. null,
  2095. null
  2096. );
  2097. }
  2098. $statusCode = $response->getStatusCode();
  2099. switch($statusCode) {
  2100. case 200:
  2101. return $this->handleResponseWithDataType(
  2102. '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response',
  2103. $request,
  2104. $response,
  2105. );
  2106. case 401:
  2107. return $this->handleResponseWithDataType(
  2108. '\WikipaliApi\Model\ProblemDetails',
  2109. $request,
  2110. $response,
  2111. );
  2112. case 403:
  2113. return $this->handleResponseWithDataType(
  2114. '\WikipaliApi\Model\ProblemDetails',
  2115. $request,
  2116. $response,
  2117. );
  2118. case 422:
  2119. return $this->handleResponseWithDataType(
  2120. '\WikipaliApi\Model\ProblemDetails',
  2121. $request,
  2122. $response,
  2123. );
  2124. }
  2125. if ($statusCode < 200 || $statusCode > 299) {
  2126. throw new ApiException(
  2127. sprintf(
  2128. '[%d] Error connecting to the API (%s)',
  2129. $statusCode,
  2130. (string) $request->getUri()
  2131. ),
  2132. $statusCode,
  2133. $response->getHeaders(),
  2134. (string) $response->getBody()
  2135. );
  2136. }
  2137. return $this->handleResponseWithDataType(
  2138. '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response',
  2139. $request,
  2140. $response,
  2141. );
  2142. } catch (ApiException $e) {
  2143. switch ($e->getCode()) {
  2144. case 200:
  2145. $data = ObjectSerializer::deserialize(
  2146. $e->getResponseBody(),
  2147. '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response',
  2148. $e->getResponseHeaders()
  2149. );
  2150. $e->setResponseObject($data);
  2151. throw $e;
  2152. case 401:
  2153. $data = ObjectSerializer::deserialize(
  2154. $e->getResponseBody(),
  2155. '\WikipaliApi\Model\ProblemDetails',
  2156. $e->getResponseHeaders()
  2157. );
  2158. $e->setResponseObject($data);
  2159. throw $e;
  2160. case 403:
  2161. $data = ObjectSerializer::deserialize(
  2162. $e->getResponseBody(),
  2163. '\WikipaliApi\Model\ProblemDetails',
  2164. $e->getResponseHeaders()
  2165. );
  2166. $e->setResponseObject($data);
  2167. throw $e;
  2168. case 422:
  2169. $data = ObjectSerializer::deserialize(
  2170. $e->getResponseBody(),
  2171. '\WikipaliApi\Model\ProblemDetails',
  2172. $e->getResponseHeaders()
  2173. );
  2174. $e->setResponseObject($data);
  2175. throw $e;
  2176. }
  2177. throw $e;
  2178. }
  2179. }
  2180. /**
  2181. * Operation patchApiV3ChannelsChannelLinksAsync
  2182. *
  2183. * 改 channel 的关系设置
  2184. *
  2185. * @param string $channel channel uid (required)
  2186. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelLinksRequest|null $patch_api_v3_channels_channel_links_request (optional)
  2187. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannelLinks'] to see the possible values for this operation
  2188. *
  2189. * @throws \InvalidArgumentException
  2190. * @return \GuzzleHttp\Promise\PromiseInterface
  2191. */
  2192. public function patchApiV3ChannelsChannelLinksAsync($channel, $patch_api_v3_channels_channel_links_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannelLinks'][0])
  2193. {
  2194. return $this->patchApiV3ChannelsChannelLinksAsyncWithHttpInfo($channel, $patch_api_v3_channels_channel_links_request, $contentType)
  2195. ->then(
  2196. function ($response) {
  2197. return $response[0];
  2198. }
  2199. );
  2200. }
  2201. /**
  2202. * Operation patchApiV3ChannelsChannelLinksAsyncWithHttpInfo
  2203. *
  2204. * 改 channel 的关系设置
  2205. *
  2206. * @param string $channel channel uid (required)
  2207. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelLinksRequest|null $patch_api_v3_channels_channel_links_request (optional)
  2208. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannelLinks'] to see the possible values for this operation
  2209. *
  2210. * @throws \InvalidArgumentException
  2211. * @return \GuzzleHttp\Promise\PromiseInterface
  2212. */
  2213. public function patchApiV3ChannelsChannelLinksAsyncWithHttpInfo($channel, $patch_api_v3_channels_channel_links_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannelLinks'][0])
  2214. {
  2215. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response';
  2216. $request = $this->patchApiV3ChannelsChannelLinksRequest($channel, $patch_api_v3_channels_channel_links_request, $contentType);
  2217. return $this->client
  2218. ->sendAsync($request, $this->createHttpClientOption())
  2219. ->then(
  2220. function ($response) use ($returnType) {
  2221. if ($returnType === '\SplFileObject') {
  2222. $content = $response->getBody(); //stream goes to serializer
  2223. } else {
  2224. $content = (string) $response->getBody();
  2225. if ($returnType !== 'string') {
  2226. $content = json_decode($content);
  2227. }
  2228. }
  2229. return [
  2230. ObjectSerializer::deserialize($content, $returnType, []),
  2231. $response->getStatusCode(),
  2232. $response->getHeaders()
  2233. ];
  2234. },
  2235. function ($exception) {
  2236. $response = $exception->getResponse();
  2237. $statusCode = $response->getStatusCode();
  2238. throw new ApiException(
  2239. sprintf(
  2240. '[%d] Error connecting to the API (%s)',
  2241. $statusCode,
  2242. $exception->getRequest()->getUri()
  2243. ),
  2244. $statusCode,
  2245. $response->getHeaders(),
  2246. (string) $response->getBody()
  2247. );
  2248. }
  2249. );
  2250. }
  2251. /**
  2252. * Create request for operation 'patchApiV3ChannelsChannelLinks'
  2253. *
  2254. * @param string $channel channel uid (required)
  2255. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelLinksRequest|null $patch_api_v3_channels_channel_links_request (optional)
  2256. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannelLinks'] to see the possible values for this operation
  2257. *
  2258. * @throws \InvalidArgumentException
  2259. * @return \GuzzleHttp\Psr7\Request
  2260. */
  2261. public function patchApiV3ChannelsChannelLinksRequest($channel, $patch_api_v3_channels_channel_links_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannelLinks'][0])
  2262. {
  2263. // verify the required parameter 'channel' is set
  2264. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  2265. throw new \InvalidArgumentException(
  2266. 'Missing the required parameter $channel when calling patchApiV3ChannelsChannelLinks'
  2267. );
  2268. }
  2269. $resourcePath = '/v3/channels/{channel}/links';
  2270. $formParams = [];
  2271. $queryParams = [];
  2272. $headerParams = [];
  2273. $httpBody = '';
  2274. $multipart = false;
  2275. // path params
  2276. if ($channel !== null) {
  2277. $resourcePath = str_replace(
  2278. '{channel}',
  2279. ObjectSerializer::toPathValue($channel),
  2280. $resourcePath
  2281. );
  2282. }
  2283. $headers = $this->headerSelector->selectHeaders(
  2284. ['application/json', 'application/problem+json', ],
  2285. $contentType,
  2286. $multipart
  2287. );
  2288. // for model (json/xml)
  2289. if (isset($patch_api_v3_channels_channel_links_request)) {
  2290. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  2291. # if Content-Type contains "application/json", json_encode the body
  2292. try {
  2293. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($patch_api_v3_channels_channel_links_request), JSON_THROW_ON_ERROR);
  2294. } catch (\JsonException $e) {
  2295. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  2296. }
  2297. } else {
  2298. $httpBody = $patch_api_v3_channels_channel_links_request;
  2299. }
  2300. } elseif (count($formParams) > 0) {
  2301. if ($multipart) {
  2302. $multipartContents = [];
  2303. foreach ($formParams as $formParamName => $formParamValue) {
  2304. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  2305. foreach ($formParamValueItems as $formParamValueItem) {
  2306. $multipartContents[] = [
  2307. 'name' => $formParamName,
  2308. 'contents' => $formParamValueItem
  2309. ];
  2310. }
  2311. }
  2312. // for HTTP post (form)
  2313. $httpBody = new MultipartStream($multipartContents);
  2314. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  2315. # if Content-Type contains "application/json", json_encode the form parameters
  2316. try {
  2317. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  2318. } catch (\JsonException $e) {
  2319. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  2320. }
  2321. } else {
  2322. // for HTTP post (form)
  2323. $httpBody = ObjectSerializer::buildQuery($formParams);
  2324. }
  2325. }
  2326. // this endpoint requires Bearer authentication (access token)
  2327. if (!empty($this->config->getAccessToken())) {
  2328. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  2329. }
  2330. $defaultHeaders = [];
  2331. if ($this->config->getUserAgent()) {
  2332. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  2333. }
  2334. $headers = array_merge(
  2335. $defaultHeaders,
  2336. $headerParams,
  2337. $headers
  2338. );
  2339. $operationHost = $this->config->getHost();
  2340. $query = ObjectSerializer::buildQuery($queryParams);
  2341. return new Request(
  2342. 'PATCH',
  2343. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  2344. $headers,
  2345. $httpBody
  2346. );
  2347. }
  2348. /**
  2349. * Operation postApiV3ChannelsBatchProgress
  2350. *
  2351. * 查一批句子在各 channel 的完成度
  2352. *
  2353. * @param \WikipaliApi\Model\PostApiV3ChannelsBatchProgressRequest $post_api_v3_channels_batch_progress_request post_api_v3_channels_batch_progress_request (required)
  2354. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsBatchProgress'] to see the possible values for this operation
  2355. *
  2356. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  2357. * @throws \InvalidArgumentException
  2358. * @return \WikipaliApi\Model\PostApiV3ChannelsBatchProgress200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  2359. */
  2360. public function postApiV3ChannelsBatchProgress($post_api_v3_channels_batch_progress_request, string $contentType = self::contentTypes['postApiV3ChannelsBatchProgress'][0])
  2361. {
  2362. list($response) = $this->postApiV3ChannelsBatchProgressWithHttpInfo($post_api_v3_channels_batch_progress_request, $contentType);
  2363. return $response;
  2364. }
  2365. /**
  2366. * Operation postApiV3ChannelsBatchProgressWithHttpInfo
  2367. *
  2368. * 查一批句子在各 channel 的完成度
  2369. *
  2370. * @param \WikipaliApi\Model\PostApiV3ChannelsBatchProgressRequest $post_api_v3_channels_batch_progress_request (required)
  2371. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsBatchProgress'] to see the possible values for this operation
  2372. *
  2373. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  2374. * @throws \InvalidArgumentException
  2375. * @return array of \WikipaliApi\Model\PostApiV3ChannelsBatchProgress200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  2376. */
  2377. public function postApiV3ChannelsBatchProgressWithHttpInfo($post_api_v3_channels_batch_progress_request, string $contentType = self::contentTypes['postApiV3ChannelsBatchProgress'][0])
  2378. {
  2379. $request = $this->postApiV3ChannelsBatchProgressRequest($post_api_v3_channels_batch_progress_request, $contentType);
  2380. try {
  2381. $options = $this->createHttpClientOption();
  2382. try {
  2383. $response = $this->client->send($request, $options);
  2384. } catch (RequestException $e) {
  2385. throw new ApiException(
  2386. "[{$e->getCode()}] {$e->getMessage()}",
  2387. (int) $e->getCode(),
  2388. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  2389. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  2390. );
  2391. } catch (ConnectException $e) {
  2392. throw new ApiException(
  2393. "[{$e->getCode()}] {$e->getMessage()}",
  2394. (int) $e->getCode(),
  2395. null,
  2396. null
  2397. );
  2398. }
  2399. $statusCode = $response->getStatusCode();
  2400. switch($statusCode) {
  2401. case 200:
  2402. return $this->handleResponseWithDataType(
  2403. '\WikipaliApi\Model\PostApiV3ChannelsBatchProgress200Response',
  2404. $request,
  2405. $response,
  2406. );
  2407. case 403:
  2408. return $this->handleResponseWithDataType(
  2409. '\WikipaliApi\Model\ProblemDetails',
  2410. $request,
  2411. $response,
  2412. );
  2413. case 422:
  2414. return $this->handleResponseWithDataType(
  2415. '\WikipaliApi\Model\ProblemDetails',
  2416. $request,
  2417. $response,
  2418. );
  2419. }
  2420. if ($statusCode < 200 || $statusCode > 299) {
  2421. throw new ApiException(
  2422. sprintf(
  2423. '[%d] Error connecting to the API (%s)',
  2424. $statusCode,
  2425. (string) $request->getUri()
  2426. ),
  2427. $statusCode,
  2428. $response->getHeaders(),
  2429. (string) $response->getBody()
  2430. );
  2431. }
  2432. return $this->handleResponseWithDataType(
  2433. '\WikipaliApi\Model\PostApiV3ChannelsBatchProgress200Response',
  2434. $request,
  2435. $response,
  2436. );
  2437. } catch (ApiException $e) {
  2438. switch ($e->getCode()) {
  2439. case 200:
  2440. $data = ObjectSerializer::deserialize(
  2441. $e->getResponseBody(),
  2442. '\WikipaliApi\Model\PostApiV3ChannelsBatchProgress200Response',
  2443. $e->getResponseHeaders()
  2444. );
  2445. $e->setResponseObject($data);
  2446. throw $e;
  2447. case 403:
  2448. $data = ObjectSerializer::deserialize(
  2449. $e->getResponseBody(),
  2450. '\WikipaliApi\Model\ProblemDetails',
  2451. $e->getResponseHeaders()
  2452. );
  2453. $e->setResponseObject($data);
  2454. throw $e;
  2455. case 422:
  2456. $data = ObjectSerializer::deserialize(
  2457. $e->getResponseBody(),
  2458. '\WikipaliApi\Model\ProblemDetails',
  2459. $e->getResponseHeaders()
  2460. );
  2461. $e->setResponseObject($data);
  2462. throw $e;
  2463. }
  2464. throw $e;
  2465. }
  2466. }
  2467. /**
  2468. * Operation postApiV3ChannelsBatchProgressAsync
  2469. *
  2470. * 查一批句子在各 channel 的完成度
  2471. *
  2472. * @param \WikipaliApi\Model\PostApiV3ChannelsBatchProgressRequest $post_api_v3_channels_batch_progress_request (required)
  2473. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsBatchProgress'] to see the possible values for this operation
  2474. *
  2475. * @throws \InvalidArgumentException
  2476. * @return \GuzzleHttp\Promise\PromiseInterface
  2477. */
  2478. public function postApiV3ChannelsBatchProgressAsync($post_api_v3_channels_batch_progress_request, string $contentType = self::contentTypes['postApiV3ChannelsBatchProgress'][0])
  2479. {
  2480. return $this->postApiV3ChannelsBatchProgressAsyncWithHttpInfo($post_api_v3_channels_batch_progress_request, $contentType)
  2481. ->then(
  2482. function ($response) {
  2483. return $response[0];
  2484. }
  2485. );
  2486. }
  2487. /**
  2488. * Operation postApiV3ChannelsBatchProgressAsyncWithHttpInfo
  2489. *
  2490. * 查一批句子在各 channel 的完成度
  2491. *
  2492. * @param \WikipaliApi\Model\PostApiV3ChannelsBatchProgressRequest $post_api_v3_channels_batch_progress_request (required)
  2493. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsBatchProgress'] to see the possible values for this operation
  2494. *
  2495. * @throws \InvalidArgumentException
  2496. * @return \GuzzleHttp\Promise\PromiseInterface
  2497. */
  2498. public function postApiV3ChannelsBatchProgressAsyncWithHttpInfo($post_api_v3_channels_batch_progress_request, string $contentType = self::contentTypes['postApiV3ChannelsBatchProgress'][0])
  2499. {
  2500. $returnType = '\WikipaliApi\Model\PostApiV3ChannelsBatchProgress200Response';
  2501. $request = $this->postApiV3ChannelsBatchProgressRequest($post_api_v3_channels_batch_progress_request, $contentType);
  2502. return $this->client
  2503. ->sendAsync($request, $this->createHttpClientOption())
  2504. ->then(
  2505. function ($response) use ($returnType) {
  2506. if ($returnType === '\SplFileObject') {
  2507. $content = $response->getBody(); //stream goes to serializer
  2508. } else {
  2509. $content = (string) $response->getBody();
  2510. if ($returnType !== 'string') {
  2511. $content = json_decode($content);
  2512. }
  2513. }
  2514. return [
  2515. ObjectSerializer::deserialize($content, $returnType, []),
  2516. $response->getStatusCode(),
  2517. $response->getHeaders()
  2518. ];
  2519. },
  2520. function ($exception) {
  2521. $response = $exception->getResponse();
  2522. $statusCode = $response->getStatusCode();
  2523. throw new ApiException(
  2524. sprintf(
  2525. '[%d] Error connecting to the API (%s)',
  2526. $statusCode,
  2527. $exception->getRequest()->getUri()
  2528. ),
  2529. $statusCode,
  2530. $response->getHeaders(),
  2531. (string) $response->getBody()
  2532. );
  2533. }
  2534. );
  2535. }
  2536. /**
  2537. * Create request for operation 'postApiV3ChannelsBatchProgress'
  2538. *
  2539. * @param \WikipaliApi\Model\PostApiV3ChannelsBatchProgressRequest $post_api_v3_channels_batch_progress_request (required)
  2540. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsBatchProgress'] to see the possible values for this operation
  2541. *
  2542. * @throws \InvalidArgumentException
  2543. * @return \GuzzleHttp\Psr7\Request
  2544. */
  2545. public function postApiV3ChannelsBatchProgressRequest($post_api_v3_channels_batch_progress_request, string $contentType = self::contentTypes['postApiV3ChannelsBatchProgress'][0])
  2546. {
  2547. // verify the required parameter 'post_api_v3_channels_batch_progress_request' is set
  2548. 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)) {
  2549. throw new \InvalidArgumentException(
  2550. 'Missing the required parameter $post_api_v3_channels_batch_progress_request when calling postApiV3ChannelsBatchProgress'
  2551. );
  2552. }
  2553. $resourcePath = '/v3/channels/batch-progress';
  2554. $formParams = [];
  2555. $queryParams = [];
  2556. $headerParams = [];
  2557. $httpBody = '';
  2558. $multipart = false;
  2559. $headers = $this->headerSelector->selectHeaders(
  2560. ['application/json', 'application/problem+json', ],
  2561. $contentType,
  2562. $multipart
  2563. );
  2564. // for model (json/xml)
  2565. if (isset($post_api_v3_channels_batch_progress_request)) {
  2566. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  2567. # if Content-Type contains "application/json", json_encode the body
  2568. try {
  2569. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_channels_batch_progress_request), JSON_THROW_ON_ERROR);
  2570. } catch (\JsonException $e) {
  2571. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  2572. }
  2573. } else {
  2574. $httpBody = $post_api_v3_channels_batch_progress_request;
  2575. }
  2576. } elseif (count($formParams) > 0) {
  2577. if ($multipart) {
  2578. $multipartContents = [];
  2579. foreach ($formParams as $formParamName => $formParamValue) {
  2580. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  2581. foreach ($formParamValueItems as $formParamValueItem) {
  2582. $multipartContents[] = [
  2583. 'name' => $formParamName,
  2584. 'contents' => $formParamValueItem
  2585. ];
  2586. }
  2587. }
  2588. // for HTTP post (form)
  2589. $httpBody = new MultipartStream($multipartContents);
  2590. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  2591. # if Content-Type contains "application/json", json_encode the form parameters
  2592. try {
  2593. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  2594. } catch (\JsonException $e) {
  2595. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  2596. }
  2597. } else {
  2598. // for HTTP post (form)
  2599. $httpBody = ObjectSerializer::buildQuery($formParams);
  2600. }
  2601. }
  2602. // this endpoint requires Bearer authentication (access token)
  2603. if (!empty($this->config->getAccessToken())) {
  2604. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  2605. }
  2606. $defaultHeaders = [];
  2607. if ($this->config->getUserAgent()) {
  2608. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  2609. }
  2610. $headers = array_merge(
  2611. $defaultHeaders,
  2612. $headerParams,
  2613. $headers
  2614. );
  2615. $operationHost = $this->config->getHost();
  2616. $query = ObjectSerializer::buildQuery($queryParams);
  2617. return new Request(
  2618. 'POST',
  2619. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  2620. $headers,
  2621. $httpBody
  2622. );
  2623. }
  2624. /**
  2625. * Create http client option
  2626. *
  2627. * @throws \RuntimeException on file opening failure
  2628. * @return array of http client options
  2629. */
  2630. protected function createHttpClientOption()
  2631. {
  2632. $options = [];
  2633. if ($this->config->getDebug()) {
  2634. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  2635. if (!$options[RequestOptions::DEBUG]) {
  2636. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  2637. }
  2638. }
  2639. if ($this->config->getCertFile()) {
  2640. $options[RequestOptions::CERT] = $this->config->getCertFile();
  2641. }
  2642. if ($this->config->getKeyFile()) {
  2643. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  2644. }
  2645. return $options;
  2646. }
  2647. private function handleResponseWithDataType(
  2648. string $dataType,
  2649. RequestInterface $request,
  2650. ResponseInterface $response
  2651. ): array {
  2652. if ($dataType === '\SplFileObject') {
  2653. $content = $response->getBody(); //stream goes to serializer
  2654. } else {
  2655. $content = (string) $response->getBody();
  2656. if ($dataType !== 'string') {
  2657. try {
  2658. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  2659. } catch (\JsonException $exception) {
  2660. throw new ApiException(
  2661. sprintf(
  2662. 'Error JSON decoding server response (%s)',
  2663. $request->getUri()
  2664. ),
  2665. $response->getStatusCode(),
  2666. $response->getHeaders(),
  2667. $content
  2668. );
  2669. }
  2670. }
  2671. }
  2672. return [
  2673. ObjectSerializer::deserialize($content, $dataType, []),
  2674. $response->getStatusCode(),
  2675. $response->getHeaders()
  2676. ];
  2677. }
  2678. private function responseWithinRangeCode(
  2679. string $rangeCode,
  2680. int $statusCode
  2681. ): bool {
  2682. $left = (int) ($rangeCode[0].'00');
  2683. $right = (int) ($rangeCode[0].'99');
  2684. return $statusCode >= $left && $statusCode <= $right;
  2685. }
  2686. }