Skip to content

Commit

Permalink
Merge pull request #39 from fodderstompf/add-status-page-resource
Browse files Browse the repository at this point in the history
Adds Status Page and Status Page Incidents resources
  • Loading branch information
Cannonb4ll authored Sep 13, 2021
2 parents 02b7e96 + 3b00d84 commit 0e704c9
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,38 @@ $ploi->user()->serverProviders();
// Get server providers
$ploi->user()->serverProviders($providerId);
```

### Status Pages

Available methods for status pages:
```php
// List status pages
$ploi->statusPage()->get();

// Paginate status pages
$ploi->statusPage()->perPage($amountPerPage)->page($pageNumber);

// Get status page
$ploi->statusPage(123)->get();
```

### Status Page Incidents

Available methods for status page incidents:
```php
// Create incident
$ploi->statusPage(123)->incident()->create(
$title,
$description,
$severity
);

// List incidents
$ploi->statusPage(123)->incident()->get();

// Paginate incidents
$ploi->statusPage(123)->incident()->perPage($amountPerPage)->page($pageNumber);

// Delete incident
$ploi->statusPage(123)->incident(123)->delete();
```
6 changes: 6 additions & 0 deletions src/Ploi/Ploi.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Client;
use Ploi\Http\Response;
use Ploi\Resources\Script;
use Ploi\Resources\StatusPage;
use Ploi\Resources\User;
use Ploi\Resources\Server;
use Ploi\Exceptions\Http\NotFound;
Expand Down Expand Up @@ -159,6 +160,11 @@ public function scripts(int $id = null): Script
return new Script($this, $id);
}

public function statusPage(?int $id = null): StatusPage
{
return new StatusPage($this, $id);
}

public function user()
{
return new User($this);
Expand Down
83 changes: 83 additions & 0 deletions src/Ploi/Resources/Incident.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace Ploi\Resources;

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

class Incident extends Resource
{
use HasPagination;

private $statusPage;

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

$this->setStatusPage($statusPage);

$this->buildEndpoint();
}

public function setStatusPage(StatusPage $statusPage): self
{
$this->statusPage = $statusPage;

return $this;
}

public function getStatusPage(): ?StatusPage
{
return $this->statusPage;
}

public function buildEndpoint(): self
{
$endpoint = $this->getStatusPage()->getEndpoint() . '/incidents';

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 create(string $title, string $description, string $severity): Response
{

$options = [
'body' => json_encode([
'title' => $title,
'description' => $description,
'severity' => $severity,
]),
];

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options);
}

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

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete');
}
}
48 changes: 48 additions & 0 deletions src/Ploi/Resources/StatusPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Ploi\Resources;

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

class StatusPage extends Resource
{
use HasPagination;

public function __construct(Ploi $ploi = null, int $id = null)
{
parent::__construct($ploi, $id);

$this->buildEndpoint();
}

public function buildEndpoint(): self
{
$endpoint = 'status-pages';

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 incident(?int $id = null): Incident
{
return new Incident($this, $id);
}
}

0 comments on commit 0e704c9

Please sign in to comment.