Skip to content

Commit

Permalink
Merge pull request #43 from fodderstompf/add-insights-resource
Browse files Browse the repository at this point in the history
Adds insights resource
  • Loading branch information
Cannonb4ll authored Nov 11, 2021
2 parents cecdc07 + 7ab1e70 commit 1c1a29e
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,30 @@ $ploi->servers(123)->sshKeys(123)->get();
$ploi->servers(123)->sshKeys(123)->delete();
```

### Insights
```php
// List insights
$ploi->servers(123)->insights()->get();

// Paginate insights
$ploi->servers(123)->insights()->perPage($amountPerPage)->page($pageNumber);

// Get insight
$ploi->servers(123)->insights(123)->get();

// Get insight detail
$ploi->servers(123)->insights(123)->detail();

// Automatically fix insight
$ploi->servers(123)->insights(123)->automaticallyFix();

// Ignore insight
$ploi->servers(123)->insights(123)->ignore();

// Delete insight
$ploi->servers(123)->insights(123)->delete();
```

### User

Available methods for user:
Expand Down
82 changes: 82 additions & 0 deletions src/Ploi/Resources/Insight.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Ploi\Resources;

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

class Insight extends Resource
{
use HasPagination;

private $server;

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

$this->setServer($server);

$this->buildEndpoint();
}

public function buildEndpoint(): self
{
$endpoint = $this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/insights';

if ($this->getId()) {
$endpoint .= '/' . $this->getId();
}

$this->setEndpoint($endpoint);

return $this;
}

public function get(?int $id = null): Response
{
if ($id) {
$this->setId($id);
}

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function detail(?int $id = null): Response
{
$this->setIdOrFail($id);

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint() . '/detail');
}

public function automaticallyFix(?int $id = null): Response
{
$this->setIdOrFail($id);

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint() . '/automatically-fix', 'post');
}

public function ignore(?int $id = null): Response
{
$this->setIdOrFail($id);

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint() . '/ignore', 'post');
}

public function delete(?int $id = null): Response
{
$this->setIdOrFail($id);

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete');
}
}
5 changes: 5 additions & 0 deletions src/Ploi/Resources/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,9 @@ public function opcache($id = null): Opcache
{
return new Opcache($this, $id);
}

public function insights($id = null): Insight
{
return new Insight($this, $id);
}
}

0 comments on commit 1c1a29e

Please sign in to comment.