-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpushbullet.py
56 lines (40 loc) · 1.49 KB
/
pushbullet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from api_client import BaseAPIClient
class PushbulletAPIClient(BaseAPIClient):
force_trailing_backslash = False
def __init__(self, api_key=None, *args, **kwargs):
super(PushbulletAPIClient, self).__init__(*args, **kwargs)
if api_key:
self.api_key = api_key
else:
try:
with open("api_key.txt", "r") as key_file:
self.api_key = key_file.read().strip()
except:
raise Exception(
"API key wasn't specified nor in start parameters, "
"neither in api_key.txt file")
def get_endpoint(self):
return "https://api.pushbullet.com/v2/"
def prepare_headers(self, extra_headers=None):
headers = super(PushbulletAPIClient, self).prepare_headers(
extra_headers=extra_headers)
headers["Access-Token"] = self.api_key
return headers
def get_devices(self):
response = self.get("devices")
return response.json()
def push_to_device(self, device_id, push_data):
data = {
"device_iden": device_id,
}
data.update(push_data)
response = self.post("pushes", data=data)
return response.json()
def push_note_to_device(self, device_id, body, title=""):
note = {
"type": "note",
"title": title,
"body": body,
}
result = self.push_to_device(device_id, note)
return result