Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #18 from mathiasose/master
Browse files Browse the repository at this point in the history
Allows entering an email (str) directly instead of having to send to Contact objects
  • Loading branch information
richard-better committed Dec 7, 2014
2 parents df02754 + f043a52 commit 1c4ce4c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pushbullet/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.0"
__version__ = "0.6.0"
53 changes: 27 additions & 26 deletions pushbullet/pushbullet.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ def _load_user_info(self):
else:
self.user_info = {}

@staticmethod
def _recipient(device=None, contact=None, email=None):
data = dict()

if device:
data["device_iden"] = device.device_iden
elif contact:
data["email"] = contact.email
elif email:
data["email"] = email

return data

def new_device(self, nickname):
data = {"nickname": nickname, "type": "stream"}
r = self._session.post(self.DEVICES_URL, data=json.dumps(data))
Expand All @@ -65,7 +78,7 @@ def new_device(self, nickname):
return False, None

def new_contact(self, name, email):
data = {"name": nickname, "email": email}
data = {"name": name, "email": email}
r = self._session.post(self.CONTACTS_URL, data=json.dumps(data))
if r.status_code == requests.codes.ok:
new_contact = Contact(self, r.json())
Expand Down Expand Up @@ -162,52 +175,40 @@ def upload_file(self, f, file_name, file_type=None):

return True, {"file_type": file_type, "file_url": file_url, "file_name": file_name}

def push_file(self, file_name, file_url, file_type, body=None, device=None, contact=None):
def push_file(self, file_name, file_url, file_type, body=None, device=None, contact=None, email=None):
data = {"type": "file", "file_type": file_type, "file_url": file_url, "file_name": file_name}
if body:
data["body"] = body

if device:
data["device_iden"] = device.device_iden
elif contact:
data["email"] = contact.email
data.update(PushBullet._recipient(device, contact, email))

return self._push(data)

def push_note(self, title, body, device=None, contact=None):
def push_note(self, title, body, device=None, contact=None, email=None):
data = {"type": "note", "title": title, "body": body}
if device:
data["device_iden"] = device.device_iden
elif contact:
data["email"] = contact.email

data.update(PushBullet._recipient(device, contact, email))

return self._push(data)

def push_address(self, name, address, device=None, contact=None):
def push_address(self, name, address, device=None, contact=None, email=None):
data = {"type": "address", "name": name, "address": address}
if device:
data["device_iden"] = device.device_iden
elif contact:
data["email"] = contact.email

data.update(PushBullet._recipient(device, contact, email))

return self._push(data)

def push_list(self, title, items, device=None, contact=None):
def push_list(self, title, items, device=None, contact=None, email=None):
data = {"type": "list", "title": title, "items": items}
if device:
data["device_iden"] = device.device_iden
elif contact:
data["email"] = contact.email

data.update(PushBullet._recipient(device, contact, email))

return self._push(data)

def push_link(self, title, url, body=None, device=None, contact=None):
def push_link(self, title, url, body=None, device=None, contact=None, email=None):
data = {"type": "link", "title": title, "url": url, "body": body}

if device:
data["device_iden"] = device.device_iden
elif contact:
data["email"] = contact.email
data.update(PushBullet._recipient(device, contact, email))

return self._push(data)

Expand Down

0 comments on commit 1c4ce4c

Please sign in to comment.