diff --git a/app/Commands/BaseCommand.php b/app/Commands/BaseCommand.php index 45d1d21..b5d1eff 100644 --- a/app/Commands/BaseCommand.php +++ b/app/Commands/BaseCommand.php @@ -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()); diff --git a/app/Helpers/Configuration.php b/app/Helpers/Configuration.php index 5e60641..621f812 100644 --- a/app/Helpers/Configuration.php +++ b/app/Helpers/Configuration.php @@ -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];