Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions pushnotifier/PushNotifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ def __init__(self, username, password, package_name, api_key):
self.login_url = self.base_url + '/user/login'
self.devices_url = self.base_url + '/devices'
self.refresh_url = self.base_url + '/user/refresh'
self.send_text_url = self.base_url + '/notifications/text'
self.send_image_url = self.base_url + '/notifications/image'
self.endpoint_text = self.base_url + '/notifications/text'
self.endpoint_url = self.base_url + '/notifications/url'
self.endpoint_image = self.base_url + '/notifications/image'
self.endpoint_notification = self.base_url + '/notifications/notification'
self.username = username
self.package_name = package_name
self.api_key = api_key
Expand Down Expand Up @@ -53,7 +55,8 @@ def __get_app_token(self, password):
'username': self.username,
'password': password
}
r = requests.post(self.login_url, data=login_data, auth=(self.package_name, self.api_key))
r = requests.post(self.login_url, data=login_data,
auth=(self.package_name, self.api_key))

if r.status_code == 401:
raise UnauthorizedError
Expand Down Expand Up @@ -125,7 +128,7 @@ def send_text(self, text, devices=None, silent=False):
"silent": silent
}

r = requests.put(self.send_text_url, json=body, auth=(
r = requests.put(self.endpoint_text, json=body, auth=(
self.package_name, self.api_key), headers=self.headers)
if r.status_code == 200:
return 200
Expand Down Expand Up @@ -154,17 +157,17 @@ def send_url(self, url, devices=None, silent=False):
if devices == None:
body = {
"devices": self.get_all_devices(),
"content": url,
"url": url,
"silent": silent
}
else:
body = {
"devices": devices,
"content": url,
"url": url,
"silent": silent
}

r = requests.put(self.send_text_url, json=body, auth=(
r = requests.put(self.endpoint_url, json=body, auth=(
self.package_name, self.api_key), headers=self.headers)

if r.status_code == 200:
Expand Down Expand Up @@ -207,7 +210,7 @@ def send_notification(self, text, url, devices=None, silent=False):
"silent": silent
}

r = requests.put(self.send_text_url, json=body, auth=(
r = requests.put(self.endpoint_notification, json=body, auth=(
self.package_name, self.api_key), headers=self.headers)

if r.status_code == 200:
Expand Down Expand Up @@ -261,7 +264,7 @@ def send_image(self, image_path, devices=None, silent=False):
"silent": silent
}

r = requests.put(self.send_image_url, json=body, auth=(
r = requests.put(self.endpoint_image, json=body, auth=(
self.package_name, self.api_key), headers=self.headers)

if r.status_code == 200:
Expand Down