Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
olucurious committed Jun 18, 2024
1 parent 88a1203 commit 58de1d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 9 additions & 7 deletions pyfcm/baseapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

# Migration to v1 - https://firebase.google.com/docs/cloud-messaging/migrate-v1


class BaseAPI(object):
FCM_END_POINT = "https://fcm.googleapis.com/v1/projects"

Expand Down Expand Up @@ -49,7 +50,7 @@ def __init__(
self.custom_adapter = adapter
self.thread_local = threading.local()

if (not service_account_file):
if not service_account_file:
raise AuthenticationError(
"Please provide a service account file path in the constructor"
)
Expand Down Expand Up @@ -191,16 +192,15 @@ def parse_response(self, response):
return response.json()

elif response.status_code == 401:
raise (
"There was an error authenticating the sender account"
)
raise ("There was an error authenticating the sender account")
elif response.status_code == 400:
raise InvalidDataError(response.text)
elif response.status_code == 404:
raise FCMNotRegisteredError("Token not registered")
else:
raise FCMServerError(f"FCM server error: Unexpected status code {response.status_code}. The server might be temporarily unavailable.")

raise FCMServerError(
f"FCM server error: Unexpected status code {response.status_code}. The server might be temporarily unavailable."
)

def parse_payload(
self,
Expand Down Expand Up @@ -261,7 +261,9 @@ def parse_payload(
else:
raise InvalidDataError("Provided fcm_options is in the wrong format")

fcm_payload["notification"] = {} # - https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification
fcm_payload["notification"] = (
{}
) # - https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification
# If title is present, use it
if notification_title:
fcm_payload["notification"]["title"] = notification_title
Expand Down
5 changes: 2 additions & 3 deletions pyfcm/fcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def notify(
apns_config=None,
fcm_options=None,
dry_run=False,
timeout=120
timeout=120,
):
"""
Send push notification to a single device
Expand Down Expand Up @@ -61,12 +61,11 @@ def notify(
apns_config=apns_config,
webpush_config=webpush_config,
fcm_options=fcm_options,
dry_run=dry_run
dry_run=dry_run,
)
response = self.send_request(payload, timeout)
return self.parse_response(response)


def async_notify_multiple_devices(self, params_list=None, timeout=5):
"""
Sends push notification to multiple devices with personalized templates
Expand Down

0 comments on commit 58de1d6

Please sign in to comment.