Skip to content

Commit

Permalink
Merge pull request #61 from srdante/patch-6
Browse files Browse the repository at this point in the history
Fix get() method not respecting perPage() definitions
  • Loading branch information
fodderstompf authored Mar 22, 2022
2 parents 4d25a6f + b939531 commit c2c5d8e
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 22 deletions.
4 changes: 3 additions & 1 deletion src/Ploi/Resources/AuthUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function get(?int $id = null): Response

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $name, string $password): Response
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/Certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public function get(int $id = null): Response
// Make sure the endpoint is built
$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $certificate, string $type = 'letsencrypt'): Response
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/Cronjob.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public function get(int $id = null): Response
// Make sure the endpoint is built
$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $command, string $frequency, string $user = 'ploi'): Response
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/Daemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public function get(int $id = null): Response
// Make sure the endpoint is built
$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $command, string $systemUser, int $processes, ?string $directory = null): Response
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function get(int $id = null): Response
// Make sure the endpoint is built
$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $name, string $user, string $password, $description = null, $siteId = null): Response
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/DatabaseBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function get(int $id = null): Response
// Make sure the endpoint is built
$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/DatabaseUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public function get(int $id = null): Response

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $user, string $password): Response
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/Incident.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public function get(?int $id = null): Response

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $title, string $description, string $severity): Response
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/Insight.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function get(?int $id = null): Response

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function detail(?int $id = null): Response
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/NetworkRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public function get(int $id = null): Response
// Make sure the endpoint is built
$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $name, int $port, string $type = 'tcp', ?string $fromIpAddress = null, string $ruleType = 'allow'): Response
Expand Down
3 changes: 1 addition & 2 deletions src/Ploi/Resources/Opcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
namespace Ploi\Resources;

use Ploi\Http\Response;
use Ploi\Traits\HasPagination;

class Opcache extends Resource
{
private $server;

public function __construct(Server $server, int $id = null)
public function __construct(Server $server, ?int $id = null)
{
parent::__construct($server->getPloi(), $id);

Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public function get(int $id = null): Response
// Make sure the endpoint is built
$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public function get(int $id = null): Response
// Make sure the endpoint is built
$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $redirectFrom, string $redirectTo, $type = 'redirect'): Response
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public function get(int $id = null): Response
$this->setEndpoint($this->getEndpoint() . '/' . $this->getId());
}

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(
Expand Down
9 changes: 7 additions & 2 deletions src/Ploi/Resources/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(Ploi $ploi = null, int $id = null)

public function buildEndpoint(string $path = null): string
{
$base = 'servers';
$base = $this->endpoint;

if ($this->getId()) {
$base = "{$base}/{$this->getId()}";
Expand Down Expand Up @@ -51,7 +51,12 @@ public function get(int $id = null): Response
$this->setId($id);
}

return $this->callApi();
// This method do not need the special callApi() method on pagination
// Since its a the simple get of the servers using the $this->endpoint url

return (is_null($this->getId()))
? $this->page()
: $this->callApi();
}

public function delete(int $id = null): Response
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function get(int $id = null)
// Make sure the endpoint is built
$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function getServer(): Server
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/SshKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function get(?int $id = null): Response

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $name, string $key, ?string $systemUser = null): Response
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/StatusPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function get(?int $id = null): Response

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function incident(?int $id = null): Incident
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/SystemUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public function get(int $id = null): Response
// Make sure the endpoint is built
$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $name, bool $sudo = false): Response
Expand Down
4 changes: 3 additions & 1 deletion src/Ploi/Resources/WebserverTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public function get(?int $id = null): Response
$this->setEndpoint($this->getEndpoint() . '/' . $this->getId());
}

return $this->getPloi()->makeAPICall($this->getEndpoint());
return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}
}

0 comments on commit c2c5d8e

Please sign in to comment.