|
29 | 29 | USER_URL = BASE_URL + "users/validate.json"
|
30 | 30 | SOUND_URL = BASE_URL + "sounds.json"
|
31 | 31 | RECEIPT_URL = BASE_URL + "receipts/"
|
| 32 | +GLANCE_URL = BASE_URL + "glances.json" |
32 | 33 |
|
33 | 34 | SOUNDS = None
|
34 | 35 | TOKEN = None
|
@@ -164,6 +165,16 @@ def poll(self):
|
164 | 165 | return request
|
165 | 166 |
|
166 | 167 |
|
| 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 | + |
167 | 178 | class Client:
|
168 | 179 | """This is the main class of the module. It represents a specific Pushover
|
169 | 180 | user to whom messages will be sent when calling the :func:`send_message`
|
@@ -242,6 +253,31 @@ def send_message(self, message, **kwords):
|
242 | 253 |
|
243 | 254 | return MessageRequest(payload)
|
244 | 255 |
|
| 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 | + |
245 | 281 |
|
246 | 282 | def _get_config(profile='Default', config_path='~/.pushoverrc',
|
247 | 283 | user_key=None, api_token=None, device=None):
|
|
0 commit comments