当前位置: 首页>>代码示例>>Python>>正文


Python urbanairship.notification函数代码示例

本文整理汇总了Python中urbanairship.notification函数的典型用法代码示例。如果您正苦于以下问题:Python notification函数的具体用法?Python notification怎么用?Python notification使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了notification函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ios_unicode

    def test_ios_unicode(self):
        self.assertEqual(
            ua.notification(
                ios=ua.ios(
                    alert=u'Hello',
                    badge=u'+1',
                    expiry=u'time',
                )
            ),
            {
                'ios': {
                    'alert': 'Hello',
                    'badge': '+1',
                    'expiry': 'time'
                }
            }
        )

        self.assertEqual(
            ua.notification(
                ios=ua.ios(
                    content_available=True
                )
            ),
            {
                'ios': {
                    'content-available': True
                }
            }
        )
开发者ID:afresh1,项目名称:python-library,代码行数:30,代码来源:test_message.py

示例2: test_wns_payload

    def test_wns_payload(self):
        self.assertEqual(
            ua.notification(wns=ua.wns_payload(
                alert='Hello',
            )),
            {'wns': {
                'alert': 'Hello',
            }})

        self.assertEqual(
            ua.notification(wns=ua.wns_payload(
                toast={'key': 'value'},
            )),
            {'wns': {
                'toast': {'key': 'value'},
            }})

        self.assertEqual(
            ua.notification(wns=ua.wns_payload(
                tile={'key': 'value'},
            )),
            {'wns': {
                'tile': {'key': 'value'},
            }})

        self.assertEqual(
            ua.notification(wns=ua.wns_payload(
                badge={'key': 'Hello'},
            )),
            {'wns': {
                'badge': {'key': 'Hello'},
            }})
        self.assertRaises(ValueError, ua.wns_payload, alert='Hello',
            tile='Foo')
开发者ID:05bit,项目名称:python-urbanairship3,代码行数:34,代码来源:test_message.py

示例3: test_blackberry

    def test_blackberry(self):
        self.assertEqual(
            ua.notification(
                blackberry=ua.blackberry(
                    alert='Hello',
                )
            ),
            {
                'blackberry': {
                    'body': 'Hello',
                    'content_type': 'text/plain',
                }
            }
        )

        self.assertEqual(
            ua.notification(
                blackberry=ua.blackberry(
                    body='Hello',
                    content_type='text/html',
                )
            ),
            {
                'blackberry': {
                    'body': 'Hello',
                    'content_type': 'text/html',
                }
            }
        )
        self.assertRaises(
            ValueError,
            ua.blackberry,
            body='Hello'
        )
开发者ID:afresh1,项目名称:python-library,代码行数:34,代码来源:test_message.py

示例4: test_update_schedule

    def test_update_schedule(self):
        airship = ua.Airship('key', 'secret')
        sched = ua.ScheduledPush(airship)
        # Fail w/o URL
        self.assertRaises(ValueError, sched.update)

        with mock.patch.object(ua.Airship, '_request') as mock_request:
            url = "https://go.urbanairship.com/api/schedules/0492662a-1b52-4343-a1f9-c6b0c72931c0"

            response = requests.Response()
            response.status_code = 202
            response._content = (
                '''{"schedule_urls": ["https://go.urbanairship.com/api/schedules/0492662a-1b52-4343-a1f9-c6b0c72931c0"]}''')

            mock_request.return_value = response

            sched.url = url
            push = airship.create_push()
            push.audience = ua.all_
            push.notification = ua.notification(alert='Hello')
            push.device_types = ua.all_
            sched.push = push
            sched.schedule = ua.scheduled_time(datetime.datetime.now())

            sched.update()
开发者ID:KineticHub,项目名称:python-library,代码行数:25,代码来源:test_push.py

示例5: create_notification

def create_notification(receiver, reporter, content_object, notification_type):
    # If the receiver of this notification is the same as the reporter or
    # if the user has blocked this type, then don't create
    if receiver == reporter or not NotificationSetting.objects.get(notification_type=notification_type, user=receiver).allow:
        return

    notification = Notification.objects.create(user=receiver,
                                               reporter=reporter,
                                               content_object=content_object,
                                               notification_type=notification_type)
    notification.save()

    if AirshipToken.objects.filter(user=receiver, expired=False).exists():
        try:
            device_tokens = list(AirshipToken.objects.filter(user=receiver, expired=False).values_list('token', flat=True))
            airship = urbanairship.Airship(settings.AIRSHIP_APP_KEY, settings.AIRSHIP_APP_MASTER_SECRET)

            for device_token in device_tokens:
                push = airship.create_push()
                push.audience = urbanairship.device_token(device_token)
                push.notification = urbanairship.notification(ios=urbanairship.ios(alert=notification.push_message(), badge='+1'))
                push.device_types = urbanairship.device_types('ios')
                push.send()
        except urbanairship.AirshipFailure:
            pass
开发者ID:tashiro-wni,项目名称:manticore-tastypie-social,代码行数:25,代码来源:models.py

示例6: test_sms_overrides

    def test_sms_overrides(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(
            alert='top level alert',
            sms=ua.sms(
                alert='sms override alert',
                expiry='2018-04-01T12:00:00',
            )
        )
        p.device_types = ua.device_types('sms')

        self.assertEqual(
            p.payload,
            {
                'audience': 'all',
                'device_types': ['sms'],
                'notification': {
                    'alert': 'top level alert',
                    'sms': {
                        'alert': 'sms override alert',
                        'expiry': '2018-04-01T12:00:00'
                    }
                }
            }
        )
开发者ID:urbanairship,项目名称:python-library,代码行数:26,代码来源:test_push.py

示例7: test_full_scheduled_payload

    def test_full_scheduled_payload(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(alert='Hello')
        p.options = {}
        p.device_types = ua.all_
        p.message = ua.message("Title", "Body", "text/html", "utf8")
        sched = ua.ScheduledPush(None)
        sched.push = p
        sched.name = "a schedule"
        sched.schedule = ua.scheduled_time(
            datetime.datetime(2014, 1, 1, 12, 0, 0))

        self.assertEqual(sched.payload, {
            "name": "a schedule",
            "schedule": {'scheduled_time': '2014-01-01T12:00:00'},
            "push": {
                "audience": "all",
                "notification": {"alert": "Hello"},
                "device_types": "all",
                "options": {},
                "message": {
                    "title": "Title",
                    "body": "Body",
                    "content_type": "text/html",
                    "content_encoding": "utf8",
                },
            }
        })
开发者ID:KineticHub,项目名称:python-library,代码行数:29,代码来源:test_push.py

示例8: test_web_push

    def test_web_push(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(
            alert='Hello',
            web={
                'title': 'This is a title.',
                'icon': {'url': 'https://example.com/icon.png'},
                'extra': {'attribute': 'id'},
                'time_to_live': 12345,
                'require_interaction': False
            }
        )
        p.device_types = 'web'

        self.assertEqual(
            p.payload,
            {
                'audience': 'all',
                'device_types': 'web',
                'notification': {
                    'alert': 'Hello',
                    'web': {
                        'title': 'This is a title.',
                        'icon': {'url': 'https://example.com/icon.png'},
                        'extra': {'attribute': 'id'},
                        'time_to_live': 12345,
                        'require_interaction': False
                    },
                }
            }
        )
开发者ID:urbanairship,项目名称:python-library,代码行数:32,代码来源:test_push.py

示例9: options

 def options(self):
     airship = ua.Airship('key', 'secret')
     push = ua.Push(None)
     push.audience = ua.all_
     push.notification = ua.notification(alert='Hello Expiry')
     push.options = ua.options(expiry='2013-04-01T18:45:0')
     push.device_types = ua.all_
开发者ID:afresh1,项目名称:python-library,代码行数:7,代码来源:test_message.py

示例10: push

    def push(self, notification):

        if not config.get(config.SERVICES_ENABLED, 'off') == 'on':
            logger.info('notifications disabled: %s marked as pending' % notification.id)
            return

        push = self.airship.create_push()
        push.audience = self.make_tags(notification.tags)
        push.notification = ua.notification(ios=ua.ios(alert=notification.message, extra=notification.payload))
        push.device_types = ua.device_types('ios')

        if notification.scheduled_for:

            schedule = self.airship.create_scheduled_push()
            schedule.push = push
            schedule.name = notification.type

            if notification.scheduled_for_local:
                schedule.schedule = local_scheduled_time(notification.scheduled_for)
            else:
                schedule.schedule = ua.scheduled_time(notification.scheduled_for)

            logger.info("Sending scheduled push to Urban Airship")
            resp = schedule.send()

        else:
            logger.info("Sending push to Urban Airship")
            resp = push.send()

        notification.meta['ua_response'] = resp.payload
        notification.sent = True
开发者ID:jcarbaugh,项目名称:norrin,代码行数:31,代码来源:adapters.py

示例11: test_standard_ios_opts

    def test_standard_ios_opts(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(
            alert='Top level alert',
            ios=ua.ios(
                alert='iOS override alert',
                sound='cat.caf',
            )
        )
        p.device_types = ua.device_types('ios')

        self.assertEqual(
            p.payload,
            {
                'audience': 'all',
                'device_types': ['ios'],
                'notification': {
                    'alert': 'Top level alert',
                    'ios': {
                        'alert': 'iOS override alert',
                        'sound': 'cat.caf'
                    }
                }
            }
        )
开发者ID:urbanairship,项目名称:python-library,代码行数:26,代码来源:test_push.py

示例12: test_email_overrides

    def test_email_overrides(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(
            email=ua.email(
                message_type='transactional',
                plaintext_body='hello',
                reply_to='[email protected]',
                sender_address='[email protected]',
                sender_name='test_name',
                subject='hi',
                html_body='<html>so rich!</html>'
            )
        )
        p.device_types = ua.device_types('email')

        self.assertEqual(
            p.payload,
            {
                'audience': 'all',
                'device_types': ['email'],
                'notification': {
                    'email': {
                        'message_type': 'transactional',
                        'plaintext_body': 'hello',
                        'reply_to': '[email protected]',
                        'sender_address': '[email protected]',
                        'sender_name': 'test_name',
                        'subject': 'hi',
                        'html_body': '<html>so rich!</html>'
                    }
                }
            }
        )
开发者ID:urbanairship,项目名称:python-library,代码行数:34,代码来源:test_push.py

示例13: test_local_schedule_success

    def test_local_schedule_success(self):
        with mock.patch.object(ua.Airship, '_request') as mock_request:
            response = requests.Response()
            response._content = json.dumps(
                {
                    'schedule_urls': [
                        (
                            'https://go.urbanairship.com/api/schedules/'
                            '0492662a-1b52-4343-a1f9-c6b0c72931c0'
                        )
                    ]
                }
            ).encode('utf-8')
            response.status_code = 202
            mock_request.return_value = response

            airship = ua.Airship('key', 'secret')
            sched = ua.ScheduledPush(airship)
            push = airship.create_push()
            push.audience = ua.all_
            push.notification = ua.notification(alert='Hello')
            push.device_types = ua.all_
            sched.push = push
            sched.schedule = ua.local_scheduled_time(datetime.datetime.now())
            sched.send()

            self.assertEquals(
                sched.url,
                (
                    'https://go.urbanairship.com/api/schedules/'
                    '0492662a-1b52-4343-a1f9-c6b0c72931c0'
                )
            )
开发者ID:afresh1,项目名称:python-library,代码行数:33,代码来源:test_push.py

示例14: send_push_notification

def send_push_notification():
    push = airship.create_push()
    push.audience = ua.all_
    push.notification = ua.notification(
        alert="Betimlenecek bir gorsel var",
        ios=ios(sound='betim', badge=1),
    )
    push.device_types = ua.all_
    push.send()
开发者ID:betim-app,项目名称:betim,代码行数:9,代码来源:app.py

示例15: test_simple_alert

 def test_simple_alert(self):
     self.assertEqual(
         ua.notification(
             alert='Hello'
         ),
         {
             'alert': 'Hello'
         }
     )
开发者ID:afresh1,项目名称:python-library,代码行数:9,代码来源:test_message.py


注:本文中的urbanairship.notification函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。