Skip to content

Commit 362f468

Browse files
committed
use config values and setup $endpointPath
1 parent 36848e2 commit 362f468

File tree

4 files changed

+41
-101
lines changed

4 files changed

+41
-101
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "developerayo/fireblocks-laravel-sdk",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "A Laravel Package for Fireblocks",
55
"keywords": [
66
"developerayo",

config/fireblocks.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
'default_headers' => [],
1111
'temp_folder_path' => env('FIREBLOCKS_TEMP_FOLDER', null),
1212
'timeout' => env('FIREBLOCKS_TIMEOUT', 30),
13+
'connect_timeout' => env('FIREBLOCKS_CONNECT_TIMEOUT', 10),
14+
'verify_ssl' => env('FIREBLOCKS_VERIFY_SSL', true),
1315
'debug' => env('FIREBLOCKS_DEBUG', false),
1416
];

src/Client.php

Lines changed: 17 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ public function __construct(Config $config, ?ClientInterface $httpClient = null)
3030

3131
$this->httpClient = $httpClient ?? new GuzzleClient([
3232
'base_uri' => $config->getBasePath(),
33-
'timeout' => 30,
34-
'connect_timeout' => 10,
33+
'timeout' => $config->getTimeout(),
34+
'connect_timeout' => $config->getConnectTimeout(),
3535
'http_errors' => false,
36+
'verify' => $config->getVerifySSL(),
3637
]);
3738

3839
$this->defaultHeaders = [
@@ -79,11 +80,22 @@ public function makeRequest(
7980
$pathWithQuery .= '?' . http_build_query($queryParams);
8081
}
8182

82-
$token = $this->generateToken($method, $pathWithQuery, $requestBody);
83+
if ($endpointPath !== null) {
84+
$url = $endpointPath;
85+
if (!empty($queryParams)) {
86+
$url .= '?' . http_build_query($queryParams);
87+
}
88+
} else {
89+
$url = $this->config->getBasePath() . $pathWithQuery;
90+
}
91+
92+
$tokenPath = $endpointPath !== null
93+
? parse_url($endpointPath, PHP_URL_PATH) . (parse_url($endpointPath, PHP_URL_QUERY) ? '?' . parse_url($endpointPath, PHP_URL_QUERY) : '')
94+
: $pathWithQuery;
95+
96+
$token = $this->generateToken($method, $tokenPath, $requestBody);
8397
$headers['Authorization'] = 'Bearer ' . $token;
8498

85-
$url = $this->config->getBasePath() . $pathWithQuery;
86-
8799
$requestPayload = null;
88100
if ($requestBody !== null) {
89101
$requestPayload = is_string($requestBody) ? $requestBody : json_encode($requestBody);
@@ -118,31 +130,6 @@ public function getConfig(): Config
118130
return $this->config;
119131
}
120132

121-
public function buildAcceptHeader(array $accept): ?string
122-
{
123-
if (empty($accept)) {
124-
return null;
125-
}
126-
127-
if (in_array('application/json', $accept, true)) {
128-
return 'application/json';
129-
}
130-
131-
return implode(',', $accept);
132-
}
133-
134-
public function buildContentTypeHeader(array $contentTypes): string
135-
{
136-
if (empty($contentTypes)) {
137-
return 'application/json';
138-
}
139-
140-
if (in_array('application/json', $contentTypes, true)) {
141-
return 'application/json';
142-
}
143-
144-
return $contentTypes[0];
145-
}
146133

147134
/**
148135
* Generate JWT for api auth
@@ -236,74 +223,4 @@ private function handleApiError(int $statusCode, string $body, array $headers):
236223
}
237224
}
238225

239-
public static function sanitizeForSerialization($data)
240-
{
241-
if (is_scalar($data) || null === $data) {
242-
return $data;
243-
}
244-
245-
if ($data instanceof \DateTime) {
246-
return $data->format(\DateTime::ATOM);
247-
}
248-
249-
if (is_array($data)) {
250-
foreach ($data as $property => $value) {
251-
$data[$property] = self::sanitizeForSerialization($value);
252-
}
253-
return $data;
254-
}
255-
256-
if (is_object($data)) {
257-
$values = [];
258-
if ($data instanceof \JsonSerializable) {
259-
$values = $data->jsonSerialize();
260-
} else {
261-
$values = (array) $data;
262-
}
263-
foreach ($values as $property => $value) {
264-
$values[$property] = self::sanitizeForSerialization($value);
265-
}
266-
return $values;
267-
}
268-
269-
return (string) $data;
270-
}
271-
272-
public static function processFormData(array $formData, array $files = []): array
273-
{
274-
$processedData = [];
275-
276-
foreach ($formData as $name => $value) {
277-
if (is_array($value)) {
278-
foreach ($value as $item) {
279-
$processedData[] = [
280-
'name' => $name . '[]',
281-
'contents' => $item
282-
];
283-
}
284-
} else {
285-
$processedData[] = [
286-
'name' => $name,
287-
'contents' => $value
288-
];
289-
}
290-
}
291-
292-
foreach ($files as $name => $file) {
293-
if (is_array($file)) {
294-
$processedData[] = [
295-
'name' => $name,
296-
'contents' => $file['contents'] ?? '',
297-
'filename' => $file['filename'] ?? $name
298-
];
299-
} else {
300-
$processedData[] = [
301-
'name' => $name,
302-
'contents' => $file
303-
];
304-
}
305-
}
306-
307-
return $processedData;
308-
}
309226
}

src/Config.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class Config
1313
public bool $debug;
1414
public array $defaultHeaders;
1515
public ?string $tempFolderPath;
16+
public int $timeout;
17+
public int $connectTimeout;
18+
public bool $verifySSL;
1619

1720
// constants for base path
1821
public const SANDBOX = 'https://sandbox-api.fireblocks.io/v1';
@@ -31,6 +34,9 @@ public function __construct(array $config = [])
3134
$this->debug = $config['debug'] ?? config('app.debug', false);
3235
$this->defaultHeaders = $config['default_headers'] ?? [];
3336
$this->tempFolderPath = $config['temp_folder_path'] ?? null;
37+
$this->timeout = $config['timeout'] ?? config('fireblocks.timeout') ?? 30;
38+
$this->connectTimeout = $config['connect_timeout'] ?? config('fireblocks.connect_timeout') ?? 10;
39+
$this->verifySSL = $config['verify_ssl'] ?? config('fireblocks.verify_ssl') ?? true;
3440

3541
$this->validate();
3642
}
@@ -80,6 +86,21 @@ public function getTempFolderPath(): ?string
8086
return $this->tempFolderPath;
8187
}
8288

89+
public function getTimeout(): int
90+
{
91+
return $this->timeout;
92+
}
93+
94+
public function getConnectTimeout(): int
95+
{
96+
return $this->connectTimeout;
97+
}
98+
99+
public function getVerifySSL(): bool
100+
{
101+
return $this->verifySSL;
102+
}
103+
83104
public function setApiKey(string $apiKey): self
84105
{
85106
$this->apiKey = $apiKey;

0 commit comments

Comments
 (0)