diff --git a/README.md b/README.md index 80d3963..8a38044 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/onesignalclient/notification.py b/onesignalclient/notification.py index 07591aa..ce4443f 100644 --- a/onesignalclient/notification.py +++ b/onesignalclient/notification.py @@ -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): """ @@ -172,16 +175,16 @@ 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', } - + # 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}) if len(self.headings) > 0: payload.update({'headings': self.headings}) @@ -189,12 +192,27 @@ def get_payload_for_request(self): 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, diff --git a/onesignalclient/user_client.py b/onesignalclient/user_client.py index 0ebb093..0015568 100644 --- a/onesignalclient/user_client.py +++ b/onesignalclient/user_client.py @@ -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)) diff --git a/tests/base_test.py b/tests/base_test.py index 87e1ce7..63640ad 100644 --- a/tests/base_test.py +++ b/tests/base_test.py @@ -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), diff --git a/tests/test_user_client.py b/tests/test_user_client.py index 35d68f3..4c08b49 100644 --- a/tests/test_user_client.py +++ b/tests/test_user_client.py @@ -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)