aboutsummaryrefslogtreecommitdiffstats
path: root/pushover.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2018-02-07 13:54:38 -0500
committerGitHub <noreply@github.com>2018-02-07 13:54:38 -0500
commit8522972b34f23c59204e7bd4ab1531b34aa9d571 (patch)
tree636ddc36a93c72521a487ea6d231928d22a7bbe3 /pushover.py
parent3915fd1088d03f6e7d078105bfc831170e0ee81c (diff)
parent21048f9689f24841df2ec2ac223c1acc4499622b (diff)
downloadpython-pushover-8522972b34f23c59204e7bd4ab1531b34aa9d571.tar.gz
Merge pull request #24 from chevell/master
Support for sending image attachments with messages
Diffstat (limited to 'pushover.py')
-rw-r--r--pushover.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/pushover.py b/pushover.py
index c5c3793..8160966 100644
--- a/pushover.py
+++ b/pushover.py
@@ -99,12 +99,12 @@ class Request:
a :class:`RequestError` exception when the request is rejected.
"""
- def __init__(self, request_type, url, payload):
+ def __init__(self, request_type, url, payload, files={}):
if not TOKEN:
raise InitError
payload["token"] = TOKEN
- request = getattr(requests, request_type)(url, params=payload)
+ request = getattr(requests, request_type)(url, params=payload, files=files)
self.answer = request.json()
if 400 <= request.status_code < 500:
raise RequestError(self.answer["errors"])
@@ -125,8 +125,8 @@ class MessageRequest(Request):
:func:`poll` function.
"""
- def __init__(self, payload):
- Request.__init__(self, "post", MESSAGE_URL, payload)
+ def __init__(self, payload, files):
+ Request.__init__(self, "post", MESSAGE_URL, payload, files)
self.receipt = None
if payload.get("priority", 0) == 2:
self.receipt = self.answer["receipt"]
@@ -234,7 +234,7 @@ class Client:
self.devices = request.answer["devices"]
return True
- def send_message(self, message, **kwords):
+ def send_message(self, message, attachment=None, **kwords):
"""Send a message to the user. It is possible to specify additional
properties of the message by passing keyword arguments. The list of
valid keywords is ``title, priority, sound, callback, timestamp, url,
@@ -242,6 +242,9 @@ class Client:
Pushover API documentation. For convenience, you can simply set
``timestamp=True`` to set the timestamp to the current timestamp.
+ An image can be attached to a message by passing a file-like object
+ with the `attachment` keyword argument.
+
This method returns a :class:`MessageRequest` object.
"""
valid_keywords = ["title", "priority", "sound", "callback",
@@ -249,6 +252,7 @@ class Client:
"retry", "expire", "html"]
payload = {"message": message, "user": self.user_key}
+ files = {'attachment': attachment} if attachment else {}
if self.device:
payload["device"] = self.device
@@ -268,7 +272,7 @@ class Client:
elif value:
payload[key] = value
- return MessageRequest(payload)
+ return MessageRequest(payload, files)
def send_glance(self, text=None, **kwords):
"""Send a glance to the user. The default property is ``text``,