Skip to content

Commit edaf510

Browse files
authored
Merge pull request Thibauth#19 from chevell/master
Added support for new Glances API
2 parents 38fdcc7 + 6c4fdf3 commit edaf510

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

pushover.py

+36
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
USER_URL = BASE_URL + "users/validate.json"
3030
SOUND_URL = BASE_URL + "sounds.json"
3131
RECEIPT_URL = BASE_URL + "receipts/"
32+
GLANCE_URL = BASE_URL + "glances.json"
3233

3334
SOUNDS = None
3435
TOKEN = None
@@ -164,6 +165,16 @@ def poll(self):
164165
return request
165166

166167

168+
class GlanceRequest(Request):
169+
"""Class representing a glance request to the Pushover API. This is
170+
a heavily simplified version of the MessageRequest class, with all
171+
polling-related features removed.
172+
"""
173+
174+
def __init__(self, payload):
175+
Request.__init__(self, "post", GLANCE_URL, payload)
176+
177+
167178
class Client:
168179
"""This is the main class of the module. It represents a specific Pushover
169180
user to whom messages will be sent when calling the :func:`send_message`
@@ -242,6 +253,31 @@ def send_message(self, message, **kwords):
242253

243254
return MessageRequest(payload)
244255

256+
def send_glance(self, text=None, **kwords):
257+
"""Send a glance to the user. The default property is ``text``,
258+
as this is used on most glances, however a valid glance does not
259+
need to require text and can be constructed using any combination
260+
of valid keyword properties. The list of valid keywords is ``title,
261+
text, subtext, count and percent`` which are described in the
262+
Pushover Glance API documentation.
263+
264+
This method returns a :class:`GlanceRequest` object.
265+
"""
266+
valid_keywords = ["title", "text", "subtext", "count", "percent"]
267+
268+
payload = {"user": self.user_key}
269+
if text:
270+
payload["text"] = text
271+
if self.device:
272+
payload["device"] = self.device
273+
274+
for key, value in kwords.iteritems():
275+
if key not in valid_keywords:
276+
raise ValueError("{0}: invalid message parameter".format(key))
277+
payload[key] = value
278+
279+
return GlanceRequest(payload)
280+
245281

246282
def _get_config(profile='Default', config_path='~/.pushoverrc',
247283
user_key=None, api_token=None, device=None):

0 commit comments

Comments
 (0)