Add initial implementation for Payload class

This commit is contained in:
Sergey Petrov
2016-01-28 12:05:16 +03:00
parent 5313b9a3bd
commit 0f186aed66
2 changed files with 102 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
MAX_PAYLOAD_SIZE = 4096
class PayloadAlert(object):
def __init__(self, title=None, title_localized_key=None, title_localized_args=None,
body=None, body_localized_key=None, body_localized_args=None,
action_localized_key=None,
launch_image=None
):
super().__init__()
self.title = title
self.title_localized_key = title_localized_key
self.title_localized_args = title_localized_args
self.body = body
self.body_localized_key = body_localized_key
self.body_localized_args = body_localized_args
self.action_localized_key = action_localized_key
self.launch_image = launch_image
def dict(self):
result = {}
if self.title:
result['title'] = self.title
if self.title_localized_key:
result['title-loc-key'] = self.title_localized_key
if self.title_localized_args:
result['title-loc-args'] = self.title_localized_args
if self.body:
result['body'] = self.body
if self.body_localized_key:
result['loc-key'] = self.body_localized_key
if self.body_localized_args:
result['loc-args'] = self.body_localized_args
if self.action_localized_key:
result['action-loc-key'] = self.action_localized_key
if self.launch_image:
result['launch-image'] = self.launch_image
return result
class Payload(object):
def __init__(self, alert=None, badge=None, sound=None, content_available=None, category=None, custom=None):
super().__init__()
self.alert = alert
self.badge = badge
self.sound = sound
self.content_available = content_available
self.category = category
self.custom = custom
def dict(self):
result = {
'aps': {}
}
if self.alert:
if self.alert is PayloadAlert:
result['aps']['alert'] = self.alert.dict()
else:
result['aps']['alert'] = self.alert
if self.badge:
result['aps']['badge'] = self.badge
if self.sound:
result['aps']['sound'] = self.sound
if self.content_available:
result['aps']['content-available'] = 1
if self.category:
result['aps']['category'] = self.category
if self.custom:
result.update(self.custom)
return result
+26
View File
@@ -0,0 +1,26 @@
from typing import Any, Dict, List, Optional, Union
class PayloadAlert(object):
def __init__(self,
title: Optional[str] = None,
title_localized_key: Optional[str] = None,
title_localized_args: Optional[List[str]] = None,
body: Optional[str] = None,
body_localized_key: Optional[str] = None,
body_localized_args: Optional[List[str]] = None,
action_localized_key: Optional[str] = None,
launch_image: Optional[str] = None
) -> None: ...
def dict(self) -> Dict[str, Any]: ...
class Payload(object):
def __init__(self,
alert: Union[PayloadAlert, str, None] = None,
badge: Optional[int] = None,
sound: Optional[str] = None,
content_available: Optional[bool] = None,
category: Optional[str] = None,
custom: Optional[Dict[str, Any]] = None) -> None: ...
def dict(self) -> Dict[str, Any]: ...