-
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 'trafficPool' into 'master'
added trafficpool endpoint See merge request transip/restapi-php-library!139
- Loading branch information
Showing
5 changed files
with
156 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
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,117 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Entity; | ||
|
||
class TrafficPoolInformation extends AbstractEntity | ||
{ | ||
/** | ||
* @var string $startDate | ||
*/ | ||
protected $startDate; | ||
|
||
/** | ||
* @var string $endDate | ||
*/ | ||
protected $endDate; | ||
|
||
/** | ||
* @var int $usedInBytes | ||
*/ | ||
protected $usedInBytes; | ||
|
||
/** | ||
* @var int $usedTotalBytes | ||
*/ | ||
protected $usedTotalBytes; | ||
|
||
/** | ||
* @var int $maxInBytes | ||
*/ | ||
protected $maxInBytes; | ||
|
||
/** | ||
* @var int $expectedBytes | ||
*/ | ||
protected $expectedBytes; | ||
|
||
public function getStartDate(): string | ||
{ | ||
return $this->startDate; | ||
} | ||
|
||
public function getEndDate(): string | ||
{ | ||
return $this->endDate; | ||
} | ||
|
||
public function getUsedInBytes(): int | ||
{ | ||
return $this->usedInBytes; | ||
} | ||
|
||
public function getUsedOutBytes(): int | ||
{ | ||
return $this->getUsedTotalBytes() - $this->getUsedInBytes(); | ||
} | ||
|
||
public function getUsedTotalBytes(): int | ||
{ | ||
return $this->usedTotalBytes; | ||
} | ||
|
||
public function getMaxInBytes(): int | ||
{ | ||
return $this->maxInBytes; | ||
} | ||
|
||
public function getexpectedBytes(): int | ||
{ | ||
return $this->expectedBytes; | ||
} | ||
|
||
public function getUsedInMegabytes(): float | ||
{ | ||
return round($this->getUsedInBytes() / 1024, 2); | ||
} | ||
|
||
public function getUsedOutMegabytes(): int | ||
{ | ||
$usedInMegabytes = $this->getUsedInBytes() / 1024; | ||
$usedTotalMegabytes = $this->getUsedTotalBytes() / 1024; | ||
|
||
return round($usedTotalMegabytes - $usedInMegabytes, 2); | ||
} | ||
|
||
public function getUsedTotalMegabytes(): float | ||
{ | ||
return round($this->getUsedTotalBytes() / 1024, 2); | ||
} | ||
|
||
public function getMaxInMegabytes(): float | ||
{ | ||
return round($this->getMaxInBytes() / 1024, 2); | ||
} | ||
|
||
public function getUsedInGigabytes(): float | ||
{ | ||
return round($this->getUsedInBytes() / 1024 / 1024, 2); | ||
} | ||
|
||
public function getUsedOutGigabytes(): int | ||
{ | ||
$usedInGigabytes = $this->getUsedInBytes() / 1024 / 1024; | ||
$usedTotalGigabytes = $this->getUsedTotalBytes() / 1024 / 1024; | ||
|
||
return round($usedTotalGigabytes - $usedInGigabytes, 2); | ||
} | ||
|
||
public function getUsedTotalGigabytes(): float | ||
{ | ||
return round($this->getUsedTotalBytes() / 1024 / 1024, 2); | ||
} | ||
|
||
public function getMaxInGigabytes(): float | ||
{ | ||
return round($this->getMaxInBytes() / 1024 / 1024, 2); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Transip\Api\Library\Repository; | ||
|
||
use Transip\Api\Library\Entity\TrafficPoolInformation; | ||
|
||
class TrafficPoolRepository extends ApiRepository | ||
{ | ||
public const RESOURCE_NAME = 'traffic-pool'; | ||
|
||
public function getTrafficPool(): array | ||
{ | ||
return $this->getByVpsName(''); | ||
} | ||
|
||
public function getByVpsName(string $vpsName): array | ||
{ | ||
$response = $this->httpClient->get($this->getResourceUrl($vpsName)); | ||
$TrafficDatasArray = $this->getParameterFromResponse($response, 'trafficPoolInformation'); | ||
$trafficPoolInformation = []; | ||
foreach ($TrafficDatasArray as $TrafficDataArray) { | ||
$trafficPoolInformation[] = new TrafficPoolInformation($TrafficDataArray); | ||
} | ||
return $trafficPoolInformation; | ||
} | ||
} |
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