Skip to content

Commit

Permalink
Add support for the warnings api
Browse files Browse the repository at this point in the history
  • Loading branch information
turtle0x1 committed May 4, 2021
1 parent 49f5fb5 commit 755d8b0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All Notable changes to `php-lxd` will be documented in this file.

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

# [0.19.0]

## Added
- Support for the warnings API

# [0.18.2]

Expand Down
50 changes: 50 additions & 0 deletions src/Endpoint/Warnings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint;

use Opensaucesystems\Lxd\Exception\InvalidEndpointException;

class Warnings extends AbstractEndpoint
{
protected function getEndpoint()
{
return '/warnings/';
}

public function all(string $project = null, int $recursion = 1)
{
$config = [
"recursion"=>1
];

if (!empty($project)) {
$config["project"] = $project;
}


return $this->get($this->getEndpoint(), $config);
}

public function info(string $uuid)
{
return $this->get($this->getEndpoint() . $uuid);
}

public function remove(string $uuid)
{
return $this->delete($this->getEndpoint() . $uuid);
}

public function __get($endpoint)
{
$class = __NAMESPACE__.'\\Warnings\\'.ucfirst($endpoint);

if (class_exists($class)) {
return new $class($this->client);
} else {
throw new InvalidEndpointException(
'Endpoint '.$class.', not implemented.'
);
}
}
}
25 changes: 25 additions & 0 deletions src/Endpoint/Warnings/Status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint\Warnings;

use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;

class Status extends AbstractEndpoint
{
protected function getEndpoint()
{
return '/warnings/';
}

public function new(string $uuid)
{
$data = ["status"=>"new"];
return $this->put($this->getEndpoint() . $uuid, $data);
}

public function acknowledge(string $uuid)
{
$data = ["status"=>"acknowledged"];
return $this->put($this->getEndpoint() . $uuid, $data);
}
}

0 comments on commit 755d8b0

Please sign in to comment.