-
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 'settingsAndRescueImageResource' into 'master'
Settings and rescue image resource See merge request transip/restapi-php-library!179
- Loading branch information
Showing
6 changed files
with
282 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Entity\Vps; | ||
|
||
use Transip\Api\Library\Entity\AbstractEntity; | ||
|
||
class RescueImage extends AbstractEntity | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
|
||
public $name; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
*/ | ||
public function setName(string $name): void | ||
{ | ||
$this->name = $name; | ||
} | ||
} |
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,92 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Entity\Vps; | ||
|
||
use Transip\Api\Library\Entity\AbstractEntity; | ||
|
||
class Setting extends AbstractEntity | ||
{ | ||
/** | ||
* @var string $name | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @var string $dataType | ||
*/ | ||
public $dataType; | ||
|
||
/** | ||
* @var bool $readOnly | ||
*/ | ||
public $readOnly; | ||
|
||
/** | ||
* @var SettingValue $value | ||
*/ | ||
public $value; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
*/ | ||
public function setName(string $name): void | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDataType(): string | ||
{ | ||
return $this->dataType; | ||
} | ||
|
||
/** | ||
* @param string $dataType | ||
*/ | ||
public function setDataType(string $dataType): void | ||
{ | ||
$this->dataType = $dataType; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isReadOnly(): bool | ||
{ | ||
return $this->readOnly; | ||
} | ||
|
||
/** | ||
* @param bool $readOnly | ||
*/ | ||
public function setReadOnly(bool $readOnly): void | ||
{ | ||
$this->readOnly = $readOnly; | ||
} | ||
|
||
/** | ||
* @return SettingValue | ||
*/ | ||
public function getValue(): SettingValue | ||
{ | ||
return $this->value; | ||
} | ||
|
||
/** | ||
* @param SettingValue $value | ||
*/ | ||
public function setValue(SettingValue $value): void | ||
{ | ||
$this->value = $value; | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Entity\Vps; | ||
|
||
use Transip\Api\Library\Entity\AbstractEntity; | ||
|
||
class SettingValue extends AbstractEntity | ||
{ | ||
/** | ||
* @var bool | ||
*/ | ||
public $valueBoolean; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $valueString; | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function getValueBoolean(): bool | ||
{ | ||
return $this->valueBoolean; | ||
} | ||
|
||
/** | ||
* @param bool $valueBoolean | ||
*/ | ||
public function setValueBoolean(bool $valueBoolean): void | ||
{ | ||
$this->valueBoolean = $valueBoolean; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getValueString(): string | ||
{ | ||
return $this->valueString; | ||
} | ||
|
||
/** | ||
* @param string $valueString | ||
*/ | ||
public function setValueString(string $valueString): void | ||
{ | ||
$this->valueString = $valueString; | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Repository\Vps; | ||
|
||
use Transip\Api\Library\Entity\Vps\RescueImage; | ||
use Transip\Api\Library\Repository\ApiRepository; | ||
use Transip\Api\Library\Repository\VpsRepository; | ||
|
||
class RescueImageRepository extends ApiRepository | ||
{ | ||
public const RESOURCE_NAME = 'rescue-images'; | ||
|
||
protected function getRepositoryResourceNames(): array | ||
{ | ||
return [VpsRepository::RESOURCE_NAME, self::RESOURCE_NAME]; | ||
} | ||
|
||
/** | ||
* @param string $vpsName | ||
* @return array | ||
*/ | ||
public function getByVpsName(string $vpsName): array | ||
{ | ||
$rescueImages = []; | ||
$response = $this->httpClient->get($this->getResourceUrl($vpsName)); | ||
$rescueImagesArray = $this->getParameterFromResponse($response, 'rescueImages'); | ||
|
||
foreach ($rescueImagesArray as $rescueImage) { | ||
$rescueImages[] = new RescueImage($rescueImage); | ||
} | ||
|
||
return $rescueImages; | ||
} | ||
|
||
/** | ||
* @param string $vpsName | ||
* @param string $rescueImageName | ||
* @return void | ||
*/ | ||
public function bootRescueImage(string $vpsName, string $rescueImageName): void | ||
{ | ||
$url = $this->getResourceUrl($vpsName); | ||
$this->httpClient->patch($url, ['name' => $rescueImageName]); | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Repository\Vps; | ||
|
||
use Transip\Api\Library\Entity\Vps\Setting; | ||
use Transip\Api\Library\Repository\ApiRepository; | ||
use Transip\Api\Library\Repository\VpsRepository; | ||
|
||
class SettingRepository extends ApiRepository | ||
{ | ||
public const RESOURCE_NAME = 'settings'; | ||
|
||
protected function getRepositoryResourceNames(): array | ||
{ | ||
return [VpsRepository::RESOURCE_NAME, self::RESOURCE_NAME]; | ||
} | ||
|
||
/** | ||
* @param string $vpsName | ||
* @return array | ||
*/ | ||
public function getByVpsName(string $vpsName): array | ||
{ | ||
$settings = []; | ||
$response = $this->httpClient->get($this->getResourceUrl($vpsName)); | ||
$settingArray = $this->getParameterFromResponse($response, 'settings'); | ||
|
||
foreach ($settingArray as $setting) { | ||
$settings[] = new Setting($setting); | ||
} | ||
|
||
return $settings; | ||
} | ||
|
||
/** | ||
* @param string $vpsName | ||
* @param string $settingName | ||
* @return void | ||
*/ | ||
public function getByVpsNameSettingName(string $vpsName, string $settingName): Setting | ||
{ | ||
$response = $this->httpClient->get($this->getResourceUrl($vpsName, $settingName)); | ||
$setting = $this->getParameterFromResponse($response, 'setting'); | ||
|
||
return new Setting($setting); | ||
} | ||
|
||
public function update(string $vpsName, Setting $setting): void | ||
{ | ||
$url = $this->getResourceUrl($vpsName, $setting->getName()); | ||
$this->httpClient->put($url, ['setting' => $setting]); | ||
} | ||
} |
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