Skip to content

Commit

Permalink
Merge pull request #6 from deliciousbrains/3-client-user-agent
Browse files Browse the repository at this point in the history
Updating user agent for all cli requests
  • Loading branch information
A5hleyRich authored Dec 1, 2021
2 parents ea6a007 + 63930fa commit 70f3bbf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
25 changes: 10 additions & 15 deletions app/Commands/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,16 @@ public function handle(): int

try {
if (!$this->spinupwp->hasApiKey()) {
$this->spinupwp->setApiKey($this->apiToken())->setClient();
}
// allow to use a different API URL
if (!empty($this->config->get('api_url', $this->profile()))) {
$this->spinupwp->setClient(
new Client([
'base_uri' => $this->config->get('api_url', $this->profile()),
'http_errors' => false,
'headers' => [
'Authorization' => "Bearer {$this->config->get('api_token', $this->profile())}",
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
])
);
$this->spinupwp->setClient(new Client([
'base_uri' => $this->config->get('api_url', $this->profile(), 'https://api.spinupwp.app/v1/'),
'http_errors' => false,
'headers' => [
'Authorization' => "Bearer {$this->apiToken()}",
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'User-Agent' => 'SpinupWP/' . config('app.version'),
],
]));
}

$this->format($this->action());
Expand Down
8 changes: 4 additions & 4 deletions app/Helpers/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ public function isConfigured(): bool
return file_exists($this->configFilePath());
}

public function get(string $key, string $profile = 'default'): string
public function get(string $key, string $profile = 'default', string $default = ''): string
{
$this->config = $this->readConfig();
if (empty($this->config)) {
return '';
return $default;
}

if (!$this->teamExists($profile)) {
return '';
return $default;
}

$profileConfig = $this->config[$profile];

if (!isset($profileConfig[$key])) {
return '';
return $default;
}

return $profileConfig[$key];
Expand Down

0 comments on commit 70f3bbf

Please sign in to comment.