-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApplicationMessage.php
More file actions
60 lines (51 loc) · 1.68 KB
/
ApplicationMessage.php
File metadata and controls
60 lines (51 loc) · 1.68 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
<?php
declare(strict_types=1);
namespace Gotify\Endpoint;
use Gotify\Json;
use stdClass;
/**
* Class for interacting with the message methods in Application API endpoint
*
* @see https://gotify.net/api-docs#/message API docs for message endpoint
*/
class ApplicationMessage extends AbstractEndpoint
{
/** @var string $endpoint API endpoint */
private string $endpoint = 'application';
/**
* Get all messages for an application (ordered by most recent)
*
* @param int $id Application Id
* @param int $limit Maximum number of messages to return
* @param int $since Return all messages after a message id
*
* @return stdClass
*
* @see https://gotify.net/api-docs#/message/getAppMessages API docs for getting all messages for an application
*/
public function getAll(int $id, int $limit = 100, int $since = 0): stdClass
{
$query = [
'limit' => $limit,
'since' => $since
];
$response = $this->guzzle->get($this->endpoint . '/' . $id . '/message', $query);
$messages = Json::decode($response->getBody()->getContents());
return (object) $messages;
}
/**
* Delete all messages for an application
*
* @param int $id Application Id
*
* @return boolean
*
* @see https://gotify.net/api-docs#/message/deleteAppMessages API docs for deleting all messages for an application
*/
public function deleteAll(int $id): bool
{
$response = $this->guzzle->delete($this->endpoint . '/' . $id . '/message');
$body = $response->getBody()->getContents();
return $response->getStatusCode() === 200 ? true : false;
}
}