diff --git a/pushbullet/__version__.py b/pushbullet/__version__.py index 3d18726..906d362 100644 --- a/pushbullet/__version__.py +++ b/pushbullet/__version__.py @@ -1 +1 @@ -__version__ = "0.5.0" +__version__ = "0.6.0" diff --git a/pushbullet/pushbullet.py b/pushbullet/pushbullet.py index 4cd208f..0e72bd7 100644 --- a/pushbullet/pushbullet.py +++ b/pushbullet/pushbullet.py @@ -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)) @@ -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()) @@ -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)