Repository navigation
Expand file tree
/
Copy pathPushoverAPI.inc
More file actions
101 lines (83 loc) · 1.99 KB
/
Copy pathPushoverAPI.inc
File metadata and controls
101 lines (83 loc) · 1.99 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
<?php
/**
* Pushover API
*
* @description Send a message via the Pushover API
* @author Frank Grijze
* @link https://www.yourwww.nl
* @version 1.0.0
*/
class PushoverAPI {
private array $availablePriorities = [
"LOWEST" => -2,
"LOW" => -1,
"NORMAL" => 0,
"HIGH" => 1,
"EMERGENCY" => 2
];
private string $url = "https://api.pushover.net/1/messages.json";
private string $appToken = "";
private string $userKey = "";
private string $message = "";
private string $title = "";
private string $priority = "NORMAL";
private int $retry = 60;
public function setAppToken ($appToken) {
$this->appToken = $appToken;
}
public function getAppToken () {
return $this->appToken;
}
public function setUserKey ($userKey) {
$this->userKey = $userKey;
}
public function getUserKey () {
return $this->userKey;
}
public function setMessage ($message) {
$this->message = $message;
}
public function getMessage () {
return $this->message;
}
public function setTitle ($title) {
$this->title = $title;
}
public function getTitle () {
return $this->title;
}
public function setPriority ($priority) {
$this->priority = $priority;
}
public function getPriority () {
return $this->priority;
}
public function setRetry ($retry) {
$this->retry = $retry;
}
public function getRetry () {
return $this->retry;
}
public function sendMessage () {
$cURL = curl_init();
curl_setopt_array($cURL, [
CURLOPT_URL => $this->url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => [
"token" => $this->appToken,
"user" => $this->userKey,
"message" => $this->getMessage(),
"title" => $this->getTitle(),
"priority" => $this->availablePriorities[$this->getPriority()],
"retry" => $this->getRetry(),
"expire" => 10800,
"sound" => false
]
]);
$response = curl_exec($cURL);
curl_close($cURL);
$response = json_decode($response);
if ($response->status != 1)
throw new Exception($response->errors[0]);
}
}