-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from fodderstompf/add-status-page-resource
Adds Status Page and Status Page Incidents resources
- Loading branch information
Showing
4 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |