Skip to content

Commit 140316a

Browse files
author
Rik Morskate
committed
Added support for multiple api keys and secrets
1 parent fb39901 commit 140316a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Sendcloud.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ class Sendcloud implements SendcloudContract
1212
{
1313
private bool $verbose = false;
1414

15+
public function __construct(
16+
private ?string $apiKey = null,
17+
private ?string $apiSecret = null
18+
)
19+
{
20+
$this->apiKey ??= config('sendcloud.key');
21+
$this->apiSecret ??= $this->apiSecret ?? config('sendcloud.secret');
22+
}
23+
1524
public function getParcels(array $optionalParameters = []): array
1625
{
1726
$endpoint = self::PARCELS_ENDPOINT;
@@ -58,7 +67,7 @@ public function shippingMethods(array $optionalParameters = []): array
5867

5968
public function download(string $url): string
6069
{
61-
$response = Http::withBasicAuth(config('sendcloud.key'), config('sendcloud.secret'))
70+
$response = Http::withBasicAuth($this->apiKey, $this->apiSecret)
6271
->get($url);
6372

6473
$response->throw();
@@ -75,7 +84,7 @@ public function verbose(bool $verbose = true): self
7584

7685
private function request(string $method, string $endpoint, array $data = [], bool $throwException = true, array $query = []): array
7786
{
78-
$request = Http::withBasicAuth(config('sendcloud.key'), config('sendcloud.secret'));
87+
$request = Http::withBasicAuth($this->apiKey, $this->apiSecret);
7988

8089
if ($this->verbose) {
8190
$query['errors'] ??= 'verbose-carrier';

0 commit comments

Comments
 (0)