Skip to content

Commit

Permalink
revert of some unneeded addition and type check for title_loc_args an…
Browse files Browse the repository at this point in the history
…d body_loc_args
  • Loading branch information
olucurious committed May 31, 2017
1 parent 45c1bc2 commit f43b9ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pyfcm/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__summary__ = 'Python client for FCM - Firebase Cloud Messaging (Android & iOS)..'
__url__ = 'https://github.com/olucurious/pyfcm'

__version__ = '1.3.0'
__version__ = '1.3.1'

__install_requires__ = ['requests', 'requests-toolbelt']

Expand Down
25 changes: 8 additions & 17 deletions pyfcm/baseapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def parse_payload(self,
title_loc_key=None,
title_loc_args=None,
content_available=None,
is_ios=False,
**extra_kwargs):

"""
Expand Down Expand Up @@ -148,32 +147,24 @@ def parse_payload(self,
#Else use body_loc_key and body_loc_args for body
else:
if body_loc_key:
if is_ios:
fcm_payload['notification']['loc-key'] = body_loc_key
else:
fcm_payload['notification']['body_loc_key'] = body_loc_key
fcm_payload['notification']['body_loc_key'] = body_loc_key
if body_loc_args:
body_loc_args = str(body_loc_args)
if is_ios:
fcm_payload['notification']['loc-args'] = body_loc_args
else:
if isinstance(body_loc_args, list):
fcm_payload['notification']['body_loc_args'] = body_loc_args
else:
raise InvalidDataError('body_loc_args should be an array')
#If title is present, use it
if message_title:
fcm_payload['notification']['title'] = message_title
#Else use title_loc_key and title_loc_args for title
else:
if title_loc_key:
if is_ios:
fcm_payload['notification']['title-loc-key'] = title_loc_key
else:
fcm_payload['notification']['title_loc_key'] = title_loc_key
fcm_payload['notification']['title_loc_key'] = title_loc_key
if title_loc_args:
title_loc_args = str(body_loc_args)
if is_ios:
fcm_payload['notification']['title-loc-args'] = title_loc_args
else:
if isinstance(title_loc_args, list):
fcm_payload['notification']['title_loc_args'] = title_loc_args
else:
raise InvalidDataError('title_loc_args should be an array')

# This is needed for iOS when we are sending only custom data messages
if content_available and isinstance(content_available, bool):
Expand Down
16 changes: 7 additions & 9 deletions pyfcm/fcm.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .baseapi import BaseAPI
from .errors import *


class FCMNotification(BaseAPI):

def notify_single_device(self,
registration_id=None,
message_body=None,
Expand All @@ -26,7 +26,6 @@ def notify_single_device(self,
title_loc_key=None,
title_loc_args=None,
content_available=None,
is_ios=False,
extra_kwargs={}):

"""
Expand Down Expand Up @@ -65,12 +64,15 @@ def notify_single_device(self,
InvalidDataError: Invalid data provided
InternalPackageError: Mostly from changes in the response of FCM, contact the project owner to resolve the issue
"""
if registration_id is None:
raise InvalidDataError('Invalid registration ID')
# [registration_id] cos we're sending to a single device
payload = self.parse_payload(registration_ids=[registration_id],
message_body=message_body,
message_title=message_title,
message_icon=message_icon,
sound=sound,
condition=condition,
collapse_key=collapse_key,
delay_while_idle=delay_while_idle,
time_to_live=time_to_live,
Expand All @@ -85,7 +87,6 @@ def notify_single_device(self,
title_loc_key=title_loc_key,
title_loc_args=title_loc_args,
content_available=content_available,
is_ios=is_ios,
**extra_kwargs)

self.send_request([payload])
Expand Down Expand Up @@ -114,7 +115,6 @@ def notify_multiple_devices(self,
title_loc_key=None,
title_loc_args=None,
content_available=None,
is_ios=False,
extra_kwargs={}):

"""
Expand Down Expand Up @@ -162,8 +162,9 @@ def notify_multiple_devices(self,
payloads.append(self.parse_payload(registration_ids=registration_ids,
message_body=message_body,
message_title=message_title,
sound=sound,
message_icon=message_icon,
sound=sound,
condition=condition,
collapse_key=collapse_key,
delay_while_idle=delay_while_idle,
time_to_live=time_to_live,
Expand All @@ -179,7 +180,6 @@ def notify_multiple_devices(self,
title_loc_key=title_loc_key,
title_loc_args=title_loc_args,
content_available=content_available,
is_ios=is_ios,
**extra_kwargs))
self.send_request(payloads)
return self.parse_responses()
Expand All @@ -189,6 +189,7 @@ def notify_multiple_devices(self,
message_title=message_title,
message_icon=message_icon,
sound=sound,
condition=condition,
collapse_key=collapse_key,
delay_while_idle=delay_while_idle,
time_to_live=time_to_live,
Expand All @@ -203,7 +204,6 @@ def notify_multiple_devices(self,
title_loc_key=title_loc_key,
title_loc_args=title_loc_args,
content_available=content_available,
is_ios=is_ios,
**extra_kwargs)
self.send_request([payload])
return self.parse_responses()
Expand Down Expand Up @@ -231,7 +231,6 @@ def notify_topic_subscribers(self,
title_loc_key=None,
title_loc_args=None,
content_available=None,
is_ios=False,
extra_kwargs={}):

"""
Expand Down Expand Up @@ -292,7 +291,6 @@ def notify_topic_subscribers(self,
title_loc_key=title_loc_key,
title_loc_args=title_loc_args,
content_available=content_available,
is_ios=is_ios,
**extra_kwargs)
self.send_request([payload])
return self.parse_responses()[-1:][0]

0 comments on commit f43b9ae

Please sign in to comment.