Skip to content

Instantly share code, notes, and snippets.

@eiszfuchs
Created July 1, 2015 14:05
Show Gist options
  • Save eiszfuchs/f0756c4b75153ba69e59 to your computer and use it in GitHub Desktop.
Save eiszfuchs/f0756c4b75153ba69e59 to your computer and use it in GitHub Desktop.
import requests
class APIError:
pass
class Pyshbullet:
push_url = "https://api.pushbullet.com/v2/pushes"
def __init__(self, api_key=None):
self.api_key = api_key
def get_authorization(self):
return {"Authorization": "Bearer %s" % self.api_key}
def push(self, push_type, **kwargs):
headers = self.get_authorization()
data = {"type": push_type}
for key, value in kwargs.items():
data[key] = value
response = requests.post(self.push_url, headers=headers, data=data)
if response.status_code != 200:
raise APIError
def push_note(self, title, body):
self.push("note", title=title, body=body)
def push_link(self, title, body, url):
self.push("link", title=title, body=body, url=url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment