Merge pull request #10 from 72squared/master
support for apns-expiration header …
This commit is contained in:
+4
-1
@@ -21,7 +21,7 @@ class APNsClient(object):
|
|||||||
ssl_context.load_cert_chain(cert_file)
|
ssl_context.load_cert_chain(cert_file)
|
||||||
self.__connection = HTTP20Connection(server, port, ssl_context=ssl_context, force_proto=proto or 'h2')
|
self.__connection = HTTP20Connection(server, port, ssl_context=ssl_context, force_proto=proto or 'h2')
|
||||||
|
|
||||||
def send_notification(self, token_hex, notification, priority=NotificationPriority.Immediate, topic=None):
|
def send_notification(self, token_hex, notification, priority=NotificationPriority.Immediate, topic=None, expiration=None):
|
||||||
json_payload = dumps(notification.dict(), ensure_ascii=False, separators=(',', ':')).encode('utf-8')
|
json_payload = dumps(notification.dict(), ensure_ascii=False, separators=(',', ':')).encode('utf-8')
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
@@ -30,6 +30,9 @@ class APNsClient(object):
|
|||||||
if topic:
|
if topic:
|
||||||
headers['apns-topic'] = topic
|
headers['apns-topic'] = topic
|
||||||
|
|
||||||
|
if expiration is not None:
|
||||||
|
headers['apns-expiration'] = "%d" % expiration
|
||||||
|
|
||||||
url = '/3/device/{}'.format(token_hex)
|
url = '/3/device/{}'.format(token_hex)
|
||||||
stream_id = self.__connection.request('POST', url, json_payload, headers)
|
stream_id = self.__connection.request('POST', url, json_payload, headers)
|
||||||
resp = self.__connection.get_response(stream_id)
|
resp = self.__connection.get_response(stream_id)
|
||||||
|
|||||||
+2
-1
@@ -14,4 +14,5 @@ class APNsClient(object):
|
|||||||
token_hex: str,
|
token_hex: str,
|
||||||
notification: Payload,
|
notification: Payload,
|
||||||
priority: NotificationPriority = NotificationPriority.Immediate,
|
priority: NotificationPriority = NotificationPriority.Immediate,
|
||||||
topic: Optional[str] = None) -> None: ...
|
topic: Optional[str] = None,
|
||||||
|
expiration: Optional[int] = None) -> None: ...
|
||||||
|
|||||||
Reference in New Issue
Block a user