ChannelsApi.php 166 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101
  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. 'getApiV3ChannelsChannelTerms' => [
  81. 'application/json',
  82. ],
  83. 'getApiV3ChannelsEditable' => [
  84. 'application/json',
  85. ],
  86. 'patchApiV3ChannelsChannel' => [
  87. 'application/json',
  88. ],
  89. 'patchApiV3ChannelsChannelLinks' => [
  90. 'application/json',
  91. ],
  92. 'postApiV3ChannelsBatchProgress' => [
  93. 'application/json',
  94. ],
  95. 'postApiV3ChannelsChannelTerms' => [
  96. 'application/json',
  97. ],
  98. 'postApiV3ChannelsChannelTermsImports' => [
  99. 'multipart/form-data',
  100. ],
  101. ];
  102. /**
  103. * @param ClientInterface $client
  104. * @param Configuration $config
  105. * @param HeaderSelector $selector
  106. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  107. */
  108. public function __construct(
  109. ?ClientInterface $client = null,
  110. ?Configuration $config = null,
  111. ?HeaderSelector $selector = null,
  112. int $hostIndex = 0
  113. ) {
  114. $this->client = $client ?: new Client();
  115. $this->config = $config ?: Configuration::getDefaultConfiguration();
  116. $this->headerSelector = $selector ?: new HeaderSelector();
  117. $this->hostIndex = $hostIndex;
  118. }
  119. /**
  120. * Set the host index
  121. *
  122. * @param int $hostIndex Host index (required)
  123. */
  124. public function setHostIndex($hostIndex): void
  125. {
  126. $this->hostIndex = $hostIndex;
  127. }
  128. /**
  129. * Get the host index
  130. *
  131. * @return int Host index
  132. */
  133. public function getHostIndex()
  134. {
  135. return $this->hostIndex;
  136. }
  137. /**
  138. * @return Configuration
  139. */
  140. public function getConfig()
  141. {
  142. return $this->config;
  143. }
  144. /**
  145. * Operation deleteApiV3ChannelsChannel
  146. *
  147. * 删除 channel
  148. *
  149. * @param string $channel channel uid (required)
  150. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3ChannelsChannel'] to see the possible values for this operation
  151. *
  152. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  153. * @throws \InvalidArgumentException
  154. * @return \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  155. */
  156. public function deleteApiV3ChannelsChannel($channel, string $contentType = self::contentTypes['deleteApiV3ChannelsChannel'][0])
  157. {
  158. list($response) = $this->deleteApiV3ChannelsChannelWithHttpInfo($channel, $contentType);
  159. return $response;
  160. }
  161. /**
  162. * Operation deleteApiV3ChannelsChannelWithHttpInfo
  163. *
  164. * 删除 channel
  165. *
  166. * @param string $channel channel uid (required)
  167. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3ChannelsChannel'] to see the possible values for this operation
  168. *
  169. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  170. * @throws \InvalidArgumentException
  171. * @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)
  172. */
  173. public function deleteApiV3ChannelsChannelWithHttpInfo($channel, string $contentType = self::contentTypes['deleteApiV3ChannelsChannel'][0])
  174. {
  175. $request = $this->deleteApiV3ChannelsChannelRequest($channel, $contentType);
  176. try {
  177. $options = $this->createHttpClientOption();
  178. try {
  179. $response = $this->client->send($request, $options);
  180. } catch (RequestException $e) {
  181. throw new ApiException(
  182. "[{$e->getCode()}] {$e->getMessage()}",
  183. (int) $e->getCode(),
  184. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  185. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  186. );
  187. } catch (ConnectException $e) {
  188. throw new ApiException(
  189. "[{$e->getCode()}] {$e->getMessage()}",
  190. (int) $e->getCode(),
  191. null,
  192. null
  193. );
  194. }
  195. $statusCode = $response->getStatusCode();
  196. switch($statusCode) {
  197. case 200:
  198. return $this->handleResponseWithDataType(
  199. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  200. $request,
  201. $response,
  202. );
  203. case 401:
  204. return $this->handleResponseWithDataType(
  205. '\WikipaliApi\Model\ProblemDetails',
  206. $request,
  207. $response,
  208. );
  209. case 403:
  210. return $this->handleResponseWithDataType(
  211. '\WikipaliApi\Model\ProblemDetails',
  212. $request,
  213. $response,
  214. );
  215. case 409:
  216. return $this->handleResponseWithDataType(
  217. '\WikipaliApi\Model\ProblemDetails',
  218. $request,
  219. $response,
  220. );
  221. case 422:
  222. return $this->handleResponseWithDataType(
  223. '\WikipaliApi\Model\ProblemDetails',
  224. $request,
  225. $response,
  226. );
  227. }
  228. if ($statusCode < 200 || $statusCode > 299) {
  229. throw new ApiException(
  230. sprintf(
  231. '[%d] Error connecting to the API (%s)',
  232. $statusCode,
  233. (string) $request->getUri()
  234. ),
  235. $statusCode,
  236. $response->getHeaders(),
  237. (string) $response->getBody()
  238. );
  239. }
  240. return $this->handleResponseWithDataType(
  241. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  242. $request,
  243. $response,
  244. );
  245. } catch (ApiException $e) {
  246. switch ($e->getCode()) {
  247. case 200:
  248. $data = ObjectSerializer::deserialize(
  249. $e->getResponseBody(),
  250. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  251. $e->getResponseHeaders()
  252. );
  253. $e->setResponseObject($data);
  254. throw $e;
  255. case 401:
  256. $data = ObjectSerializer::deserialize(
  257. $e->getResponseBody(),
  258. '\WikipaliApi\Model\ProblemDetails',
  259. $e->getResponseHeaders()
  260. );
  261. $e->setResponseObject($data);
  262. throw $e;
  263. case 403:
  264. $data = ObjectSerializer::deserialize(
  265. $e->getResponseBody(),
  266. '\WikipaliApi\Model\ProblemDetails',
  267. $e->getResponseHeaders()
  268. );
  269. $e->setResponseObject($data);
  270. throw $e;
  271. case 409:
  272. $data = ObjectSerializer::deserialize(
  273. $e->getResponseBody(),
  274. '\WikipaliApi\Model\ProblemDetails',
  275. $e->getResponseHeaders()
  276. );
  277. $e->setResponseObject($data);
  278. throw $e;
  279. case 422:
  280. $data = ObjectSerializer::deserialize(
  281. $e->getResponseBody(),
  282. '\WikipaliApi\Model\ProblemDetails',
  283. $e->getResponseHeaders()
  284. );
  285. $e->setResponseObject($data);
  286. throw $e;
  287. }
  288. throw $e;
  289. }
  290. }
  291. /**
  292. * Operation deleteApiV3ChannelsChannelAsync
  293. *
  294. * 删除 channel
  295. *
  296. * @param string $channel channel uid (required)
  297. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3ChannelsChannel'] to see the possible values for this operation
  298. *
  299. * @throws \InvalidArgumentException
  300. * @return \GuzzleHttp\Promise\PromiseInterface
  301. */
  302. public function deleteApiV3ChannelsChannelAsync($channel, string $contentType = self::contentTypes['deleteApiV3ChannelsChannel'][0])
  303. {
  304. return $this->deleteApiV3ChannelsChannelAsyncWithHttpInfo($channel, $contentType)
  305. ->then(
  306. function ($response) {
  307. return $response[0];
  308. }
  309. );
  310. }
  311. /**
  312. * Operation deleteApiV3ChannelsChannelAsyncWithHttpInfo
  313. *
  314. * 删除 channel
  315. *
  316. * @param string $channel channel uid (required)
  317. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3ChannelsChannel'] to see the possible values for this operation
  318. *
  319. * @throws \InvalidArgumentException
  320. * @return \GuzzleHttp\Promise\PromiseInterface
  321. */
  322. public function deleteApiV3ChannelsChannelAsyncWithHttpInfo($channel, string $contentType = self::contentTypes['deleteApiV3ChannelsChannel'][0])
  323. {
  324. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response';
  325. $request = $this->deleteApiV3ChannelsChannelRequest($channel, $contentType);
  326. return $this->client
  327. ->sendAsync($request, $this->createHttpClientOption())
  328. ->then(
  329. function ($response) use ($returnType) {
  330. if ($returnType === '\SplFileObject') {
  331. $content = $response->getBody(); //stream goes to serializer
  332. } else {
  333. $content = (string) $response->getBody();
  334. if ($returnType !== 'string') {
  335. $content = json_decode($content);
  336. }
  337. }
  338. return [
  339. ObjectSerializer::deserialize($content, $returnType, []),
  340. $response->getStatusCode(),
  341. $response->getHeaders()
  342. ];
  343. },
  344. function ($exception) {
  345. $response = $exception->getResponse();
  346. $statusCode = $response->getStatusCode();
  347. throw new ApiException(
  348. sprintf(
  349. '[%d] Error connecting to the API (%s)',
  350. $statusCode,
  351. $exception->getRequest()->getUri()
  352. ),
  353. $statusCode,
  354. $response->getHeaders(),
  355. (string) $response->getBody()
  356. );
  357. }
  358. );
  359. }
  360. /**
  361. * Create request for operation 'deleteApiV3ChannelsChannel'
  362. *
  363. * @param string $channel channel uid (required)
  364. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3ChannelsChannel'] to see the possible values for this operation
  365. *
  366. * @throws \InvalidArgumentException
  367. * @return \GuzzleHttp\Psr7\Request
  368. */
  369. public function deleteApiV3ChannelsChannelRequest($channel, string $contentType = self::contentTypes['deleteApiV3ChannelsChannel'][0])
  370. {
  371. // verify the required parameter 'channel' is set
  372. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  373. throw new \InvalidArgumentException(
  374. 'Missing the required parameter $channel when calling deleteApiV3ChannelsChannel'
  375. );
  376. }
  377. $resourcePath = '/v3/channels/{channel}';
  378. $formParams = [];
  379. $queryParams = [];
  380. $headerParams = [];
  381. $httpBody = '';
  382. $multipart = false;
  383. // path params
  384. if ($channel !== null) {
  385. $resourcePath = str_replace(
  386. '{channel}',
  387. ObjectSerializer::toPathValue($channel),
  388. $resourcePath
  389. );
  390. }
  391. $headers = $this->headerSelector->selectHeaders(
  392. ['application/json', 'application/problem+json', ],
  393. $contentType,
  394. $multipart
  395. );
  396. // for model (json/xml)
  397. if (count($formParams) > 0) {
  398. if ($multipart) {
  399. $multipartContents = [];
  400. foreach ($formParams as $formParamName => $formParamValue) {
  401. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  402. foreach ($formParamValueItems as $formParamValueItem) {
  403. $multipartContents[] = [
  404. 'name' => $formParamName,
  405. 'contents' => $formParamValueItem
  406. ];
  407. }
  408. }
  409. // for HTTP post (form)
  410. $httpBody = new MultipartStream($multipartContents);
  411. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  412. # if Content-Type contains "application/json", json_encode the form parameters
  413. try {
  414. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  415. } catch (\JsonException $e) {
  416. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  417. }
  418. } else {
  419. // for HTTP post (form)
  420. $httpBody = ObjectSerializer::buildQuery($formParams);
  421. }
  422. }
  423. // this endpoint requires Bearer authentication (access token)
  424. if (!empty($this->config->getAccessToken())) {
  425. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  426. }
  427. $defaultHeaders = [];
  428. if ($this->config->getUserAgent()) {
  429. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  430. }
  431. $headers = array_merge(
  432. $defaultHeaders,
  433. $headerParams,
  434. $headers
  435. );
  436. $operationHost = $this->config->getHost();
  437. $query = ObjectSerializer::buildQuery($queryParams);
  438. return new Request(
  439. 'DELETE',
  440. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  441. $headers,
  442. $httpBody
  443. );
  444. }
  445. /**
  446. * Operation getApiV3Channels
  447. *
  448. * 公开 channel 目录
  449. *
  450. * @param bool|null $system 只列系统 channel (optional)
  451. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  452. * @param string|null $search 按名字模糊匹配 (optional)
  453. * @param string|null $type channel 类型 (optional)
  454. * @param string|null $lang 语言 (optional)
  455. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  456. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  457. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  458. * @param string|null $dir 排序方向 (optional, default to 'desc')
  459. * @param int|null $page 页码 (optional, default to 1)
  460. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Channels'] to see the possible values for this operation
  461. *
  462. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  463. * @throws \InvalidArgumentException
  464. * @return \WikipaliApi\Model\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails
  465. */
  466. 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])
  467. {
  468. list($response) = $this->getApiV3ChannelsWithHttpInfo($system, $per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  469. return $response;
  470. }
  471. /**
  472. * Operation getApiV3ChannelsWithHttpInfo
  473. *
  474. * 公开 channel 目录
  475. *
  476. * @param bool|null $system 只列系统 channel (optional)
  477. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  478. * @param string|null $search 按名字模糊匹配 (optional)
  479. * @param string|null $type channel 类型 (optional)
  480. * @param string|null $lang 语言 (optional)
  481. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  482. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  483. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  484. * @param string|null $dir 排序方向 (optional, default to 'desc')
  485. * @param int|null $page 页码 (optional, default to 1)
  486. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Channels'] to see the possible values for this operation
  487. *
  488. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  489. * @throws \InvalidArgumentException
  490. * @return array of \WikipaliApi\Model\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  491. */
  492. 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])
  493. {
  494. $request = $this->getApiV3ChannelsRequest($system, $per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  495. try {
  496. $options = $this->createHttpClientOption();
  497. try {
  498. $response = $this->client->send($request, $options);
  499. } catch (RequestException $e) {
  500. throw new ApiException(
  501. "[{$e->getCode()}] {$e->getMessage()}",
  502. (int) $e->getCode(),
  503. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  504. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  505. );
  506. } catch (ConnectException $e) {
  507. throw new ApiException(
  508. "[{$e->getCode()}] {$e->getMessage()}",
  509. (int) $e->getCode(),
  510. null,
  511. null
  512. );
  513. }
  514. $statusCode = $response->getStatusCode();
  515. switch($statusCode) {
  516. case 200:
  517. return $this->handleResponseWithDataType(
  518. '\WikipaliApi\Model\GetApiV3Channels200Response',
  519. $request,
  520. $response,
  521. );
  522. case 422:
  523. return $this->handleResponseWithDataType(
  524. '\WikipaliApi\Model\ProblemDetails',
  525. $request,
  526. $response,
  527. );
  528. }
  529. if ($statusCode < 200 || $statusCode > 299) {
  530. throw new ApiException(
  531. sprintf(
  532. '[%d] Error connecting to the API (%s)',
  533. $statusCode,
  534. (string) $request->getUri()
  535. ),
  536. $statusCode,
  537. $response->getHeaders(),
  538. (string) $response->getBody()
  539. );
  540. }
  541. return $this->handleResponseWithDataType(
  542. '\WikipaliApi\Model\GetApiV3Channels200Response',
  543. $request,
  544. $response,
  545. );
  546. } catch (ApiException $e) {
  547. switch ($e->getCode()) {
  548. case 200:
  549. $data = ObjectSerializer::deserialize(
  550. $e->getResponseBody(),
  551. '\WikipaliApi\Model\GetApiV3Channels200Response',
  552. $e->getResponseHeaders()
  553. );
  554. $e->setResponseObject($data);
  555. throw $e;
  556. case 422:
  557. $data = ObjectSerializer::deserialize(
  558. $e->getResponseBody(),
  559. '\WikipaliApi\Model\ProblemDetails',
  560. $e->getResponseHeaders()
  561. );
  562. $e->setResponseObject($data);
  563. throw $e;
  564. }
  565. throw $e;
  566. }
  567. }
  568. /**
  569. * Operation getApiV3ChannelsAsync
  570. *
  571. * 公开 channel 目录
  572. *
  573. * @param bool|null $system 只列系统 channel (optional)
  574. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  575. * @param string|null $search 按名字模糊匹配 (optional)
  576. * @param string|null $type channel 类型 (optional)
  577. * @param string|null $lang 语言 (optional)
  578. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  579. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  580. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  581. * @param string|null $dir 排序方向 (optional, default to 'desc')
  582. * @param int|null $page 页码 (optional, default to 1)
  583. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Channels'] to see the possible values for this operation
  584. *
  585. * @throws \InvalidArgumentException
  586. * @return \GuzzleHttp\Promise\PromiseInterface
  587. */
  588. 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])
  589. {
  590. return $this->getApiV3ChannelsAsyncWithHttpInfo($system, $per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType)
  591. ->then(
  592. function ($response) {
  593. return $response[0];
  594. }
  595. );
  596. }
  597. /**
  598. * Operation getApiV3ChannelsAsyncWithHttpInfo
  599. *
  600. * 公开 channel 目录
  601. *
  602. * @param bool|null $system 只列系统 channel (optional)
  603. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  604. * @param string|null $search 按名字模糊匹配 (optional)
  605. * @param string|null $type channel 类型 (optional)
  606. * @param string|null $lang 语言 (optional)
  607. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  608. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  609. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  610. * @param string|null $dir 排序方向 (optional, default to 'desc')
  611. * @param int|null $page 页码 (optional, default to 1)
  612. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Channels'] to see the possible values for this operation
  613. *
  614. * @throws \InvalidArgumentException
  615. * @return \GuzzleHttp\Promise\PromiseInterface
  616. */
  617. 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])
  618. {
  619. $returnType = '\WikipaliApi\Model\GetApiV3Channels200Response';
  620. $request = $this->getApiV3ChannelsRequest($system, $per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  621. return $this->client
  622. ->sendAsync($request, $this->createHttpClientOption())
  623. ->then(
  624. function ($response) use ($returnType) {
  625. if ($returnType === '\SplFileObject') {
  626. $content = $response->getBody(); //stream goes to serializer
  627. } else {
  628. $content = (string) $response->getBody();
  629. if ($returnType !== 'string') {
  630. $content = json_decode($content);
  631. }
  632. }
  633. return [
  634. ObjectSerializer::deserialize($content, $returnType, []),
  635. $response->getStatusCode(),
  636. $response->getHeaders()
  637. ];
  638. },
  639. function ($exception) {
  640. $response = $exception->getResponse();
  641. $statusCode = $response->getStatusCode();
  642. throw new ApiException(
  643. sprintf(
  644. '[%d] Error connecting to the API (%s)',
  645. $statusCode,
  646. $exception->getRequest()->getUri()
  647. ),
  648. $statusCode,
  649. $response->getHeaders(),
  650. (string) $response->getBody()
  651. );
  652. }
  653. );
  654. }
  655. /**
  656. * Create request for operation 'getApiV3Channels'
  657. *
  658. * @param bool|null $system 只列系统 channel (optional)
  659. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  660. * @param string|null $search 按名字模糊匹配 (optional)
  661. * @param string|null $type channel 类型 (optional)
  662. * @param string|null $lang 语言 (optional)
  663. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  664. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  665. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  666. * @param string|null $dir 排序方向 (optional, default to 'desc')
  667. * @param int|null $page 页码 (optional, default to 1)
  668. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Channels'] to see the possible values for this operation
  669. *
  670. * @throws \InvalidArgumentException
  671. * @return \GuzzleHttp\Psr7\Request
  672. */
  673. 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])
  674. {
  675. $resourcePath = '/v3/channels';
  676. $formParams = [];
  677. $queryParams = [];
  678. $headerParams = [];
  679. $httpBody = '';
  680. $multipart = false;
  681. // query params
  682. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  683. $system,
  684. 'system', // param base name
  685. 'boolean', // openApiType
  686. 'form', // style
  687. true, // explode
  688. false // required
  689. ) ?? []);
  690. // query params
  691. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  692. $per_page,
  693. 'per_page', // param base name
  694. 'integer', // openApiType
  695. 'form', // style
  696. true, // explode
  697. false // required
  698. ) ?? []);
  699. // query params
  700. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  701. $search,
  702. 'search', // 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. $type,
  711. 'type', // 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. $lang,
  720. 'lang', // param base name
  721. 'string', // openApiType
  722. 'form', // style
  723. true, // explode
  724. false // required
  725. ) ?? []);
  726. // query params
  727. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  728. $book,
  729. 'book', // 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. $para,
  738. 'para', // param base name
  739. 'integer', // openApiType
  740. 'form', // style
  741. true, // explode
  742. false // required
  743. ) ?? []);
  744. // query params
  745. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  746. $order,
  747. 'order', // 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. $dir,
  756. 'dir', // param base name
  757. 'string', // openApiType
  758. 'form', // style
  759. true, // explode
  760. false // required
  761. ) ?? []);
  762. // query params
  763. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  764. $page,
  765. 'page', // param base name
  766. 'integer', // openApiType
  767. 'form', // style
  768. true, // explode
  769. false // required
  770. ) ?? []);
  771. $headers = $this->headerSelector->selectHeaders(
  772. ['application/json', 'application/problem+json', ],
  773. $contentType,
  774. $multipart
  775. );
  776. // for model (json/xml)
  777. if (count($formParams) > 0) {
  778. if ($multipart) {
  779. $multipartContents = [];
  780. foreach ($formParams as $formParamName => $formParamValue) {
  781. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  782. foreach ($formParamValueItems as $formParamValueItem) {
  783. $multipartContents[] = [
  784. 'name' => $formParamName,
  785. 'contents' => $formParamValueItem
  786. ];
  787. }
  788. }
  789. // for HTTP post (form)
  790. $httpBody = new MultipartStream($multipartContents);
  791. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  792. # if Content-Type contains "application/json", json_encode the form parameters
  793. try {
  794. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  795. } catch (\JsonException $e) {
  796. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  797. }
  798. } else {
  799. // for HTTP post (form)
  800. $httpBody = ObjectSerializer::buildQuery($formParams);
  801. }
  802. }
  803. // this endpoint requires Bearer authentication (access token)
  804. if (!empty($this->config->getAccessToken())) {
  805. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  806. }
  807. $defaultHeaders = [];
  808. if ($this->config->getUserAgent()) {
  809. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  810. }
  811. $headers = array_merge(
  812. $defaultHeaders,
  813. $headerParams,
  814. $headers
  815. );
  816. $operationHost = $this->config->getHost();
  817. $query = ObjectSerializer::buildQuery($queryParams);
  818. return new Request(
  819. 'GET',
  820. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  821. $headers,
  822. $httpBody
  823. );
  824. }
  825. /**
  826. * Operation getApiV3ChannelsChannel
  827. *
  828. * channel 详情
  829. *
  830. * @param string $channel channel uid (required)
  831. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannel'] to see the possible values for this operation
  832. *
  833. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  834. * @throws \InvalidArgumentException
  835. * @return \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  836. */
  837. public function getApiV3ChannelsChannel($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannel'][0])
  838. {
  839. list($response) = $this->getApiV3ChannelsChannelWithHttpInfo($channel, $contentType);
  840. return $response;
  841. }
  842. /**
  843. * Operation getApiV3ChannelsChannelWithHttpInfo
  844. *
  845. * channel 详情
  846. *
  847. * @param string $channel channel uid (required)
  848. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannel'] to see the possible values for this operation
  849. *
  850. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  851. * @throws \InvalidArgumentException
  852. * @return array of \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  853. */
  854. public function getApiV3ChannelsChannelWithHttpInfo($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannel'][0])
  855. {
  856. $request = $this->getApiV3ChannelsChannelRequest($channel, $contentType);
  857. try {
  858. $options = $this->createHttpClientOption();
  859. try {
  860. $response = $this->client->send($request, $options);
  861. } catch (RequestException $e) {
  862. throw new ApiException(
  863. "[{$e->getCode()}] {$e->getMessage()}",
  864. (int) $e->getCode(),
  865. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  866. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  867. );
  868. } catch (ConnectException $e) {
  869. throw new ApiException(
  870. "[{$e->getCode()}] {$e->getMessage()}",
  871. (int) $e->getCode(),
  872. null,
  873. null
  874. );
  875. }
  876. $statusCode = $response->getStatusCode();
  877. switch($statusCode) {
  878. case 200:
  879. return $this->handleResponseWithDataType(
  880. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  881. $request,
  882. $response,
  883. );
  884. case 403:
  885. return $this->handleResponseWithDataType(
  886. '\WikipaliApi\Model\ProblemDetails',
  887. $request,
  888. $response,
  889. );
  890. case 422:
  891. return $this->handleResponseWithDataType(
  892. '\WikipaliApi\Model\ProblemDetails',
  893. $request,
  894. $response,
  895. );
  896. }
  897. if ($statusCode < 200 || $statusCode > 299) {
  898. throw new ApiException(
  899. sprintf(
  900. '[%d] Error connecting to the API (%s)',
  901. $statusCode,
  902. (string) $request->getUri()
  903. ),
  904. $statusCode,
  905. $response->getHeaders(),
  906. (string) $response->getBody()
  907. );
  908. }
  909. return $this->handleResponseWithDataType(
  910. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  911. $request,
  912. $response,
  913. );
  914. } catch (ApiException $e) {
  915. switch ($e->getCode()) {
  916. case 200:
  917. $data = ObjectSerializer::deserialize(
  918. $e->getResponseBody(),
  919. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  920. $e->getResponseHeaders()
  921. );
  922. $e->setResponseObject($data);
  923. throw $e;
  924. case 403:
  925. $data = ObjectSerializer::deserialize(
  926. $e->getResponseBody(),
  927. '\WikipaliApi\Model\ProblemDetails',
  928. $e->getResponseHeaders()
  929. );
  930. $e->setResponseObject($data);
  931. throw $e;
  932. case 422:
  933. $data = ObjectSerializer::deserialize(
  934. $e->getResponseBody(),
  935. '\WikipaliApi\Model\ProblemDetails',
  936. $e->getResponseHeaders()
  937. );
  938. $e->setResponseObject($data);
  939. throw $e;
  940. }
  941. throw $e;
  942. }
  943. }
  944. /**
  945. * Operation getApiV3ChannelsChannelAsync
  946. *
  947. * channel 详情
  948. *
  949. * @param string $channel channel uid (required)
  950. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannel'] to see the possible values for this operation
  951. *
  952. * @throws \InvalidArgumentException
  953. * @return \GuzzleHttp\Promise\PromiseInterface
  954. */
  955. public function getApiV3ChannelsChannelAsync($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannel'][0])
  956. {
  957. return $this->getApiV3ChannelsChannelAsyncWithHttpInfo($channel, $contentType)
  958. ->then(
  959. function ($response) {
  960. return $response[0];
  961. }
  962. );
  963. }
  964. /**
  965. * Operation getApiV3ChannelsChannelAsyncWithHttpInfo
  966. *
  967. * channel 详情
  968. *
  969. * @param string $channel channel uid (required)
  970. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannel'] to see the possible values for this operation
  971. *
  972. * @throws \InvalidArgumentException
  973. * @return \GuzzleHttp\Promise\PromiseInterface
  974. */
  975. public function getApiV3ChannelsChannelAsyncWithHttpInfo($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannel'][0])
  976. {
  977. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response';
  978. $request = $this->getApiV3ChannelsChannelRequest($channel, $contentType);
  979. return $this->client
  980. ->sendAsync($request, $this->createHttpClientOption())
  981. ->then(
  982. function ($response) use ($returnType) {
  983. if ($returnType === '\SplFileObject') {
  984. $content = $response->getBody(); //stream goes to serializer
  985. } else {
  986. $content = (string) $response->getBody();
  987. if ($returnType !== 'string') {
  988. $content = json_decode($content);
  989. }
  990. }
  991. return [
  992. ObjectSerializer::deserialize($content, $returnType, []),
  993. $response->getStatusCode(),
  994. $response->getHeaders()
  995. ];
  996. },
  997. function ($exception) {
  998. $response = $exception->getResponse();
  999. $statusCode = $response->getStatusCode();
  1000. throw new ApiException(
  1001. sprintf(
  1002. '[%d] Error connecting to the API (%s)',
  1003. $statusCode,
  1004. $exception->getRequest()->getUri()
  1005. ),
  1006. $statusCode,
  1007. $response->getHeaders(),
  1008. (string) $response->getBody()
  1009. );
  1010. }
  1011. );
  1012. }
  1013. /**
  1014. * Create request for operation 'getApiV3ChannelsChannel'
  1015. *
  1016. * @param string $channel channel uid (required)
  1017. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannel'] to see the possible values for this operation
  1018. *
  1019. * @throws \InvalidArgumentException
  1020. * @return \GuzzleHttp\Psr7\Request
  1021. */
  1022. public function getApiV3ChannelsChannelRequest($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannel'][0])
  1023. {
  1024. // verify the required parameter 'channel' is set
  1025. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  1026. throw new \InvalidArgumentException(
  1027. 'Missing the required parameter $channel when calling getApiV3ChannelsChannel'
  1028. );
  1029. }
  1030. $resourcePath = '/v3/channels/{channel}';
  1031. $formParams = [];
  1032. $queryParams = [];
  1033. $headerParams = [];
  1034. $httpBody = '';
  1035. $multipart = false;
  1036. // path params
  1037. if ($channel !== null) {
  1038. $resourcePath = str_replace(
  1039. '{channel}',
  1040. ObjectSerializer::toPathValue($channel),
  1041. $resourcePath
  1042. );
  1043. }
  1044. $headers = $this->headerSelector->selectHeaders(
  1045. ['application/json', 'application/problem+json', ],
  1046. $contentType,
  1047. $multipart
  1048. );
  1049. // for model (json/xml)
  1050. if (count($formParams) > 0) {
  1051. if ($multipart) {
  1052. $multipartContents = [];
  1053. foreach ($formParams as $formParamName => $formParamValue) {
  1054. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1055. foreach ($formParamValueItems as $formParamValueItem) {
  1056. $multipartContents[] = [
  1057. 'name' => $formParamName,
  1058. 'contents' => $formParamValueItem
  1059. ];
  1060. }
  1061. }
  1062. // for HTTP post (form)
  1063. $httpBody = new MultipartStream($multipartContents);
  1064. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1065. # if Content-Type contains "application/json", json_encode the form parameters
  1066. try {
  1067. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1068. } catch (\JsonException $e) {
  1069. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1070. }
  1071. } else {
  1072. // for HTTP post (form)
  1073. $httpBody = ObjectSerializer::buildQuery($formParams);
  1074. }
  1075. }
  1076. // this endpoint requires Bearer authentication (access token)
  1077. if (!empty($this->config->getAccessToken())) {
  1078. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1079. }
  1080. $defaultHeaders = [];
  1081. if ($this->config->getUserAgent()) {
  1082. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1083. }
  1084. $headers = array_merge(
  1085. $defaultHeaders,
  1086. $headerParams,
  1087. $headers
  1088. );
  1089. $operationHost = $this->config->getHost();
  1090. $query = ObjectSerializer::buildQuery($queryParams);
  1091. return new Request(
  1092. 'GET',
  1093. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1094. $headers,
  1095. $httpBody
  1096. );
  1097. }
  1098. /**
  1099. * Operation getApiV3ChannelsChannelLinks
  1100. *
  1101. * channel 的关系设置
  1102. *
  1103. * @param string $channel channel uid (required)
  1104. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelLinks'] to see the possible values for this operation
  1105. *
  1106. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1107. * @throws \InvalidArgumentException
  1108. * @return \WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  1109. */
  1110. public function getApiV3ChannelsChannelLinks($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannelLinks'][0])
  1111. {
  1112. list($response) = $this->getApiV3ChannelsChannelLinksWithHttpInfo($channel, $contentType);
  1113. return $response;
  1114. }
  1115. /**
  1116. * Operation getApiV3ChannelsChannelLinksWithHttpInfo
  1117. *
  1118. * channel 的关系设置
  1119. *
  1120. * @param string $channel channel uid (required)
  1121. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelLinks'] to see the possible values for this operation
  1122. *
  1123. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1124. * @throws \InvalidArgumentException
  1125. * @return array of \WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  1126. */
  1127. public function getApiV3ChannelsChannelLinksWithHttpInfo($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannelLinks'][0])
  1128. {
  1129. $request = $this->getApiV3ChannelsChannelLinksRequest($channel, $contentType);
  1130. try {
  1131. $options = $this->createHttpClientOption();
  1132. try {
  1133. $response = $this->client->send($request, $options);
  1134. } catch (RequestException $e) {
  1135. throw new ApiException(
  1136. "[{$e->getCode()}] {$e->getMessage()}",
  1137. (int) $e->getCode(),
  1138. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1139. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1140. );
  1141. } catch (ConnectException $e) {
  1142. throw new ApiException(
  1143. "[{$e->getCode()}] {$e->getMessage()}",
  1144. (int) $e->getCode(),
  1145. null,
  1146. null
  1147. );
  1148. }
  1149. $statusCode = $response->getStatusCode();
  1150. switch($statusCode) {
  1151. case 200:
  1152. return $this->handleResponseWithDataType(
  1153. '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response',
  1154. $request,
  1155. $response,
  1156. );
  1157. case 403:
  1158. return $this->handleResponseWithDataType(
  1159. '\WikipaliApi\Model\ProblemDetails',
  1160. $request,
  1161. $response,
  1162. );
  1163. case 422:
  1164. return $this->handleResponseWithDataType(
  1165. '\WikipaliApi\Model\ProblemDetails',
  1166. $request,
  1167. $response,
  1168. );
  1169. }
  1170. if ($statusCode < 200 || $statusCode > 299) {
  1171. throw new ApiException(
  1172. sprintf(
  1173. '[%d] Error connecting to the API (%s)',
  1174. $statusCode,
  1175. (string) $request->getUri()
  1176. ),
  1177. $statusCode,
  1178. $response->getHeaders(),
  1179. (string) $response->getBody()
  1180. );
  1181. }
  1182. return $this->handleResponseWithDataType(
  1183. '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response',
  1184. $request,
  1185. $response,
  1186. );
  1187. } catch (ApiException $e) {
  1188. switch ($e->getCode()) {
  1189. case 200:
  1190. $data = ObjectSerializer::deserialize(
  1191. $e->getResponseBody(),
  1192. '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response',
  1193. $e->getResponseHeaders()
  1194. );
  1195. $e->setResponseObject($data);
  1196. throw $e;
  1197. case 403:
  1198. $data = ObjectSerializer::deserialize(
  1199. $e->getResponseBody(),
  1200. '\WikipaliApi\Model\ProblemDetails',
  1201. $e->getResponseHeaders()
  1202. );
  1203. $e->setResponseObject($data);
  1204. throw $e;
  1205. case 422:
  1206. $data = ObjectSerializer::deserialize(
  1207. $e->getResponseBody(),
  1208. '\WikipaliApi\Model\ProblemDetails',
  1209. $e->getResponseHeaders()
  1210. );
  1211. $e->setResponseObject($data);
  1212. throw $e;
  1213. }
  1214. throw $e;
  1215. }
  1216. }
  1217. /**
  1218. * Operation getApiV3ChannelsChannelLinksAsync
  1219. *
  1220. * channel 的关系设置
  1221. *
  1222. * @param string $channel channel uid (required)
  1223. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelLinks'] to see the possible values for this operation
  1224. *
  1225. * @throws \InvalidArgumentException
  1226. * @return \GuzzleHttp\Promise\PromiseInterface
  1227. */
  1228. public function getApiV3ChannelsChannelLinksAsync($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannelLinks'][0])
  1229. {
  1230. return $this->getApiV3ChannelsChannelLinksAsyncWithHttpInfo($channel, $contentType)
  1231. ->then(
  1232. function ($response) {
  1233. return $response[0];
  1234. }
  1235. );
  1236. }
  1237. /**
  1238. * Operation getApiV3ChannelsChannelLinksAsyncWithHttpInfo
  1239. *
  1240. * channel 的关系设置
  1241. *
  1242. * @param string $channel channel uid (required)
  1243. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelLinks'] to see the possible values for this operation
  1244. *
  1245. * @throws \InvalidArgumentException
  1246. * @return \GuzzleHttp\Promise\PromiseInterface
  1247. */
  1248. public function getApiV3ChannelsChannelLinksAsyncWithHttpInfo($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannelLinks'][0])
  1249. {
  1250. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response';
  1251. $request = $this->getApiV3ChannelsChannelLinksRequest($channel, $contentType);
  1252. return $this->client
  1253. ->sendAsync($request, $this->createHttpClientOption())
  1254. ->then(
  1255. function ($response) use ($returnType) {
  1256. if ($returnType === '\SplFileObject') {
  1257. $content = $response->getBody(); //stream goes to serializer
  1258. } else {
  1259. $content = (string) $response->getBody();
  1260. if ($returnType !== 'string') {
  1261. $content = json_decode($content);
  1262. }
  1263. }
  1264. return [
  1265. ObjectSerializer::deserialize($content, $returnType, []),
  1266. $response->getStatusCode(),
  1267. $response->getHeaders()
  1268. ];
  1269. },
  1270. function ($exception) {
  1271. $response = $exception->getResponse();
  1272. $statusCode = $response->getStatusCode();
  1273. throw new ApiException(
  1274. sprintf(
  1275. '[%d] Error connecting to the API (%s)',
  1276. $statusCode,
  1277. $exception->getRequest()->getUri()
  1278. ),
  1279. $statusCode,
  1280. $response->getHeaders(),
  1281. (string) $response->getBody()
  1282. );
  1283. }
  1284. );
  1285. }
  1286. /**
  1287. * Create request for operation 'getApiV3ChannelsChannelLinks'
  1288. *
  1289. * @param string $channel channel uid (required)
  1290. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelLinks'] to see the possible values for this operation
  1291. *
  1292. * @throws \InvalidArgumentException
  1293. * @return \GuzzleHttp\Psr7\Request
  1294. */
  1295. public function getApiV3ChannelsChannelLinksRequest($channel, string $contentType = self::contentTypes['getApiV3ChannelsChannelLinks'][0])
  1296. {
  1297. // verify the required parameter 'channel' is set
  1298. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  1299. throw new \InvalidArgumentException(
  1300. 'Missing the required parameter $channel when calling getApiV3ChannelsChannelLinks'
  1301. );
  1302. }
  1303. $resourcePath = '/v3/channels/{channel}/links';
  1304. $formParams = [];
  1305. $queryParams = [];
  1306. $headerParams = [];
  1307. $httpBody = '';
  1308. $multipart = false;
  1309. // path params
  1310. if ($channel !== null) {
  1311. $resourcePath = str_replace(
  1312. '{channel}',
  1313. ObjectSerializer::toPathValue($channel),
  1314. $resourcePath
  1315. );
  1316. }
  1317. $headers = $this->headerSelector->selectHeaders(
  1318. ['application/json', 'application/problem+json', ],
  1319. $contentType,
  1320. $multipart
  1321. );
  1322. // for model (json/xml)
  1323. if (count($formParams) > 0) {
  1324. if ($multipart) {
  1325. $multipartContents = [];
  1326. foreach ($formParams as $formParamName => $formParamValue) {
  1327. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1328. foreach ($formParamValueItems as $formParamValueItem) {
  1329. $multipartContents[] = [
  1330. 'name' => $formParamName,
  1331. 'contents' => $formParamValueItem
  1332. ];
  1333. }
  1334. }
  1335. // for HTTP post (form)
  1336. $httpBody = new MultipartStream($multipartContents);
  1337. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1338. # if Content-Type contains "application/json", json_encode the form parameters
  1339. try {
  1340. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1341. } catch (\JsonException $e) {
  1342. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1343. }
  1344. } else {
  1345. // for HTTP post (form)
  1346. $httpBody = ObjectSerializer::buildQuery($formParams);
  1347. }
  1348. }
  1349. // this endpoint requires Bearer authentication (access token)
  1350. if (!empty($this->config->getAccessToken())) {
  1351. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1352. }
  1353. $defaultHeaders = [];
  1354. if ($this->config->getUserAgent()) {
  1355. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1356. }
  1357. $headers = array_merge(
  1358. $defaultHeaders,
  1359. $headerParams,
  1360. $headers
  1361. );
  1362. $operationHost = $this->config->getHost();
  1363. $query = ObjectSerializer::buildQuery($queryParams);
  1364. return new Request(
  1365. 'GET',
  1366. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1367. $headers,
  1368. $httpBody
  1369. );
  1370. }
  1371. /**
  1372. * Operation getApiV3ChannelsChannelTerms
  1373. *
  1374. * channel 的术语列表
  1375. *
  1376. * @param string $channel channel uid (required)
  1377. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  1378. * @param string|null $search 按词、释义搜索 (optional)
  1379. * @param string|null $quality 质量;pending 含未评级的 (optional)
  1380. * @param string|null $category 百科分类 (optional)
  1381. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1382. * @param string|null $dir 排序方向 (optional)
  1383. * @param int|null $page 页码 (optional)
  1384. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelTerms'] to see the possible values for this operation
  1385. *
  1386. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1387. * @throws \InvalidArgumentException
  1388. * @return \WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  1389. */
  1390. public function getApiV3ChannelsChannelTerms($channel, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3ChannelsChannelTerms'][0])
  1391. {
  1392. list($response) = $this->getApiV3ChannelsChannelTermsWithHttpInfo($channel, $per_page, $search, $quality, $category, $order, $dir, $page, $contentType);
  1393. return $response;
  1394. }
  1395. /**
  1396. * Operation getApiV3ChannelsChannelTermsWithHttpInfo
  1397. *
  1398. * channel 的术语列表
  1399. *
  1400. * @param string $channel channel uid (required)
  1401. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  1402. * @param string|null $search 按词、释义搜索 (optional)
  1403. * @param string|null $quality 质量;pending 含未评级的 (optional)
  1404. * @param string|null $category 百科分类 (optional)
  1405. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1406. * @param string|null $dir 排序方向 (optional)
  1407. * @param int|null $page 页码 (optional)
  1408. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelTerms'] to see the possible values for this operation
  1409. *
  1410. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1411. * @throws \InvalidArgumentException
  1412. * @return array of \WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  1413. */
  1414. public function getApiV3ChannelsChannelTermsWithHttpInfo($channel, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3ChannelsChannelTerms'][0])
  1415. {
  1416. $request = $this->getApiV3ChannelsChannelTermsRequest($channel, $per_page, $search, $quality, $category, $order, $dir, $page, $contentType);
  1417. try {
  1418. $options = $this->createHttpClientOption();
  1419. try {
  1420. $response = $this->client->send($request, $options);
  1421. } catch (RequestException $e) {
  1422. throw new ApiException(
  1423. "[{$e->getCode()}] {$e->getMessage()}",
  1424. (int) $e->getCode(),
  1425. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1426. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1427. );
  1428. } catch (ConnectException $e) {
  1429. throw new ApiException(
  1430. "[{$e->getCode()}] {$e->getMessage()}",
  1431. (int) $e->getCode(),
  1432. null,
  1433. null
  1434. );
  1435. }
  1436. $statusCode = $response->getStatusCode();
  1437. switch($statusCode) {
  1438. case 200:
  1439. return $this->handleResponseWithDataType(
  1440. '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response',
  1441. $request,
  1442. $response,
  1443. );
  1444. case 403:
  1445. return $this->handleResponseWithDataType(
  1446. '\WikipaliApi\Model\ProblemDetails',
  1447. $request,
  1448. $response,
  1449. );
  1450. case 422:
  1451. return $this->handleResponseWithDataType(
  1452. '\WikipaliApi\Model\ProblemDetails',
  1453. $request,
  1454. $response,
  1455. );
  1456. }
  1457. if ($statusCode < 200 || $statusCode > 299) {
  1458. throw new ApiException(
  1459. sprintf(
  1460. '[%d] Error connecting to the API (%s)',
  1461. $statusCode,
  1462. (string) $request->getUri()
  1463. ),
  1464. $statusCode,
  1465. $response->getHeaders(),
  1466. (string) $response->getBody()
  1467. );
  1468. }
  1469. return $this->handleResponseWithDataType(
  1470. '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response',
  1471. $request,
  1472. $response,
  1473. );
  1474. } catch (ApiException $e) {
  1475. switch ($e->getCode()) {
  1476. case 200:
  1477. $data = ObjectSerializer::deserialize(
  1478. $e->getResponseBody(),
  1479. '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response',
  1480. $e->getResponseHeaders()
  1481. );
  1482. $e->setResponseObject($data);
  1483. throw $e;
  1484. case 403:
  1485. $data = ObjectSerializer::deserialize(
  1486. $e->getResponseBody(),
  1487. '\WikipaliApi\Model\ProblemDetails',
  1488. $e->getResponseHeaders()
  1489. );
  1490. $e->setResponseObject($data);
  1491. throw $e;
  1492. case 422:
  1493. $data = ObjectSerializer::deserialize(
  1494. $e->getResponseBody(),
  1495. '\WikipaliApi\Model\ProblemDetails',
  1496. $e->getResponseHeaders()
  1497. );
  1498. $e->setResponseObject($data);
  1499. throw $e;
  1500. }
  1501. throw $e;
  1502. }
  1503. }
  1504. /**
  1505. * Operation getApiV3ChannelsChannelTermsAsync
  1506. *
  1507. * channel 的术语列表
  1508. *
  1509. * @param string $channel channel uid (required)
  1510. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  1511. * @param string|null $search 按词、释义搜索 (optional)
  1512. * @param string|null $quality 质量;pending 含未评级的 (optional)
  1513. * @param string|null $category 百科分类 (optional)
  1514. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1515. * @param string|null $dir 排序方向 (optional)
  1516. * @param int|null $page 页码 (optional)
  1517. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelTerms'] to see the possible values for this operation
  1518. *
  1519. * @throws \InvalidArgumentException
  1520. * @return \GuzzleHttp\Promise\PromiseInterface
  1521. */
  1522. public function getApiV3ChannelsChannelTermsAsync($channel, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3ChannelsChannelTerms'][0])
  1523. {
  1524. return $this->getApiV3ChannelsChannelTermsAsyncWithHttpInfo($channel, $per_page, $search, $quality, $category, $order, $dir, $page, $contentType)
  1525. ->then(
  1526. function ($response) {
  1527. return $response[0];
  1528. }
  1529. );
  1530. }
  1531. /**
  1532. * Operation getApiV3ChannelsChannelTermsAsyncWithHttpInfo
  1533. *
  1534. * channel 的术语列表
  1535. *
  1536. * @param string $channel channel uid (required)
  1537. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  1538. * @param string|null $search 按词、释义搜索 (optional)
  1539. * @param string|null $quality 质量;pending 含未评级的 (optional)
  1540. * @param string|null $category 百科分类 (optional)
  1541. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1542. * @param string|null $dir 排序方向 (optional)
  1543. * @param int|null $page 页码 (optional)
  1544. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelTerms'] to see the possible values for this operation
  1545. *
  1546. * @throws \InvalidArgumentException
  1547. * @return \GuzzleHttp\Promise\PromiseInterface
  1548. */
  1549. public function getApiV3ChannelsChannelTermsAsyncWithHttpInfo($channel, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3ChannelsChannelTerms'][0])
  1550. {
  1551. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response';
  1552. $request = $this->getApiV3ChannelsChannelTermsRequest($channel, $per_page, $search, $quality, $category, $order, $dir, $page, $contentType);
  1553. return $this->client
  1554. ->sendAsync($request, $this->createHttpClientOption())
  1555. ->then(
  1556. function ($response) use ($returnType) {
  1557. if ($returnType === '\SplFileObject') {
  1558. $content = $response->getBody(); //stream goes to serializer
  1559. } else {
  1560. $content = (string) $response->getBody();
  1561. if ($returnType !== 'string') {
  1562. $content = json_decode($content);
  1563. }
  1564. }
  1565. return [
  1566. ObjectSerializer::deserialize($content, $returnType, []),
  1567. $response->getStatusCode(),
  1568. $response->getHeaders()
  1569. ];
  1570. },
  1571. function ($exception) {
  1572. $response = $exception->getResponse();
  1573. $statusCode = $response->getStatusCode();
  1574. throw new ApiException(
  1575. sprintf(
  1576. '[%d] Error connecting to the API (%s)',
  1577. $statusCode,
  1578. $exception->getRequest()->getUri()
  1579. ),
  1580. $statusCode,
  1581. $response->getHeaders(),
  1582. (string) $response->getBody()
  1583. );
  1584. }
  1585. );
  1586. }
  1587. /**
  1588. * Create request for operation 'getApiV3ChannelsChannelTerms'
  1589. *
  1590. * @param string $channel channel uid (required)
  1591. * @param int|null $per_page 每页条数,最大 200 (optional, default to 20)
  1592. * @param string|null $search 按词、释义搜索 (optional)
  1593. * @param string|null $quality 质量;pending 含未评级的 (optional)
  1594. * @param string|null $category 百科分类 (optional)
  1595. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1596. * @param string|null $dir 排序方向 (optional)
  1597. * @param int|null $page 页码 (optional)
  1598. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsChannelTerms'] to see the possible values for this operation
  1599. *
  1600. * @throws \InvalidArgumentException
  1601. * @return \GuzzleHttp\Psr7\Request
  1602. */
  1603. public function getApiV3ChannelsChannelTermsRequest($channel, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3ChannelsChannelTerms'][0])
  1604. {
  1605. // verify the required parameter 'channel' is set
  1606. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  1607. throw new \InvalidArgumentException(
  1608. 'Missing the required parameter $channel when calling getApiV3ChannelsChannelTerms'
  1609. );
  1610. }
  1611. $resourcePath = '/v3/channels/{channel}/terms';
  1612. $formParams = [];
  1613. $queryParams = [];
  1614. $headerParams = [];
  1615. $httpBody = '';
  1616. $multipart = false;
  1617. // query params
  1618. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1619. $per_page,
  1620. 'per_page', // param base name
  1621. 'integer', // openApiType
  1622. 'form', // style
  1623. true, // explode
  1624. false // required
  1625. ) ?? []);
  1626. // query params
  1627. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1628. $search,
  1629. 'search', // param base name
  1630. 'string', // openApiType
  1631. 'form', // style
  1632. true, // explode
  1633. false // required
  1634. ) ?? []);
  1635. // query params
  1636. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1637. $quality,
  1638. 'quality', // param base name
  1639. 'string', // openApiType
  1640. 'form', // style
  1641. true, // explode
  1642. false // required
  1643. ) ?? []);
  1644. // query params
  1645. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1646. $category,
  1647. 'category', // param base name
  1648. 'string', // openApiType
  1649. 'form', // style
  1650. true, // explode
  1651. false // required
  1652. ) ?? []);
  1653. // query params
  1654. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1655. $order,
  1656. 'order', // param base name
  1657. 'string', // openApiType
  1658. 'form', // style
  1659. true, // explode
  1660. false // required
  1661. ) ?? []);
  1662. // query params
  1663. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1664. $dir,
  1665. 'dir', // param base name
  1666. 'string', // openApiType
  1667. 'form', // style
  1668. true, // explode
  1669. false // required
  1670. ) ?? []);
  1671. // query params
  1672. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1673. $page,
  1674. 'page', // param base name
  1675. 'integer', // openApiType
  1676. 'form', // style
  1677. true, // explode
  1678. false // required
  1679. ) ?? []);
  1680. // path params
  1681. if ($channel !== null) {
  1682. $resourcePath = str_replace(
  1683. '{channel}',
  1684. ObjectSerializer::toPathValue($channel),
  1685. $resourcePath
  1686. );
  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 getApiV3ChannelsEditable
  1744. *
  1745. * 列出我能写的 channel
  1746. *
  1747. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  1748. * @param string|null $search 按名字模糊匹配 (optional)
  1749. * @param string|null $type channel 类型 (optional)
  1750. * @param string|null $lang 语言 (optional)
  1751. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  1752. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  1753. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1754. * @param string|null $dir 排序方向 (optional, default to 'desc')
  1755. * @param int|null $page 页码 (optional, default to 1)
  1756. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsEditable'] to see the possible values for this operation
  1757. *
  1758. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1759. * @throws \InvalidArgumentException
  1760. * @return \WikipaliApi\Model\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  1761. */
  1762. 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])
  1763. {
  1764. list($response) = $this->getApiV3ChannelsEditableWithHttpInfo($per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  1765. return $response;
  1766. }
  1767. /**
  1768. * Operation getApiV3ChannelsEditableWithHttpInfo
  1769. *
  1770. * 列出我能写的 channel
  1771. *
  1772. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  1773. * @param string|null $search 按名字模糊匹配 (optional)
  1774. * @param string|null $type channel 类型 (optional)
  1775. * @param string|null $lang 语言 (optional)
  1776. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  1777. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  1778. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1779. * @param string|null $dir 排序方向 (optional, default to 'desc')
  1780. * @param int|null $page 页码 (optional, default to 1)
  1781. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsEditable'] to see the possible values for this operation
  1782. *
  1783. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1784. * @throws \InvalidArgumentException
  1785. * @return array of \WikipaliApi\Model\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  1786. */
  1787. 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])
  1788. {
  1789. $request = $this->getApiV3ChannelsEditableRequest($per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  1790. try {
  1791. $options = $this->createHttpClientOption();
  1792. try {
  1793. $response = $this->client->send($request, $options);
  1794. } catch (RequestException $e) {
  1795. throw new ApiException(
  1796. "[{$e->getCode()}] {$e->getMessage()}",
  1797. (int) $e->getCode(),
  1798. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1799. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1800. );
  1801. } catch (ConnectException $e) {
  1802. throw new ApiException(
  1803. "[{$e->getCode()}] {$e->getMessage()}",
  1804. (int) $e->getCode(),
  1805. null,
  1806. null
  1807. );
  1808. }
  1809. $statusCode = $response->getStatusCode();
  1810. switch($statusCode) {
  1811. case 200:
  1812. return $this->handleResponseWithDataType(
  1813. '\WikipaliApi\Model\GetApiV3Channels200Response',
  1814. $request,
  1815. $response,
  1816. );
  1817. case 401:
  1818. return $this->handleResponseWithDataType(
  1819. '\WikipaliApi\Model\ProblemDetails',
  1820. $request,
  1821. $response,
  1822. );
  1823. case 422:
  1824. return $this->handleResponseWithDataType(
  1825. '\WikipaliApi\Model\ProblemDetails',
  1826. $request,
  1827. $response,
  1828. );
  1829. }
  1830. if ($statusCode < 200 || $statusCode > 299) {
  1831. throw new ApiException(
  1832. sprintf(
  1833. '[%d] Error connecting to the API (%s)',
  1834. $statusCode,
  1835. (string) $request->getUri()
  1836. ),
  1837. $statusCode,
  1838. $response->getHeaders(),
  1839. (string) $response->getBody()
  1840. );
  1841. }
  1842. return $this->handleResponseWithDataType(
  1843. '\WikipaliApi\Model\GetApiV3Channels200Response',
  1844. $request,
  1845. $response,
  1846. );
  1847. } catch (ApiException $e) {
  1848. switch ($e->getCode()) {
  1849. case 200:
  1850. $data = ObjectSerializer::deserialize(
  1851. $e->getResponseBody(),
  1852. '\WikipaliApi\Model\GetApiV3Channels200Response',
  1853. $e->getResponseHeaders()
  1854. );
  1855. $e->setResponseObject($data);
  1856. throw $e;
  1857. case 401:
  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 getApiV3ChannelsEditableAsync
  1879. *
  1880. * 列出我能写的 channel
  1881. *
  1882. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  1883. * @param string|null $search 按名字模糊匹配 (optional)
  1884. * @param string|null $type channel 类型 (optional)
  1885. * @param string|null $lang 语言 (optional)
  1886. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  1887. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  1888. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1889. * @param string|null $dir 排序方向 (optional, default to 'desc')
  1890. * @param int|null $page 页码 (optional, default to 1)
  1891. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsEditable'] to see the possible values for this operation
  1892. *
  1893. * @throws \InvalidArgumentException
  1894. * @return \GuzzleHttp\Promise\PromiseInterface
  1895. */
  1896. 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])
  1897. {
  1898. return $this->getApiV3ChannelsEditableAsyncWithHttpInfo($per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType)
  1899. ->then(
  1900. function ($response) {
  1901. return $response[0];
  1902. }
  1903. );
  1904. }
  1905. /**
  1906. * Operation getApiV3ChannelsEditableAsyncWithHttpInfo
  1907. *
  1908. * 列出我能写的 channel
  1909. *
  1910. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  1911. * @param string|null $search 按名字模糊匹配 (optional)
  1912. * @param string|null $type channel 类型 (optional)
  1913. * @param string|null $lang 语言 (optional)
  1914. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  1915. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  1916. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1917. * @param string|null $dir 排序方向 (optional, default to 'desc')
  1918. * @param int|null $page 页码 (optional, default to 1)
  1919. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsEditable'] to see the possible values for this operation
  1920. *
  1921. * @throws \InvalidArgumentException
  1922. * @return \GuzzleHttp\Promise\PromiseInterface
  1923. */
  1924. 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])
  1925. {
  1926. $returnType = '\WikipaliApi\Model\GetApiV3Channels200Response';
  1927. $request = $this->getApiV3ChannelsEditableRequest($per_page, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType);
  1928. return $this->client
  1929. ->sendAsync($request, $this->createHttpClientOption())
  1930. ->then(
  1931. function ($response) use ($returnType) {
  1932. if ($returnType === '\SplFileObject') {
  1933. $content = $response->getBody(); //stream goes to serializer
  1934. } else {
  1935. $content = (string) $response->getBody();
  1936. if ($returnType !== 'string') {
  1937. $content = json_decode($content);
  1938. }
  1939. }
  1940. return [
  1941. ObjectSerializer::deserialize($content, $returnType, []),
  1942. $response->getStatusCode(),
  1943. $response->getHeaders()
  1944. ];
  1945. },
  1946. function ($exception) {
  1947. $response = $exception->getResponse();
  1948. $statusCode = $response->getStatusCode();
  1949. throw new ApiException(
  1950. sprintf(
  1951. '[%d] Error connecting to the API (%s)',
  1952. $statusCode,
  1953. $exception->getRequest()->getUri()
  1954. ),
  1955. $statusCode,
  1956. $response->getHeaders(),
  1957. (string) $response->getBody()
  1958. );
  1959. }
  1960. );
  1961. }
  1962. /**
  1963. * Create request for operation 'getApiV3ChannelsEditable'
  1964. *
  1965. * @param int|null $per_page 每页数量,最大 200 (optional, default to 20)
  1966. * @param string|null $search 按名字模糊匹配 (optional)
  1967. * @param string|null $type channel 类型 (optional)
  1968. * @param string|null $lang 语言 (optional)
  1969. * @param int|null $book 章节所在的书(与 para 同时给) (optional)
  1970. * @param int|null $para 章节起始段(与 book 同时给) (optional)
  1971. * @param string|null $order 排序字段 (optional, default to 'updated_at')
  1972. * @param string|null $dir 排序方向 (optional, default to 'desc')
  1973. * @param int|null $page 页码 (optional, default to 1)
  1974. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3ChannelsEditable'] to see the possible values for this operation
  1975. *
  1976. * @throws \InvalidArgumentException
  1977. * @return \GuzzleHttp\Psr7\Request
  1978. */
  1979. 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])
  1980. {
  1981. $resourcePath = '/v3/channels/editable';
  1982. $formParams = [];
  1983. $queryParams = [];
  1984. $headerParams = [];
  1985. $httpBody = '';
  1986. $multipart = false;
  1987. // query params
  1988. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1989. $per_page,
  1990. 'per_page', // param base name
  1991. 'integer', // openApiType
  1992. 'form', // style
  1993. true, // explode
  1994. false // required
  1995. ) ?? []);
  1996. // query params
  1997. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  1998. $search,
  1999. 'search', // param base name
  2000. 'string', // openApiType
  2001. 'form', // style
  2002. true, // explode
  2003. false // required
  2004. ) ?? []);
  2005. // query params
  2006. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  2007. $type,
  2008. 'type', // param base name
  2009. 'string', // openApiType
  2010. 'form', // style
  2011. true, // explode
  2012. false // required
  2013. ) ?? []);
  2014. // query params
  2015. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  2016. $lang,
  2017. 'lang', // param base name
  2018. 'string', // openApiType
  2019. 'form', // style
  2020. true, // explode
  2021. false // required
  2022. ) ?? []);
  2023. // query params
  2024. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  2025. $book,
  2026. 'book', // param base name
  2027. 'integer', // openApiType
  2028. 'form', // style
  2029. true, // explode
  2030. false // required
  2031. ) ?? []);
  2032. // query params
  2033. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  2034. $para,
  2035. 'para', // param base name
  2036. 'integer', // openApiType
  2037. 'form', // style
  2038. true, // explode
  2039. false // required
  2040. ) ?? []);
  2041. // query params
  2042. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  2043. $order,
  2044. 'order', // param base name
  2045. 'string', // openApiType
  2046. 'form', // style
  2047. true, // explode
  2048. false // required
  2049. ) ?? []);
  2050. // query params
  2051. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  2052. $dir,
  2053. 'dir', // param base name
  2054. 'string', // openApiType
  2055. 'form', // style
  2056. true, // explode
  2057. false // required
  2058. ) ?? []);
  2059. // query params
  2060. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  2061. $page,
  2062. 'page', // param base name
  2063. 'integer', // openApiType
  2064. 'form', // style
  2065. true, // explode
  2066. false // required
  2067. ) ?? []);
  2068. $headers = $this->headerSelector->selectHeaders(
  2069. ['application/json', 'application/problem+json', ],
  2070. $contentType,
  2071. $multipart
  2072. );
  2073. // for model (json/xml)
  2074. if (count($formParams) > 0) {
  2075. if ($multipart) {
  2076. $multipartContents = [];
  2077. foreach ($formParams as $formParamName => $formParamValue) {
  2078. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  2079. foreach ($formParamValueItems as $formParamValueItem) {
  2080. $multipartContents[] = [
  2081. 'name' => $formParamName,
  2082. 'contents' => $formParamValueItem
  2083. ];
  2084. }
  2085. }
  2086. // for HTTP post (form)
  2087. $httpBody = new MultipartStream($multipartContents);
  2088. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  2089. # if Content-Type contains "application/json", json_encode the form parameters
  2090. try {
  2091. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  2092. } catch (\JsonException $e) {
  2093. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  2094. }
  2095. } else {
  2096. // for HTTP post (form)
  2097. $httpBody = ObjectSerializer::buildQuery($formParams);
  2098. }
  2099. }
  2100. // this endpoint requires Bearer authentication (access token)
  2101. if (!empty($this->config->getAccessToken())) {
  2102. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  2103. }
  2104. $defaultHeaders = [];
  2105. if ($this->config->getUserAgent()) {
  2106. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  2107. }
  2108. $headers = array_merge(
  2109. $defaultHeaders,
  2110. $headerParams,
  2111. $headers
  2112. );
  2113. $operationHost = $this->config->getHost();
  2114. $query = ObjectSerializer::buildQuery($queryParams);
  2115. return new Request(
  2116. 'GET',
  2117. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  2118. $headers,
  2119. $httpBody
  2120. );
  2121. }
  2122. /**
  2123. * Operation patchApiV3ChannelsChannel
  2124. *
  2125. * 改 channel 信息
  2126. *
  2127. * @param string $channel channel uid (required)
  2128. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelRequest|null $patch_api_v3_channels_channel_request patch_api_v3_channels_channel_request (optional)
  2129. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannel'] to see the possible values for this operation
  2130. *
  2131. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  2132. * @throws \InvalidArgumentException
  2133. * @return \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  2134. */
  2135. public function patchApiV3ChannelsChannel($channel, $patch_api_v3_channels_channel_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannel'][0])
  2136. {
  2137. list($response) = $this->patchApiV3ChannelsChannelWithHttpInfo($channel, $patch_api_v3_channels_channel_request, $contentType);
  2138. return $response;
  2139. }
  2140. /**
  2141. * Operation patchApiV3ChannelsChannelWithHttpInfo
  2142. *
  2143. * 改 channel 信息
  2144. *
  2145. * @param string $channel channel uid (required)
  2146. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelRequest|null $patch_api_v3_channels_channel_request (optional)
  2147. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannel'] to see the possible values for this operation
  2148. *
  2149. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  2150. * @throws \InvalidArgumentException
  2151. * @return array of \WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  2152. */
  2153. public function patchApiV3ChannelsChannelWithHttpInfo($channel, $patch_api_v3_channels_channel_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannel'][0])
  2154. {
  2155. $request = $this->patchApiV3ChannelsChannelRequest($channel, $patch_api_v3_channels_channel_request, $contentType);
  2156. try {
  2157. $options = $this->createHttpClientOption();
  2158. try {
  2159. $response = $this->client->send($request, $options);
  2160. } catch (RequestException $e) {
  2161. throw new ApiException(
  2162. "[{$e->getCode()}] {$e->getMessage()}",
  2163. (int) $e->getCode(),
  2164. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  2165. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  2166. );
  2167. } catch (ConnectException $e) {
  2168. throw new ApiException(
  2169. "[{$e->getCode()}] {$e->getMessage()}",
  2170. (int) $e->getCode(),
  2171. null,
  2172. null
  2173. );
  2174. }
  2175. $statusCode = $response->getStatusCode();
  2176. switch($statusCode) {
  2177. case 200:
  2178. return $this->handleResponseWithDataType(
  2179. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  2180. $request,
  2181. $response,
  2182. );
  2183. case 401:
  2184. return $this->handleResponseWithDataType(
  2185. '\WikipaliApi\Model\ProblemDetails',
  2186. $request,
  2187. $response,
  2188. );
  2189. case 403:
  2190. return $this->handleResponseWithDataType(
  2191. '\WikipaliApi\Model\ProblemDetails',
  2192. $request,
  2193. $response,
  2194. );
  2195. case 422:
  2196. return $this->handleResponseWithDataType(
  2197. '\WikipaliApi\Model\ProblemDetails',
  2198. $request,
  2199. $response,
  2200. );
  2201. }
  2202. if ($statusCode < 200 || $statusCode > 299) {
  2203. throw new ApiException(
  2204. sprintf(
  2205. '[%d] Error connecting to the API (%s)',
  2206. $statusCode,
  2207. (string) $request->getUri()
  2208. ),
  2209. $statusCode,
  2210. $response->getHeaders(),
  2211. (string) $response->getBody()
  2212. );
  2213. }
  2214. return $this->handleResponseWithDataType(
  2215. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  2216. $request,
  2217. $response,
  2218. );
  2219. } catch (ApiException $e) {
  2220. switch ($e->getCode()) {
  2221. case 200:
  2222. $data = ObjectSerializer::deserialize(
  2223. $e->getResponseBody(),
  2224. '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response',
  2225. $e->getResponseHeaders()
  2226. );
  2227. $e->setResponseObject($data);
  2228. throw $e;
  2229. case 401:
  2230. $data = ObjectSerializer::deserialize(
  2231. $e->getResponseBody(),
  2232. '\WikipaliApi\Model\ProblemDetails',
  2233. $e->getResponseHeaders()
  2234. );
  2235. $e->setResponseObject($data);
  2236. throw $e;
  2237. case 403:
  2238. $data = ObjectSerializer::deserialize(
  2239. $e->getResponseBody(),
  2240. '\WikipaliApi\Model\ProblemDetails',
  2241. $e->getResponseHeaders()
  2242. );
  2243. $e->setResponseObject($data);
  2244. throw $e;
  2245. case 422:
  2246. $data = ObjectSerializer::deserialize(
  2247. $e->getResponseBody(),
  2248. '\WikipaliApi\Model\ProblemDetails',
  2249. $e->getResponseHeaders()
  2250. );
  2251. $e->setResponseObject($data);
  2252. throw $e;
  2253. }
  2254. throw $e;
  2255. }
  2256. }
  2257. /**
  2258. * Operation patchApiV3ChannelsChannelAsync
  2259. *
  2260. * 改 channel 信息
  2261. *
  2262. * @param string $channel channel uid (required)
  2263. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelRequest|null $patch_api_v3_channels_channel_request (optional)
  2264. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannel'] to see the possible values for this operation
  2265. *
  2266. * @throws \InvalidArgumentException
  2267. * @return \GuzzleHttp\Promise\PromiseInterface
  2268. */
  2269. public function patchApiV3ChannelsChannelAsync($channel, $patch_api_v3_channels_channel_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannel'][0])
  2270. {
  2271. return $this->patchApiV3ChannelsChannelAsyncWithHttpInfo($channel, $patch_api_v3_channels_channel_request, $contentType)
  2272. ->then(
  2273. function ($response) {
  2274. return $response[0];
  2275. }
  2276. );
  2277. }
  2278. /**
  2279. * Operation patchApiV3ChannelsChannelAsyncWithHttpInfo
  2280. *
  2281. * 改 channel 信息
  2282. *
  2283. * @param string $channel channel uid (required)
  2284. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelRequest|null $patch_api_v3_channels_channel_request (optional)
  2285. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannel'] to see the possible values for this operation
  2286. *
  2287. * @throws \InvalidArgumentException
  2288. * @return \GuzzleHttp\Promise\PromiseInterface
  2289. */
  2290. public function patchApiV3ChannelsChannelAsyncWithHttpInfo($channel, $patch_api_v3_channels_channel_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannel'][0])
  2291. {
  2292. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response';
  2293. $request = $this->patchApiV3ChannelsChannelRequest($channel, $patch_api_v3_channels_channel_request, $contentType);
  2294. return $this->client
  2295. ->sendAsync($request, $this->createHttpClientOption())
  2296. ->then(
  2297. function ($response) use ($returnType) {
  2298. if ($returnType === '\SplFileObject') {
  2299. $content = $response->getBody(); //stream goes to serializer
  2300. } else {
  2301. $content = (string) $response->getBody();
  2302. if ($returnType !== 'string') {
  2303. $content = json_decode($content);
  2304. }
  2305. }
  2306. return [
  2307. ObjectSerializer::deserialize($content, $returnType, []),
  2308. $response->getStatusCode(),
  2309. $response->getHeaders()
  2310. ];
  2311. },
  2312. function ($exception) {
  2313. $response = $exception->getResponse();
  2314. $statusCode = $response->getStatusCode();
  2315. throw new ApiException(
  2316. sprintf(
  2317. '[%d] Error connecting to the API (%s)',
  2318. $statusCode,
  2319. $exception->getRequest()->getUri()
  2320. ),
  2321. $statusCode,
  2322. $response->getHeaders(),
  2323. (string) $response->getBody()
  2324. );
  2325. }
  2326. );
  2327. }
  2328. /**
  2329. * Create request for operation 'patchApiV3ChannelsChannel'
  2330. *
  2331. * @param string $channel channel uid (required)
  2332. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelRequest|null $patch_api_v3_channels_channel_request (optional)
  2333. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannel'] to see the possible values for this operation
  2334. *
  2335. * @throws \InvalidArgumentException
  2336. * @return \GuzzleHttp\Psr7\Request
  2337. */
  2338. public function patchApiV3ChannelsChannelRequest($channel, $patch_api_v3_channels_channel_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannel'][0])
  2339. {
  2340. // verify the required parameter 'channel' is set
  2341. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  2342. throw new \InvalidArgumentException(
  2343. 'Missing the required parameter $channel when calling patchApiV3ChannelsChannel'
  2344. );
  2345. }
  2346. $resourcePath = '/v3/channels/{channel}';
  2347. $formParams = [];
  2348. $queryParams = [];
  2349. $headerParams = [];
  2350. $httpBody = '';
  2351. $multipart = false;
  2352. // path params
  2353. if ($channel !== null) {
  2354. $resourcePath = str_replace(
  2355. '{channel}',
  2356. ObjectSerializer::toPathValue($channel),
  2357. $resourcePath
  2358. );
  2359. }
  2360. $headers = $this->headerSelector->selectHeaders(
  2361. ['application/json', 'application/problem+json', ],
  2362. $contentType,
  2363. $multipart
  2364. );
  2365. // for model (json/xml)
  2366. if (isset($patch_api_v3_channels_channel_request)) {
  2367. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  2368. # if Content-Type contains "application/json", json_encode the body
  2369. try {
  2370. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($patch_api_v3_channels_channel_request), JSON_THROW_ON_ERROR);
  2371. } catch (\JsonException $e) {
  2372. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  2373. }
  2374. } else {
  2375. $httpBody = $patch_api_v3_channels_channel_request;
  2376. }
  2377. } elseif (count($formParams) > 0) {
  2378. if ($multipart) {
  2379. $multipartContents = [];
  2380. foreach ($formParams as $formParamName => $formParamValue) {
  2381. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  2382. foreach ($formParamValueItems as $formParamValueItem) {
  2383. $multipartContents[] = [
  2384. 'name' => $formParamName,
  2385. 'contents' => $formParamValueItem
  2386. ];
  2387. }
  2388. }
  2389. // for HTTP post (form)
  2390. $httpBody = new MultipartStream($multipartContents);
  2391. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  2392. # if Content-Type contains "application/json", json_encode the form parameters
  2393. try {
  2394. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  2395. } catch (\JsonException $e) {
  2396. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  2397. }
  2398. } else {
  2399. // for HTTP post (form)
  2400. $httpBody = ObjectSerializer::buildQuery($formParams);
  2401. }
  2402. }
  2403. // this endpoint requires Bearer authentication (access token)
  2404. if (!empty($this->config->getAccessToken())) {
  2405. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  2406. }
  2407. $defaultHeaders = [];
  2408. if ($this->config->getUserAgent()) {
  2409. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  2410. }
  2411. $headers = array_merge(
  2412. $defaultHeaders,
  2413. $headerParams,
  2414. $headers
  2415. );
  2416. $operationHost = $this->config->getHost();
  2417. $query = ObjectSerializer::buildQuery($queryParams);
  2418. return new Request(
  2419. 'PATCH',
  2420. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  2421. $headers,
  2422. $httpBody
  2423. );
  2424. }
  2425. /**
  2426. * Operation patchApiV3ChannelsChannelLinks
  2427. *
  2428. * 改 channel 的关系设置
  2429. *
  2430. * @param string $channel channel uid (required)
  2431. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelLinksRequest|null $patch_api_v3_channels_channel_links_request patch_api_v3_channels_channel_links_request (optional)
  2432. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannelLinks'] to see the possible values for this operation
  2433. *
  2434. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  2435. * @throws \InvalidArgumentException
  2436. * @return \WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  2437. */
  2438. public function patchApiV3ChannelsChannelLinks($channel, $patch_api_v3_channels_channel_links_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannelLinks'][0])
  2439. {
  2440. list($response) = $this->patchApiV3ChannelsChannelLinksWithHttpInfo($channel, $patch_api_v3_channels_channel_links_request, $contentType);
  2441. return $response;
  2442. }
  2443. /**
  2444. * Operation patchApiV3ChannelsChannelLinksWithHttpInfo
  2445. *
  2446. * 改 channel 的关系设置
  2447. *
  2448. * @param string $channel channel uid (required)
  2449. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelLinksRequest|null $patch_api_v3_channels_channel_links_request (optional)
  2450. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannelLinks'] to see the possible values for this operation
  2451. *
  2452. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  2453. * @throws \InvalidArgumentException
  2454. * @return array of \WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  2455. */
  2456. public function patchApiV3ChannelsChannelLinksWithHttpInfo($channel, $patch_api_v3_channels_channel_links_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannelLinks'][0])
  2457. {
  2458. $request = $this->patchApiV3ChannelsChannelLinksRequest($channel, $patch_api_v3_channels_channel_links_request, $contentType);
  2459. try {
  2460. $options = $this->createHttpClientOption();
  2461. try {
  2462. $response = $this->client->send($request, $options);
  2463. } catch (RequestException $e) {
  2464. throw new ApiException(
  2465. "[{$e->getCode()}] {$e->getMessage()}",
  2466. (int) $e->getCode(),
  2467. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  2468. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  2469. );
  2470. } catch (ConnectException $e) {
  2471. throw new ApiException(
  2472. "[{$e->getCode()}] {$e->getMessage()}",
  2473. (int) $e->getCode(),
  2474. null,
  2475. null
  2476. );
  2477. }
  2478. $statusCode = $response->getStatusCode();
  2479. switch($statusCode) {
  2480. case 200:
  2481. return $this->handleResponseWithDataType(
  2482. '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response',
  2483. $request,
  2484. $response,
  2485. );
  2486. case 401:
  2487. return $this->handleResponseWithDataType(
  2488. '\WikipaliApi\Model\ProblemDetails',
  2489. $request,
  2490. $response,
  2491. );
  2492. case 403:
  2493. return $this->handleResponseWithDataType(
  2494. '\WikipaliApi\Model\ProblemDetails',
  2495. $request,
  2496. $response,
  2497. );
  2498. case 422:
  2499. return $this->handleResponseWithDataType(
  2500. '\WikipaliApi\Model\ProblemDetails',
  2501. $request,
  2502. $response,
  2503. );
  2504. }
  2505. if ($statusCode < 200 || $statusCode > 299) {
  2506. throw new ApiException(
  2507. sprintf(
  2508. '[%d] Error connecting to the API (%s)',
  2509. $statusCode,
  2510. (string) $request->getUri()
  2511. ),
  2512. $statusCode,
  2513. $response->getHeaders(),
  2514. (string) $response->getBody()
  2515. );
  2516. }
  2517. return $this->handleResponseWithDataType(
  2518. '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response',
  2519. $request,
  2520. $response,
  2521. );
  2522. } catch (ApiException $e) {
  2523. switch ($e->getCode()) {
  2524. case 200:
  2525. $data = ObjectSerializer::deserialize(
  2526. $e->getResponseBody(),
  2527. '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response',
  2528. $e->getResponseHeaders()
  2529. );
  2530. $e->setResponseObject($data);
  2531. throw $e;
  2532. case 401:
  2533. $data = ObjectSerializer::deserialize(
  2534. $e->getResponseBody(),
  2535. '\WikipaliApi\Model\ProblemDetails',
  2536. $e->getResponseHeaders()
  2537. );
  2538. $e->setResponseObject($data);
  2539. throw $e;
  2540. case 403:
  2541. $data = ObjectSerializer::deserialize(
  2542. $e->getResponseBody(),
  2543. '\WikipaliApi\Model\ProblemDetails',
  2544. $e->getResponseHeaders()
  2545. );
  2546. $e->setResponseObject($data);
  2547. throw $e;
  2548. case 422:
  2549. $data = ObjectSerializer::deserialize(
  2550. $e->getResponseBody(),
  2551. '\WikipaliApi\Model\ProblemDetails',
  2552. $e->getResponseHeaders()
  2553. );
  2554. $e->setResponseObject($data);
  2555. throw $e;
  2556. }
  2557. throw $e;
  2558. }
  2559. }
  2560. /**
  2561. * Operation patchApiV3ChannelsChannelLinksAsync
  2562. *
  2563. * 改 channel 的关系设置
  2564. *
  2565. * @param string $channel channel uid (required)
  2566. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelLinksRequest|null $patch_api_v3_channels_channel_links_request (optional)
  2567. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannelLinks'] to see the possible values for this operation
  2568. *
  2569. * @throws \InvalidArgumentException
  2570. * @return \GuzzleHttp\Promise\PromiseInterface
  2571. */
  2572. public function patchApiV3ChannelsChannelLinksAsync($channel, $patch_api_v3_channels_channel_links_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannelLinks'][0])
  2573. {
  2574. return $this->patchApiV3ChannelsChannelLinksAsyncWithHttpInfo($channel, $patch_api_v3_channels_channel_links_request, $contentType)
  2575. ->then(
  2576. function ($response) {
  2577. return $response[0];
  2578. }
  2579. );
  2580. }
  2581. /**
  2582. * Operation patchApiV3ChannelsChannelLinksAsyncWithHttpInfo
  2583. *
  2584. * 改 channel 的关系设置
  2585. *
  2586. * @param string $channel channel uid (required)
  2587. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelLinksRequest|null $patch_api_v3_channels_channel_links_request (optional)
  2588. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannelLinks'] to see the possible values for this operation
  2589. *
  2590. * @throws \InvalidArgumentException
  2591. * @return \GuzzleHttp\Promise\PromiseInterface
  2592. */
  2593. public function patchApiV3ChannelsChannelLinksAsyncWithHttpInfo($channel, $patch_api_v3_channels_channel_links_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannelLinks'][0])
  2594. {
  2595. $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannelLinks200Response';
  2596. $request = $this->patchApiV3ChannelsChannelLinksRequest($channel, $patch_api_v3_channels_channel_links_request, $contentType);
  2597. return $this->client
  2598. ->sendAsync($request, $this->createHttpClientOption())
  2599. ->then(
  2600. function ($response) use ($returnType) {
  2601. if ($returnType === '\SplFileObject') {
  2602. $content = $response->getBody(); //stream goes to serializer
  2603. } else {
  2604. $content = (string) $response->getBody();
  2605. if ($returnType !== 'string') {
  2606. $content = json_decode($content);
  2607. }
  2608. }
  2609. return [
  2610. ObjectSerializer::deserialize($content, $returnType, []),
  2611. $response->getStatusCode(),
  2612. $response->getHeaders()
  2613. ];
  2614. },
  2615. function ($exception) {
  2616. $response = $exception->getResponse();
  2617. $statusCode = $response->getStatusCode();
  2618. throw new ApiException(
  2619. sprintf(
  2620. '[%d] Error connecting to the API (%s)',
  2621. $statusCode,
  2622. $exception->getRequest()->getUri()
  2623. ),
  2624. $statusCode,
  2625. $response->getHeaders(),
  2626. (string) $response->getBody()
  2627. );
  2628. }
  2629. );
  2630. }
  2631. /**
  2632. * Create request for operation 'patchApiV3ChannelsChannelLinks'
  2633. *
  2634. * @param string $channel channel uid (required)
  2635. * @param \WikipaliApi\Model\PatchApiV3ChannelsChannelLinksRequest|null $patch_api_v3_channels_channel_links_request (optional)
  2636. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3ChannelsChannelLinks'] to see the possible values for this operation
  2637. *
  2638. * @throws \InvalidArgumentException
  2639. * @return \GuzzleHttp\Psr7\Request
  2640. */
  2641. public function patchApiV3ChannelsChannelLinksRequest($channel, $patch_api_v3_channels_channel_links_request = null, string $contentType = self::contentTypes['patchApiV3ChannelsChannelLinks'][0])
  2642. {
  2643. // verify the required parameter 'channel' is set
  2644. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  2645. throw new \InvalidArgumentException(
  2646. 'Missing the required parameter $channel when calling patchApiV3ChannelsChannelLinks'
  2647. );
  2648. }
  2649. $resourcePath = '/v3/channels/{channel}/links';
  2650. $formParams = [];
  2651. $queryParams = [];
  2652. $headerParams = [];
  2653. $httpBody = '';
  2654. $multipart = false;
  2655. // path params
  2656. if ($channel !== null) {
  2657. $resourcePath = str_replace(
  2658. '{channel}',
  2659. ObjectSerializer::toPathValue($channel),
  2660. $resourcePath
  2661. );
  2662. }
  2663. $headers = $this->headerSelector->selectHeaders(
  2664. ['application/json', 'application/problem+json', ],
  2665. $contentType,
  2666. $multipart
  2667. );
  2668. // for model (json/xml)
  2669. if (isset($patch_api_v3_channels_channel_links_request)) {
  2670. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  2671. # if Content-Type contains "application/json", json_encode the body
  2672. try {
  2673. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($patch_api_v3_channels_channel_links_request), JSON_THROW_ON_ERROR);
  2674. } catch (\JsonException $e) {
  2675. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  2676. }
  2677. } else {
  2678. $httpBody = $patch_api_v3_channels_channel_links_request;
  2679. }
  2680. } elseif (count($formParams) > 0) {
  2681. if ($multipart) {
  2682. $multipartContents = [];
  2683. foreach ($formParams as $formParamName => $formParamValue) {
  2684. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  2685. foreach ($formParamValueItems as $formParamValueItem) {
  2686. $multipartContents[] = [
  2687. 'name' => $formParamName,
  2688. 'contents' => $formParamValueItem
  2689. ];
  2690. }
  2691. }
  2692. // for HTTP post (form)
  2693. $httpBody = new MultipartStream($multipartContents);
  2694. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  2695. # if Content-Type contains "application/json", json_encode the form parameters
  2696. try {
  2697. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  2698. } catch (\JsonException $e) {
  2699. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  2700. }
  2701. } else {
  2702. // for HTTP post (form)
  2703. $httpBody = ObjectSerializer::buildQuery($formParams);
  2704. }
  2705. }
  2706. // this endpoint requires Bearer authentication (access token)
  2707. if (!empty($this->config->getAccessToken())) {
  2708. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  2709. }
  2710. $defaultHeaders = [];
  2711. if ($this->config->getUserAgent()) {
  2712. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  2713. }
  2714. $headers = array_merge(
  2715. $defaultHeaders,
  2716. $headerParams,
  2717. $headers
  2718. );
  2719. $operationHost = $this->config->getHost();
  2720. $query = ObjectSerializer::buildQuery($queryParams);
  2721. return new Request(
  2722. 'PATCH',
  2723. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  2724. $headers,
  2725. $httpBody
  2726. );
  2727. }
  2728. /**
  2729. * Operation postApiV3ChannelsBatchProgress
  2730. *
  2731. * 查一批句子在各 channel 的完成度
  2732. *
  2733. * @param \WikipaliApi\Model\PostApiV3ChannelsBatchProgressRequest $post_api_v3_channels_batch_progress_request post_api_v3_channels_batch_progress_request (required)
  2734. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsBatchProgress'] to see the possible values for this operation
  2735. *
  2736. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  2737. * @throws \InvalidArgumentException
  2738. * @return \WikipaliApi\Model\PostApiV3ChannelsBatchProgress200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  2739. */
  2740. public function postApiV3ChannelsBatchProgress($post_api_v3_channels_batch_progress_request, string $contentType = self::contentTypes['postApiV3ChannelsBatchProgress'][0])
  2741. {
  2742. list($response) = $this->postApiV3ChannelsBatchProgressWithHttpInfo($post_api_v3_channels_batch_progress_request, $contentType);
  2743. return $response;
  2744. }
  2745. /**
  2746. * Operation postApiV3ChannelsBatchProgressWithHttpInfo
  2747. *
  2748. * 查一批句子在各 channel 的完成度
  2749. *
  2750. * @param \WikipaliApi\Model\PostApiV3ChannelsBatchProgressRequest $post_api_v3_channels_batch_progress_request (required)
  2751. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsBatchProgress'] to see the possible values for this operation
  2752. *
  2753. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  2754. * @throws \InvalidArgumentException
  2755. * @return array of \WikipaliApi\Model\PostApiV3ChannelsBatchProgress200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  2756. */
  2757. public function postApiV3ChannelsBatchProgressWithHttpInfo($post_api_v3_channels_batch_progress_request, string $contentType = self::contentTypes['postApiV3ChannelsBatchProgress'][0])
  2758. {
  2759. $request = $this->postApiV3ChannelsBatchProgressRequest($post_api_v3_channels_batch_progress_request, $contentType);
  2760. try {
  2761. $options = $this->createHttpClientOption();
  2762. try {
  2763. $response = $this->client->send($request, $options);
  2764. } catch (RequestException $e) {
  2765. throw new ApiException(
  2766. "[{$e->getCode()}] {$e->getMessage()}",
  2767. (int) $e->getCode(),
  2768. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  2769. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  2770. );
  2771. } catch (ConnectException $e) {
  2772. throw new ApiException(
  2773. "[{$e->getCode()}] {$e->getMessage()}",
  2774. (int) $e->getCode(),
  2775. null,
  2776. null
  2777. );
  2778. }
  2779. $statusCode = $response->getStatusCode();
  2780. switch($statusCode) {
  2781. case 200:
  2782. return $this->handleResponseWithDataType(
  2783. '\WikipaliApi\Model\PostApiV3ChannelsBatchProgress200Response',
  2784. $request,
  2785. $response,
  2786. );
  2787. case 403:
  2788. return $this->handleResponseWithDataType(
  2789. '\WikipaliApi\Model\ProblemDetails',
  2790. $request,
  2791. $response,
  2792. );
  2793. case 422:
  2794. return $this->handleResponseWithDataType(
  2795. '\WikipaliApi\Model\ProblemDetails',
  2796. $request,
  2797. $response,
  2798. );
  2799. }
  2800. if ($statusCode < 200 || $statusCode > 299) {
  2801. throw new ApiException(
  2802. sprintf(
  2803. '[%d] Error connecting to the API (%s)',
  2804. $statusCode,
  2805. (string) $request->getUri()
  2806. ),
  2807. $statusCode,
  2808. $response->getHeaders(),
  2809. (string) $response->getBody()
  2810. );
  2811. }
  2812. return $this->handleResponseWithDataType(
  2813. '\WikipaliApi\Model\PostApiV3ChannelsBatchProgress200Response',
  2814. $request,
  2815. $response,
  2816. );
  2817. } catch (ApiException $e) {
  2818. switch ($e->getCode()) {
  2819. case 200:
  2820. $data = ObjectSerializer::deserialize(
  2821. $e->getResponseBody(),
  2822. '\WikipaliApi\Model\PostApiV3ChannelsBatchProgress200Response',
  2823. $e->getResponseHeaders()
  2824. );
  2825. $e->setResponseObject($data);
  2826. throw $e;
  2827. case 403:
  2828. $data = ObjectSerializer::deserialize(
  2829. $e->getResponseBody(),
  2830. '\WikipaliApi\Model\ProblemDetails',
  2831. $e->getResponseHeaders()
  2832. );
  2833. $e->setResponseObject($data);
  2834. throw $e;
  2835. case 422:
  2836. $data = ObjectSerializer::deserialize(
  2837. $e->getResponseBody(),
  2838. '\WikipaliApi\Model\ProblemDetails',
  2839. $e->getResponseHeaders()
  2840. );
  2841. $e->setResponseObject($data);
  2842. throw $e;
  2843. }
  2844. throw $e;
  2845. }
  2846. }
  2847. /**
  2848. * Operation postApiV3ChannelsBatchProgressAsync
  2849. *
  2850. * 查一批句子在各 channel 的完成度
  2851. *
  2852. * @param \WikipaliApi\Model\PostApiV3ChannelsBatchProgressRequest $post_api_v3_channels_batch_progress_request (required)
  2853. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsBatchProgress'] to see the possible values for this operation
  2854. *
  2855. * @throws \InvalidArgumentException
  2856. * @return \GuzzleHttp\Promise\PromiseInterface
  2857. */
  2858. public function postApiV3ChannelsBatchProgressAsync($post_api_v3_channels_batch_progress_request, string $contentType = self::contentTypes['postApiV3ChannelsBatchProgress'][0])
  2859. {
  2860. return $this->postApiV3ChannelsBatchProgressAsyncWithHttpInfo($post_api_v3_channels_batch_progress_request, $contentType)
  2861. ->then(
  2862. function ($response) {
  2863. return $response[0];
  2864. }
  2865. );
  2866. }
  2867. /**
  2868. * Operation postApiV3ChannelsBatchProgressAsyncWithHttpInfo
  2869. *
  2870. * 查一批句子在各 channel 的完成度
  2871. *
  2872. * @param \WikipaliApi\Model\PostApiV3ChannelsBatchProgressRequest $post_api_v3_channels_batch_progress_request (required)
  2873. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsBatchProgress'] to see the possible values for this operation
  2874. *
  2875. * @throws \InvalidArgumentException
  2876. * @return \GuzzleHttp\Promise\PromiseInterface
  2877. */
  2878. public function postApiV3ChannelsBatchProgressAsyncWithHttpInfo($post_api_v3_channels_batch_progress_request, string $contentType = self::contentTypes['postApiV3ChannelsBatchProgress'][0])
  2879. {
  2880. $returnType = '\WikipaliApi\Model\PostApiV3ChannelsBatchProgress200Response';
  2881. $request = $this->postApiV3ChannelsBatchProgressRequest($post_api_v3_channels_batch_progress_request, $contentType);
  2882. return $this->client
  2883. ->sendAsync($request, $this->createHttpClientOption())
  2884. ->then(
  2885. function ($response) use ($returnType) {
  2886. if ($returnType === '\SplFileObject') {
  2887. $content = $response->getBody(); //stream goes to serializer
  2888. } else {
  2889. $content = (string) $response->getBody();
  2890. if ($returnType !== 'string') {
  2891. $content = json_decode($content);
  2892. }
  2893. }
  2894. return [
  2895. ObjectSerializer::deserialize($content, $returnType, []),
  2896. $response->getStatusCode(),
  2897. $response->getHeaders()
  2898. ];
  2899. },
  2900. function ($exception) {
  2901. $response = $exception->getResponse();
  2902. $statusCode = $response->getStatusCode();
  2903. throw new ApiException(
  2904. sprintf(
  2905. '[%d] Error connecting to the API (%s)',
  2906. $statusCode,
  2907. $exception->getRequest()->getUri()
  2908. ),
  2909. $statusCode,
  2910. $response->getHeaders(),
  2911. (string) $response->getBody()
  2912. );
  2913. }
  2914. );
  2915. }
  2916. /**
  2917. * Create request for operation 'postApiV3ChannelsBatchProgress'
  2918. *
  2919. * @param \WikipaliApi\Model\PostApiV3ChannelsBatchProgressRequest $post_api_v3_channels_batch_progress_request (required)
  2920. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsBatchProgress'] to see the possible values for this operation
  2921. *
  2922. * @throws \InvalidArgumentException
  2923. * @return \GuzzleHttp\Psr7\Request
  2924. */
  2925. public function postApiV3ChannelsBatchProgressRequest($post_api_v3_channels_batch_progress_request, string $contentType = self::contentTypes['postApiV3ChannelsBatchProgress'][0])
  2926. {
  2927. // verify the required parameter 'post_api_v3_channels_batch_progress_request' is set
  2928. 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)) {
  2929. throw new \InvalidArgumentException(
  2930. 'Missing the required parameter $post_api_v3_channels_batch_progress_request when calling postApiV3ChannelsBatchProgress'
  2931. );
  2932. }
  2933. $resourcePath = '/v3/channels/batch-progress';
  2934. $formParams = [];
  2935. $queryParams = [];
  2936. $headerParams = [];
  2937. $httpBody = '';
  2938. $multipart = false;
  2939. $headers = $this->headerSelector->selectHeaders(
  2940. ['application/json', 'application/problem+json', ],
  2941. $contentType,
  2942. $multipart
  2943. );
  2944. // for model (json/xml)
  2945. if (isset($post_api_v3_channels_batch_progress_request)) {
  2946. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  2947. # if Content-Type contains "application/json", json_encode the body
  2948. try {
  2949. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_channels_batch_progress_request), JSON_THROW_ON_ERROR);
  2950. } catch (\JsonException $e) {
  2951. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  2952. }
  2953. } else {
  2954. $httpBody = $post_api_v3_channels_batch_progress_request;
  2955. }
  2956. } elseif (count($formParams) > 0) {
  2957. if ($multipart) {
  2958. $multipartContents = [];
  2959. foreach ($formParams as $formParamName => $formParamValue) {
  2960. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  2961. foreach ($formParamValueItems as $formParamValueItem) {
  2962. $multipartContents[] = [
  2963. 'name' => $formParamName,
  2964. 'contents' => $formParamValueItem
  2965. ];
  2966. }
  2967. }
  2968. // for HTTP post (form)
  2969. $httpBody = new MultipartStream($multipartContents);
  2970. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  2971. # if Content-Type contains "application/json", json_encode the form parameters
  2972. try {
  2973. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  2974. } catch (\JsonException $e) {
  2975. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  2976. }
  2977. } else {
  2978. // for HTTP post (form)
  2979. $httpBody = ObjectSerializer::buildQuery($formParams);
  2980. }
  2981. }
  2982. // this endpoint requires Bearer authentication (access token)
  2983. if (!empty($this->config->getAccessToken())) {
  2984. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  2985. }
  2986. $defaultHeaders = [];
  2987. if ($this->config->getUserAgent()) {
  2988. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  2989. }
  2990. $headers = array_merge(
  2991. $defaultHeaders,
  2992. $headerParams,
  2993. $headers
  2994. );
  2995. $operationHost = $this->config->getHost();
  2996. $query = ObjectSerializer::buildQuery($queryParams);
  2997. return new Request(
  2998. 'POST',
  2999. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  3000. $headers,
  3001. $httpBody
  3002. );
  3003. }
  3004. /**
  3005. * Operation postApiV3ChannelsChannelTerms
  3006. *
  3007. * 在 channel 里新建术语
  3008. *
  3009. * @param string $channel channel uid (required)
  3010. * @param \WikipaliApi\Model\PostApiV3ChannelsChannelTermsRequest $post_api_v3_channels_channel_terms_request post_api_v3_channels_channel_terms_request (required)
  3011. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsChannelTerms'] to see the possible values for this operation
  3012. *
  3013. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  3014. * @throws \InvalidArgumentException
  3015. * @return \WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  3016. */
  3017. public function postApiV3ChannelsChannelTerms($channel, $post_api_v3_channels_channel_terms_request, string $contentType = self::contentTypes['postApiV3ChannelsChannelTerms'][0])
  3018. {
  3019. list($response) = $this->postApiV3ChannelsChannelTermsWithHttpInfo($channel, $post_api_v3_channels_channel_terms_request, $contentType);
  3020. return $response;
  3021. }
  3022. /**
  3023. * Operation postApiV3ChannelsChannelTermsWithHttpInfo
  3024. *
  3025. * 在 channel 里新建术语
  3026. *
  3027. * @param string $channel channel uid (required)
  3028. * @param \WikipaliApi\Model\PostApiV3ChannelsChannelTermsRequest $post_api_v3_channels_channel_terms_request (required)
  3029. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsChannelTerms'] to see the possible values for this operation
  3030. *
  3031. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  3032. * @throws \InvalidArgumentException
  3033. * @return array of \WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  3034. */
  3035. public function postApiV3ChannelsChannelTermsWithHttpInfo($channel, $post_api_v3_channels_channel_terms_request, string $contentType = self::contentTypes['postApiV3ChannelsChannelTerms'][0])
  3036. {
  3037. $request = $this->postApiV3ChannelsChannelTermsRequest($channel, $post_api_v3_channels_channel_terms_request, $contentType);
  3038. try {
  3039. $options = $this->createHttpClientOption();
  3040. try {
  3041. $response = $this->client->send($request, $options);
  3042. } catch (RequestException $e) {
  3043. throw new ApiException(
  3044. "[{$e->getCode()}] {$e->getMessage()}",
  3045. (int) $e->getCode(),
  3046. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  3047. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  3048. );
  3049. } catch (ConnectException $e) {
  3050. throw new ApiException(
  3051. "[{$e->getCode()}] {$e->getMessage()}",
  3052. (int) $e->getCode(),
  3053. null,
  3054. null
  3055. );
  3056. }
  3057. $statusCode = $response->getStatusCode();
  3058. switch($statusCode) {
  3059. case 200:
  3060. return $this->handleResponseWithDataType(
  3061. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  3062. $request,
  3063. $response,
  3064. );
  3065. case 201:
  3066. return $this->handleResponseWithDataType(
  3067. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  3068. $request,
  3069. $response,
  3070. );
  3071. case 401:
  3072. return $this->handleResponseWithDataType(
  3073. '\WikipaliApi\Model\ProblemDetails',
  3074. $request,
  3075. $response,
  3076. );
  3077. case 403:
  3078. return $this->handleResponseWithDataType(
  3079. '\WikipaliApi\Model\ProblemDetails',
  3080. $request,
  3081. $response,
  3082. );
  3083. case 409:
  3084. return $this->handleResponseWithDataType(
  3085. '\WikipaliApi\Model\ProblemDetails',
  3086. $request,
  3087. $response,
  3088. );
  3089. case 422:
  3090. return $this->handleResponseWithDataType(
  3091. '\WikipaliApi\Model\ProblemDetails',
  3092. $request,
  3093. $response,
  3094. );
  3095. }
  3096. if ($statusCode < 200 || $statusCode > 299) {
  3097. throw new ApiException(
  3098. sprintf(
  3099. '[%d] Error connecting to the API (%s)',
  3100. $statusCode,
  3101. (string) $request->getUri()
  3102. ),
  3103. $statusCode,
  3104. $response->getHeaders(),
  3105. (string) $response->getBody()
  3106. );
  3107. }
  3108. return $this->handleResponseWithDataType(
  3109. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  3110. $request,
  3111. $response,
  3112. );
  3113. } catch (ApiException $e) {
  3114. switch ($e->getCode()) {
  3115. case 200:
  3116. $data = ObjectSerializer::deserialize(
  3117. $e->getResponseBody(),
  3118. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  3119. $e->getResponseHeaders()
  3120. );
  3121. $e->setResponseObject($data);
  3122. throw $e;
  3123. case 201:
  3124. $data = ObjectSerializer::deserialize(
  3125. $e->getResponseBody(),
  3126. '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response',
  3127. $e->getResponseHeaders()
  3128. );
  3129. $e->setResponseObject($data);
  3130. throw $e;
  3131. case 401:
  3132. $data = ObjectSerializer::deserialize(
  3133. $e->getResponseBody(),
  3134. '\WikipaliApi\Model\ProblemDetails',
  3135. $e->getResponseHeaders()
  3136. );
  3137. $e->setResponseObject($data);
  3138. throw $e;
  3139. case 403:
  3140. $data = ObjectSerializer::deserialize(
  3141. $e->getResponseBody(),
  3142. '\WikipaliApi\Model\ProblemDetails',
  3143. $e->getResponseHeaders()
  3144. );
  3145. $e->setResponseObject($data);
  3146. throw $e;
  3147. case 409:
  3148. $data = ObjectSerializer::deserialize(
  3149. $e->getResponseBody(),
  3150. '\WikipaliApi\Model\ProblemDetails',
  3151. $e->getResponseHeaders()
  3152. );
  3153. $e->setResponseObject($data);
  3154. throw $e;
  3155. case 422:
  3156. $data = ObjectSerializer::deserialize(
  3157. $e->getResponseBody(),
  3158. '\WikipaliApi\Model\ProblemDetails',
  3159. $e->getResponseHeaders()
  3160. );
  3161. $e->setResponseObject($data);
  3162. throw $e;
  3163. }
  3164. throw $e;
  3165. }
  3166. }
  3167. /**
  3168. * Operation postApiV3ChannelsChannelTermsAsync
  3169. *
  3170. * 在 channel 里新建术语
  3171. *
  3172. * @param string $channel channel uid (required)
  3173. * @param \WikipaliApi\Model\PostApiV3ChannelsChannelTermsRequest $post_api_v3_channels_channel_terms_request (required)
  3174. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsChannelTerms'] to see the possible values for this operation
  3175. *
  3176. * @throws \InvalidArgumentException
  3177. * @return \GuzzleHttp\Promise\PromiseInterface
  3178. */
  3179. public function postApiV3ChannelsChannelTermsAsync($channel, $post_api_v3_channels_channel_terms_request, string $contentType = self::contentTypes['postApiV3ChannelsChannelTerms'][0])
  3180. {
  3181. return $this->postApiV3ChannelsChannelTermsAsyncWithHttpInfo($channel, $post_api_v3_channels_channel_terms_request, $contentType)
  3182. ->then(
  3183. function ($response) {
  3184. return $response[0];
  3185. }
  3186. );
  3187. }
  3188. /**
  3189. * Operation postApiV3ChannelsChannelTermsAsyncWithHttpInfo
  3190. *
  3191. * 在 channel 里新建术语
  3192. *
  3193. * @param string $channel channel uid (required)
  3194. * @param \WikipaliApi\Model\PostApiV3ChannelsChannelTermsRequest $post_api_v3_channels_channel_terms_request (required)
  3195. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsChannelTerms'] to see the possible values for this operation
  3196. *
  3197. * @throws \InvalidArgumentException
  3198. * @return \GuzzleHttp\Promise\PromiseInterface
  3199. */
  3200. public function postApiV3ChannelsChannelTermsAsyncWithHttpInfo($channel, $post_api_v3_channels_channel_terms_request, string $contentType = self::contentTypes['postApiV3ChannelsChannelTerms'][0])
  3201. {
  3202. $returnType = '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response';
  3203. $request = $this->postApiV3ChannelsChannelTermsRequest($channel, $post_api_v3_channels_channel_terms_request, $contentType);
  3204. return $this->client
  3205. ->sendAsync($request, $this->createHttpClientOption())
  3206. ->then(
  3207. function ($response) use ($returnType) {
  3208. if ($returnType === '\SplFileObject') {
  3209. $content = $response->getBody(); //stream goes to serializer
  3210. } else {
  3211. $content = (string) $response->getBody();
  3212. if ($returnType !== 'string') {
  3213. $content = json_decode($content);
  3214. }
  3215. }
  3216. return [
  3217. ObjectSerializer::deserialize($content, $returnType, []),
  3218. $response->getStatusCode(),
  3219. $response->getHeaders()
  3220. ];
  3221. },
  3222. function ($exception) {
  3223. $response = $exception->getResponse();
  3224. $statusCode = $response->getStatusCode();
  3225. throw new ApiException(
  3226. sprintf(
  3227. '[%d] Error connecting to the API (%s)',
  3228. $statusCode,
  3229. $exception->getRequest()->getUri()
  3230. ),
  3231. $statusCode,
  3232. $response->getHeaders(),
  3233. (string) $response->getBody()
  3234. );
  3235. }
  3236. );
  3237. }
  3238. /**
  3239. * Create request for operation 'postApiV3ChannelsChannelTerms'
  3240. *
  3241. * @param string $channel channel uid (required)
  3242. * @param \WikipaliApi\Model\PostApiV3ChannelsChannelTermsRequest $post_api_v3_channels_channel_terms_request (required)
  3243. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsChannelTerms'] to see the possible values for this operation
  3244. *
  3245. * @throws \InvalidArgumentException
  3246. * @return \GuzzleHttp\Psr7\Request
  3247. */
  3248. public function postApiV3ChannelsChannelTermsRequest($channel, $post_api_v3_channels_channel_terms_request, string $contentType = self::contentTypes['postApiV3ChannelsChannelTerms'][0])
  3249. {
  3250. // verify the required parameter 'channel' is set
  3251. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  3252. throw new \InvalidArgumentException(
  3253. 'Missing the required parameter $channel when calling postApiV3ChannelsChannelTerms'
  3254. );
  3255. }
  3256. // verify the required parameter 'post_api_v3_channels_channel_terms_request' is set
  3257. if ($post_api_v3_channels_channel_terms_request === null || (is_array($post_api_v3_channels_channel_terms_request) && count($post_api_v3_channels_channel_terms_request) === 0)) {
  3258. throw new \InvalidArgumentException(
  3259. 'Missing the required parameter $post_api_v3_channels_channel_terms_request when calling postApiV3ChannelsChannelTerms'
  3260. );
  3261. }
  3262. $resourcePath = '/v3/channels/{channel}/terms';
  3263. $formParams = [];
  3264. $queryParams = [];
  3265. $headerParams = [];
  3266. $httpBody = '';
  3267. $multipart = false;
  3268. // path params
  3269. if ($channel !== null) {
  3270. $resourcePath = str_replace(
  3271. '{channel}',
  3272. ObjectSerializer::toPathValue($channel),
  3273. $resourcePath
  3274. );
  3275. }
  3276. $headers = $this->headerSelector->selectHeaders(
  3277. ['application/json', 'application/problem+json', ],
  3278. $contentType,
  3279. $multipart
  3280. );
  3281. // for model (json/xml)
  3282. if (isset($post_api_v3_channels_channel_terms_request)) {
  3283. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  3284. # if Content-Type contains "application/json", json_encode the body
  3285. try {
  3286. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_channels_channel_terms_request), JSON_THROW_ON_ERROR);
  3287. } catch (\JsonException $e) {
  3288. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  3289. }
  3290. } else {
  3291. $httpBody = $post_api_v3_channels_channel_terms_request;
  3292. }
  3293. } elseif (count($formParams) > 0) {
  3294. if ($multipart) {
  3295. $multipartContents = [];
  3296. foreach ($formParams as $formParamName => $formParamValue) {
  3297. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  3298. foreach ($formParamValueItems as $formParamValueItem) {
  3299. $multipartContents[] = [
  3300. 'name' => $formParamName,
  3301. 'contents' => $formParamValueItem
  3302. ];
  3303. }
  3304. }
  3305. // for HTTP post (form)
  3306. $httpBody = new MultipartStream($multipartContents);
  3307. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  3308. # if Content-Type contains "application/json", json_encode the form parameters
  3309. try {
  3310. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  3311. } catch (\JsonException $e) {
  3312. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  3313. }
  3314. } else {
  3315. // for HTTP post (form)
  3316. $httpBody = ObjectSerializer::buildQuery($formParams);
  3317. }
  3318. }
  3319. // this endpoint requires Bearer authentication (access token)
  3320. if (!empty($this->config->getAccessToken())) {
  3321. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  3322. }
  3323. $defaultHeaders = [];
  3324. if ($this->config->getUserAgent()) {
  3325. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  3326. }
  3327. $headers = array_merge(
  3328. $defaultHeaders,
  3329. $headerParams,
  3330. $headers
  3331. );
  3332. $operationHost = $this->config->getHost();
  3333. $query = ObjectSerializer::buildQuery($queryParams);
  3334. return new Request(
  3335. 'POST',
  3336. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  3337. $headers,
  3338. $httpBody
  3339. );
  3340. }
  3341. /**
  3342. * Operation postApiV3ChannelsChannelTermsImports
  3343. *
  3344. * 向 channel 导入术语
  3345. *
  3346. * @param string $channel channel uid (required)
  3347. * @param \SplFileObject $file xlsx 表格,不超过 5MB (required)
  3348. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsChannelTermsImports'] to see the possible values for this operation
  3349. *
  3350. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  3351. * @throws \InvalidArgumentException
  3352. * @return \WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  3353. */
  3354. public function postApiV3ChannelsChannelTermsImports($channel, $file, string $contentType = self::contentTypes['postApiV3ChannelsChannelTermsImports'][0])
  3355. {
  3356. list($response) = $this->postApiV3ChannelsChannelTermsImportsWithHttpInfo($channel, $file, $contentType);
  3357. return $response;
  3358. }
  3359. /**
  3360. * Operation postApiV3ChannelsChannelTermsImportsWithHttpInfo
  3361. *
  3362. * 向 channel 导入术语
  3363. *
  3364. * @param string $channel channel uid (required)
  3365. * @param \SplFileObject $file xlsx 表格,不超过 5MB (required)
  3366. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsChannelTermsImports'] to see the possible values for this operation
  3367. *
  3368. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  3369. * @throws \InvalidArgumentException
  3370. * @return array of \WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  3371. */
  3372. public function postApiV3ChannelsChannelTermsImportsWithHttpInfo($channel, $file, string $contentType = self::contentTypes['postApiV3ChannelsChannelTermsImports'][0])
  3373. {
  3374. $request = $this->postApiV3ChannelsChannelTermsImportsRequest($channel, $file, $contentType);
  3375. try {
  3376. $options = $this->createHttpClientOption();
  3377. try {
  3378. $response = $this->client->send($request, $options);
  3379. } catch (RequestException $e) {
  3380. throw new ApiException(
  3381. "[{$e->getCode()}] {$e->getMessage()}",
  3382. (int) $e->getCode(),
  3383. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  3384. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  3385. );
  3386. } catch (ConnectException $e) {
  3387. throw new ApiException(
  3388. "[{$e->getCode()}] {$e->getMessage()}",
  3389. (int) $e->getCode(),
  3390. null,
  3391. null
  3392. );
  3393. }
  3394. $statusCode = $response->getStatusCode();
  3395. switch($statusCode) {
  3396. case 200:
  3397. return $this->handleResponseWithDataType(
  3398. '\WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response',
  3399. $request,
  3400. $response,
  3401. );
  3402. case 401:
  3403. return $this->handleResponseWithDataType(
  3404. '\WikipaliApi\Model\ProblemDetails',
  3405. $request,
  3406. $response,
  3407. );
  3408. case 403:
  3409. return $this->handleResponseWithDataType(
  3410. '\WikipaliApi\Model\ProblemDetails',
  3411. $request,
  3412. $response,
  3413. );
  3414. case 422:
  3415. return $this->handleResponseWithDataType(
  3416. '\WikipaliApi\Model\ProblemDetails',
  3417. $request,
  3418. $response,
  3419. );
  3420. }
  3421. if ($statusCode < 200 || $statusCode > 299) {
  3422. throw new ApiException(
  3423. sprintf(
  3424. '[%d] Error connecting to the API (%s)',
  3425. $statusCode,
  3426. (string) $request->getUri()
  3427. ),
  3428. $statusCode,
  3429. $response->getHeaders(),
  3430. (string) $response->getBody()
  3431. );
  3432. }
  3433. return $this->handleResponseWithDataType(
  3434. '\WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response',
  3435. $request,
  3436. $response,
  3437. );
  3438. } catch (ApiException $e) {
  3439. switch ($e->getCode()) {
  3440. case 200:
  3441. $data = ObjectSerializer::deserialize(
  3442. $e->getResponseBody(),
  3443. '\WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response',
  3444. $e->getResponseHeaders()
  3445. );
  3446. $e->setResponseObject($data);
  3447. throw $e;
  3448. case 401:
  3449. $data = ObjectSerializer::deserialize(
  3450. $e->getResponseBody(),
  3451. '\WikipaliApi\Model\ProblemDetails',
  3452. $e->getResponseHeaders()
  3453. );
  3454. $e->setResponseObject($data);
  3455. throw $e;
  3456. case 403:
  3457. $data = ObjectSerializer::deserialize(
  3458. $e->getResponseBody(),
  3459. '\WikipaliApi\Model\ProblemDetails',
  3460. $e->getResponseHeaders()
  3461. );
  3462. $e->setResponseObject($data);
  3463. throw $e;
  3464. case 422:
  3465. $data = ObjectSerializer::deserialize(
  3466. $e->getResponseBody(),
  3467. '\WikipaliApi\Model\ProblemDetails',
  3468. $e->getResponseHeaders()
  3469. );
  3470. $e->setResponseObject($data);
  3471. throw $e;
  3472. }
  3473. throw $e;
  3474. }
  3475. }
  3476. /**
  3477. * Operation postApiV3ChannelsChannelTermsImportsAsync
  3478. *
  3479. * 向 channel 导入术语
  3480. *
  3481. * @param string $channel channel uid (required)
  3482. * @param \SplFileObject $file xlsx 表格,不超过 5MB (required)
  3483. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsChannelTermsImports'] to see the possible values for this operation
  3484. *
  3485. * @throws \InvalidArgumentException
  3486. * @return \GuzzleHttp\Promise\PromiseInterface
  3487. */
  3488. public function postApiV3ChannelsChannelTermsImportsAsync($channel, $file, string $contentType = self::contentTypes['postApiV3ChannelsChannelTermsImports'][0])
  3489. {
  3490. return $this->postApiV3ChannelsChannelTermsImportsAsyncWithHttpInfo($channel, $file, $contentType)
  3491. ->then(
  3492. function ($response) {
  3493. return $response[0];
  3494. }
  3495. );
  3496. }
  3497. /**
  3498. * Operation postApiV3ChannelsChannelTermsImportsAsyncWithHttpInfo
  3499. *
  3500. * 向 channel 导入术语
  3501. *
  3502. * @param string $channel channel uid (required)
  3503. * @param \SplFileObject $file xlsx 表格,不超过 5MB (required)
  3504. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsChannelTermsImports'] to see the possible values for this operation
  3505. *
  3506. * @throws \InvalidArgumentException
  3507. * @return \GuzzleHttp\Promise\PromiseInterface
  3508. */
  3509. public function postApiV3ChannelsChannelTermsImportsAsyncWithHttpInfo($channel, $file, string $contentType = self::contentTypes['postApiV3ChannelsChannelTermsImports'][0])
  3510. {
  3511. $returnType = '\WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response';
  3512. $request = $this->postApiV3ChannelsChannelTermsImportsRequest($channel, $file, $contentType);
  3513. return $this->client
  3514. ->sendAsync($request, $this->createHttpClientOption())
  3515. ->then(
  3516. function ($response) use ($returnType) {
  3517. if ($returnType === '\SplFileObject') {
  3518. $content = $response->getBody(); //stream goes to serializer
  3519. } else {
  3520. $content = (string) $response->getBody();
  3521. if ($returnType !== 'string') {
  3522. $content = json_decode($content);
  3523. }
  3524. }
  3525. return [
  3526. ObjectSerializer::deserialize($content, $returnType, []),
  3527. $response->getStatusCode(),
  3528. $response->getHeaders()
  3529. ];
  3530. },
  3531. function ($exception) {
  3532. $response = $exception->getResponse();
  3533. $statusCode = $response->getStatusCode();
  3534. throw new ApiException(
  3535. sprintf(
  3536. '[%d] Error connecting to the API (%s)',
  3537. $statusCode,
  3538. $exception->getRequest()->getUri()
  3539. ),
  3540. $statusCode,
  3541. $response->getHeaders(),
  3542. (string) $response->getBody()
  3543. );
  3544. }
  3545. );
  3546. }
  3547. /**
  3548. * Create request for operation 'postApiV3ChannelsChannelTermsImports'
  3549. *
  3550. * @param string $channel channel uid (required)
  3551. * @param \SplFileObject $file xlsx 表格,不超过 5MB (required)
  3552. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3ChannelsChannelTermsImports'] to see the possible values for this operation
  3553. *
  3554. * @throws \InvalidArgumentException
  3555. * @return \GuzzleHttp\Psr7\Request
  3556. */
  3557. public function postApiV3ChannelsChannelTermsImportsRequest($channel, $file, string $contentType = self::contentTypes['postApiV3ChannelsChannelTermsImports'][0])
  3558. {
  3559. // verify the required parameter 'channel' is set
  3560. if ($channel === null || (is_array($channel) && count($channel) === 0)) {
  3561. throw new \InvalidArgumentException(
  3562. 'Missing the required parameter $channel when calling postApiV3ChannelsChannelTermsImports'
  3563. );
  3564. }
  3565. // verify the required parameter 'file' is set
  3566. if ($file === null || (is_array($file) && count($file) === 0)) {
  3567. throw new \InvalidArgumentException(
  3568. 'Missing the required parameter $file when calling postApiV3ChannelsChannelTermsImports'
  3569. );
  3570. }
  3571. $resourcePath = '/v3/channels/{channel}/terms/imports';
  3572. $formParams = [];
  3573. $queryParams = [];
  3574. $headerParams = [];
  3575. $httpBody = '';
  3576. $multipart = false;
  3577. // path params
  3578. if ($channel !== null) {
  3579. $resourcePath = str_replace(
  3580. '{channel}',
  3581. ObjectSerializer::toPathValue($channel),
  3582. $resourcePath
  3583. );
  3584. }
  3585. // form params
  3586. $formDataProcessor = new FormDataProcessor();
  3587. $formData = $formDataProcessor->prepare([
  3588. 'file' => $file,
  3589. ]);
  3590. $formParams = $formDataProcessor->flatten($formData);
  3591. $multipart = $formDataProcessor->has_file;
  3592. $multipart = true;
  3593. $headers = $this->headerSelector->selectHeaders(
  3594. ['application/json', 'application/problem+json', ],
  3595. $contentType,
  3596. $multipart
  3597. );
  3598. // for model (json/xml)
  3599. if (count($formParams) > 0) {
  3600. if ($multipart) {
  3601. $multipartContents = [];
  3602. foreach ($formParams as $formParamName => $formParamValue) {
  3603. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  3604. foreach ($formParamValueItems as $formParamValueItem) {
  3605. $multipartContents[] = [
  3606. 'name' => $formParamName,
  3607. 'contents' => $formParamValueItem
  3608. ];
  3609. }
  3610. }
  3611. // for HTTP post (form)
  3612. $httpBody = new MultipartStream($multipartContents);
  3613. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  3614. # if Content-Type contains "application/json", json_encode the form parameters
  3615. try {
  3616. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  3617. } catch (\JsonException $e) {
  3618. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  3619. }
  3620. } else {
  3621. // for HTTP post (form)
  3622. $httpBody = ObjectSerializer::buildQuery($formParams);
  3623. }
  3624. }
  3625. // this endpoint requires Bearer authentication (access token)
  3626. if (!empty($this->config->getAccessToken())) {
  3627. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  3628. }
  3629. $defaultHeaders = [];
  3630. if ($this->config->getUserAgent()) {
  3631. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  3632. }
  3633. $headers = array_merge(
  3634. $defaultHeaders,
  3635. $headerParams,
  3636. $headers
  3637. );
  3638. $operationHost = $this->config->getHost();
  3639. $query = ObjectSerializer::buildQuery($queryParams);
  3640. return new Request(
  3641. 'POST',
  3642. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  3643. $headers,
  3644. $httpBody
  3645. );
  3646. }
  3647. /**
  3648. * Create http client option
  3649. *
  3650. * @throws \RuntimeException on file opening failure
  3651. * @return array of http client options
  3652. */
  3653. protected function createHttpClientOption()
  3654. {
  3655. $options = [];
  3656. if ($this->config->getDebug()) {
  3657. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  3658. if (!$options[RequestOptions::DEBUG]) {
  3659. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  3660. }
  3661. }
  3662. if ($this->config->getCertFile()) {
  3663. $options[RequestOptions::CERT] = $this->config->getCertFile();
  3664. }
  3665. if ($this->config->getKeyFile()) {
  3666. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  3667. }
  3668. return $options;
  3669. }
  3670. private function handleResponseWithDataType(
  3671. string $dataType,
  3672. RequestInterface $request,
  3673. ResponseInterface $response
  3674. ): array {
  3675. if ($dataType === '\SplFileObject') {
  3676. $content = $response->getBody(); //stream goes to serializer
  3677. } else {
  3678. $content = (string) $response->getBody();
  3679. if ($dataType !== 'string') {
  3680. try {
  3681. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  3682. } catch (\JsonException $exception) {
  3683. throw new ApiException(
  3684. sprintf(
  3685. 'Error JSON decoding server response (%s)',
  3686. $request->getUri()
  3687. ),
  3688. $response->getStatusCode(),
  3689. $response->getHeaders(),
  3690. $content
  3691. );
  3692. }
  3693. }
  3694. }
  3695. return [
  3696. ObjectSerializer::deserialize($content, $dataType, []),
  3697. $response->getStatusCode(),
  3698. $response->getHeaders()
  3699. ];
  3700. }
  3701. private function responseWithinRangeCode(
  3702. string $rangeCode,
  3703. int $statusCode
  3704. ): bool {
  3705. $left = (int) ($rangeCode[0].'00');
  3706. $right = (int) ($rangeCode[0].'99');
  3707. return $statusCode >= $left && $statusCode <= $right;
  3708. }
  3709. }