Skip to content

Commit 784311f

Browse files
committed
chore: sdk update
1 parent 05fc979 commit 784311f

File tree

136 files changed

+5785
-34475
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+5785
-34475
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hostinger/api-php-sdk",
3-
"version": "0.0.27",
3+
"version": "0.0.28",
44
"description": "Hostinger API PHP SDK",
55
"keywords": [
66
"hostinger",
@@ -24,7 +24,8 @@
2424
"ext-json": "*",
2525
"ext-mbstring": "*",
2626
"guzzlehttp/guzzle": "^7.4.5",
27-
"guzzlehttp/psr7": "^2.0"
27+
"guzzlehttp/psr7": "^2.0",
28+
"symfony/serializer-pack": "^1.3"
2829
},
2930
"require-dev": {
3031
"friendsofphp/php-cs-fixer": "^3.5",

src/Api/BillingCatalogApi.php

Lines changed: 52 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
/** @noinspection PhpFullyQualifiedNameUsageInspection */
23

34
/**
45
* Hostinger API PHP SDK
@@ -12,17 +13,18 @@
1213

1314
namespace Hostinger\Api;
1415

15-
use InvalidArgumentException;
1616
use GuzzleHttp\Client;
1717
use GuzzleHttp\ClientInterface;
1818
use GuzzleHttp\Exception\ConnectException;
1919
use GuzzleHttp\Exception\GuzzleException;
2020
use GuzzleHttp\Exception\RequestException;
2121
use GuzzleHttp\Psr7\Request;
2222
use GuzzleHttp\RequestOptions;
23+
use Symfony\Component\Serializer\Encoder\JsonEncoder;
24+
use Symfony\Component\Serializer\Exception\ExceptionInterface;
25+
use Symfony\Component\Serializer\SerializerInterface;
2326
use Hostinger\ApiException;
2427
use Hostinger\Configuration;
25-
use Hostinger\HeaderSelector;
2628
use Hostinger\ObjectSerializer;
2729

2830
class BillingCatalogApi
@@ -31,16 +33,15 @@ class BillingCatalogApi
3133

3234
protected Configuration $config;
3335

34-
protected HeaderSelector $headerSelector;
36+
protected SerializerInterface $serializer;
3537

3638
public function __construct(
37-
?ClientInterface $client = null,
3839
?Configuration $config = null,
39-
?HeaderSelector $selector = null,
40+
?ClientInterface $client = null,
4041
) {
41-
$this->client = $client ?: new Client();
4242
$this->config = $config ?: Configuration::getDefaultConfiguration();
43-
$this->headerSelector = $selector ?: new HeaderSelector();
43+
$this->client = $client ?: new Client();
44+
$this->serializer = ObjectSerializer::getSerializer();
4445
}
4546

4647
public function getConfig(): Configuration
@@ -49,83 +50,68 @@ public function getConfig(): Configuration
4950
}
5051

5152
/**
52-
* Operation getCatalogItemListV1
53-
*
54-
* Get catalog item list
55-
*
56-
* @return \Hostinger\Model\BillingV1CatalogCatalogItemCollection|\Hostinger\Model\InlineObject1|\Hostinger\Model\InlineObject
57-
* @throws ApiException on non-2xx response or if the response body is not in the expected format
58-
* @throws InvalidArgumentException
59-
* @throws GuzzleException
60-
*/
61-
public function getCatalogItemListV1(?string $category = null, ?string $name = null, ): \Hostinger\Model\BillingV1CatalogCatalogItemCollection|\Hostinger\Model\InlineObject1|\Hostinger\Model\InlineObject
53+
* @throws ExceptionInterface
54+
* @throws ApiException
55+
* @throws GuzzleException
56+
*/
57+
public function getCatalogItemListV1(?string $category = null, ?string $name = null): \Hostinger\Model\BillingV1CatalogCatalogItemCollection
6258
{
63-
$request = $this->getCatalogItemListV1Request($category, $name, );
59+
$query = http_build_query(
60+
array_filter([
61+
'category' => $category,
62+
])
63+
);
64+
65+
$query = http_build_query(
66+
array_filter([
67+
', '
68+
'name' => $name,
69+
])
70+
);
71+
72+
$request = new Request(
73+
method: 'GET',
74+
uri: '/api/billing/v1/catalog' . $query . $query,
75+
headers: $this->getHeaders(),
76+
);
6477

6578
try {
6679
$response = $this->client->send($request, $this->createHttpClientOption());
6780
} catch (RequestException $e) {
68-
if ($this->config->shouldThrowException()) {
69-
throw ApiException::fromRequestException($e);
70-
} else {
71-
$response = $e->getResponse();
72-
}
81+
throw ApiException::fromRequestException($e);
7382
} catch (ConnectException $e) {
7483
throw ApiException::fromConnectException($e);
7584
}
7685

77-
$statusCode = $response->getStatusCode();
78-
$returnType = null;
79-
80-
switch ($statusCode) {
81-
case 200:
82-
$returnType = '\Hostinger\Model\BillingV1CatalogCatalogItemCollection';
83-
break;
84-
case 401:
85-
$returnType = '\Hostinger\Model\InlineObject1';
86-
break;
87-
case 500:
88-
$returnType = '\Hostinger\Model\InlineObject';
89-
break;
86+
return $this->serializer->deserialize($response->getBody()->getContents(), \Hostinger\Model\BillingV1CatalogCatalogItemCollection::class, JsonEncoder::FORMAT);
87+
}
88+
89+
private function buildResourcePath(string $path, ...$values): string
90+
{
91+
foreach ($values as $value) {
92+
if (is_array($value)) {
93+
$value = implode(',', $value);
94+
}
95+
96+
$path = str_replace('{' . 'BillingCatalog' . '}', $value, $path);
9097
}
9198

92-
return ObjectSerializer::deserialize($response->getBody()->getContents(), $returnType);
99+
return $path;
93100
}
94101

95102
/**
96-
* Create request for operation 'getCatalogItemListV1'
97-
*
98-
* @throws InvalidArgumentException
103+
* @return array<string, string>
99104
*/
100-
protected function getCatalogItemListV1Request(?string $category = null,?string $name = null,): Request
105+
private function getHeaders(): array
101106
{
102-
$resourcePath = '/api/billing/v1/catalog';
103-
104-
$body = null;
105-
$query = ObjectSerializer::toQueryValue(
106-
$category,
107-
'category', // param base name
108-
'string', // openApiType
109-
'form', // style
110-
true, // explode
111-
false // required
112-
);
113-
$query = ObjectSerializer::toQueryValue(
114-
$name,
115-
'name', // param base name
116-
'string', // openApiType
117-
'form', // style
118-
true, // explode
119-
false // required
120-
);
121-
122-
return $this->buildRequest('GET', $resourcePath, $body, $query);
107+
return [
108+
'Authorization' => 'Bearer ' . $this->config->getAccessToken(),
109+
'Content-Type' => 'application/json',
110+
'User-Agent' => $this->config->getUserAgent(),
111+
];
123112
}
124113

125-
/**
126-
* @return array<string, mixed>
127-
*/
128-
protected function createHttpClientOption(): array
114+
private function createHttpClientOption(): array
129115
{
130116
$options = [];
131117
if ($this->config->getDebug()) {
@@ -137,36 +123,4 @@ protected function createHttpClientOption(): array
137123

138124
return $options;
139125
}
140-
141-
/**
142-
* @param array<string, string> $query
143-
*/
144-
protected function buildRequest(
145-
string $httpMethod,
146-
string $resourcePath,
147-
?string $body = null,
148-
array $query = [],
149-
string $contentType = 'application/json',
150-
): Request {
151-
$headers = $this->headerSelector->selectHeaders(
152-
accept: ['application/json'],
153-
contentType: $contentType,
154-
isMultipart: false
155-
);
156-
$headers['User-Agent'] = $this->config->getUserAgent();
157-
158-
// this endpoint requires Bearer authentication (access token)
159-
if (!empty($this->config->getAccessToken())) {
160-
$headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
161-
}
162-
163-
$query = ObjectSerializer::buildQuery($query);
164-
165-
return new Request(
166-
$httpMethod,
167-
$this->config->getHost() . $resourcePath . ($query ? "?$query" : ''),
168-
$headers,
169-
$body
170-
);
171-
}
172126
}

0 commit comments

Comments
 (0)