Skip to content

Commit 755d8b0

Browse files
committed
Add support for the warnings api
1 parent 49f5fb5 commit 755d8b0

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All Notable changes to `php-lxd` will be documented in this file.
44

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

7+
# [0.19.0]
8+
9+
## Added
10+
- Support for the warnings API
711

812
# [0.18.2]
913

src/Endpoint/Warnings.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint;
4+
5+
use Opensaucesystems\Lxd\Exception\InvalidEndpointException;
6+
7+
class Warnings extends AbstractEndpoint
8+
{
9+
protected function getEndpoint()
10+
{
11+
return '/warnings/';
12+
}
13+
14+
public function all(string $project = null, int $recursion = 1)
15+
{
16+
$config = [
17+
"recursion"=>1
18+
];
19+
20+
if (!empty($project)) {
21+
$config["project"] = $project;
22+
}
23+
24+
25+
return $this->get($this->getEndpoint(), $config);
26+
}
27+
28+
public function info(string $uuid)
29+
{
30+
return $this->get($this->getEndpoint() . $uuid);
31+
}
32+
33+
public function remove(string $uuid)
34+
{
35+
return $this->delete($this->getEndpoint() . $uuid);
36+
}
37+
38+
public function __get($endpoint)
39+
{
40+
$class = __NAMESPACE__.'\\Warnings\\'.ucfirst($endpoint);
41+
42+
if (class_exists($class)) {
43+
return new $class($this->client);
44+
} else {
45+
throw new InvalidEndpointException(
46+
'Endpoint '.$class.', not implemented.'
47+
);
48+
}
49+
}
50+
}

src/Endpoint/Warnings/Status.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\Warnings;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;
6+
7+
class Status extends AbstractEndpoint
8+
{
9+
protected function getEndpoint()
10+
{
11+
return '/warnings/';
12+
}
13+
14+
public function new(string $uuid)
15+
{
16+
$data = ["status"=>"new"];
17+
return $this->put($this->getEndpoint() . $uuid, $data);
18+
}
19+
20+
public function acknowledge(string $uuid)
21+
{
22+
$data = ["status"=>"acknowledged"];
23+
return $this->put($this->getEndpoint() . $uuid, $data);
24+
}
25+
}

0 commit comments

Comments
 (0)