diff --git a/src/Api/Campaigns.php b/src/Api/Campaigns.php index 0fe1c24..42691b5 100644 --- a/src/Api/Campaigns.php +++ b/src/Api/Campaigns.php @@ -26,6 +26,7 @@ namespace SkillDisplay\PHPToolKit\Api; use GuzzleHttp\Client; use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Psr7\Request; +use InvalidArgumentException; use SkillDisplay\PHPToolKit\Configuration\Settings; use SkillDisplay\PHPToolKit\Entity\Campaign; @@ -45,6 +46,9 @@ class Campaigns public function getForUser(): array { + if (!$this->settings->getApiKey()) { + throw new InvalidArgumentException('Missing API key', 1688660942); + } $url = $this->settings->getAPIUrl() . '/api/v1/campaigns'; try { $result = $this->client->send(new Request( diff --git a/src/Api/MemberSkills.php b/src/Api/MemberSkills.php index ec2c7f6..1920c55 100644 --- a/src/Api/MemberSkills.php +++ b/src/Api/MemberSkills.php @@ -6,11 +6,9 @@ namespace SkillDisplay\PHPToolKit\Api; use GuzzleHttp\Client; use GuzzleHttp\Exception\ClientException; -use GuzzleHttp\Exception\GuzzleException; +use InvalidArgumentException; use SkillDisplay\PHPToolKit\Configuration\Settings; use GuzzleHttp\Psr7\Request; -use SkillDisplay\PHPToolKit\Entity\Campaign; -use SkillDisplay\PHPToolKit\Entity\MemberSkill; use SkillDisplay\PHPToolKit\Entity\MemberSkill as Entity; class MemberSkills @@ -32,6 +30,9 @@ class MemberSkills if ($id <= 0) { throw new \Exception('ID of Organisation has to be a positive integer.'); } + if (!$this->settings->getApiKey()) { + throw new InvalidArgumentException('Missing API key', 1688660942); + } $url = $this->settings->getAPIUrl() . '/api/v1/organisation/' . $id . '/listVerifications/json'; try { $result = $this->client->send(new Request( diff --git a/src/Api/Organisation.php b/src/Api/Organisation.php index 67e2bc1..bf65fdd 100644 --- a/src/Api/Organisation.php +++ b/src/Api/Organisation.php @@ -6,7 +6,7 @@ namespace SkillDisplay\PHPToolKit\Api; use GuzzleHttp\Client; use GuzzleHttp\Exception\ClientException; -use GuzzleHttp\Exception\GuzzleException; +use InvalidArgumentException; use SkillDisplay\PHPToolKit\Configuration\Settings; use GuzzleHttp\Psr7\Request; use SkillDisplay\PHPToolKit\Entity\Organisation as Entity; @@ -30,7 +30,10 @@ class Organisation if ($id <= 0) { throw new \Exception('ID of Organisation has to be a positive integer.'); } - $url = $this->settings->getAPIUrl() . '/api/v1/organisation/' . $id . '/statistic'; + if (!$this->settings->getApiKey()) { + throw new InvalidArgumentException('Missing API key', 1688660942); + } + $url = $this->settings->getAPIUrl() . '/api/v1/organisation/' . $id . '/statistics'; try { $result = $this->client->send(new Request( 'GET', diff --git a/src/Api/SkillSetProgress.php b/src/Api/SkillSetProgress.php index 788cb0a..14375a9 100644 --- a/src/Api/SkillSetProgress.php +++ b/src/Api/SkillSetProgress.php @@ -26,6 +26,7 @@ namespace SkillDisplay\PHPToolKit\Api; use GuzzleHttp\Client; use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Psr7\Request; +use InvalidArgumentException; use SkillDisplay\PHPToolKit\Configuration\Settings; use SkillDisplay\PHPToolKit\Entity\SkillSetProgress as Entity; @@ -47,7 +48,9 @@ class SkillSetProgress if ($id <= 0) { throw new \Exception('ID of SkillSet has to be a positive integer.', 1688639724754); } - + if (!$this->settings->getApiKey()) { + throw new InvalidArgumentException('Missing API key', 1688660942); + } $url = $this->settings->getAPIUrl() . '/api/v1/skillset/' . $id . '/progress'; try { $result = $this->client->send(new Request( @@ -60,7 +63,7 @@ class SkillSetProgress )); } catch (ClientException $e) { if ($e->getCode() === 404) { - throw new \InvalidArgumentException('Given SkillSet with id "' . $id . '" not available.', 1688639748718); + throw new InvalidArgumentException('Given SkillSet with id "' . $id . '" not available.', 1688639748718); } throw $e; }