-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush.py
More file actions
23 lines (19 loc) · 984 Bytes
/
push.py
File metadata and controls
23 lines (19 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from .base import PushbulletException, Pushbullet
from requests import post
class Push(Pushbullet):
"""Push notification."""
def __init__(self, access_token):
super().__init__(access_token)
self.url = 'https://api.pushbullet.com/v2/pushes'
def send_push(self, title, message, target, target_type='email'):
# Check to see if the target type is an available option.
types = ['device_iden', 'email', 'channel_tag', 'client_iden']
if target_type not in types:
raise PushbulletException('Target type {0} doesn\'t exist.\n'
'Please use one of the following: {1}.'
.format(target_type, types))
data = {target_type: target, 'type': 'note', 'title': title, 'body': message}
response = post(self.url, json=data, headers=self.header)
if response.status_code == 200:
self.ratelimit(response)
return response