Skip to content

Commit fee06f0

Browse files
authored
Merge pull request #14 from SkillDisplay/organisation
Added new Entities (Organisation, MemberSkills and SkillSetProgress)
2 parents d4bc19d + a6756cc commit fee06f0

23 files changed

+1063
-118
lines changed

src/Api/Campaigns.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@
3131

3232
class Campaigns
3333
{
34-
/**
35-
* @var Settings
36-
*/
37-
protected $settings;
34+
protected Settings $settings;
3835

39-
/**
40-
* @var Client
41-
*/
42-
protected $client;
36+
protected Client $client;
4337

4438
public function __construct(
4539
Settings $settings,

src/Api/MemberSkills.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SkillDisplay\PHPToolKit\Api;
6+
7+
use GuzzleHttp\Client;
8+
use GuzzleHttp\Exception\ClientException;
9+
use GuzzleHttp\Exception\GuzzleException;
10+
use SkillDisplay\PHPToolKit\Configuration\Settings;
11+
use GuzzleHttp\Psr7\Request;
12+
use SkillDisplay\PHPToolKit\Entity\Campaign;
13+
use SkillDisplay\PHPToolKit\Entity\MemberSkill;
14+
use SkillDisplay\PHPToolKit\Entity\MemberSkill as Entity;
15+
16+
class MemberSkills
17+
{
18+
protected Settings $settings;
19+
20+
protected Client $client;
21+
22+
public function __construct(
23+
Settings $settings,
24+
Client $client
25+
) {
26+
$this->settings = $settings;
27+
$this->client = $client;
28+
}
29+
30+
public function getMemberSkillsById(int $id)
31+
{
32+
if ($id <= 0) {
33+
throw new \Exception('ID of Organisation has to be a positive integer.');
34+
}
35+
$url = $this->settings->getAPIUrl() . '/api/v1/organisation/' . $id . '/listVerifications/json';
36+
try {
37+
$result = $this->client->send(new Request(
38+
'GET',
39+
$url,
40+
[
41+
'Content-Type' => 'application/json',
42+
'x-api-key' => $this->settings->getApiKey()
43+
]
44+
));
45+
} catch (ClientException $e) {
46+
if ($e->getCode() === 404) {
47+
throw new \InvalidArgumentException('Given Organisation with id "' . $id . '" not available.', 1601881616);
48+
}
49+
throw $e;
50+
}
51+
52+
if ($result->getStatusCode() !== 200) {
53+
throw new \Exception('Did not get proper response for Organisation.', 1600693562);
54+
}
55+
56+
$body = (string) $result->getBody();
57+
58+
if (strpos($body, 'Oops, an error occurred') !== false) {
59+
throw new \Exception('Did not get proper response for Organisation. Organisation with id "' . $id . '" does probably not exist.', 1600694312);
60+
}
61+
62+
$body = json_decode((string) $result->getBody(), true);
63+
$skills = [];
64+
foreach ($body as $skill) {
65+
$skills[] = Entity::createFromJson(json_encode($skill), $this->settings);
66+
}
67+
return $skills;
68+
}
69+
}

src/Api/Organisation.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SkillDisplay\PHPToolKit\Api;
6+
7+
use GuzzleHttp\Client;
8+
use GuzzleHttp\Exception\ClientException;
9+
use GuzzleHttp\Exception\GuzzleException;
10+
use SkillDisplay\PHPToolKit\Configuration\Settings;
11+
use GuzzleHttp\Psr7\Request;
12+
use SkillDisplay\PHPToolKit\Entity\Organisation as Entity;
13+
14+
class Organisation
15+
{
16+
protected Settings $settings;
17+
18+
protected Client $client;
19+
20+
public function __construct(
21+
Settings $settings,
22+
Client $client
23+
) {
24+
$this->settings = $settings;
25+
$this->client = $client;
26+
}
27+
28+
public function getStatisticById(int $id)
29+
{
30+
if ($id <= 0) {
31+
throw new \Exception('ID of Organisation has to be a positive integer.');
32+
}
33+
$url = $this->settings->getAPIUrl() . '/api/v1/organisation/' . $id . '/statistic';
34+
try {
35+
$result = $this->client->send(new Request(
36+
'GET',
37+
$url,
38+
[
39+
'Content-Type' => 'application/json',
40+
'x-api-key' => $this->settings->getApiKey()
41+
]
42+
));
43+
} catch (ClientException $e) {
44+
if ($e->getCode() === 404) {
45+
throw new \InvalidArgumentException('Given Organisation with id "' . $id . '" not available.', 1601881616);
46+
}
47+
throw $e;
48+
}
49+
50+
if ($result->getStatusCode() !== 200) {
51+
throw new \Exception('Did not get proper response for Organisation.', 1600693562);
52+
}
53+
54+
$body = (string) $result->getBody();
55+
56+
if (strpos($body, 'Oops, an error occurred') !== false) {
57+
throw new \Exception('Did not get proper response for Organisation. Organisation with id "' . $id . '" does probably not exist.', 1600694312);
58+
}
59+
return Entity::createFromJson($body, $this->settings);
60+
}
61+
}

src/Api/Skill.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@
3131

3232
class Skill
3333
{
34-
/**
35-
* @var Settings
36-
*/
37-
protected $settings;
34+
protected Settings $settings;
3835

39-
/**
40-
* @var Client
41-
*/
42-
protected $client;
36+
protected Client $client;
4337

4438
public function __construct(
4539
Settings $settings,

src/Api/SkillSet.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@
3131

3232
class SkillSet
3333
{
34-
/**
35-
* @var Settings
36-
*/
37-
protected $settings;
34+
protected Settings $settings;
3835

39-
/**
40-
* @var Client
41-
*/
42-
protected $client;
36+
protected Client $client;
4337

4438
public function __construct(
4539
Settings $settings,

src/Api/SkillSetProgress.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SkillDisplay\PHPToolKit\Api;
6+
7+
/*
8+
* Copyright (C) 2023 Julian Zangl <julian.zangl@outlook.com>
9+
*
10+
* This program is free software; you can redistribute it and/or
11+
* modify it under the terms of the GNU General Public License
12+
* as published by the Free Software Foundation; either version 2
13+
* of the License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program; if not, write to the Free Software
22+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23+
* 02110-1301, USA.
24+
*/
25+
26+
use GuzzleHttp\Client;
27+
use GuzzleHttp\Exception\ClientException;
28+
use GuzzleHttp\Psr7\Request;
29+
use SkillDisplay\PHPToolKit\Configuration\Settings;
30+
use SkillDisplay\PHPToolKit\Entity\SkillSetProgress as Entity;
31+
32+
class SkillSetProgress
33+
{
34+
protected Settings $settings;
35+
protected Client $client;
36+
37+
public function __construct(
38+
Settings $settings,
39+
Client $client
40+
) {
41+
$this->settings = $settings;
42+
$this->client = $client;
43+
}
44+
45+
public function getById(int $id): Entity
46+
{
47+
if ($id <= 0) {
48+
throw new \Exception('ID of SkillSet has to be a positive integer.', 1688639724754);
49+
}
50+
51+
$url = $this->settings->getAPIUrl() . '/api/v1/skillset/' . $id . '/progress';
52+
try {
53+
$result = $this->client->send(new Request(
54+
'GET',
55+
$url,
56+
[
57+
'Content-Type' => 'application/json',
58+
'x-api-key' => $this->settings->getApiKey()
59+
]
60+
));
61+
} catch (ClientException $e) {
62+
if ($e->getCode() === 404) {
63+
throw new \InvalidArgumentException('Given SkillSet with id "' . $id . '" not available.', 1688639748718);
64+
}
65+
throw $e;
66+
}
67+
68+
if ($result->getStatusCode() !== 200) {
69+
throw new \Exception('Did not get proper response for SkillSetProgress.', 1688639840720);
70+
}
71+
72+
$body = (string) $result->getBody();
73+
74+
if (strpos($body, 'Oops, an error occurred') !== false) {
75+
throw new \Exception('Did not get proper response for SkillSetProgress. SkillSet with id "' . $id . '" does probably not exist.', 1688639873065);
76+
}
77+
78+
return Entity::createFromJson($body, $this->settings);
79+
}
80+
}

src/Configuration/Settings.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,15 @@
66

77
class Settings
88
{
9-
/**
10-
* @var string
11-
*/
12-
private $user_secret = '';
9+
private string $user_secret = '';
1310

14-
/**
15-
* @var string
16-
*/
17-
private $apiKey = '';
11+
private string $apiKey = '';
1812

19-
/**
20-
* @var int
21-
*/
22-
private $verifierID = 0;
13+
private int $verifierID = 0;
2314

24-
/**
25-
* @var string
26-
*/
27-
private $APIUrl = '';
15+
private string $APIUrl = '';
2816

29-
/**
30-
* @var string
31-
*/
32-
private $mySkillDisplayUrl = '';
17+
private string $mySkillDisplayUrl = '';
3318

3419
public function getVerifierID(): int
3520
{

src/Entity/Brand.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@
2727

2828
class Brand
2929
{
30-
/**
31-
* @var array
32-
*/
33-
private $data;
30+
private array $data;
3431

35-
/**
36-
* @var Settings
37-
*/
38-
private $settings;
32+
private Settings $settings;
3933

4034
private function __construct(array $data, Settings $settings)
4135
{

src/Entity/Campaign.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@
2727

2828
class Campaign
2929
{
30-
/**
31-
* @var array
32-
*/
33-
private $data;
30+
private array $data;
3431

35-
/**
36-
* @var Settings
37-
*/
38-
private $settings;
32+
private Settings $settings;
3933

4034
public function __construct(array $data, Settings $settings)
4135
{

0 commit comments

Comments
 (0)