<?php
/**
* DefaultApi
* PHP version 7.4
*
* @category Class
* @package OpenAPI\Client
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
/**
* GameBrain API
*
* GameBrain API
*
* The version of the OpenAPI document: 1.0.1
* Contact: mail@gamebrain.co
* Generated by: https://openapi-generator.tech
* Generator version: 7.8.0-SNAPSHOT
*/
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
namespace OpenAPI\Client\Api;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use OpenAPI\Client\ApiException;
use OpenAPI\Client\Configuration;
use OpenAPI\Client\HeaderSelector;
use OpenAPI\Client\ObjectSerializer;
/**
* DefaultApi Class Doc Comment
*
* @category Class
* @package OpenAPI\Client
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
class DefaultApi
{
/**
* @var ClientInterface
*/
protected $client;
/**
* @var Configuration
*/
protected $config;
/**
* @var HeaderSelector
*/
protected $headerSelector;
/**
* @var int Host index
*/
protected $hostIndex;
/** @var string[] $contentTypes **/
public const contentTypes = [
'detail' => [
'application/json',
],
'news' => [
'application/json',
],
'search' => [
'application/json',
],
'similar' => [
'application/json',
],
'suggest' => [
'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,
$hostIndex = 0
) {
$this->client = $client ?: new Client();
$this->config = $config ?: new Configuration();
$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 detail
*
* Get Game Details
*
* @param int $id The unique identifier of the game. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['detail'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return \OpenAPI\Client\Model\GameResponse
*/
public function detail($id, $api_key, string $contentType = self::contentTypes['detail'][0])
{
list($response) = $this->detailWithHttpInfo($id, $api_key, $contentType);
return $response;
}
/**
* Operation detailWithHttpInfo
*
* Get Game Details
*
* @param int $id The unique identifier of the game. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['detail'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return array of \OpenAPI\Client\Model\GameResponse, HTTP status code, HTTP response headers (array of strings)
*/
public function detailWithHttpInfo($id, $api_key, string $contentType = self::contentTypes['detail'][0])
{
$request = $this->detailRequest($id, $api_key, $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();
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()
);
}
switch($statusCode) {
case 200:
if ('\OpenAPI\Client\Model\GameResponse' === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\GameResponse' !== '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()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\GameResponse', []),
$response->getStatusCode(),
$response->getHeaders()
];
}
$returnType = '\OpenAPI\Client\Model\GameResponse';
if ($returnType === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== '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()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, $returnType, []),
$response->getStatusCode(),
$response->getHeaders()
];
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
'\OpenAPI\Client\Model\GameResponse',
$e->getResponseHeaders()
);
$e->setResponseObject($data);
break;
}
throw $e;
}
}
/**
* Operation detailAsync
*
* Get Game Details
*
* @param int $id The unique identifier of the game. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['detail'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function detailAsync($id, $api_key, string $contentType = self::contentTypes['detail'][0])
{
return $this->detailAsyncWithHttpInfo($id, $api_key, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation detailAsyncWithHttpInfo
*
* Get Game Details
*
* @param int $id The unique identifier of the game. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['detail'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function detailAsyncWithHttpInfo($id, $api_key, string $contentType = self::contentTypes['detail'][0])
{
$returnType = '\OpenAPI\Client\Model\GameResponse';
$request = $this->detailRequest($id, $api_key, $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 'detail'
*
* @param int $id The unique identifier of the game. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['detail'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function detailRequest($id, $api_key, string $contentType = self::contentTypes['detail'][0])
{
// verify the required parameter 'id' is set
if ($id === null || (is_array($id) && count($id) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $id when calling detail'
);
}
// verify the required parameter 'api_key' is set
if ($api_key === null || (is_array($api_key) && count($api_key) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $api_key when calling detail'
);
}
if (strlen($api_key) > 300) {
throw new \InvalidArgumentException('invalid length for "$api_key" when calling DefaultApi.detail, must be smaller than or equal to 300.');
}
if (!preg_match("/.*/", $api_key)) {
throw new \InvalidArgumentException("invalid value for \"api_key\" when calling DefaultApi.detail, must conform to the pattern /.*/.");
}
$resourcePath = '/games/{id}';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$api_key,
'api-key', // param base name
'string', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// path params
if ($id !== null) {
$resourcePath = str_replace(
'{' . 'id' . '}',
ObjectSerializer::toPathValue($id),
$resourcePath
);
}
$headers = $this->headerSelector->selectHeaders(
['application/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
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
}
}
// this endpoint requires API key authentication
$apiKey = $this->config->getApiKeyWithPrefix('api-key');
if ($apiKey !== null) {
$queryParams['api-key'] = $apiKey;
}
// this endpoint requires API key authentication
$apiKey = $this->config->getApiKeyWithPrefix('x-api-key');
if ($apiKey !== null) {
$headers['x-api-key'] = $apiKey;
}
$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 news
*
* Get Game News
*
* @param int $id id (required)
* @param int $offset offset (required)
* @param int $limit limit (required)
* @param string $api_key api_key (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['news'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return \OpenAPI\Client\Model\GameNewsResponse
*/
public function news($id, $offset, $limit, $api_key, string $contentType = self::contentTypes['news'][0])
{
list($response) = $this->newsWithHttpInfo($id, $offset, $limit, $api_key, $contentType);
return $response;
}
/**
* Operation newsWithHttpInfo
*
* Get Game News
*
* @param int $id (required)
* @param int $offset (required)
* @param int $limit (required)
* @param string $api_key (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['news'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return array of \OpenAPI\Client\Model\GameNewsResponse, HTTP status code, HTTP response headers (array of strings)
*/
public function newsWithHttpInfo($id, $offset, $limit, $api_key, string $contentType = self::contentTypes['news'][0])
{
$request = $this->newsRequest($id, $offset, $limit, $api_key, $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();
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()
);
}
switch($statusCode) {
case 200:
if ('\OpenAPI\Client\Model\GameNewsResponse' === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\GameNewsResponse' !== '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()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\GameNewsResponse', []),
$response->getStatusCode(),
$response->getHeaders()
];
}
$returnType = '\OpenAPI\Client\Model\GameNewsResponse';
if ($returnType === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== '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()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, $returnType, []),
$response->getStatusCode(),
$response->getHeaders()
];
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
'\OpenAPI\Client\Model\GameNewsResponse',
$e->getResponseHeaders()
);
$e->setResponseObject($data);
break;
}
throw $e;
}
}
/**
* Operation newsAsync
*
* Get Game News
*
* @param int $id (required)
* @param int $offset (required)
* @param int $limit (required)
* @param string $api_key (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['news'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function newsAsync($id, $offset, $limit, $api_key, string $contentType = self::contentTypes['news'][0])
{
return $this->newsAsyncWithHttpInfo($id, $offset, $limit, $api_key, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation newsAsyncWithHttpInfo
*
* Get Game News
*
* @param int $id (required)
* @param int $offset (required)
* @param int $limit (required)
* @param string $api_key (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['news'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function newsAsyncWithHttpInfo($id, $offset, $limit, $api_key, string $contentType = self::contentTypes['news'][0])
{
$returnType = '\OpenAPI\Client\Model\GameNewsResponse';
$request = $this->newsRequest($id, $offset, $limit, $api_key, $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 'news'
*
* @param int $id (required)
* @param int $offset (required)
* @param int $limit (required)
* @param string $api_key (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['news'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function newsRequest($id, $offset, $limit, $api_key, string $contentType = self::contentTypes['news'][0])
{
// verify the required parameter 'id' is set
if ($id === null || (is_array($id) && count($id) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $id when calling news'
);
}
// verify the required parameter 'offset' is set
if ($offset === null || (is_array($offset) && count($offset) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $offset when calling news'
);
}
// verify the required parameter 'limit' is set
if ($limit === null || (is_array($limit) && count($limit) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $limit when calling news'
);
}
// verify the required parameter 'api_key' is set
if ($api_key === null || (is_array($api_key) && count($api_key) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $api_key when calling news'
);
}
if (strlen($api_key) > 300) {
throw new \InvalidArgumentException('invalid length for "$api_key" when calling DefaultApi.news, must be smaller than or equal to 300.');
}
if (!preg_match("/.*/", $api_key)) {
throw new \InvalidArgumentException("invalid value for \"api_key\" when calling DefaultApi.news, must conform to the pattern /.*/.");
}
$resourcePath = '/games/{id}/news';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$offset,
'offset', // param base name
'integer', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$limit,
'limit', // param base name
'integer', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$api_key,
'api-key', // param base name
'string', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// path params
if ($id !== null) {
$resourcePath = str_replace(
'{' . 'id' . '}',
ObjectSerializer::toPathValue($id),
$resourcePath
);
}
$headers = $this->headerSelector->selectHeaders(
['application/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
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
}
}
// this endpoint requires API key authentication
$apiKey = $this->config->getApiKeyWithPrefix('api-key');
if ($apiKey !== null) {
$queryParams['api-key'] = $apiKey;
}
// this endpoint requires API key authentication
$apiKey = $this->config->getApiKeyWithPrefix('x-api-key');
if ($apiKey !== null) {
$headers['x-api-key'] = $apiKey;
}
$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 search
*
* Search Games
*
* @param string $query The search query, e.g., game name, platform, genre, or any combination. (required)
* @param int $offset The number of results to skip before starting to collect the result set. Between 0 and 1000. (required)
* @param int $limit The maximum number of results to return between 1 and 10. (required)
* @param string $filters JSON array of filter objects to apply to the search. (required)
* @param string $sort The field by which to sort the results, either computed_rating, price, or release_date (required)
* @param string $sort_order The sort order: 'asc' for ascending or 'desc' for descending. (required)
* @param bool $generate_filter_options Whether to generate filter options in the response. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['search'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return \OpenAPI\Client\Model\SearchResponse
*/
public function search($query, $offset, $limit, $filters, $sort, $sort_order, $generate_filter_options, $api_key, string $contentType = self::contentTypes['search'][0])
{
list($response) = $this->searchWithHttpInfo($query, $offset, $limit, $filters, $sort, $sort_order, $generate_filter_options, $api_key, $contentType);
return $response;
}
/**
* Operation searchWithHttpInfo
*
* Search Games
*
* @param string $query The search query, e.g., game name, platform, genre, or any combination. (required)
* @param int $offset The number of results to skip before starting to collect the result set. Between 0 and 1000. (required)
* @param int $limit The maximum number of results to return between 1 and 10. (required)
* @param string $filters JSON array of filter objects to apply to the search. (required)
* @param string $sort The field by which to sort the results, either computed_rating, price, or release_date (required)
* @param string $sort_order The sort order: 'asc' for ascending or 'desc' for descending. (required)
* @param bool $generate_filter_options Whether to generate filter options in the response. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['search'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return array of \OpenAPI\Client\Model\SearchResponse, HTTP status code, HTTP response headers (array of strings)
*/
public function searchWithHttpInfo($query, $offset, $limit, $filters, $sort, $sort_order, $generate_filter_options, $api_key, string $contentType = self::contentTypes['search'][0])
{
$request = $this->searchRequest($query, $offset, $limit, $filters, $sort, $sort_order, $generate_filter_options, $api_key, $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();
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()
);
}
switch($statusCode) {
case 200:
if ('\OpenAPI\Client\Model\SearchResponse' === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\SearchResponse' !== '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()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\SearchResponse', []),
$response->getStatusCode(),
$response->getHeaders()
];
}
$returnType = '\OpenAPI\Client\Model\SearchResponse';
if ($returnType === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== '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()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, $returnType, []),
$response->getStatusCode(),
$response->getHeaders()
];
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
'\OpenAPI\Client\Model\SearchResponse',
$e->getResponseHeaders()
);
$e->setResponseObject($data);
break;
}
throw $e;
}
}
/**
* Operation searchAsync
*
* Search Games
*
* @param string $query The search query, e.g., game name, platform, genre, or any combination. (required)
* @param int $offset The number of results to skip before starting to collect the result set. Between 0 and 1000. (required)
* @param int $limit The maximum number of results to return between 1 and 10. (required)
* @param string $filters JSON array of filter objects to apply to the search. (required)
* @param string $sort The field by which to sort the results, either computed_rating, price, or release_date (required)
* @param string $sort_order The sort order: 'asc' for ascending or 'desc' for descending. (required)
* @param bool $generate_filter_options Whether to generate filter options in the response. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['search'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function searchAsync($query, $offset, $limit, $filters, $sort, $sort_order, $generate_filter_options, $api_key, string $contentType = self::contentTypes['search'][0])
{
return $this->searchAsyncWithHttpInfo($query, $offset, $limit, $filters, $sort, $sort_order, $generate_filter_options, $api_key, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation searchAsyncWithHttpInfo
*
* Search Games
*
* @param string $query The search query, e.g., game name, platform, genre, or any combination. (required)
* @param int $offset The number of results to skip before starting to collect the result set. Between 0 and 1000. (required)
* @param int $limit The maximum number of results to return between 1 and 10. (required)
* @param string $filters JSON array of filter objects to apply to the search. (required)
* @param string $sort The field by which to sort the results, either computed_rating, price, or release_date (required)
* @param string $sort_order The sort order: 'asc' for ascending or 'desc' for descending. (required)
* @param bool $generate_filter_options Whether to generate filter options in the response. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['search'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function searchAsyncWithHttpInfo($query, $offset, $limit, $filters, $sort, $sort_order, $generate_filter_options, $api_key, string $contentType = self::contentTypes['search'][0])
{
$returnType = '\OpenAPI\Client\Model\SearchResponse';
$request = $this->searchRequest($query, $offset, $limit, $filters, $sort, $sort_order, $generate_filter_options, $api_key, $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 'search'
*
* @param string $query The search query, e.g., game name, platform, genre, or any combination. (required)
* @param int $offset The number of results to skip before starting to collect the result set. Between 0 and 1000. (required)
* @param int $limit The maximum number of results to return between 1 and 10. (required)
* @param string $filters JSON array of filter objects to apply to the search. (required)
* @param string $sort The field by which to sort the results, either computed_rating, price, or release_date (required)
* @param string $sort_order The sort order: 'asc' for ascending or 'desc' for descending. (required)
* @param bool $generate_filter_options Whether to generate filter options in the response. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['search'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function searchRequest($query, $offset, $limit, $filters, $sort, $sort_order, $generate_filter_options, $api_key, string $contentType = self::contentTypes['search'][0])
{
// verify the required parameter 'query' is set
if ($query === null || (is_array($query) && count($query) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $query when calling search'
);
}
if (strlen($query) > 300) {
throw new \InvalidArgumentException('invalid length for "$query" when calling DefaultApi.search, must be smaller than or equal to 300.');
}
if (!preg_match("/.*/", $query)) {
throw new \InvalidArgumentException("invalid value for \"query\" when calling DefaultApi.search, must conform to the pattern /.*/.");
}
// verify the required parameter 'offset' is set
if ($offset === null || (is_array($offset) && count($offset) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $offset when calling search'
);
}
// verify the required parameter 'limit' is set
if ($limit === null || (is_array($limit) && count($limit) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $limit when calling search'
);
}
// verify the required parameter 'filters' is set
if ($filters === null || (is_array($filters) && count($filters) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $filters when calling search'
);
}
if (strlen($filters) > 3000) {
throw new \InvalidArgumentException('invalid length for "$filters" when calling DefaultApi.search, must be smaller than or equal to 3000.');
}
if (!preg_match("/.*/", $filters)) {
throw new \InvalidArgumentException("invalid value for \"filters\" when calling DefaultApi.search, must conform to the pattern /.*/.");
}
// verify the required parameter 'sort' is set
if ($sort === null || (is_array($sort) && count($sort) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $sort when calling search'
);
}
if (strlen($sort) > 300) {
throw new \InvalidArgumentException('invalid length for "$sort" when calling DefaultApi.search, must be smaller than or equal to 300.');
}
if (!preg_match("/.*/", $sort)) {
throw new \InvalidArgumentException("invalid value for \"sort\" when calling DefaultApi.search, must conform to the pattern /.*/.");
}
// verify the required parameter 'sort_order' is set
if ($sort_order === null || (is_array($sort_order) && count($sort_order) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $sort_order when calling search'
);
}
if (strlen($sort_order) > 4) {
throw new \InvalidArgumentException('invalid length for "$sort_order" when calling DefaultApi.search, must be smaller than or equal to 4.');
}
if (!preg_match("/(asc|desc)/", $sort_order)) {
throw new \InvalidArgumentException("invalid value for \"sort_order\" when calling DefaultApi.search, must conform to the pattern /(asc|desc)/.");
}
// verify the required parameter 'generate_filter_options' is set
if ($generate_filter_options === null || (is_array($generate_filter_options) && count($generate_filter_options) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $generate_filter_options when calling search'
);
}
// verify the required parameter 'api_key' is set
if ($api_key === null || (is_array($api_key) && count($api_key) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $api_key when calling search'
);
}
if (strlen($api_key) > 300) {
throw new \InvalidArgumentException('invalid length for "$api_key" when calling DefaultApi.search, must be smaller than or equal to 300.');
}
if (!preg_match("/.*/", $api_key)) {
throw new \InvalidArgumentException("invalid value for \"api_key\" when calling DefaultApi.search, must conform to the pattern /.*/.");
}
$resourcePath = '/games';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$query,
'query', // param base name
'string', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$offset,
'offset', // param base name
'integer', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$limit,
'limit', // param base name
'integer', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$filters,
'filters', // param base name
'string', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$sort,
'sort', // param base name
'string', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$sort_order,
'sort-order', // param base name
'string', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$generate_filter_options,
'generate-filter-options', // param base name
'boolean', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$api_key,
'api-key', // param base name
'string', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
$headers = $this->headerSelector->selectHeaders(
['application/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
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
}
}
// this endpoint requires API key authentication
$apiKey = $this->config->getApiKeyWithPrefix('api-key');
if ($apiKey !== null) {
$queryParams['api-key'] = $apiKey;
}
// this endpoint requires API key authentication
$apiKey = $this->config->getApiKeyWithPrefix('x-api-key');
if ($apiKey !== null) {
$headers['x-api-key'] = $apiKey;
}
$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 similar
*
* Get Similar Games
*
* @param int $id id (required)
* @param int $limit limit (required)
* @param string $api_key api_key (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['similar'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return \OpenAPI\Client\Model\SimilarGamesResponse
*/
public function similar($id, $limit, $api_key, string $contentType = self::contentTypes['similar'][0])
{
list($response) = $this->similarWithHttpInfo($id, $limit, $api_key, $contentType);
return $response;
}
/**
* Operation similarWithHttpInfo
*
* Get Similar Games
*
* @param int $id (required)
* @param int $limit (required)
* @param string $api_key (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['similar'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return array of \OpenAPI\Client\Model\SimilarGamesResponse, HTTP status code, HTTP response headers (array of strings)
*/
public function similarWithHttpInfo($id, $limit, $api_key, string $contentType = self::contentTypes['similar'][0])
{
$request = $this->similarRequest($id, $limit, $api_key, $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();
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()
);
}
switch($statusCode) {
case 200:
if ('\OpenAPI\Client\Model\SimilarGamesResponse' === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\SimilarGamesResponse' !== '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()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\SimilarGamesResponse', []),
$response->getStatusCode(),
$response->getHeaders()
];
}
$returnType = '\OpenAPI\Client\Model\SimilarGamesResponse';
if ($returnType === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== '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()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, $returnType, []),
$response->getStatusCode(),
$response->getHeaders()
];
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
'\OpenAPI\Client\Model\SimilarGamesResponse',
$e->getResponseHeaders()
);
$e->setResponseObject($data);
break;
}
throw $e;
}
}
/**
* Operation similarAsync
*
* Get Similar Games
*
* @param int $id (required)
* @param int $limit (required)
* @param string $api_key (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['similar'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function similarAsync($id, $limit, $api_key, string $contentType = self::contentTypes['similar'][0])
{
return $this->similarAsyncWithHttpInfo($id, $limit, $api_key, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation similarAsyncWithHttpInfo
*
* Get Similar Games
*
* @param int $id (required)
* @param int $limit (required)
* @param string $api_key (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['similar'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function similarAsyncWithHttpInfo($id, $limit, $api_key, string $contentType = self::contentTypes['similar'][0])
{
$returnType = '\OpenAPI\Client\Model\SimilarGamesResponse';
$request = $this->similarRequest($id, $limit, $api_key, $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 'similar'
*
* @param int $id (required)
* @param int $limit (required)
* @param string $api_key (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['similar'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function similarRequest($id, $limit, $api_key, string $contentType = self::contentTypes['similar'][0])
{
// verify the required parameter 'id' is set
if ($id === null || (is_array($id) && count($id) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $id when calling similar'
);
}
// verify the required parameter 'limit' is set
if ($limit === null || (is_array($limit) && count($limit) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $limit when calling similar'
);
}
// verify the required parameter 'api_key' is set
if ($api_key === null || (is_array($api_key) && count($api_key) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $api_key when calling similar'
);
}
if (strlen($api_key) > 300) {
throw new \InvalidArgumentException('invalid length for "$api_key" when calling DefaultApi.similar, must be smaller than or equal to 300.');
}
if (!preg_match("/.*/", $api_key)) {
throw new \InvalidArgumentException("invalid value for \"api_key\" when calling DefaultApi.similar, must conform to the pattern /.*/.");
}
$resourcePath = '/games/{id}/similar';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$limit,
'limit', // param base name
'integer', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$api_key,
'api-key', // param base name
'string', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// path params
if ($id !== null) {
$resourcePath = str_replace(
'{' . 'id' . '}',
ObjectSerializer::toPathValue($id),
$resourcePath
);
}
$headers = $this->headerSelector->selectHeaders(
['application/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
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
}
}
// this endpoint requires API key authentication
$apiKey = $this->config->getApiKeyWithPrefix('api-key');
if ($apiKey !== null) {
$queryParams['api-key'] = $apiKey;
}
// this endpoint requires API key authentication
$apiKey = $this->config->getApiKeyWithPrefix('x-api-key');
if ($apiKey !== null) {
$headers['x-api-key'] = $apiKey;
}
$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 suggest
*
* Get Game Suggestions
*
* @param string $query The partial search query to get suggestions for. (required)
* @param int $limit The maximum number of suggestions to return. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['suggest'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return \OpenAPI\Client\Model\SearchSuggestionResponse
*/
public function suggest($query, $limit, $api_key, string $contentType = self::contentTypes['suggest'][0])
{
list($response) = $this->suggestWithHttpInfo($query, $limit, $api_key, $contentType);
return $response;
}
/**
* Operation suggestWithHttpInfo
*
* Get Game Suggestions
*
* @param string $query The partial search query to get suggestions for. (required)
* @param int $limit The maximum number of suggestions to return. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['suggest'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return array of \OpenAPI\Client\Model\SearchSuggestionResponse, HTTP status code, HTTP response headers (array of strings)
*/
public function suggestWithHttpInfo($query, $limit, $api_key, string $contentType = self::contentTypes['suggest'][0])
{
$request = $this->suggestRequest($query, $limit, $api_key, $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();
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()
);
}
switch($statusCode) {
case 200:
if ('\OpenAPI\Client\Model\SearchSuggestionResponse' === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\SearchSuggestionResponse' !== '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()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\SearchSuggestionResponse', []),
$response->getStatusCode(),
$response->getHeaders()
];
}
$returnType = '\OpenAPI\Client\Model\SearchSuggestionResponse';
if ($returnType === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== '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()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, $returnType, []),
$response->getStatusCode(),
$response->getHeaders()
];
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
'\OpenAPI\Client\Model\SearchSuggestionResponse',
$e->getResponseHeaders()
);
$e->setResponseObject($data);
break;
}
throw $e;
}
}
/**
* Operation suggestAsync
*
* Get Game Suggestions
*
* @param string $query The partial search query to get suggestions for. (required)
* @param int $limit The maximum number of suggestions to return. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['suggest'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function suggestAsync($query, $limit, $api_key, string $contentType = self::contentTypes['suggest'][0])
{
return $this->suggestAsyncWithHttpInfo($query, $limit, $api_key, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation suggestAsyncWithHttpInfo
*
* Get Game Suggestions
*
* @param string $query The partial search query to get suggestions for. (required)
* @param int $limit The maximum number of suggestions to return. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['suggest'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function suggestAsyncWithHttpInfo($query, $limit, $api_key, string $contentType = self::contentTypes['suggest'][0])
{
$returnType = '\OpenAPI\Client\Model\SearchSuggestionResponse';
$request = $this->suggestRequest($query, $limit, $api_key, $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 'suggest'
*
* @param string $query The partial search query to get suggestions for. (required)
* @param int $limit The maximum number of suggestions to return. (required)
* @param string $api_key Your API key for authentication. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['suggest'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function suggestRequest($query, $limit, $api_key, string $contentType = self::contentTypes['suggest'][0])
{
// verify the required parameter 'query' is set
if ($query === null || (is_array($query) && count($query) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $query when calling suggest'
);
}
if (strlen($query) > 300) {
throw new \InvalidArgumentException('invalid length for "$query" when calling DefaultApi.suggest, must be smaller than or equal to 300.');
}
if (!preg_match("/.*/", $query)) {
throw new \InvalidArgumentException("invalid value for \"query\" when calling DefaultApi.suggest, must conform to the pattern /.*/.");
}
// verify the required parameter 'limit' is set
if ($limit === null || (is_array($limit) && count($limit) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $limit when calling suggest'
);
}
// verify the required parameter 'api_key' is set
if ($api_key === null || (is_array($api_key) && count($api_key) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $api_key when calling suggest'
);
}
if (strlen($api_key) > 300) {
throw new \InvalidArgumentException('invalid length for "$api_key" when calling DefaultApi.suggest, must be smaller than or equal to 300.');
}
if (!preg_match("/.*/", $api_key)) {
throw new \InvalidArgumentException("invalid value for \"api_key\" when calling DefaultApi.suggest, must conform to the pattern /.*/.");
}
$resourcePath = '/games/suggestions';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$query,
'query', // param base name
'string', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$limit,
'limit', // param base name
'integer', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$api_key,
'api-key', // param base name
'string', // openApiType
'form', // style
true, // explode
true // required
) ?? []);
$headers = $this->headerSelector->selectHeaders(
['application/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
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
}
}
// this endpoint requires API key authentication
$apiKey = $this->config->getApiKeyWithPrefix('api-key');
if ($apiKey !== null) {
$queryParams['api-key'] = $apiKey;
}
// this endpoint requires API key authentication
$apiKey = $this->config->getApiKeyWithPrefix('x-api-key');
if ($apiKey !== null) {
$headers['x-api-key'] = $apiKey;
}
$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
);
}
/**
* 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());
}
}
return $options;
}
}