Skip to content

Commit

Permalink
Merge pull request #2 from RandomWeasel/patch-1
Browse files Browse the repository at this point in the history
Allow Harvest API Credentials be added after initialisation
  • Loading branch information
djam90 authored Oct 31, 2018
2 parents 70d33b1 + 8f5ba1d commit a4216ed
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Api/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function __construct()
$this->token = config('harvest.personal_access_token');
$this->account_id = config('harvest.account_id');

if (! $this->hasCredentials()) {
throw new Exception('Credentials not found, please ensure you published the package config file with artisan vendor:publish');
}
// if (! $this->hasCredentials()) {
// throw new Exception('Credentials not found, please ensure you published the package config file with artisan vendor:publish');
// }

$apiClient = new Client([
'headers' => [
Expand All @@ -44,8 +44,17 @@ public function getWithoutBase($uri, $data = null)

public function get($uri, $data = null)
{
//explicitly pass the headers here
//this accounts for a case where the harvest credentials weren't set when __construct was run
//or where they have since been updated

$response = $this->apiClient->request('GET', $this->uri . $uri, [
'json' => $data
'json' => $data,
'headers' => [
'Authorization' => 'Bearer ' . config('harvest.personal_access_token'),
'Harvest-Account-Id' => config('harvest.account_id'),
'User-Agent' => 'Harvest API App'
]
]);

return $this->transformResponse($response);
Expand Down Expand Up @@ -87,4 +96,4 @@ public function transformResponse($response)
{
return (new Response($response))->toObject();
}
}
}

0 comments on commit a4216ed

Please sign in to comment.