Skip to content

Commit

Permalink
Added pagination support for all list endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jamsouf committed Nov 3, 2023
1 parent c90215f commit a488436
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
/.idea
tests/ApiTest.php
composer.lock
.phpunit.result.cache
6 changes: 4 additions & 2 deletions src/Actions/ApiAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ public function __construct(Pipetower $pt)
*/
protected function transformCollection(array $collection, string $class): array
{
return array_map(function ($attributes) use ($class) {
$collection['data'] = array_map(function ($attributes) use ($class) {
return new $class($attributes, $this->pt);
}, $collection);
}, $collection['data']);

return $collection;
}
}
9 changes: 9 additions & 0 deletions src/Actions/ManagesAccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Pipetower\PhpSdk\Actions;

use Pipetower\PhpSdk\Resources\Account;
use Pipetower\PhpSdk\Resources\Variable;

class ManagesAccounts extends ApiAction
{
Expand All @@ -13,4 +14,12 @@ public function info(): Account
{
return new Account($this->pt->get('account'));
}

/**
* Get the user variables of the current authenticated account
*/
public function vars(array $params = []): array
{
return $this->transformCollection($this->pt->get("account/vars", $params), Variable::class);
}
}
8 changes: 4 additions & 4 deletions src/Actions/ManagesServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ public function runs(string $serverId, array $params = []): array
/**
* Get the metrics of the specified server
*/
public function metrics(string $serverId): array
public function metrics(string $serverId, array $params = []): array
{
return $this->transformCollection($this->pt->get("servers/$serverId/metrics"), Metric::class);
return $this->transformCollection($this->pt->get("servers/$serverId/metrics", $params), Metric::class);
}

/**
* Get the environment variables of the specified server
*/
public function vars(string $serverId): array
public function vars(string $serverId, array $params = []): array
{
return $this->transformCollection($this->pt->get("servers/$serverId/vars"), Variable::class);
return $this->transformCollection($this->pt->get("servers/$serverId/vars", $params), Variable::class);
}
}
4 changes: 2 additions & 2 deletions src/Actions/ManagesTeams.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function retrieve(string $teamId): Team
/**
* Get the team variables of the specified team
*/
public function vars(string $teamId): array
public function vars(string $teamId, array $params = []): array
{
return $this->transformCollection($this->pt->get("teams/$teamId/vars"), Variable::class);
return $this->transformCollection($this->pt->get("teams/$teamId/vars", $params), Variable::class);
}
}
4 changes: 2 additions & 2 deletions src/MakesHttpRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ trait MakesHttpRequests
*/
public function get(string $uri, array $params = []): mixed
{
return $this->request('GET', $uri, $params)['data'];
return $this->request('GET', $uri, $params);
}

/**
* Perform a POST request
*/
public function post(string $uri, array $payload = []): mixed
{
return $this->request('POST', $uri, $payload)['data'];
return $this->request('POST', $uri, $payload);
}

/**
Expand Down

0 comments on commit a488436

Please sign in to comment.