[ 'application/json', ], 'getApiV3Discussions' => [ 'application/json', ], 'getApiV3DiscussionsDiscussion' => [ 'application/json', ], 'getApiV3DiscussionsDiscussionReplies' => [ 'application/json', ], 'getApiV3DiscussionsSummary' => [ 'application/json', ], 'patchApiV3DiscussionsDiscussion' => [ 'application/json', ], 'postApiV3Discussions' => [ 'application/json', ], 'postApiV3DiscussionsBatchCount' => [ 'application/json', ], 'postApiV3DiscussionsDiscussionReplies' => [ 'application/json', ], ]; /** * @param ClientInterface $client * @param Configuration $config * @param HeaderSelector $selector * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec */ public function __construct( ?ClientInterface $client = null, ?Configuration $config = null, ?HeaderSelector $selector = null, int $hostIndex = 0 ) { $this->client = $client ?: new Client(); $this->config = $config ?: Configuration::getDefaultConfiguration(); $this->headerSelector = $selector ?: new HeaderSelector(); $this->hostIndex = $hostIndex; } /** * Set the host index * * @param int $hostIndex Host index (required) */ public function setHostIndex($hostIndex): void { $this->hostIndex = $hostIndex; } /** * Get the host index * * @return int Host index */ public function getHostIndex() { return $this->hostIndex; } /** * @return Configuration */ public function getConfig() { return $this->config; } /** * Operation deleteApiV3DiscussionsDiscussion * * 删除话题或回复(软删除) * * @param string $discussion 话题或回复的 uuid (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \WikipaliApi\Model\PostApiV3Discussions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails */ public function deleteApiV3DiscussionsDiscussion($discussion, string $contentType = self::contentTypes['deleteApiV3DiscussionsDiscussion'][0]) { list($response) = $this->deleteApiV3DiscussionsDiscussionWithHttpInfo($discussion, $contentType); return $response; } /** * Operation deleteApiV3DiscussionsDiscussionWithHttpInfo * * 删除话题或回复(软删除) * * @param string $discussion 话题或回复的 uuid (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \WikipaliApi\Model\PostApiV3Discussions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings) */ public function deleteApiV3DiscussionsDiscussionWithHttpInfo($discussion, string $contentType = self::contentTypes['deleteApiV3DiscussionsDiscussion'][0]) { $request = $this->deleteApiV3DiscussionsDiscussionRequest($discussion, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3Discussions200Response', $request, $response, ); case 401: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); case 403: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); case 422: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3Discussions200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\PostApiV3Discussions200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 401: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 403: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 422: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation deleteApiV3DiscussionsDiscussionAsync * * 删除话题或回复(软删除) * * @param string $discussion 话题或回复的 uuid (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function deleteApiV3DiscussionsDiscussionAsync($discussion, string $contentType = self::contentTypes['deleteApiV3DiscussionsDiscussion'][0]) { return $this->deleteApiV3DiscussionsDiscussionAsyncWithHttpInfo($discussion, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation deleteApiV3DiscussionsDiscussionAsyncWithHttpInfo * * 删除话题或回复(软删除) * * @param string $discussion 话题或回复的 uuid (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function deleteApiV3DiscussionsDiscussionAsyncWithHttpInfo($discussion, string $contentType = self::contentTypes['deleteApiV3DiscussionsDiscussion'][0]) { $returnType = '\WikipaliApi\Model\PostApiV3Discussions200Response'; $request = $this->deleteApiV3DiscussionsDiscussionRequest($discussion, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'deleteApiV3DiscussionsDiscussion' * * @param string $discussion 话题或回复的 uuid (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function deleteApiV3DiscussionsDiscussionRequest($discussion, string $contentType = self::contentTypes['deleteApiV3DiscussionsDiscussion'][0]) { // verify the required parameter 'discussion' is set if ($discussion === null || (is_array($discussion) && count($discussion) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $discussion when calling deleteApiV3DiscussionsDiscussion' ); } $resourcePath = '/v3/discussions/{discussion}'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($discussion !== null) { $resourcePath = str_replace( '{discussion}', ObjectSerializer::toPathValue($discussion), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', 'application/problem+json', ], $contentType, $multipart ); // for model (json/xml) if (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters try { $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires Bearer authentication (access token) if (!empty($this->config->getAccessToken())) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'DELETE', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation getApiV3Discussions * * 列出某个对象上的话题 * * @param string $target_type 挂靠对象的类型 (required) * @param string $target_id 挂靠对象的 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 15) * @param string|null $type 类型,不传则只列评论线程 (optional) * @param string|null $status 话题状态,不传则两种都要 (optional) * @param string|null $severity 严重程度,逗号分隔多选 (optional) * @param string|null $sort 排序,前缀 - 表示倒序 (optional, default to '-created_at') * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Discussions'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \WikipaliApi\Model\GetApiV3Discussions200Response|\WikipaliApi\Model\ProblemDetails */ 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]) { list($response) = $this->getApiV3DiscussionsWithHttpInfo($target_type, $target_id, $per_page, $type, $status, $severity, $sort, $page, $contentType); return $response; } /** * Operation getApiV3DiscussionsWithHttpInfo * * 列出某个对象上的话题 * * @param string $target_type 挂靠对象的类型 (required) * @param string $target_id 挂靠对象的 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 15) * @param string|null $type 类型,不传则只列评论线程 (optional) * @param string|null $status 话题状态,不传则两种都要 (optional) * @param string|null $severity 严重程度,逗号分隔多选 (optional) * @param string|null $sort 排序,前缀 - 表示倒序 (optional, default to '-created_at') * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Discussions'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \WikipaliApi\Model\GetApiV3Discussions200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings) */ 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]) { $request = $this->getApiV3DiscussionsRequest($target_type, $target_id, $per_page, $type, $status, $severity, $sort, $page, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\WikipaliApi\Model\GetApiV3Discussions200Response', $request, $response, ); case 422: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\WikipaliApi\Model\GetApiV3Discussions200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\GetApiV3Discussions200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 422: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation getApiV3DiscussionsAsync * * 列出某个对象上的话题 * * @param string $target_type 挂靠对象的类型 (required) * @param string $target_id 挂靠对象的 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 15) * @param string|null $type 类型,不传则只列评论线程 (optional) * @param string|null $status 话题状态,不传则两种都要 (optional) * @param string|null $severity 严重程度,逗号分隔多选 (optional) * @param string|null $sort 排序,前缀 - 表示倒序 (optional, default to '-created_at') * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Discussions'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ 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]) { return $this->getApiV3DiscussionsAsyncWithHttpInfo($target_type, $target_id, $per_page, $type, $status, $severity, $sort, $page, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation getApiV3DiscussionsAsyncWithHttpInfo * * 列出某个对象上的话题 * * @param string $target_type 挂靠对象的类型 (required) * @param string $target_id 挂靠对象的 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 15) * @param string|null $type 类型,不传则只列评论线程 (optional) * @param string|null $status 话题状态,不传则两种都要 (optional) * @param string|null $severity 严重程度,逗号分隔多选 (optional) * @param string|null $sort 排序,前缀 - 表示倒序 (optional, default to '-created_at') * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Discussions'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ 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]) { $returnType = '\WikipaliApi\Model\GetApiV3Discussions200Response'; $request = $this->getApiV3DiscussionsRequest($target_type, $target_id, $per_page, $type, $status, $severity, $sort, $page, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'getApiV3Discussions' * * @param string $target_type 挂靠对象的类型 (required) * @param string $target_id 挂靠对象的 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 15) * @param string|null $type 类型,不传则只列评论线程 (optional) * @param string|null $status 话题状态,不传则两种都要 (optional) * @param string|null $severity 严重程度,逗号分隔多选 (optional) * @param string|null $sort 排序,前缀 - 表示倒序 (optional, default to '-created_at') * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Discussions'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ 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]) { // verify the required parameter 'target_type' is set if ($target_type === null || (is_array($target_type) && count($target_type) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $target_type when calling getApiV3Discussions' ); } // verify the required parameter 'target_id' is set if ($target_id === null || (is_array($target_id) && count($target_id) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $target_id when calling getApiV3Discussions' ); } $resourcePath = '/v3/discussions'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $per_page, 'per_page', // param base name 'integer', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $target_type, 'target_type', // param base name 'string', // openApiType 'form', // style true, // explode true // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $target_id, 'target_id', // param base name 'string', // openApiType 'form', // style true, // explode true // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $type, 'type', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $status, 'status', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $severity, 'severity', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $sort, 'sort', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $page, 'page', // param base name 'integer', // openApiType 'form', // style true, // explode false // required ) ?? []); $headers = $this->headerSelector->selectHeaders( ['application/json', 'application/problem+json', ], $contentType, $multipart ); // for model (json/xml) if (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters try { $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires Bearer authentication (access token) if (!empty($this->config->getAccessToken())) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'GET', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation getApiV3DiscussionsDiscussion * * 获取单条话题或回复 * * @param string $discussion 话题或回复的 uuid (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \WikipaliApi\Model\PostApiV3Discussions200Response|\WikipaliApi\Model\ProblemDetails */ public function getApiV3DiscussionsDiscussion($discussion, string $contentType = self::contentTypes['getApiV3DiscussionsDiscussion'][0]) { list($response) = $this->getApiV3DiscussionsDiscussionWithHttpInfo($discussion, $contentType); return $response; } /** * Operation getApiV3DiscussionsDiscussionWithHttpInfo * * 获取单条话题或回复 * * @param string $discussion 话题或回复的 uuid (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \WikipaliApi\Model\PostApiV3Discussions200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings) */ public function getApiV3DiscussionsDiscussionWithHttpInfo($discussion, string $contentType = self::contentTypes['getApiV3DiscussionsDiscussion'][0]) { $request = $this->getApiV3DiscussionsDiscussionRequest($discussion, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3Discussions200Response', $request, $response, ); case 422: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3Discussions200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\PostApiV3Discussions200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 422: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation getApiV3DiscussionsDiscussionAsync * * 获取单条话题或回复 * * @param string $discussion 话题或回复的 uuid (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getApiV3DiscussionsDiscussionAsync($discussion, string $contentType = self::contentTypes['getApiV3DiscussionsDiscussion'][0]) { return $this->getApiV3DiscussionsDiscussionAsyncWithHttpInfo($discussion, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation getApiV3DiscussionsDiscussionAsyncWithHttpInfo * * 获取单条话题或回复 * * @param string $discussion 话题或回复的 uuid (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getApiV3DiscussionsDiscussionAsyncWithHttpInfo($discussion, string $contentType = self::contentTypes['getApiV3DiscussionsDiscussion'][0]) { $returnType = '\WikipaliApi\Model\PostApiV3Discussions200Response'; $request = $this->getApiV3DiscussionsDiscussionRequest($discussion, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'getApiV3DiscussionsDiscussion' * * @param string $discussion 话题或回复的 uuid (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function getApiV3DiscussionsDiscussionRequest($discussion, string $contentType = self::contentTypes['getApiV3DiscussionsDiscussion'][0]) { // verify the required parameter 'discussion' is set if ($discussion === null || (is_array($discussion) && count($discussion) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $discussion when calling getApiV3DiscussionsDiscussion' ); } $resourcePath = '/v3/discussions/{discussion}'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($discussion !== null) { $resourcePath = str_replace( '{discussion}', ObjectSerializer::toPathValue($discussion), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', 'application/problem+json', ], $contentType, $multipart ); // for model (json/xml) if (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters try { $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires Bearer authentication (access token) if (!empty($this->config->getAccessToken())) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'GET', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation getApiV3DiscussionsDiscussionReplies * * 列出话题的回复 * * @param string $discussion 话题的 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 50) * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsDiscussionReplies'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \WikipaliApi\Model\GetApiV3Discussions200Response|\WikipaliApi\Model\ProblemDetails */ public function getApiV3DiscussionsDiscussionReplies($discussion, $per_page = 50, $page = 1, string $contentType = self::contentTypes['getApiV3DiscussionsDiscussionReplies'][0]) { list($response) = $this->getApiV3DiscussionsDiscussionRepliesWithHttpInfo($discussion, $per_page, $page, $contentType); return $response; } /** * Operation getApiV3DiscussionsDiscussionRepliesWithHttpInfo * * 列出话题的回复 * * @param string $discussion 话题的 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 50) * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsDiscussionReplies'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \WikipaliApi\Model\GetApiV3Discussions200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings) */ public function getApiV3DiscussionsDiscussionRepliesWithHttpInfo($discussion, $per_page = 50, $page = 1, string $contentType = self::contentTypes['getApiV3DiscussionsDiscussionReplies'][0]) { $request = $this->getApiV3DiscussionsDiscussionRepliesRequest($discussion, $per_page, $page, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\WikipaliApi\Model\GetApiV3Discussions200Response', $request, $response, ); case 422: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\WikipaliApi\Model\GetApiV3Discussions200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\GetApiV3Discussions200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 422: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation getApiV3DiscussionsDiscussionRepliesAsync * * 列出话题的回复 * * @param string $discussion 话题的 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 50) * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsDiscussionReplies'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getApiV3DiscussionsDiscussionRepliesAsync($discussion, $per_page = 50, $page = 1, string $contentType = self::contentTypes['getApiV3DiscussionsDiscussionReplies'][0]) { return $this->getApiV3DiscussionsDiscussionRepliesAsyncWithHttpInfo($discussion, $per_page, $page, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation getApiV3DiscussionsDiscussionRepliesAsyncWithHttpInfo * * 列出话题的回复 * * @param string $discussion 话题的 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 50) * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsDiscussionReplies'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getApiV3DiscussionsDiscussionRepliesAsyncWithHttpInfo($discussion, $per_page = 50, $page = 1, string $contentType = self::contentTypes['getApiV3DiscussionsDiscussionReplies'][0]) { $returnType = '\WikipaliApi\Model\GetApiV3Discussions200Response'; $request = $this->getApiV3DiscussionsDiscussionRepliesRequest($discussion, $per_page, $page, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'getApiV3DiscussionsDiscussionReplies' * * @param string $discussion 话题的 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 50) * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsDiscussionReplies'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function getApiV3DiscussionsDiscussionRepliesRequest($discussion, $per_page = 50, $page = 1, string $contentType = self::contentTypes['getApiV3DiscussionsDiscussionReplies'][0]) { // verify the required parameter 'discussion' is set if ($discussion === null || (is_array($discussion) && count($discussion) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $discussion when calling getApiV3DiscussionsDiscussionReplies' ); } $resourcePath = '/v3/discussions/{discussion}/replies'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $per_page, 'per_page', // param base name 'integer', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $page, 'page', // param base name 'integer', // openApiType 'form', // style true, // explode false // required ) ?? []); // path params if ($discussion !== null) { $resourcePath = str_replace( '{discussion}', ObjectSerializer::toPathValue($discussion), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', 'application/problem+json', ], $contentType, $multipart ); // for model (json/xml) if (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters try { $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires Bearer authentication (access token) if (!empty($this->config->getAccessToken())) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'GET', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation getApiV3DiscussionsSummary * * 话题概况 * * @param string $target_type 挂靠对象的类型 (required) * @param string $target_id 挂靠对象的 uuid (required) * @param string|null $type 只数这种类型,不传则只数评论线程 (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsSummary'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \WikipaliApi\Model\GetApiV3DiscussionsSummary200Response|\WikipaliApi\Model\ProblemDetails */ public function getApiV3DiscussionsSummary($target_type, $target_id, $type = null, string $contentType = self::contentTypes['getApiV3DiscussionsSummary'][0]) { list($response) = $this->getApiV3DiscussionsSummaryWithHttpInfo($target_type, $target_id, $type, $contentType); return $response; } /** * Operation getApiV3DiscussionsSummaryWithHttpInfo * * 话题概况 * * @param string $target_type 挂靠对象的类型 (required) * @param string $target_id 挂靠对象的 uuid (required) * @param string|null $type 只数这种类型,不传则只数评论线程 (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsSummary'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \WikipaliApi\Model\GetApiV3DiscussionsSummary200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings) */ public function getApiV3DiscussionsSummaryWithHttpInfo($target_type, $target_id, $type = null, string $contentType = self::contentTypes['getApiV3DiscussionsSummary'][0]) { $request = $this->getApiV3DiscussionsSummaryRequest($target_type, $target_id, $type, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\WikipaliApi\Model\GetApiV3DiscussionsSummary200Response', $request, $response, ); case 422: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\WikipaliApi\Model\GetApiV3DiscussionsSummary200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\GetApiV3DiscussionsSummary200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 422: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation getApiV3DiscussionsSummaryAsync * * 话题概况 * * @param string $target_type 挂靠对象的类型 (required) * @param string $target_id 挂靠对象的 uuid (required) * @param string|null $type 只数这种类型,不传则只数评论线程 (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsSummary'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getApiV3DiscussionsSummaryAsync($target_type, $target_id, $type = null, string $contentType = self::contentTypes['getApiV3DiscussionsSummary'][0]) { return $this->getApiV3DiscussionsSummaryAsyncWithHttpInfo($target_type, $target_id, $type, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation getApiV3DiscussionsSummaryAsyncWithHttpInfo * * 话题概况 * * @param string $target_type 挂靠对象的类型 (required) * @param string $target_id 挂靠对象的 uuid (required) * @param string|null $type 只数这种类型,不传则只数评论线程 (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsSummary'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getApiV3DiscussionsSummaryAsyncWithHttpInfo($target_type, $target_id, $type = null, string $contentType = self::contentTypes['getApiV3DiscussionsSummary'][0]) { $returnType = '\WikipaliApi\Model\GetApiV3DiscussionsSummary200Response'; $request = $this->getApiV3DiscussionsSummaryRequest($target_type, $target_id, $type, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'getApiV3DiscussionsSummary' * * @param string $target_type 挂靠对象的类型 (required) * @param string $target_id 挂靠对象的 uuid (required) * @param string|null $type 只数这种类型,不传则只数评论线程 (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3DiscussionsSummary'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function getApiV3DiscussionsSummaryRequest($target_type, $target_id, $type = null, string $contentType = self::contentTypes['getApiV3DiscussionsSummary'][0]) { // verify the required parameter 'target_type' is set if ($target_type === null || (is_array($target_type) && count($target_type) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $target_type when calling getApiV3DiscussionsSummary' ); } // verify the required parameter 'target_id' is set if ($target_id === null || (is_array($target_id) && count($target_id) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $target_id when calling getApiV3DiscussionsSummary' ); } $resourcePath = '/v3/discussions/summary'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $target_type, 'target_type', // param base name 'string', // openApiType 'form', // style true, // explode true // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $target_id, 'target_id', // param base name 'string', // openApiType 'form', // style true, // explode true // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $type, 'type', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); $headers = $this->headerSelector->selectHeaders( ['application/json', 'application/problem+json', ], $contentType, $multipart ); // for model (json/xml) if (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters try { $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires Bearer authentication (access token) if (!empty($this->config->getAccessToken())) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'GET', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation patchApiV3DiscussionsDiscussion * * 修改话题或回复(局部更新) * * @param string $discussion 话题或回复的 uuid (required) * @param \WikipaliApi\Model\PatchApiV3DiscussionsDiscussionRequest|null $patch_api_v3_discussions_discussion_request patch_api_v3_discussions_discussion_request (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \WikipaliApi\Model\PostApiV3Discussions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails */ public function patchApiV3DiscussionsDiscussion($discussion, $patch_api_v3_discussions_discussion_request = null, string $contentType = self::contentTypes['patchApiV3DiscussionsDiscussion'][0]) { list($response) = $this->patchApiV3DiscussionsDiscussionWithHttpInfo($discussion, $patch_api_v3_discussions_discussion_request, $contentType); return $response; } /** * Operation patchApiV3DiscussionsDiscussionWithHttpInfo * * 修改话题或回复(局部更新) * * @param string $discussion 话题或回复的 uuid (required) * @param \WikipaliApi\Model\PatchApiV3DiscussionsDiscussionRequest|null $patch_api_v3_discussions_discussion_request (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \WikipaliApi\Model\PostApiV3Discussions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings) */ public function patchApiV3DiscussionsDiscussionWithHttpInfo($discussion, $patch_api_v3_discussions_discussion_request = null, string $contentType = self::contentTypes['patchApiV3DiscussionsDiscussion'][0]) { $request = $this->patchApiV3DiscussionsDiscussionRequest($discussion, $patch_api_v3_discussions_discussion_request, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3Discussions200Response', $request, $response, ); case 401: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); case 403: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); case 422: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3Discussions200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\PostApiV3Discussions200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 401: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 403: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 422: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation patchApiV3DiscussionsDiscussionAsync * * 修改话题或回复(局部更新) * * @param string $discussion 话题或回复的 uuid (required) * @param \WikipaliApi\Model\PatchApiV3DiscussionsDiscussionRequest|null $patch_api_v3_discussions_discussion_request (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function patchApiV3DiscussionsDiscussionAsync($discussion, $patch_api_v3_discussions_discussion_request = null, string $contentType = self::contentTypes['patchApiV3DiscussionsDiscussion'][0]) { return $this->patchApiV3DiscussionsDiscussionAsyncWithHttpInfo($discussion, $patch_api_v3_discussions_discussion_request, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation patchApiV3DiscussionsDiscussionAsyncWithHttpInfo * * 修改话题或回复(局部更新) * * @param string $discussion 话题或回复的 uuid (required) * @param \WikipaliApi\Model\PatchApiV3DiscussionsDiscussionRequest|null $patch_api_v3_discussions_discussion_request (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function patchApiV3DiscussionsDiscussionAsyncWithHttpInfo($discussion, $patch_api_v3_discussions_discussion_request = null, string $contentType = self::contentTypes['patchApiV3DiscussionsDiscussion'][0]) { $returnType = '\WikipaliApi\Model\PostApiV3Discussions200Response'; $request = $this->patchApiV3DiscussionsDiscussionRequest($discussion, $patch_api_v3_discussions_discussion_request, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'patchApiV3DiscussionsDiscussion' * * @param string $discussion 话题或回复的 uuid (required) * @param \WikipaliApi\Model\PatchApiV3DiscussionsDiscussionRequest|null $patch_api_v3_discussions_discussion_request (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3DiscussionsDiscussion'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function patchApiV3DiscussionsDiscussionRequest($discussion, $patch_api_v3_discussions_discussion_request = null, string $contentType = self::contentTypes['patchApiV3DiscussionsDiscussion'][0]) { // verify the required parameter 'discussion' is set if ($discussion === null || (is_array($discussion) && count($discussion) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $discussion when calling patchApiV3DiscussionsDiscussion' ); } $resourcePath = '/v3/discussions/{discussion}'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($discussion !== null) { $resourcePath = str_replace( '{discussion}', ObjectSerializer::toPathValue($discussion), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', 'application/problem+json', ], $contentType, $multipart ); // for model (json/xml) if (isset($patch_api_v3_discussions_discussion_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body try { $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($patch_api_v3_discussions_discussion_request), JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { $httpBody = $patch_api_v3_discussions_discussion_request; } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters try { $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires Bearer authentication (access token) if (!empty($this->config->getAccessToken())) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'PATCH', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation postApiV3Discussions * * 发起话题或新建批注 * * @param \WikipaliApi\Model\PostApiV3DiscussionsRequest $post_api_v3_discussions_request post_api_v3_discussions_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Discussions'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \WikipaliApi\Model\PostApiV3Discussions200Response|\WikipaliApi\Model\PostApiV3Discussions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails */ public function postApiV3Discussions($post_api_v3_discussions_request, string $contentType = self::contentTypes['postApiV3Discussions'][0]) { list($response) = $this->postApiV3DiscussionsWithHttpInfo($post_api_v3_discussions_request, $contentType); return $response; } /** * Operation postApiV3DiscussionsWithHttpInfo * * 发起话题或新建批注 * * @param \WikipaliApi\Model\PostApiV3DiscussionsRequest $post_api_v3_discussions_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Discussions'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @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) */ public function postApiV3DiscussionsWithHttpInfo($post_api_v3_discussions_request, string $contentType = self::contentTypes['postApiV3Discussions'][0]) { $request = $this->postApiV3DiscussionsRequest($post_api_v3_discussions_request, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3Discussions200Response', $request, $response, ); case 201: return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3Discussions200Response', $request, $response, ); case 401: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); case 403: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); case 422: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3Discussions200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\PostApiV3Discussions200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 201: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\PostApiV3Discussions200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 401: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 403: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 422: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation postApiV3DiscussionsAsync * * 发起话题或新建批注 * * @param \WikipaliApi\Model\PostApiV3DiscussionsRequest $post_api_v3_discussions_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Discussions'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function postApiV3DiscussionsAsync($post_api_v3_discussions_request, string $contentType = self::contentTypes['postApiV3Discussions'][0]) { return $this->postApiV3DiscussionsAsyncWithHttpInfo($post_api_v3_discussions_request, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation postApiV3DiscussionsAsyncWithHttpInfo * * 发起话题或新建批注 * * @param \WikipaliApi\Model\PostApiV3DiscussionsRequest $post_api_v3_discussions_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Discussions'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function postApiV3DiscussionsAsyncWithHttpInfo($post_api_v3_discussions_request, string $contentType = self::contentTypes['postApiV3Discussions'][0]) { $returnType = '\WikipaliApi\Model\PostApiV3Discussions200Response'; $request = $this->postApiV3DiscussionsRequest($post_api_v3_discussions_request, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'postApiV3Discussions' * * @param \WikipaliApi\Model\PostApiV3DiscussionsRequest $post_api_v3_discussions_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3Discussions'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function postApiV3DiscussionsRequest($post_api_v3_discussions_request, string $contentType = self::contentTypes['postApiV3Discussions'][0]) { // verify the required parameter 'post_api_v3_discussions_request' is set if ($post_api_v3_discussions_request === null || (is_array($post_api_v3_discussions_request) && count($post_api_v3_discussions_request) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $post_api_v3_discussions_request when calling postApiV3Discussions' ); } $resourcePath = '/v3/discussions'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; $headers = $this->headerSelector->selectHeaders( ['application/json', 'application/problem+json', ], $contentType, $multipart ); // for model (json/xml) if (isset($post_api_v3_discussions_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body try { $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_discussions_request), JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { $httpBody = $post_api_v3_discussions_request; } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters try { $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires Bearer authentication (access token) if (!empty($this->config->getAccessToken())) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'POST', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation postApiV3DiscussionsBatchCount * * 批量取讨论角标 * * @param \WikipaliApi\Model\PostApiV3DiscussionsBatchCountRequest $post_api_v3_discussions_batch_count_request post_api_v3_discussions_batch_count_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3DiscussionsBatchCount'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \WikipaliApi\Model\PostApiV3DiscussionsBatchCount200Response|\WikipaliApi\Model\ProblemDetails */ public function postApiV3DiscussionsBatchCount($post_api_v3_discussions_batch_count_request, string $contentType = self::contentTypes['postApiV3DiscussionsBatchCount'][0]) { list($response) = $this->postApiV3DiscussionsBatchCountWithHttpInfo($post_api_v3_discussions_batch_count_request, $contentType); return $response; } /** * Operation postApiV3DiscussionsBatchCountWithHttpInfo * * 批量取讨论角标 * * @param \WikipaliApi\Model\PostApiV3DiscussionsBatchCountRequest $post_api_v3_discussions_batch_count_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3DiscussionsBatchCount'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \WikipaliApi\Model\PostApiV3DiscussionsBatchCount200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings) */ public function postApiV3DiscussionsBatchCountWithHttpInfo($post_api_v3_discussions_batch_count_request, string $contentType = self::contentTypes['postApiV3DiscussionsBatchCount'][0]) { $request = $this->postApiV3DiscussionsBatchCountRequest($post_api_v3_discussions_batch_count_request, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3DiscussionsBatchCount200Response', $request, $response, ); case 422: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3DiscussionsBatchCount200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\PostApiV3DiscussionsBatchCount200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 422: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation postApiV3DiscussionsBatchCountAsync * * 批量取讨论角标 * * @param \WikipaliApi\Model\PostApiV3DiscussionsBatchCountRequest $post_api_v3_discussions_batch_count_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3DiscussionsBatchCount'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function postApiV3DiscussionsBatchCountAsync($post_api_v3_discussions_batch_count_request, string $contentType = self::contentTypes['postApiV3DiscussionsBatchCount'][0]) { return $this->postApiV3DiscussionsBatchCountAsyncWithHttpInfo($post_api_v3_discussions_batch_count_request, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation postApiV3DiscussionsBatchCountAsyncWithHttpInfo * * 批量取讨论角标 * * @param \WikipaliApi\Model\PostApiV3DiscussionsBatchCountRequest $post_api_v3_discussions_batch_count_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3DiscussionsBatchCount'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function postApiV3DiscussionsBatchCountAsyncWithHttpInfo($post_api_v3_discussions_batch_count_request, string $contentType = self::contentTypes['postApiV3DiscussionsBatchCount'][0]) { $returnType = '\WikipaliApi\Model\PostApiV3DiscussionsBatchCount200Response'; $request = $this->postApiV3DiscussionsBatchCountRequest($post_api_v3_discussions_batch_count_request, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'postApiV3DiscussionsBatchCount' * * @param \WikipaliApi\Model\PostApiV3DiscussionsBatchCountRequest $post_api_v3_discussions_batch_count_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3DiscussionsBatchCount'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function postApiV3DiscussionsBatchCountRequest($post_api_v3_discussions_batch_count_request, string $contentType = self::contentTypes['postApiV3DiscussionsBatchCount'][0]) { // verify the required parameter 'post_api_v3_discussions_batch_count_request' is set if ($post_api_v3_discussions_batch_count_request === null || (is_array($post_api_v3_discussions_batch_count_request) && count($post_api_v3_discussions_batch_count_request) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $post_api_v3_discussions_batch_count_request when calling postApiV3DiscussionsBatchCount' ); } $resourcePath = '/v3/discussions/batch-count'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; $headers = $this->headerSelector->selectHeaders( ['application/json', 'application/problem+json', ], $contentType, $multipart ); // for model (json/xml) if (isset($post_api_v3_discussions_batch_count_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body try { $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_discussions_batch_count_request), JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { $httpBody = $post_api_v3_discussions_batch_count_request; } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters try { $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires Bearer authentication (access token) if (!empty($this->config->getAccessToken())) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'POST', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation postApiV3DiscussionsDiscussionReplies * * 回复话题 * * @param string $discussion 话题的 uuid (required) * @param \WikipaliApi\Model\PostApiV3DiscussionsDiscussionRepliesRequest $post_api_v3_discussions_discussion_replies_request post_api_v3_discussions_discussion_replies_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3DiscussionsDiscussionReplies'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \WikipaliApi\Model\PostApiV3Discussions200Response|\WikipaliApi\Model\PostApiV3Discussions200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails */ public function postApiV3DiscussionsDiscussionReplies($discussion, $post_api_v3_discussions_discussion_replies_request, string $contentType = self::contentTypes['postApiV3DiscussionsDiscussionReplies'][0]) { list($response) = $this->postApiV3DiscussionsDiscussionRepliesWithHttpInfo($discussion, $post_api_v3_discussions_discussion_replies_request, $contentType); return $response; } /** * Operation postApiV3DiscussionsDiscussionRepliesWithHttpInfo * * 回复话题 * * @param string $discussion 话题的 uuid (required) * @param \WikipaliApi\Model\PostApiV3DiscussionsDiscussionRepliesRequest $post_api_v3_discussions_discussion_replies_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3DiscussionsDiscussionReplies'] to see the possible values for this operation * * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @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) */ public function postApiV3DiscussionsDiscussionRepliesWithHttpInfo($discussion, $post_api_v3_discussions_discussion_replies_request, string $contentType = self::contentTypes['postApiV3DiscussionsDiscussionReplies'][0]) { $request = $this->postApiV3DiscussionsDiscussionRepliesRequest($discussion, $post_api_v3_discussions_discussion_replies_request, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3Discussions200Response', $request, $response, ); case 201: return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3Discussions200Response', $request, $response, ); case 401: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); case 403: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); case 409: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); case 422: return $this->handleResponseWithDataType( '\WikipaliApi\Model\ProblemDetails', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3Discussions200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\PostApiV3Discussions200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 201: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\PostApiV3Discussions200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 401: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 403: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 409: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 422: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\ProblemDetails', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation postApiV3DiscussionsDiscussionRepliesAsync * * 回复话题 * * @param string $discussion 话题的 uuid (required) * @param \WikipaliApi\Model\PostApiV3DiscussionsDiscussionRepliesRequest $post_api_v3_discussions_discussion_replies_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3DiscussionsDiscussionReplies'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function postApiV3DiscussionsDiscussionRepliesAsync($discussion, $post_api_v3_discussions_discussion_replies_request, string $contentType = self::contentTypes['postApiV3DiscussionsDiscussionReplies'][0]) { return $this->postApiV3DiscussionsDiscussionRepliesAsyncWithHttpInfo($discussion, $post_api_v3_discussions_discussion_replies_request, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation postApiV3DiscussionsDiscussionRepliesAsyncWithHttpInfo * * 回复话题 * * @param string $discussion 话题的 uuid (required) * @param \WikipaliApi\Model\PostApiV3DiscussionsDiscussionRepliesRequest $post_api_v3_discussions_discussion_replies_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3DiscussionsDiscussionReplies'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function postApiV3DiscussionsDiscussionRepliesAsyncWithHttpInfo($discussion, $post_api_v3_discussions_discussion_replies_request, string $contentType = self::contentTypes['postApiV3DiscussionsDiscussionReplies'][0]) { $returnType = '\WikipaliApi\Model\PostApiV3Discussions200Response'; $request = $this->postApiV3DiscussionsDiscussionRepliesRequest($discussion, $post_api_v3_discussions_discussion_replies_request, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'postApiV3DiscussionsDiscussionReplies' * * @param string $discussion 话题的 uuid (required) * @param \WikipaliApi\Model\PostApiV3DiscussionsDiscussionRepliesRequest $post_api_v3_discussions_discussion_replies_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3DiscussionsDiscussionReplies'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function postApiV3DiscussionsDiscussionRepliesRequest($discussion, $post_api_v3_discussions_discussion_replies_request, string $contentType = self::contentTypes['postApiV3DiscussionsDiscussionReplies'][0]) { // verify the required parameter 'discussion' is set if ($discussion === null || (is_array($discussion) && count($discussion) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $discussion when calling postApiV3DiscussionsDiscussionReplies' ); } // verify the required parameter 'post_api_v3_discussions_discussion_replies_request' is set 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)) { throw new \InvalidArgumentException( 'Missing the required parameter $post_api_v3_discussions_discussion_replies_request when calling postApiV3DiscussionsDiscussionReplies' ); } $resourcePath = '/v3/discussions/{discussion}/replies'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($discussion !== null) { $resourcePath = str_replace( '{discussion}', ObjectSerializer::toPathValue($discussion), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', 'application/problem+json', ], $contentType, $multipart ); // for model (json/xml) if (isset($post_api_v3_discussions_discussion_replies_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body try { $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($post_api_v3_discussions_discussion_replies_request), JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { $httpBody = $post_api_v3_discussions_discussion_replies_request; } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters try { $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires Bearer authentication (access token) if (!empty($this->config->getAccessToken())) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'POST', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Create http client option * * @throws \RuntimeException on file opening failure * @return array of http client options */ protected function createHttpClientOption() { $options = []; if ($this->config->getDebug()) { $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); if (!$options[RequestOptions::DEBUG]) { throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); } } if ($this->config->getCertFile()) { $options[RequestOptions::CERT] = $this->config->getCertFile(); } if ($this->config->getKeyFile()) { $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile(); } return $options; } private function handleResponseWithDataType( string $dataType, RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($dataType !== 'string') { try { $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $exception) { throw new ApiException( sprintf( 'Error JSON decoding server response (%s)', $request->getUri() ), $response->getStatusCode(), $response->getHeaders(), $content ); } } } return [ ObjectSerializer::deserialize($content, $dataType, []), $response->getStatusCode(), $response->getHeaders() ]; } private function responseWithinRangeCode( string $rangeCode, int $statusCode ): bool { $left = (int) ($rangeCode[0].'00'); $right = (int) ($rangeCode[0].'99'); return $statusCode >= $left && $statusCode <= $right; } }