Skip to content

Commit

Permalink
Merge branch 'trafficPool' into 'master'
Browse files Browse the repository at this point in the history
added trafficpool endpoint

See merge request transip/restapi-php-library!139
  • Loading branch information
tgooren committed Jun 18, 2021
2 parents 495b7cb + 7edcec1 commit 748e9b1
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
-----
* Added getByVpsName method to the OperatingSystem resource
* Added minQuantity to the LicenceProduct
* Deprecated Traffic endpoint in favor of TrafficPool endpoint

6.7.2
-----
Expand Down
117 changes: 117 additions & 0 deletions src/Entity/TrafficPoolInformation.php
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);
}
}
26 changes: 26 additions & 0 deletions src/Repository/TrafficPoolRepository.php
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;
}
}
3 changes: 3 additions & 0 deletions src/Repository/TrafficRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Transip\Api\Library\Entity\TrafficInformation;

/**
* @deprecated deprecated since version 6.8.0, use trafficPool instead
*/
class TrafficRepository extends ApiRepository
{
public const RESOURCE_NAME = 'traffic';
Expand Down
9 changes: 9 additions & 0 deletions src/TransipAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Transip\Api\Library\Repository\Product\ElementRepository as ProductElementRepository;
use Transip\Api\Library\Repository\DomainTldRepository;
use Transip\Api\Library\Repository\SshKeyRepository;
use Transip\Api\Library\Repository\TrafficPoolRepository;
use Transip\Api\Library\Repository\TrafficRepository;
use Transip\Api\Library\Repository\Vps\AddonRepository;
use Transip\Api\Library\Repository\Vps\BackupRepository as VpsBackupRepository;
Expand Down Expand Up @@ -208,11 +209,19 @@ public function domainWhitelabel(): DomainWhitelabelRepository
return new DomainWhitelabelRepository($this->httpClient);
}

/**
* @deprecated deprecated since version 6.8.0, use trafficPool instead
*/
public function traffic(): TrafficRepository
{
return new TrafficRepository($this->httpClient);
}

public function trafficPool(): TrafficPoolRepository
{
return new TrafficPoolRepository($this->httpClient);
}

public function vps(): VpsRepository
{
return new VpsRepository($this->httpClient);
Expand Down

0 comments on commit 748e9b1

Please sign in to comment.