[ 'application/json', ], 'getApiV3StudiosStudioTerms' => [ 'application/json', ], 'postApiV3StudiosStudioChannels' => [ 'application/json', ], 'postApiV3StudiosStudioTerms' => [ 'application/json', ], 'postApiV3StudiosStudioTermsImports' => [ 'multipart/form-data', ], ]; /** * @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 getApiV3StudiosStudioChannels * * 列出 studio 的 channel * * @param string $studio 用户 uuid 或团队 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 20) * @param string|null $relation 关系 (optional, default to 'own') * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional) * @param string|null $search 按名字模糊匹配 (optional) * @param string|null $type channel 类型 (optional) * @param string|null $lang 语言 (optional) * @param int|null $book 章节所在的书(与 para 同时给) (optional) * @param int|null $para 章节起始段(与 book 同时给) (optional) * @param string|null $order 排序字段 (optional, default to 'updated_at') * @param string|null $dir 排序方向 (optional, default to 'desc') * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] 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\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails */ public function getApiV3StudiosStudioChannels($studio, $per_page = 20, $relation = 'own', $collaborator = null, $search = null, $type = null, $lang = null, $book = null, $para = null, $order = 'updated_at', $dir = 'desc', $page = 1, string $contentType = self::contentTypes['getApiV3StudiosStudioChannels'][0]) { list($response) = $this->getApiV3StudiosStudioChannelsWithHttpInfo($studio, $per_page, $relation, $collaborator, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType); return $response; } /** * Operation getApiV3StudiosStudioChannelsWithHttpInfo * * 列出 studio 的 channel * * @param string $studio 用户 uuid 或团队 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 20) * @param string|null $relation 关系 (optional, default to 'own') * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional) * @param string|null $search 按名字模糊匹配 (optional) * @param string|null $type channel 类型 (optional) * @param string|null $lang 语言 (optional) * @param int|null $book 章节所在的书(与 para 同时给) (optional) * @param int|null $para 章节起始段(与 book 同时给) (optional) * @param string|null $order 排序字段 (optional, default to 'updated_at') * @param string|null $dir 排序方向 (optional, default to 'desc') * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] 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\GetApiV3Channels200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings) */ public function getApiV3StudiosStudioChannelsWithHttpInfo($studio, $per_page = 20, $relation = 'own', $collaborator = null, $search = null, $type = null, $lang = null, $book = null, $para = null, $order = 'updated_at', $dir = 'desc', $page = 1, string $contentType = self::contentTypes['getApiV3StudiosStudioChannels'][0]) { $request = $this->getApiV3StudiosStudioChannelsRequest($studio, $per_page, $relation, $collaborator, $search, $type, $lang, $book, $para, $order, $dir, $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\GetApiV3Channels200Response', $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\GetApiV3Channels200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\GetApiV3Channels200Response', $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 getApiV3StudiosStudioChannelsAsync * * 列出 studio 的 channel * * @param string $studio 用户 uuid 或团队 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 20) * @param string|null $relation 关系 (optional, default to 'own') * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional) * @param string|null $search 按名字模糊匹配 (optional) * @param string|null $type channel 类型 (optional) * @param string|null $lang 语言 (optional) * @param int|null $book 章节所在的书(与 para 同时给) (optional) * @param int|null $para 章节起始段(与 book 同时给) (optional) * @param string|null $order 排序字段 (optional, default to 'updated_at') * @param string|null $dir 排序方向 (optional, default to 'desc') * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getApiV3StudiosStudioChannelsAsync($studio, $per_page = 20, $relation = 'own', $collaborator = null, $search = null, $type = null, $lang = null, $book = null, $para = null, $order = 'updated_at', $dir = 'desc', $page = 1, string $contentType = self::contentTypes['getApiV3StudiosStudioChannels'][0]) { return $this->getApiV3StudiosStudioChannelsAsyncWithHttpInfo($studio, $per_page, $relation, $collaborator, $search, $type, $lang, $book, $para, $order, $dir, $page, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation getApiV3StudiosStudioChannelsAsyncWithHttpInfo * * 列出 studio 的 channel * * @param string $studio 用户 uuid 或团队 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 20) * @param string|null $relation 关系 (optional, default to 'own') * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional) * @param string|null $search 按名字模糊匹配 (optional) * @param string|null $type channel 类型 (optional) * @param string|null $lang 语言 (optional) * @param int|null $book 章节所在的书(与 para 同时给) (optional) * @param int|null $para 章节起始段(与 book 同时给) (optional) * @param string|null $order 排序字段 (optional, default to 'updated_at') * @param string|null $dir 排序方向 (optional, default to 'desc') * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getApiV3StudiosStudioChannelsAsyncWithHttpInfo($studio, $per_page = 20, $relation = 'own', $collaborator = null, $search = null, $type = null, $lang = null, $book = null, $para = null, $order = 'updated_at', $dir = 'desc', $page = 1, string $contentType = self::contentTypes['getApiV3StudiosStudioChannels'][0]) { $returnType = '\WikipaliApi\Model\GetApiV3Channels200Response'; $request = $this->getApiV3StudiosStudioChannelsRequest($studio, $per_page, $relation, $collaborator, $search, $type, $lang, $book, $para, $order, $dir, $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 'getApiV3StudiosStudioChannels' * * @param string $studio 用户 uuid 或团队 uuid (required) * @param int|null $per_page 每页数量,最大 200 (optional, default to 20) * @param string|null $relation 关系 (optional, default to 'own') * @param string|null $collaborator 只看这个拥有者共享过来的(uuid) (optional) * @param string|null $search 按名字模糊匹配 (optional) * @param string|null $type channel 类型 (optional) * @param string|null $lang 语言 (optional) * @param int|null $book 章节所在的书(与 para 同时给) (optional) * @param int|null $para 章节起始段(与 book 同时给) (optional) * @param string|null $order 排序字段 (optional, default to 'updated_at') * @param string|null $dir 排序方向 (optional, default to 'desc') * @param int|null $page 页码 (optional, default to 1) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioChannels'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function getApiV3StudiosStudioChannelsRequest($studio, $per_page = 20, $relation = 'own', $collaborator = null, $search = null, $type = null, $lang = null, $book = null, $para = null, $order = 'updated_at', $dir = 'desc', $page = 1, string $contentType = self::contentTypes['getApiV3StudiosStudioChannels'][0]) { // verify the required parameter 'studio' is set if ($studio === null || (is_array($studio) && count($studio) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $studio when calling getApiV3StudiosStudioChannels' ); } $resourcePath = '/v3/studios/{studio}/channels'; $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( $relation, 'relation', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $collaborator, 'collaborator', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $search, 'search', // param base name 'string', // openApiType 'form', // style true, // explode false // 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( $lang, 'lang', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $book, 'book', // param base name 'integer', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $para, 'para', // param base name 'integer', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $order, 'order', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $dir, 'dir', // 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 ) ?? []); // path params if ($studio !== null) { $resourcePath = str_replace( '{studio}', ObjectSerializer::toPathValue($studio), $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 getApiV3StudiosStudioTerms * * studio 的术语列表 * * @param string $studio 用户或团队的 uuid (required) * @param bool|null $general 只要 studio 级术语(不属于任何 channel) (optional) * @param int|null $per_page 每页条数,最大 200 (optional, default to 20) * @param string|null $search 按词、释义搜索 (optional) * @param string|null $quality 质量;pending 含未评级的 (optional) * @param string|null $category 百科分类 (optional) * @param string|null $order 排序字段 (optional, default to 'updated_at') * @param string|null $dir 排序方向 (optional) * @param int|null $page 页码 (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioTerms'] 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\GetApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails */ public function getApiV3StudiosStudioTerms($studio, $general = null, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3StudiosStudioTerms'][0]) { list($response) = $this->getApiV3StudiosStudioTermsWithHttpInfo($studio, $general, $per_page, $search, $quality, $category, $order, $dir, $page, $contentType); return $response; } /** * Operation getApiV3StudiosStudioTermsWithHttpInfo * * studio 的术语列表 * * @param string $studio 用户或团队的 uuid (required) * @param bool|null $general 只要 studio 级术语(不属于任何 channel) (optional) * @param int|null $per_page 每页条数,最大 200 (optional, default to 20) * @param string|null $search 按词、释义搜索 (optional) * @param string|null $quality 质量;pending 含未评级的 (optional) * @param string|null $category 百科分类 (optional) * @param string|null $order 排序字段 (optional, default to 'updated_at') * @param string|null $dir 排序方向 (optional) * @param int|null $page 页码 (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioTerms'] 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\GetApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings) */ public function getApiV3StudiosStudioTermsWithHttpInfo($studio, $general = null, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3StudiosStudioTerms'][0]) { $request = $this->getApiV3StudiosStudioTermsRequest($studio, $general, $per_page, $search, $quality, $category, $order, $dir, $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\GetApiV3ChannelsChannelTerms200Response', $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\GetApiV3ChannelsChannelTerms200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response', $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 getApiV3StudiosStudioTermsAsync * * studio 的术语列表 * * @param string $studio 用户或团队的 uuid (required) * @param bool|null $general 只要 studio 级术语(不属于任何 channel) (optional) * @param int|null $per_page 每页条数,最大 200 (optional, default to 20) * @param string|null $search 按词、释义搜索 (optional) * @param string|null $quality 质量;pending 含未评级的 (optional) * @param string|null $category 百科分类 (optional) * @param string|null $order 排序字段 (optional, default to 'updated_at') * @param string|null $dir 排序方向 (optional) * @param int|null $page 页码 (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioTerms'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getApiV3StudiosStudioTermsAsync($studio, $general = null, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3StudiosStudioTerms'][0]) { return $this->getApiV3StudiosStudioTermsAsyncWithHttpInfo($studio, $general, $per_page, $search, $quality, $category, $order, $dir, $page, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation getApiV3StudiosStudioTermsAsyncWithHttpInfo * * studio 的术语列表 * * @param string $studio 用户或团队的 uuid (required) * @param bool|null $general 只要 studio 级术语(不属于任何 channel) (optional) * @param int|null $per_page 每页条数,最大 200 (optional, default to 20) * @param string|null $search 按词、释义搜索 (optional) * @param string|null $quality 质量;pending 含未评级的 (optional) * @param string|null $category 百科分类 (optional) * @param string|null $order 排序字段 (optional, default to 'updated_at') * @param string|null $dir 排序方向 (optional) * @param int|null $page 页码 (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioTerms'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getApiV3StudiosStudioTermsAsyncWithHttpInfo($studio, $general = null, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3StudiosStudioTerms'][0]) { $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannelTerms200Response'; $request = $this->getApiV3StudiosStudioTermsRequest($studio, $general, $per_page, $search, $quality, $category, $order, $dir, $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 'getApiV3StudiosStudioTerms' * * @param string $studio 用户或团队的 uuid (required) * @param bool|null $general 只要 studio 级术语(不属于任何 channel) (optional) * @param int|null $per_page 每页条数,最大 200 (optional, default to 20) * @param string|null $search 按词、释义搜索 (optional) * @param string|null $quality 质量;pending 含未评级的 (optional) * @param string|null $category 百科分类 (optional) * @param string|null $order 排序字段 (optional, default to 'updated_at') * @param string|null $dir 排序方向 (optional) * @param int|null $page 页码 (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3StudiosStudioTerms'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function getApiV3StudiosStudioTermsRequest($studio, $general = null, $per_page = 20, $search = null, $quality = null, $category = null, $order = 'updated_at', $dir = null, $page = null, string $contentType = self::contentTypes['getApiV3StudiosStudioTerms'][0]) { // verify the required parameter 'studio' is set if ($studio === null || (is_array($studio) && count($studio) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $studio when calling getApiV3StudiosStudioTerms' ); } $resourcePath = '/v3/studios/{studio}/terms'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $general, 'general', // param base name 'boolean', // openApiType 'form', // style true, // explode false // required ) ?? []); // 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( $search, 'search', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $quality, 'quality', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $category, 'category', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $order, 'order', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $dir, 'dir', // 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 ) ?? []); // path params if ($studio !== null) { $resourcePath = str_replace( '{studio}', ObjectSerializer::toPathValue($studio), $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 postApiV3StudiosStudioChannels * * 在 studio 名下建 channel * * @param string $studio 用户 uuid 或团队 uuid (required) * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request post_api_v3_studios_studio_channels_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] 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\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails */ public function postApiV3StudiosStudioChannels($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0]) { list($response) = $this->postApiV3StudiosStudioChannelsWithHttpInfo($studio, $post_api_v3_studios_studio_channels_request, $contentType); return $response; } /** * Operation postApiV3StudiosStudioChannelsWithHttpInfo * * 在 studio 名下建 channel * * @param string $studio 用户 uuid 或团队 uuid (required) * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] 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\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\GetApiV3ChannelsChannel200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings) */ public function postApiV3StudiosStudioChannelsWithHttpInfo($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0]) { $request = $this->postApiV3StudiosStudioChannelsRequest($studio, $post_api_v3_studios_studio_channels_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\GetApiV3ChannelsChannel200Response', $request, $response, ); case 201: return $this->handleResponseWithDataType( '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response', $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\GetApiV3ChannelsChannel200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 201: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response', $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 postApiV3StudiosStudioChannelsAsync * * 在 studio 名下建 channel * * @param string $studio 用户 uuid 或团队 uuid (required) * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function postApiV3StudiosStudioChannelsAsync($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0]) { return $this->postApiV3StudiosStudioChannelsAsyncWithHttpInfo($studio, $post_api_v3_studios_studio_channels_request, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation postApiV3StudiosStudioChannelsAsyncWithHttpInfo * * 在 studio 名下建 channel * * @param string $studio 用户 uuid 或团队 uuid (required) * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function postApiV3StudiosStudioChannelsAsyncWithHttpInfo($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0]) { $returnType = '\WikipaliApi\Model\GetApiV3ChannelsChannel200Response'; $request = $this->postApiV3StudiosStudioChannelsRequest($studio, $post_api_v3_studios_studio_channels_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 'postApiV3StudiosStudioChannels' * * @param string $studio 用户 uuid 或团队 uuid (required) * @param \WikipaliApi\Model\PostApiV3StudiosStudioChannelsRequest $post_api_v3_studios_studio_channels_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioChannels'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function postApiV3StudiosStudioChannelsRequest($studio, $post_api_v3_studios_studio_channels_request, string $contentType = self::contentTypes['postApiV3StudiosStudioChannels'][0]) { // verify the required parameter 'studio' is set if ($studio === null || (is_array($studio) && count($studio) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $studio when calling postApiV3StudiosStudioChannels' ); } // verify the required parameter 'post_api_v3_studios_studio_channels_request' is set if ($post_api_v3_studios_studio_channels_request === null || (is_array($post_api_v3_studios_studio_channels_request) && count($post_api_v3_studios_studio_channels_request) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $post_api_v3_studios_studio_channels_request when calling postApiV3StudiosStudioChannels' ); } $resourcePath = '/v3/studios/{studio}/channels'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($studio !== null) { $resourcePath = str_replace( '{studio}', ObjectSerializer::toPathValue($studio), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', 'application/problem+json', ], $contentType, $multipart ); // for model (json/xml) if (isset($post_api_v3_studios_studio_channels_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_studios_studio_channels_request), JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { $httpBody = $post_api_v3_studios_studio_channels_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 postApiV3StudiosStudioTerms * * 新建 studio 级术语 * * @param string $studio 用户或团队的 uuid (required) * @param \WikipaliApi\Model\PostApiV3StudiosStudioTermsRequest $post_api_v3_studios_studio_terms_request post_api_v3_studios_studio_terms_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTerms'] 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\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails */ public function postApiV3StudiosStudioTerms($studio, $post_api_v3_studios_studio_terms_request, string $contentType = self::contentTypes['postApiV3StudiosStudioTerms'][0]) { list($response) = $this->postApiV3StudiosStudioTermsWithHttpInfo($studio, $post_api_v3_studios_studio_terms_request, $contentType); return $response; } /** * Operation postApiV3StudiosStudioTermsWithHttpInfo * * 新建 studio 级术语 * * @param string $studio 用户或团队的 uuid (required) * @param \WikipaliApi\Model\PostApiV3StudiosStudioTermsRequest $post_api_v3_studios_studio_terms_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTerms'] 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\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings) */ public function postApiV3StudiosStudioTermsWithHttpInfo($studio, $post_api_v3_studios_studio_terms_request, string $contentType = self::contentTypes['postApiV3StudiosStudioTerms'][0]) { $request = $this->postApiV3StudiosStudioTermsRequest($studio, $post_api_v3_studios_studio_terms_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\PostApiV3ChannelsChannelTerms200Response', $request, $response, ); case 201: return $this->handleResponseWithDataType( '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response', $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\PostApiV3ChannelsChannelTerms200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 201: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response', $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 postApiV3StudiosStudioTermsAsync * * 新建 studio 级术语 * * @param string $studio 用户或团队的 uuid (required) * @param \WikipaliApi\Model\PostApiV3StudiosStudioTermsRequest $post_api_v3_studios_studio_terms_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTerms'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function postApiV3StudiosStudioTermsAsync($studio, $post_api_v3_studios_studio_terms_request, string $contentType = self::contentTypes['postApiV3StudiosStudioTerms'][0]) { return $this->postApiV3StudiosStudioTermsAsyncWithHttpInfo($studio, $post_api_v3_studios_studio_terms_request, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation postApiV3StudiosStudioTermsAsyncWithHttpInfo * * 新建 studio 级术语 * * @param string $studio 用户或团队的 uuid (required) * @param \WikipaliApi\Model\PostApiV3StudiosStudioTermsRequest $post_api_v3_studios_studio_terms_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTerms'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function postApiV3StudiosStudioTermsAsyncWithHttpInfo($studio, $post_api_v3_studios_studio_terms_request, string $contentType = self::contentTypes['postApiV3StudiosStudioTerms'][0]) { $returnType = '\WikipaliApi\Model\PostApiV3ChannelsChannelTerms200Response'; $request = $this->postApiV3StudiosStudioTermsRequest($studio, $post_api_v3_studios_studio_terms_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 'postApiV3StudiosStudioTerms' * * @param string $studio 用户或团队的 uuid (required) * @param \WikipaliApi\Model\PostApiV3StudiosStudioTermsRequest $post_api_v3_studios_studio_terms_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTerms'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function postApiV3StudiosStudioTermsRequest($studio, $post_api_v3_studios_studio_terms_request, string $contentType = self::contentTypes['postApiV3StudiosStudioTerms'][0]) { // verify the required parameter 'studio' is set if ($studio === null || (is_array($studio) && count($studio) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $studio when calling postApiV3StudiosStudioTerms' ); } // verify the required parameter 'post_api_v3_studios_studio_terms_request' is set if ($post_api_v3_studios_studio_terms_request === null || (is_array($post_api_v3_studios_studio_terms_request) && count($post_api_v3_studios_studio_terms_request) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $post_api_v3_studios_studio_terms_request when calling postApiV3StudiosStudioTerms' ); } $resourcePath = '/v3/studios/{studio}/terms'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($studio !== null) { $resourcePath = str_replace( '{studio}', ObjectSerializer::toPathValue($studio), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', 'application/problem+json', ], $contentType, $multipart ); // for model (json/xml) if (isset($post_api_v3_studios_studio_terms_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_studios_studio_terms_request), JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e); } } else { $httpBody = $post_api_v3_studios_studio_terms_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 postApiV3StudiosStudioTermsImports * * 向 studio 导入术语 * * @param string $studio 用户或团队的 uuid (required) * @param \SplFileObject $file xlsx 表格,不超过 5MB (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTermsImports'] 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\PostApiV3ChannelsChannelTermsImports200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails */ public function postApiV3StudiosStudioTermsImports($studio, $file, string $contentType = self::contentTypes['postApiV3StudiosStudioTermsImports'][0]) { list($response) = $this->postApiV3StudiosStudioTermsImportsWithHttpInfo($studio, $file, $contentType); return $response; } /** * Operation postApiV3StudiosStudioTermsImportsWithHttpInfo * * 向 studio 导入术语 * * @param string $studio 用户或团队的 uuid (required) * @param \SplFileObject $file xlsx 表格,不超过 5MB (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTermsImports'] 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\PostApiV3ChannelsChannelTermsImports200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings) */ public function postApiV3StudiosStudioTermsImportsWithHttpInfo($studio, $file, string $contentType = self::contentTypes['postApiV3StudiosStudioTermsImports'][0]) { $request = $this->postApiV3StudiosStudioTermsImportsRequest($studio, $file, $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\PostApiV3ChannelsChannelTermsImports200Response', $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\PostApiV3ChannelsChannelTermsImports200Response', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response', $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 postApiV3StudiosStudioTermsImportsAsync * * 向 studio 导入术语 * * @param string $studio 用户或团队的 uuid (required) * @param \SplFileObject $file xlsx 表格,不超过 5MB (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTermsImports'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function postApiV3StudiosStudioTermsImportsAsync($studio, $file, string $contentType = self::contentTypes['postApiV3StudiosStudioTermsImports'][0]) { return $this->postApiV3StudiosStudioTermsImportsAsyncWithHttpInfo($studio, $file, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation postApiV3StudiosStudioTermsImportsAsyncWithHttpInfo * * 向 studio 导入术语 * * @param string $studio 用户或团队的 uuid (required) * @param \SplFileObject $file xlsx 表格,不超过 5MB (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTermsImports'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function postApiV3StudiosStudioTermsImportsAsyncWithHttpInfo($studio, $file, string $contentType = self::contentTypes['postApiV3StudiosStudioTermsImports'][0]) { $returnType = '\WikipaliApi\Model\PostApiV3ChannelsChannelTermsImports200Response'; $request = $this->postApiV3StudiosStudioTermsImportsRequest($studio, $file, $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 'postApiV3StudiosStudioTermsImports' * * @param string $studio 用户或团队的 uuid (required) * @param \SplFileObject $file xlsx 表格,不超过 5MB (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['postApiV3StudiosStudioTermsImports'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function postApiV3StudiosStudioTermsImportsRequest($studio, $file, string $contentType = self::contentTypes['postApiV3StudiosStudioTermsImports'][0]) { // verify the required parameter 'studio' is set if ($studio === null || (is_array($studio) && count($studio) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $studio when calling postApiV3StudiosStudioTermsImports' ); } // verify the required parameter 'file' is set if ($file === null || (is_array($file) && count($file) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $file when calling postApiV3StudiosStudioTermsImports' ); } $resourcePath = '/v3/studios/{studio}/terms/imports'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($studio !== null) { $resourcePath = str_replace( '{studio}', ObjectSerializer::toPathValue($studio), $resourcePath ); } // form params $formDataProcessor = new FormDataProcessor(); $formData = $formDataProcessor->prepare([ 'file' => $file, ]); $formParams = $formDataProcessor->flatten($formData); $multipart = $formDataProcessor->has_file; $multipart = true; $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( '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; } }