Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 87 additions & 89 deletions codegen/Oauth/Api/AccessTokensApi.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* AccessTokensApi
* PHP version 7.4
* PHP version 8.1
*
* @category Class
* @package HubSpot\Client\Oauth
Expand All @@ -16,7 +16,7 @@
*
* The version of the OpenAPI document: v1
* Generated by: https://openapi-generator.tech
* Generator version: 7.12.0
* Generator version: 7.19.0
*/

/**
Expand All @@ -34,8 +34,11 @@
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use HubSpot\Client\Oauth\ApiException;
use HubSpot\Client\Oauth\Configuration;
use HubSpot\Client\Oauth\FormDataProcessor;
use HubSpot\Client\Oauth\HeaderSelector;
use HubSpot\Client\Oauth\ObjectSerializer;

Expand Down Expand Up @@ -127,12 +130,13 @@ public function getConfig()
*
* Retrieve OAuth token metadata
*
* @param string $token The access token that you want to retrieve information about. (required)
* @param string $token (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['get'] to see the possible values for this operation
*
* @throws \HubSpot\Client\Oauth\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return \HubSpot\Client\Oauth\Model\AccessTokenInfoResponse|\HubSpot\Client\Oauth\Model\Error
* @deprecated
*/
public function get($token, string $contentType = self::contentTypes['get'][0])
{
Expand All @@ -145,12 +149,13 @@ public function get($token, string $contentType = self::contentTypes['get'][0])
*
* Retrieve OAuth token metadata
*
* @param string $token The access token that you want to retrieve information about. (required)
* @param string $token (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['get'] to see the possible values for this operation
*
* @throws \HubSpot\Client\Oauth\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return array of \HubSpot\Client\Oauth\Model\AccessTokenInfoResponse|\HubSpot\Client\Oauth\Model\Error, HTTP status code, HTTP response headers (array of strings)
* @deprecated
*/
public function getWithHttpInfo($token, string $contentType = self::contentTypes['get'][0])
{
Expand Down Expand Up @@ -181,61 +186,21 @@ public function getWithHttpInfo($token, string $contentType = self::contentTypes

switch($statusCode) {
case 200:
if ('\HubSpot\Client\Oauth\Model\AccessTokenInfoResponse' === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\HubSpot\Client\Oauth\Model\AccessTokenInfoResponse' !== '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, '\HubSpot\Client\Oauth\Model\AccessTokenInfoResponse', []),
$response->getStatusCode(),
$response->getHeaders()
];
return $this->handleResponseWithDataType(
'\HubSpot\Client\Oauth\Model\AccessTokenInfoResponse',
$request,
$response,
);
default:
if ('\HubSpot\Client\Oauth\Model\Error' === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\HubSpot\Client\Oauth\Model\Error' !== '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, '\HubSpot\Client\Oauth\Model\Error', []),
$response->getStatusCode(),
$response->getHeaders()
];
return $this->handleResponseWithDataType(
'\HubSpot\Client\Oauth\Model\Error',
$request,
$response,
);
}



if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
Expand All @@ -249,34 +214,11 @@ public function getWithHttpInfo($token, string $contentType = self::contentTypes
);
}

$returnType = '\HubSpot\Client\Oauth\Model\AccessTokenInfoResponse';
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()
];

return $this->handleResponseWithDataType(
'\HubSpot\Client\Oauth\Model\AccessTokenInfoResponse',
$request,
$response,
);
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
Expand All @@ -286,16 +228,18 @@ public function getWithHttpInfo($token, string $contentType = self::contentTypes
$e->getResponseHeaders()
);
$e->setResponseObject($data);
break;
throw $e;
default:
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
'\HubSpot\Client\Oauth\Model\Error',
$e->getResponseHeaders()
);
$e->setResponseObject($data);
break;
throw $e;
}


throw $e;
}
}
Expand All @@ -305,11 +249,12 @@ public function getWithHttpInfo($token, string $contentType = self::contentTypes
*
* Retrieve OAuth token metadata
*
* @param string $token The access token that you want to retrieve information about. (required)
* @param string $token (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['get'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
* @deprecated
*/
public function getAsync($token, string $contentType = self::contentTypes['get'][0])
{
Expand All @@ -326,11 +271,12 @@ function ($response) {
*
* Retrieve OAuth token metadata
*
* @param string $token The access token that you want to retrieve information about. (required)
* @param string $token (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['get'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
* @deprecated
*/
public function getAsyncWithHttpInfo($token, string $contentType = self::contentTypes['get'][0])
{
Expand Down Expand Up @@ -376,11 +322,12 @@ function ($exception) {
/**
* Create request for operation 'get'
*
* @param string $token The access token that you want to retrieve information about. (required)
* @param string $token (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['get'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
* @deprecated
*/
public function getRequest($token, string $contentType = self::contentTypes['get'][0])
{
Expand Down Expand Up @@ -481,6 +428,57 @@ protected function createHttpClientOption()
}
}

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;
}
}
Loading