Skip to content

Commit eaaf8ee

Browse files
authored
Merge pull request #450 from ptmcnally/244-licenses-client
244 licenses client
2 parents 3203c49 + 0da802b commit eaaf8ee

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

src/Licenses/Client.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace UKFast\SDK\Licenses;
4+
5+
use UKFast\SDK\Client as BaseClient;
6+
7+
class Client extends BaseClient
8+
{
9+
protected $basePath = 'licenses/';
10+
11+
/**
12+
* @return BaseClient
13+
*/
14+
public function licenses()
15+
{
16+
return (new LicensesClient($this->httpClient))->auth($this->token);
17+
}
18+
}

src/Licenses/Entities/Key.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace UKFast\SDK\Licenses\Entities;
4+
5+
use UKFast\SDK\Entity;
6+
7+
/**
8+
* @property string $key
9+
*/
10+
class Key extends Entity
11+
{
12+
}

src/Licenses/Entities/License.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace UKFast\SDK\Licenses\Entities;
4+
5+
use UKFast\SDK\Entity;
6+
7+
/**
8+
* @property int $id
9+
* @property string $ownerId
10+
* @property string $ownerType
11+
* @property string $keyId
12+
* @property string $licenseType
13+
* @property int $resellerId
14+
*/
15+
class License extends Entity
16+
{
17+
}

src/Licenses/LicensesClient.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace UKFast\SDK\Licenses;
4+
5+
use UKFast\SDK\Entities\ClientEntityInterface;
6+
use UKFast\SDK\Licenses\Entities\Key;
7+
use UKFast\SDK\Licenses\Entities\License;
8+
use UKFast\SDK\Traits\PageItems;
9+
10+
class LicensesClient extends Client implements ClientEntityInterface
11+
{
12+
use PageItems;
13+
14+
protected $collectionPath = 'v1/licenses';
15+
16+
public function loadEntity($data)
17+
{
18+
return new License(
19+
$this->apiToFriendly($data, $this->getEntityMap())
20+
);
21+
}
22+
23+
public function getEntityMap()
24+
{
25+
return [
26+
'id' => 'id',
27+
'owner_id' => 'name',
28+
'owner_type' => 'ownerType',
29+
'key_id' => 'keyId',
30+
'license_type' => 'licenseType',
31+
'reseller_id' => 'resellerId',
32+
];
33+
}
34+
35+
/**
36+
* Revoke a license
37+
* @param int $id
38+
* @return bool
39+
*/
40+
public function revoke($id)
41+
{
42+
$response = $this->post($this->collectionPath . '/' . $id . '/revoke');
43+
return $response->getStatusCode() == 204;
44+
}
45+
46+
/**
47+
* Get a license key
48+
* @param $id
49+
* @return Key
50+
*/
51+
public function key($id)
52+
{
53+
$response = $this->get($this->collectionPath . '/' . $id . '/key');
54+
$body = $this->decodeJson($response->getBody()->getContents());
55+
56+
return new Key(
57+
$this->apiToFriendly($body->data, ['key' => 'key'])
58+
);
59+
}
60+
}

0 commit comments

Comments
 (0)