-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'preinstallables-multi-licence-support' into 'master'
Added support for the License API end point See merge request transip/restapi-php-library!126
- Loading branch information
Showing
8 changed files
with
298 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
CHANGELOG | ||
========= | ||
|
||
6.6.0 | ||
----- | ||
* Added VPS license resource | ||
|
||
6.5.0 | ||
----- | ||
* Added isLocked property to HA-IP | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Entity\Vps; | ||
|
||
use Transip\Api\Library\Entity\AbstractEntity; | ||
|
||
class License extends AbstractEntity | ||
{ | ||
public const TYPE_ADDON = 'addon'; | ||
public const TYPE_OPERATING_SYSTEM = 'operating-system'; | ||
|
||
/** @var int */ | ||
protected $id; | ||
|
||
/** @var string */ | ||
protected $name; | ||
|
||
/** @var int */ | ||
protected $price; | ||
|
||
/** @var int */ | ||
protected $recurringPrice; | ||
|
||
/** @var string */ | ||
protected $type; | ||
|
||
/** @var int */ | ||
protected $quantity; | ||
|
||
/** @var int */ | ||
protected $maxQuantity; | ||
|
||
/** @var LicenseKey[] */ | ||
protected $keys; | ||
|
||
public function __construct(array $valueArray = []) | ||
{ | ||
parent::__construct($valueArray); | ||
|
||
$licenseKeysArray = $valueArray['keys'] ?? []; | ||
|
||
$licenseKeys = []; | ||
foreach ($licenseKeysArray as $licenseKey) { | ||
$licenseKeys[] = new LicenseKey($licenseKey); | ||
} | ||
$this->keys = $licenseKeys; | ||
} | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getPrice(): int | ||
{ | ||
return $this->price; | ||
} | ||
|
||
public function getRecurringPrice(): int | ||
{ | ||
return $this->recurringPrice; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getQuantity(): int | ||
{ | ||
return $this->quantity; | ||
} | ||
|
||
public function getMaxQuantity(): int | ||
{ | ||
return $this->maxQuantity; | ||
} | ||
|
||
public function getKeys(): array | ||
{ | ||
return $this->keys; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Entity\Vps; | ||
|
||
use Transip\Api\Library\Entity\AbstractEntity; | ||
|
||
class LicenseKey extends AbstractEntity | ||
{ | ||
/** @var string */ | ||
protected $name; | ||
|
||
/** @var string */ | ||
protected $key; | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getKey(): string | ||
{ | ||
return $this->key; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Entity\Vps; | ||
|
||
use Transip\Api\Library\Entity\AbstractEntity; | ||
|
||
class LicenseProduct extends AbstractEntity | ||
{ | ||
/** @var string */ | ||
protected $name; | ||
|
||
/** @var int */ | ||
protected $price; | ||
|
||
/** @var int */ | ||
protected $recurringPrice; | ||
|
||
/** @var string */ | ||
protected $type; | ||
|
||
/** @var int */ | ||
protected $maxQuantity; | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getPrice(): int | ||
{ | ||
return $this->price; | ||
} | ||
|
||
public function getRecurringPrice(): int | ||
{ | ||
return $this->recurringPrice; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getMaxQuantity(): int | ||
{ | ||
return $this->maxQuantity; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Entity\Vps; | ||
|
||
use Transip\Api\Library\Entity\AbstractEntity; | ||
|
||
class Licenses extends AbstractEntity | ||
{ | ||
/** @var License[] */ | ||
protected $active = []; | ||
|
||
/** @var License[] */ | ||
protected $cancellable = []; | ||
|
||
/** @var LicenseProduct[] */ | ||
protected $available = []; | ||
|
||
/** | ||
* @return License[] | ||
*/ | ||
public function getActive(): array | ||
{ | ||
return $this->active; | ||
} | ||
|
||
/** | ||
* @return License[] | ||
*/ | ||
public function getCancellable(): array | ||
{ | ||
return $this->cancellable; | ||
} | ||
|
||
/** | ||
* @return LicenseProduct[] | ||
*/ | ||
public function getAvailable(): array | ||
{ | ||
return $this->available; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Repository\Vps; | ||
|
||
use Transip\Api\Library\Entity\Vps\License; | ||
use Transip\Api\Library\Entity\Vps\LicenseProduct; | ||
use Transip\Api\Library\Entity\Vps\Licenses; | ||
use Transip\Api\Library\Repository\ApiRepository; | ||
use Transip\Api\Library\Repository\VpsRepository; | ||
|
||
class LicenseRepository extends ApiRepository | ||
{ | ||
public const RESOURCE_NAME = 'licenses'; | ||
|
||
protected function getRepositoryResourceNames(): array | ||
{ | ||
return [VpsRepository::RESOURCE_NAME, self::RESOURCE_NAME]; | ||
} | ||
|
||
public function getByVpsName(string $vpsName): Licenses | ||
{ | ||
$response = $this->httpClient->get($this->getResourceUrl($vpsName)); | ||
$licencesArray = $this->getParameterFromResponse($response, 'licenses'); | ||
|
||
$struct = []; | ||
foreach ($licencesArray as $licenseType => $licenses) { | ||
foreach ($licenses as $license) { | ||
if ($licenseType === 'available') { | ||
$struct[$licenseType][] = new LicenseProduct($license); | ||
continue; | ||
} | ||
|
||
$struct[$licenseType][] = new License($license); | ||
} | ||
} | ||
|
||
return new Licenses($struct); | ||
} | ||
|
||
public function order(string $vpsName, string $licenseName, int $quantity): void | ||
{ | ||
$parameters = [ | ||
'licenseName' => $licenseName, | ||
'quantity' => $quantity, | ||
]; | ||
|
||
$this->httpClient->post($this->getResourceUrl($vpsName), $parameters); | ||
} | ||
|
||
public function update(string $vpsName, int $licenseId, string $newLicenseName): void | ||
{ | ||
$this->httpClient->put($this->getResourceUrl($vpsName, $licenseId), ['newLicenseName' => $newLicenseName]); | ||
} | ||
|
||
public function cancel(string $vpsName, int $licenseId): void | ||
{ | ||
$this->httpClient->delete($this->getResourceUrl($vpsName, $licenseId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters