-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClient.php
More file actions
94 lines (80 loc) · 2.22 KB
/
Client.php
File metadata and controls
94 lines (80 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
declare(strict_types=1);
namespace Gotify\Endpoint;
use Gotify\Json;
use stdClass;
/**
* Class for interacting with client API endpoint
*
* @see https://gotify.net/api-docs#/client API docs for client endpoint
*/
class Client extends AbstractEndpoint
{
/** @var string $endpoint API endpoint */
private string $endpoint = 'client';
/**
* Get all clients
*
* @return stdClass
*
* @see https://gotify.net/api-docs#/client/getClients API docs for getting all clients
*/
public function getAll(): stdClass
{
$response = $this->guzzle->get($this->endpoint);
$clients = Json::decode($response->getBody()->getContents());
return (object) ['clients' => $clients];
}
/**
* Create a client
*
* @param string $name Client name
*
* @return stdClass
*
* @see https://gotify.net/api-docs#/client/createClient API docs for creating a client
*/
public function create(string $name): stdClass
{
$data = [
'name' => $name,
];
$response = $this->guzzle->post($this->endpoint, $data);
$client = Json::decode($response->getBody()->getContents());
return (object) $client;
}
/**
* Update a client
*
* @param int $id Client Id
* @param string $name New client name
*
* @return stdClass
*
* @see https://gotify.net/api-docs#/client/updateClient API docs for updating a client
*/
public function update(int $id, string $name): stdClass
{
$data = [
'name' => $name,
];
$response = $this->guzzle->put($this->endpoint . '/' . $id, $data);
$client = Json::decode($response->getBody()->getContents());
return (object) $client;
}
/**
* Delete a client
*
* @param int $id Client Id
*
* @return boolean
*
* @see https://gotify.net/api-docs#/client/deleteClient API docs for deleting a client
*/
public function delete(int $id): bool
{
$response = $this->guzzle->delete($this->endpoint . '/' . $id);
$body = $response->getBody()->getContents();
return $response->getStatusCode() === 200 ? true : false;
}
}