2424RECEIPT_URL = BASE_URL + "receipts/"
2525GLANCE_URL = BASE_URL + "glances.json"
2626
27+
2728class RequestError (Exception ):
2829 """Exception which is raised when Pushover's API returns an error code.
2930
@@ -38,7 +39,7 @@ def __str__(self):
3839 return "\n ==> " + "\n ==> " .join (self .errors )
3940
4041
41- class Request :
42+ class Request ( object ) :
4243 """Base class to send a request to the Pushover server and check the return
4344 status code. The request is sent on instantiation and raises
4445 a :class:`RequestError` exception when the request is rejected.
@@ -70,9 +71,11 @@ class MessageRequest(Request):
7071 can poll the status of the notification with the :func:`poll` function.
7172 """
7273
73- params = {"expired" : "expires_at" ,
74- "called_back" : "called_back_at" ,
75- "acknowledged" : "acknowledged_at" }
74+ params = {
75+ "expired" : "expires_at" ,
76+ "called_back" : "called_back_at" ,
77+ "acknowledged" : "acknowledged_at" ,
78+ }
7679
7780 def __init__ (self , payload ):
7881 Request .__init__ (self , "post" , MESSAGE_URL , payload )
@@ -122,18 +125,35 @@ def cancel(self):
122125 cancels the notification early.
123126 """
124127 if not self .status ["done" ]:
125- return Request ("post" , self .url + "/cancel.json" , {"token" : self .payload ["token" ]})
128+ return Request (
129+ "post" , self .url + "/cancel.json" , {"token" : self .payload ["token" ]}
130+ )
131+ else :
132+ return None
126133
127134
128- class Pushover :
135+ class Pushover ( object ) :
129136 """This is the main class of the module. It represents a Pushover app and
130137 is tied to a unique API token.
131138
132139 * ``token``: Pushover API token
133140 """
134141
135142 _SOUNDS = None
136- message_keywords = ["title" , "priority" , "sound" , "callback" , "timestamp" , "url" , "url_title" , "device" , "retry" , "expire" , "html" , "attachment" ]
143+ message_keywords = [
144+ "title" ,
145+ "priority" ,
146+ "sound" ,
147+ "callback" ,
148+ "timestamp" ,
149+ "url" ,
150+ "url_title" ,
151+ "device" ,
152+ "retry" ,
153+ "expire" ,
154+ "html" ,
155+ "attachment" ,
156+ ]
137157 glance_keywords = ["title" , "text" , "subtext" , "count" , "percent" , "device" ]
138158
139159 def __init__ (self , token ):
@@ -149,7 +169,6 @@ def sounds(self):
149169 Pushover ._SOUNDS = request .answer ["sounds" ]
150170 return Pushover ._SOUNDS
151171
152-
153172 def verify (self , user , device = None ):
154173 """Verify that the `user` and optional `device` exist. Returns
155174 `None` when the user/device does not exist or a list of the user's
@@ -165,14 +184,13 @@ def verify(self, user, device=None):
165184 else :
166185 return request .answer ["devices" ]
167186
168-
169187 def message (self , user , message , ** kwargs ):
170188 """Send `message` to the user specified by `user`. It is possible
171189 to specify additional properties of the message by passing keyword
172190 arguments. The list of valid keywords is ``title, priority, sound,
173191 callback, timestamp, url, url_title, device, retry, expire and html``
174192 which are described in the Pushover API documentation.
175-
193+
176194 For convenience, you can simply set ``timestamp=True`` to set the
177195 timestamp to the current timestamp.
178196
@@ -187,9 +205,9 @@ def message(self, user, message, **kwargs):
187205 if key not in Pushover .message_keywords :
188206 raise ValueError ("{0}: invalid message parameter" .format (key ))
189207 elif key == "timestamp" and value is True :
190- payload [key ] = int (time .time ())
208+ payload [key ] = int (time .time ())
191209 elif key == "sound" and value not in self .sounds :
192- raise ValueError ("{0}: invalid sound" .format (value ))
210+ raise ValueError ("{0}: invalid sound" .format (value ))
193211 else :
194212 payload [key ] = value
195213
0 commit comments