本文整理汇总了Python中apns.Frame类的典型用法代码示例。如果您正苦于以下问题:Python Frame类的具体用法?Python Frame怎么用?Python Frame使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Frame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_frame_item
def test_add_frame_item():
global has_called_check_method
has_called_check_method = False
# assert_called_once_with of Mock Class failes to compare Payload object.
# So here created custom check method for parameter checking
def check_add_item_args(token, payload, identifier, expiry, priority):
default_expiry = int(time.time()) + (60 * 60)
eq_(token, dummy_token)
eq_(payload.alert, 'Hey')
eq_(payload.badge, None)
eq_(payload.sound, None)
eq_(payload.custom, {})
eq_(payload.content_available, False)
eq_(identifier, 123)
eq_(priority, 10, 'priority should set default value when skipped')
eq_(expiry, default_expiry, 'expiry should set default value when skipped')
global has_called_check_method
has_called_check_method = True
worker = SendWorkerThread(**dummy_setting)
worker.count = 123
frame = Frame()
frame.add_item = check_add_item_args
worker.add_frame_item(frame, 'myapp', dummy_token, {'alert': 'Hey'})
ok_(has_called_check_method)
示例2: test_add_frame_item_with_full_args
def test_add_frame_item_with_full_args():
global has_called_check_method
has_called_check_method = False
# assert_called_once_with of Mock Class failes to compare Payload object.
# So here created custom check method for parameter checking
def check_add_item_args(token, payload, identifier, expiry, priority):
eq_(token, dummy_token)
eq_(payload.alert, 'Wow')
eq_(payload.badge, 50)
eq_(payload.sound, 'bell')
eq_(payload.custom, {'foo': 'bar'})
eq_(payload.content_available, True)
eq_(identifier, 1)
eq_(priority, 5)
eq_(expiry, 0)
global has_called_check_method
has_called_check_method = True
worker = SendWorkerThread(**dummy_setting)
worker.count = 1
frame = Frame()
frame.add_item = check_add_item_args
worker.add_frame_item(frame, 'myapp', dummy_token, {
'alert': 'Wow',
'badge': 50,
'sound': 'bell',
'custom': {'foo': 'bar'},
'content_available': True,
}, expiry=0, priority=5)
ok_(has_called_check_method)
示例3: handle
def handle(self, *args, **options):
while True:
ApplePushNotification.objects.filter(state=ApplePushNotification.NEW).update(state=ApplePushNotification.PENDING)
frame = Frame()
identifier = 1
expiry = time.time() + 3600
priority = 10
# retry_cnt = 10
apns = APNs(use_sandbox=False, cert_file="onoo-production.pem", key_file="onoo-production-key.pem")
# while retry_cnt > 0:
try:
cnt = 0
for noti in ApplePushNotification.objects.filter(state=ApplePushNotification.PENDING):
cnt += 1
# apns.gateway_server.send_notification(noti.device_token, Payload(alert=noti.message, badge=noti.badge_count))
frame.add_item(noti.device_token, Payload(alert=noti.message, sound="default", badge=noti.badge_count), identifier, expiry, priority)
if cnt > 0:
apns.gateway_server.send_notification_multiple(frame)
except:
import traceback
traceback.print_exc()
ApplePushNotification.objects.filter(state=ApplePushNotification.PENDING).update(state=ApplePushNotification.NEW)
# retry_cnt -= 1
# time.sleep(1)
# for (token_hex, fail_time) in apns.feedback_server.items():
# # logging 하기 ...
# pass
# ApplePushNotification.objects.filter(state=ApplePushNotification.PENDING).delete()
ApplePushNotification.objects.filter(state=ApplePushNotification.PENDING).update(state=ApplePushNotification.DONE)
time.sleep(1)
示例4: apns_notification
def apns_notification(tokens_hex, message):
apns = APNs(use_sandbox=True, cert_file='cert.pem', key_file='key.pem')
"""
# Send a notification
token_hex = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87'
payload = Payload(alert="Hello World!", sound="default", badge=1)
apns.gateway_server.send_notification(token_hex, payload)
"""
# Send multiple notifications in a single transmission
# tokens_hex = []
payload = Payload(alert=message, sound="default", badge=1)
frame = Frame()
identifier = 1
expiry = time.time()+3600
priority = 10
for token in tokens_hex:
frame.add_item(token, payload, identifier,
expiry, priority)
apns.gateway_server.send_notification_multiple(frame)
示例5: post
def post(self):
"""
post HTTP method
Send apns notification for all data in the QuestionTimeNotification
table.
Returns:
A 201 Created HTTP status code.
"""
query = QuestionTimeNotification.query.all()
print query
if len(query) < 1:
return "", 500
else:
payload = Payload(
alert="Question time is currently live.",
sound="default",
category="QUESTION_TIME_CATEGORY",
custom={
'link':
'http:/a-vide-link/playlist.m3u8'
},
badge=0)
frame = Frame()
identifer = 1
expiry = time.time() + 3600
priority = 10
for item in query:
token_hex = ''.join(item.tokenid)
frame.add_item(token_hex, payload, identifer, expiry, priority)
apns.gateway_server.send_notification_multiple(frame)
return "", 204
示例6: send
def send(tokens, payload):
frame = Frame()
expiry = time.time() + config.expiry
for token in tokens:
identifier = random.getrandbits(32)
frame.add_item(token, payload, identifier, expiry, config.priority)
apns.gateway_server.register_response_listener(error_handler)
apns.gateway_server.send_notification_multiple(frame)
示例7: sendNotification
def sendNotification(token, message, timeout):
apns = APNs(use_sandbox=False, cert_file="cert.pem", key_file="key.pem")
frame = Frame()
identifier = random.getrandbits(32)
priority = 10
payload = {"aps": {"alert": message, "sound": "default", "identifier": identifier}}
# Payload(alert=message, sound="default", custom = {"identifier":identifier})
frame.add_item(token, payload, identifier, timeout, priority)
apns.gateway_server.send_notification_multiple(frame)
return identifier
示例8: send_notification_with_payload
def send_notification_with_payload(self, message, payload_dict):
if self.device_token_list:
apns = APNs(use_sandbox=True, cert_file=self.cert_path, key_file=self.key_path)
frame = Frame()
identifier = 1
expiry = time.time() + 3600
priority = 10
payload = Payload(alert=message, sound="default", badge=1, custom=payload_dict)
for device_token in self.device_token_list:
frame.add_item(device_token, payload, identifier, expiry, priority)
apns.gateway_server.send_notification_multiple(frame)
示例9: apns_send
def apns_send(tokens, alert, message):
apns = APNs(cert_file='cert.pem', key_file='key.pem')
payload = Payload(alert=alert, custom=message)
frame = Frame()
identifier = 1
expiry = time.time()+3600
priority = 10
[frame.add_item(token, payload, identifier, expiry, priority) for token in tokens if len(token) > 10]
try:
apns.gateway_server.send_notification_multiple(frame)
except:
pass
示例10: send_notification
def send_notification(state):
device_tokens = DeviceToken.objects.values_list('token', flat=True)
payload = get_payload(state)
apns = APNs(cert_file=config('CERT_PEM'), key_file=config('KEY_PEM'), enhanced=True)
frame = Frame()
for index, token in enumerate(device_tokens):
identifier = index + 1
expiry = time.time() + 3600
priority = 10
frame.add_item(token, payload, identifier, expiry, priority)
apns.gateway_server.send_notification_multiple(frame)
示例11: get_frame
def get_frame(self, message, device_tokens):
frame = Frame()
identifier = random.getrandbits(32)
payload = Payload(alert=message)
for token in device_tokens:
frame.add_item(
token,
payload,
identifier,
self.IOS_EXPIRY_SECONDS,
self.IOS_PRIORITY
)
return frame
示例12: send_push_background
def send_push_background(tokens, text, badge, data, content_available):
apns = APNs(use_sandbox=False, cert_file='static/JukeboxBetaPush.pem', key_file='static/JukeboxBetaPush.pem')
frame = Frame()
identifier = 1
expiry = time.time()+3600
priority = 10
for device_token in tokens:
sound = None
if text:
sound = "default"
if not data:
data = {}
payload = Payload(alert=text, sound=sound, badge=badge, custom=data, content_available=content_available)
frame.add_item(device_token, payload, identifier, expiry, priority)
apns.gateway_server.send_notification_multiple(frame)
示例13: send_notifications_apns
def send_notifications_apns(self, device_tokens, payload, priority=10,
identifier=None, expiry=None):
if not device_tokens:
raise ValueError("No device tokens specified, should be a list")
apns = APNs(use_sandbox=self.use_sandbox, cert_file=self.current_cert_file)
# Send multiple notifications in a single transmission
frame = Frame()
for device_token in device_tokens:
frame.add_item(device_token, payload, identifier, expiry, priority)
return apns.gateway_server.send_notification_multiple(frame)
示例14: push_notification_multi_raw_apple
def push_notification_multi_raw_apple(apns, tokens_hex, payload=None, payloads=None):
frame = Frame()
identifier = 1
expiry = time.time() + 3600
priority = 10
if payload:
for token in tokens_hex:
frame.add_item(token, Payload(**payload), identifier, expiry, priority)
else:
for token, payload in tokens_hex, payloads:
frame.add_item(token, Payload(**payload), identifier, expiry, priority)
apns.gateway_server.send_notification_multiple(frame)
# Get feedback messages
for (token_hex, fail_time) in apns.feedback_server.items():
# do stuff with token_hex and fail_time
pass
示例15: send_multi_apn
def send_multi_apn(message, devs, pub=None):
frame = Frame()
identifier = 1
expiry = time.time()+(60*60*24) # 1 day expire time
priority = 10
send = []
unsend = []
for dev in devs:
payload = craft_apn_payload(message, dev, pub=pub)
if payload:
frame.add_item(dev.apns_token, payload, identifier, expiry, priority)
send.append(dev.name)
else:
unsend.append(dev.name)
apns.gateway_server.send_notification_multiple(frame)
return (send, unsend)