DiscussionsApi.php 118 KB

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