Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

Add url and send_after options #7

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ List of API methods to be covered by our client.
- [U] Create an app
- [U] Update an app
- [A] View devices
- View device
- ~~View device~~
- [U] Add a device
- Edit device
- [U] New session
Expand Down
26 changes: 22 additions & 4 deletions onesignalclient/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,14 @@ def __init__(self, app_id, mode=SEGMENTS_MODE):
self.contents = {'en': 'Default message.'}
self.headings = {}
self.subtitle = {}
self.send_after = None
self.url = None
self.data = {}
self.small_icon = None
self.large_icon = None
self.ios_badge_type = self.IOS_BADGE_TYPE_NONE
self.ios_badge_count = 0
self.image = None

def _validate_content_dict(self, value):
"""
Expand All @@ -172,29 +175,44 @@ def get_payload_for_request(self):
payload = {
'app_id': self.app_id,
# Should change when template/content_available support be done
'contents': self.contents
'contents': self.contents,
'android_accent_color': 'FFE42D1F',
Copy link
Owner

@joaobarbosa joaobarbosa Sep 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about making android_accent_color a property in the class?

}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unwanted space? 😬

# Mode related settings
if self.mode == self.DEVICES_MODE:
payload.update({'include_player_ids': self.include_player_ids})

# Common parameters
if len(self.data) > 0:
payload.update({'data': self.data})
payload.update({'data': self.data})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the verification? I didn't understand 🤔


if len(self.headings) > 0:
payload.update({'headings': self.headings})

if len(self.subtitle) > 0:
payload.update({'subtitle': self.subtitle})

if self.send_after:
payload.update({'send_after': self.send_after})

if self.url:
payload.update({'url': self.url})

if self.small_icon:
payload.update({'small_icon': self.small_icon})

if self.large_icon:
payload.update({'large_icon': self.large_icon})

if self.image:
payload.update({
'mutable_content': True,
'ios_attachments': {
'id': self.image
},
'big_picture': self.image
})

if self.ios_badge_count > 0:
payload.update({
'ios_badgeType': self.ios_badge_type,
Expand Down
4 changes: 4 additions & 0 deletions onesignalclient/user_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ def view_apps(self):
def view_app(self, app_id):
endpoint = 'apps/%s' % (app_id)
return self.get(self._url(endpoint))

def view_device(self, player_id, app_id):
endpoint = 'players/%s?%s' % (player_id, app_id)
return self.get(self._url(endpoint))
8 changes: 8 additions & 0 deletions tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ class BaseTest():
'uri': re.compile('%s/apps/(\w|\-)+' % (base_url)),
'status': codes.not_found
},
'test_view_device': {
'uri': re.compile('%s/players/(\w|\-)+' % (base_url)),
'body': '{"identifier": "ce777617da7f548fe7a9ab6febb56cf39fba6d2"}'
},
'test_view_device_not_found': {
'uri': re.compile('%s/players/(\w|\-)+' % (base_url)),
'status': codes.not_found
},
'test_create_notification': {
'method': responses.POST,
'uri': '%s/notifications' % (base_url),
Expand Down
8 changes: 8 additions & 0 deletions tests/test_user_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ def test_view_app(self, user_client, app_id):
def test_view_app_not_found(self, user_client, app_id):
with pytest.raises(HTTPError):
user_client.view_app(app_id)

def test_view_device(self, user_client, player_id_1, app_id):
device = user_client.view_device(player_id_1, app_id)
assert device.get('identifier', False)

def test_view_device_not_found(self, user_client, player_id_1, app_id):
with pytest.raises(HTTPError):
user_client.view_device(player_id_1, app_id)