-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlugin.php
More file actions
118 lines (103 loc) · 3.17 KB
/
Plugin.php
File metadata and controls
118 lines (103 loc) · 3.17 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
declare(strict_types=1);
namespace Gotify\Endpoint;
use Gotify\Json;
use stdClass;
/**
* Class for interacting with the plugin API endpoint
*
* @see https://gotify.net/api-docs#/plugin API docs for the user endpoint
*/
class Plugin extends AbstractEndpoint
{
/** @var string $endpoint API endpoint */
private string $endpoint = 'plugin';
/**
* Get all plugins
*
* @return stdClass
*
* @see https://gotify.net/api-docs#/plugin/getPlugins API docs for getting all plugins
*/
public function getAll(): stdClass
{
$response = $this->guzzle->get($this->endpoint);
$plugins = Json::decode($response->getBody()->getContents());
return (object) ['plugins' => $plugins];
}
/**
* Get configuration for a plugin.
*
* @param int $id Plugin Id
*
* @return string
*
* @see https://gotify.net/api-docs#/plugin/getPluginConfig API docs for getting the configuration for a plugin
*/
public function getConfig(int $id): string
{
$response = $this->guzzle->get($this->endpoint . '/' . $id . '/config');
return $response->getBody()->getContents();
}
/**
* Update configuration for a plugin.
*
* @param int $id Plugin Id
* @param string $config Configuration in YAML
*
* @return boolean
*
* @see https://gotify.net/api-docs#/plugin/updatePluginConfig API docs for updating the configuration for a plugin
*/
public function updateConfig(int $id, string $config): bool
{
$response = $this->guzzle->postYaml($this->endpoint . '/' . $id . '/config', $config);
$body = $response->getBody()->getContents();
return $response->getStatusCode() === 200 ? true : false;
}
/**
* Get display info for a plugin
*
* @param int $id Plugin Id
*
* @return string
*
* @see https://gotify.net/api-docs#/plugin/getPluginDisplay API docs for getting the display info for a plugin
*/
public function getDisplayInfo(int $id): string
{
$response = $this->guzzle->get($this->endpoint . '/' . $id . '/display');
$info = (object) Json::decode('{"data": ' . $response->getBody()->getContents() . '}');
return $info->data;
}
/**
* Enable a plugin.
*
* @param int $id Plugin Id
*
* @return boolean
*
* @see https://gotify.net/api-docs#/plugin/enablePlugin API docs for enabling a plugin
*/
public function enable(int $id): bool
{
$response = $this->guzzle->post($this->endpoint . '/' . $id . '/enable');
$body = $response->getBody()->getContents();
return $response->getStatusCode() === 200 ? true : false;
}
/**
* Disable a plugin
*
* @param int $id Plugin Id
*
* @return boolean
*
* @see https://gotify.net/api-docs#/plugin/disablePlugin API docs for disabling a plugin
*/
public function disable(int $id): bool
{
$response = $this->guzzle->post($this->endpoint . '/' . $id . '/disable');
$body = $response->getBody()->getContents();
return $response->getStatusCode() === 200 ? true : false;
}
}