Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/Api/Campaigns.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,9 @@

class Campaigns
{
/**
* @var Settings
*/
protected $settings;
protected Settings $settings;

/**
* @var Client
*/
protected $client;
protected Client $client;

public function __construct(
Settings $settings,
Expand Down
69 changes: 69 additions & 0 deletions src/Api/MemberSkills.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace SkillDisplay\PHPToolKit\Api;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
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
{
protected Settings $settings;

protected Client $client;

public function __construct(
Settings $settings,
Client $client
) {
$this->settings = $settings;
$this->client = $client;
}

public function getMemberSkillsById(int $id)
{
if ($id <= 0) {
throw new \Exception('ID of Organisation has to be a positive integer.');
}
$url = $this->settings->getAPIUrl() . '/api/v1/organisation/' . $id . '/listVerifications/json';
try {
$result = $this->client->send(new Request(
'GET',
$url,
[
'Content-Type' => 'application/json',
'x-api-key' => $this->settings->getApiKey()
]
));
} catch (ClientException $e) {
if ($e->getCode() === 404) {
throw new \InvalidArgumentException('Given Organisation with id "' . $id . '" not available.', 1601881616);
}
throw $e;
}

if ($result->getStatusCode() !== 200) {
throw new \Exception('Did not get proper response for Organisation.', 1600693562);
}

$body = (string) $result->getBody();

if (strpos($body, 'Oops, an error occurred') !== false) {
throw new \Exception('Did not get proper response for Organisation. Organisation with id "' . $id . '" does probably not exist.', 1600694312);
}

$body = json_decode((string) $result->getBody(), true);
$skills = [];
foreach ($body as $skill) {
$skills[] = Entity::createFromJson(json_encode($skill), $this->settings);
}
return $skills;
}
}
61 changes: 61 additions & 0 deletions src/Api/Organisation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace SkillDisplay\PHPToolKit\Api;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
use SkillDisplay\PHPToolKit\Configuration\Settings;
use GuzzleHttp\Psr7\Request;
use SkillDisplay\PHPToolKit\Entity\Organisation as Entity;

class Organisation
{
protected Settings $settings;

protected Client $client;

public function __construct(
Settings $settings,
Client $client
) {
$this->settings = $settings;
$this->client = $client;
}

public function getStatisticById(int $id)
{
if ($id <= 0) {
throw new \Exception('ID of Organisation has to be a positive integer.');
}
$url = $this->settings->getAPIUrl() . '/api/v1/organisation/' . $id . '/statistic';
try {
$result = $this->client->send(new Request(
'GET',
$url,
[
'Content-Type' => 'application/json',
'x-api-key' => $this->settings->getApiKey()
]
));
} catch (ClientException $e) {
if ($e->getCode() === 404) {
throw new \InvalidArgumentException('Given Organisation with id "' . $id . '" not available.', 1601881616);
}
throw $e;
}

if ($result->getStatusCode() !== 200) {
throw new \Exception('Did not get proper response for Organisation.', 1600693562);
}

$body = (string) $result->getBody();

if (strpos($body, 'Oops, an error occurred') !== false) {
throw new \Exception('Did not get proper response for Organisation. Organisation with id "' . $id . '" does probably not exist.', 1600694312);
}
return Entity::createFromJson($body, $this->settings);
}
}
10 changes: 2 additions & 8 deletions src/Api/Skill.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,9 @@

class Skill
{
/**
* @var Settings
*/
protected $settings;
protected Settings $settings;

/**
* @var Client
*/
protected $client;
protected Client $client;

public function __construct(
Settings $settings,
Expand Down
10 changes: 2 additions & 8 deletions src/Api/SkillSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,9 @@

class SkillSet
{
/**
* @var Settings
*/
protected $settings;
protected Settings $settings;

/**
* @var Client
*/
protected $client;
protected Client $client;

public function __construct(
Settings $settings,
Expand Down
80 changes: 80 additions & 0 deletions src/Api/SkillSetProgress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

namespace SkillDisplay\PHPToolKit\Api;

/*
* Copyright (C) 2023 Julian Zangl <julian.zangl@outlook.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Psr7\Request;
use SkillDisplay\PHPToolKit\Configuration\Settings;
use SkillDisplay\PHPToolKit\Entity\SkillSetProgress as Entity;

class SkillSetProgress
{
protected Settings $settings;
protected Client $client;

public function __construct(
Settings $settings,
Client $client
) {
$this->settings = $settings;
$this->client = $client;
}

public function getById(int $id): Entity
{
if ($id <= 0) {
throw new \Exception('ID of SkillSet has to be a positive integer.', 1688639724754);
}

$url = $this->settings->getAPIUrl() . '/api/v1/skillset/' . $id . '/progress';
try {
$result = $this->client->send(new Request(
'GET',
$url,
[
'Content-Type' => 'application/json',
'x-api-key' => $this->settings->getApiKey()
]
));
} catch (ClientException $e) {
if ($e->getCode() === 404) {
throw new \InvalidArgumentException('Given SkillSet with id "' . $id . '" not available.', 1688639748718);
}
throw $e;
}

if ($result->getStatusCode() !== 200) {
throw new \Exception('Did not get proper response for SkillSetProgress.', 1688639840720);
}

$body = (string) $result->getBody();

if (strpos($body, 'Oops, an error occurred') !== false) {
throw new \Exception('Did not get proper response for SkillSetProgress. SkillSet with id "' . $id . '" does probably not exist.', 1688639873065);
}

return Entity::createFromJson($body, $this->settings);
}
}
25 changes: 5 additions & 20 deletions src/Configuration/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,15 @@

class Settings
{
/**
* @var string
*/
private $user_secret = '';
private string $user_secret = '';

/**
* @var string
*/
private $apiKey = '';
private string $apiKey = '';

/**
* @var int
*/
private $verifierID = 0;
private int $verifierID = 0;

/**
* @var string
*/
private $APIUrl = '';
private string $APIUrl = '';

/**
* @var string
*/
private $mySkillDisplayUrl = '';
private string $mySkillDisplayUrl = '';

public function getVerifierID(): int
{
Expand Down
10 changes: 2 additions & 8 deletions src/Entity/Brand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@

class Brand
{
/**
* @var array
*/
private $data;
private array $data;

/**
* @var Settings
*/
private $settings;
private Settings $settings;

private function __construct(array $data, Settings $settings)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Entity/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@

class Campaign
{
/**
* @var array
*/
private $data;
private array $data;

/**
* @var Settings
*/
private $settings;
private Settings $settings;

public function __construct(array $data, Settings $settings)
{
Expand Down
Loading