Skip to content

Commit

Permalink
Add support for subtitle keys
Browse files Browse the repository at this point in the history
  • Loading branch information
karlwnw authored and Pr0Ger committed Apr 4, 2021
1 parent 5fb8c57 commit 5e4a938
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
13 changes: 13 additions & 0 deletions apns2/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def __init__(
title: Optional[str] = None,
title_localized_key: Optional[str] = None,
title_localized_args: Optional[List[str]] = None,
subtitle: Optional[str] = None,
subtitle_localized_key: Optional[str] = None,
subtitle_localized_args: Optional[List[str]] = None,
body: Optional[str] = None,
body_localized_key: Optional[str] = None,
body_localized_args: Optional[List[str]] = None,
Expand All @@ -19,6 +22,9 @@ def __init__(
self.title = title
self.title_localized_key = title_localized_key
self.title_localized_args = title_localized_args
self.subtitle = subtitle
self.subtitle_localized_key = subtitle_localized_key
self.subtitle_localized_args = subtitle_localized_args
self.body = body
self.body_localized_key = body_localized_key
self.body_localized_args = body_localized_args
Expand All @@ -36,6 +42,13 @@ def dict(self) -> Dict[str, Any]:
if self.title_localized_args:
result['title-loc-args'] = self.title_localized_args

if self.subtitle:
result['subtitle'] = self.subtitle
if self.subtitle_localized_key:
result['subtitle-loc-key'] = self.subtitle_localized_key
if self.subtitle_localized_args:
result['subtitle-loc-args'] = self.subtitle_localized_args

if self.body:
result['body'] = self.body
if self.body_localized_key:
Expand Down
21 changes: 15 additions & 6 deletions test/test_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
def payload_alert():
return PayloadAlert(
title='title',
title_localized_key='loc_k',
title_localized_args=['loc_a'],
title_localized_key='title_loc_k',
title_localized_args=['title_loc_a'],
subtitle='subtitle',
subtitle_localized_key='subtitle_loc_k',
subtitle_localized_args=['subtitle_loc_a'],
body='body',
body_localized_key='body_loc_k',
body_localized_args=['body_loc_a'],
Expand All @@ -21,8 +24,11 @@ def payload_alert():
def test_payload_alert(payload_alert):
assert payload_alert.dict() == {
'title': 'title',
'title-loc-key': 'loc_k',
'title-loc-args': ['loc_a'],
'title-loc-key': 'title_loc_k',
'title-loc-args': ['title_loc_a'],
'subtitle': 'subtitle',
'subtitle-loc-key': 'subtitle_loc_k',
'subtitle-loc-args': ['subtitle_loc_a'],
'body': 'body',
'loc-key': 'body_loc_k',
'loc-args': ['body_loc_a'],
Expand Down Expand Up @@ -61,8 +67,11 @@ def test_payload_with_payload_alert(payload_alert):
'aps': {
'alert': {
'title': 'title',
'title-loc-key': 'loc_k',
'title-loc-args': ['loc_a'],
'title-loc-key': 'title_loc_k',
'title-loc-args': ['title_loc_a'],
'subtitle': 'subtitle',
'subtitle-loc-key': 'subtitle_loc_k',
'subtitle-loc-args': ['subtitle_loc_a'],
'body': 'body',
'loc-key': 'body_loc_k',
'loc-args': ['body_loc_a'],
Expand Down

0 comments on commit 5e4a938

Please sign in to comment.