@@ -54,6 +54,10 @@ class APNsClient(object):
|
||||
stream_id = self.send_notification_async(token_hex, notification, topic, priority, expiration, collapse_id)
|
||||
result = self.get_notification_result(stream_id)
|
||||
if result != 'Success':
|
||||
if isinstance(result, tuple):
|
||||
reason, info = result
|
||||
raise exception_class_for_reason(reason)(info)
|
||||
else:
|
||||
raise exception_class_for_reason(result)
|
||||
|
||||
def send_notification_async(self, token_hex, notification, topic=None, priority=NotificationPriority.Immediate,
|
||||
@@ -83,12 +87,19 @@ class APNsClient(object):
|
||||
return stream_id
|
||||
|
||||
def get_notification_result(self, stream_id):
|
||||
"""
|
||||
Get result for specified stream
|
||||
The function returns: 'Success' or 'failure reason' or ('Unregistered', timestamp)
|
||||
"""
|
||||
with self._connection.get_response(stream_id) as response:
|
||||
if response.status == 200:
|
||||
return 'Success'
|
||||
else:
|
||||
raw_data = response.read().decode('utf-8')
|
||||
data = json.loads(raw_data)
|
||||
if response.status == 410:
|
||||
return data['reason'], data['timestamp']
|
||||
else:
|
||||
return data['reason']
|
||||
|
||||
def send_notification_batch(self, notifications, topic=None, priority=NotificationPriority.Immediate,
|
||||
|
||||
@@ -128,6 +128,11 @@ class MethodNotAllowed(InternalException):
|
||||
class Unregistered(APNsException):
|
||||
"""The device token is inactive for the specified topic."""
|
||||
|
||||
def __init__(self, timestamp=None):
|
||||
super().__init__()
|
||||
|
||||
self.timestamp = timestamp
|
||||
|
||||
|
||||
class PayloadTooLarge(BadPayloadException):
|
||||
"""The message payload was too large. The maximum payload size is 4096 bytes."""
|
||||
|
||||
Reference in New Issue
Block a user