DiscussionsApi.php 131 KB

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