From 4b417f165bff0360544af6dd46b0f6e4a8c6367e Mon Sep 17 00:00:00 2001 From: Malte Hain Date: Sat, 29 Oct 2022 12:27:28 +0200 Subject: [PATCH] fix: use dedicated endpoints --- pushnotifier/PushNotifier.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pushnotifier/PushNotifier.py b/pushnotifier/PushNotifier.py index 5e4e231..94aa2d7 100644 --- a/pushnotifier/PushNotifier.py +++ b/pushnotifier/PushNotifier.py @@ -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 @@ -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 @@ -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 @@ -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: @@ -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: @@ -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: