Skip to content

Commit

Permalink
adjusted how we handle custom urls
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislarsen committed Aug 24, 2024
1 parent f48561c commit 00ad4da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
6 changes: 2 additions & 4 deletions src/MakesHttpRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ public function put(string $uri, array $payload = []): mixed
/**
* Send a DELETE request to VanguardBackup API and return the response.
*
* @param string $uri
*
* @throws Exception|GuzzleException
* @throws GuzzleException
*/
public function delete($uri, array $payload = []): mixed
public function delete(string $uri, array $payload = []): mixed
{
return $this->request('DELETE', $uri, $payload);
}
Expand Down
28 changes: 15 additions & 13 deletions src/VanguardClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,22 @@ class VanguardClient
/**
* The base URL for the VanguardBackup API.
*/
protected string $baseUrl = 'https://app.vanguardbackup.com/api/';
protected string $baseUrl = 'https://app.vanguardbackup.com';

/**
* Create a new VanguardClient instance.
*
* @return void
*/
public function __construct(?string $apiKey = null, ?string $baseUrl = null, ?HttpClient $httpClient = null)
{
if (! is_null($baseUrl)) {
if ($baseUrl !== null) {
$this->setBaseUrl($baseUrl);
}

if (! is_null($apiKey)) {
if ($apiKey !== null) {
$this->setApiKey($apiKey, $httpClient);
}

if (! is_null($httpClient)) {
if ($httpClient !== null) {
$this->httpClient = $httpClient;
}
}
Expand All @@ -65,18 +63,16 @@ protected function transformCollection(array $collection, string $class, array $

/**
* Set the API key and set up the HTTP client.
*
* @return $this
*/
public function setApiKey(string $apiKey, ?HttpClient $httpClient = null): static
{
$this->apiKey = $apiKey;

$this->httpClient = $httpClient ?: new HttpClient([
'base_uri' => $this->baseUrl,
$this->httpClient = $httpClient ?? new HttpClient([
'base_uri' => $this->getApiUrl(),
'http_errors' => false,
'headers' => [
'Authorization' => 'Bearer '.$this->apiKey,
'Authorization' => "Bearer {$this->apiKey}",
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
Expand All @@ -87,8 +83,6 @@ public function setApiKey(string $apiKey, ?HttpClient $httpClient = null): stati

/**
* Set the base URL for the VanguardBackup API.
*
* @return $this
*/
public function setBaseUrl(string $url): static
{
Expand All @@ -105,6 +99,14 @@ public function getBaseUrl(): string
return $this->baseUrl;
}

/**
* Get the full API URL, including the '/api/' path.
*/
public function getApiUrl(): string
{
return "{$this->baseUrl}/api";
}

/**
* Get an authenticated user instance.
*/
Expand Down

0 comments on commit 00ad4da

Please sign in to comment.