コード例 #1
0
 def test_publish_should_fail_if_too_many_interests_passed(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with requests_mock.Mocker() as http_mock:
         http_mock.register_uri(
             requests_mock.ANY,
             requests_mock.ANY,
             status_code=200,
             json={
                 'publishId': '1234',
             },
         )
         with self.assertRaises(ValueError) as e:
             pn_client.publish(
                 interests=['interest-' + str(i) for i in range(0, 101)],
                 publish_body={
                     'apns': {
                         'aps': {
                             'alert': 'Hello World!',
                         },
                     },
                 },
             )
         self.assertIn('Number of interests (101) exceeds maximum', str(e.exception))
コード例 #2
0
 def test_publish_should_fail_if_body_not_dict(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with self.assertRaises(TypeError) as e:
         pn_client.publish(
             interests=['donuts'],
             publish_body=False,
         )
     self.assertIn('publish_body must be a dictionary', str(e.exception))
コード例 #3
0
ファイル: serializers.py プロジェクト: OscarRuiz15/BackendTG
def push_notify(nombre_lugar, nombre_producto, id_lugar):
    from pusher_push_notifications import PushNotifications

    pn_client = PushNotifications(
        instance_id='150ee5d4-aa83-42f8-9c65-fe6ab983f0ca',
        secret_key=
        'FA39827AAB5E866F8084A0FD034F5CB59D987D566D35ED66BBEEA1564D561E93',
    )
    message = nombre_lugar + ' ha agregado ' + nombre_producto + ' a sus productos'
    interest = str(id_lugar)
    response = pn_client.publish(interests=[interest],
                                 publish_body={
                                     'apns': {
                                         'aps': {
                                             'alert': 'Hello!'
                                         }
                                     },
                                     'fcm': {
                                         'notification': {
                                             'title': 'Nuevo Producto',
                                             'body': message
                                         }
                                     }
                                 })

    print(response['publishId'])
コード例 #4
0
ファイル: views.py プロジェクト: xiaofuhu/pyhon_firebase_test
def push_notify(name, progress, work):
    from pusher_push_notifications import PushNotifications

    pn_client = PushNotifications(
        instance_id='be2dce08-9b23-4a81-a72b-fab39797530c',
        secret_key='0D2A5BABBF132520C4CF8FB9C165D12',
    )

    response = pn_client.publish(interests=['hello'],
                                 publish_body={
                                     'apns': {
                                         'aps': {
                                             'alert': 'Report Created'
                                         }
                                     },
                                     'fcm': {
                                         'notification': {
                                             'title':
                                             str(name),
                                             'body':
                                             'Progress: ' + str(progress) +
                                             " work: " + str(work)
                                         }
                                     }
                                 })

    print(response['publishId'])
コード例 #5
0
    def vehicle_android_notify(title, vehicleNo, timedate):

        pn_client = PushNotifications(
            instance_id='8518a068-3e7f-4520-8b59-2799cb76b86c',
            secret_key=
            '9A1A920184592A9F281E7635D340E2C9C6D45C27156C7F1F742E6EF69662D67E',
        )
        response = pn_client.publish(
            interests=['hello'],
            publish_body={
                'apns': {
                    'aps': {
                        'alert': 'Report Created'
                    }
                },
                'fcm': {
                    'notification': {
                        'title':
                        str(title),
                        'body':
                        'Time: ' + str(timedate) + ', Black List Vehicle: ' +
                        str(vehicleNo) + ' on main entrance'
                    }
                }
            })
コード例 #6
0
    def test_android_notify(title, vehicleNo, timedate):

        pn_client = PushNotifications(
            instance_id=
            'dKEmXMZa2dg:APA91bGSPWTu1wgHL4IqYYpY3KN_X-HhylH1IQirN1AwIgqAx2jZZCIMuH_Yk9X0M5D6WtVMrWd-a0XqOCFY5Np8AEv6j87FeW7ObfDs5VpP3ABV2LeZnm51gzKbgZEca911Bc6XB53-',
            secret_key=
            'dKEmXMZa2dg:APA91bGSPWTu1wgHL4IqYYpY3KN_X-HhylH1IQirN1AwIgqAx2jZZCIMuH_Yk9X0M5D6WtVMrWd-a0XqOCFY5Np8AEv6j87FeW7ObfDs5VpP3ABV2LeZnm51gzKbgZEca911Bc6XB53-',
        )

        response = pn_client.publish(
            interests=['hello'],
            publish_body={
                'apns': {
                    'aps': {
                        'alert': 'Report Created'
                    }
                },
                'fcm': {
                    'notification': {
                        'title':
                        str(title),
                        'body':
                        'Time: ' + str(timedate) + ', Black List Vehicle: ' +
                        str(vehicleNo) + ' on main entrance'
                    }
                }
            })
コード例 #7
0
    def push_notif(self, data):
        pn_client = PushNotifications(
            instance_id="5fb00808-3b8d-4533-9079-9fec45c7d781",
            secret_key='11027CDC0A5627F5F6EE83961C72D34',
        )

        response = pn_client.publish(
            interests=[PUSHER_INTEREST],
            publish_body={
                'apns': {
                    'aps': {
                        'alert': 'Hello!',
                    },
                },
                'fcm': {
                    'notification': {
                        'title': 'ALERT MESSAGE',
                        'body': data['alarmname'],
                        'sound': 'default',
                    },
                },
            },
        )

        print(response['publishId'])
コード例 #8
0
 def test_publish_should_fail_if_no_interests_passed(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with self.assertRaises(ValueError) as e:
         pn_client.publish(
             interests=[],
             publish_body={
                 'apns': {
                     'aps': {
                         'alert': 'Hello World!',
                     },
                 },
             },
         )
     self.assertIn('must target at least one interest', str(e.exception))
コード例 #9
0
 def test_publish_should_fail_if_interests_not_list(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with self.assertRaises(TypeError) as e:
         pn_client.publish(
             interests=False,
             publish_body={
                 'apns': {
                     'aps': {
                         'alert': 'Hello World!',
                     },
                 },
             },
         )
     self.assertIn('interests must be a list', str(e.exception))
コード例 #10
0
 def test_publish_should_fail_if_interest_not_a_string(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with self.assertRaises(TypeError) as e:
         pn_client.publish(
             interests=[False],
             publish_body={
                 'apns': {
                     'aps': {
                         'alert': 'Hello World!',
                     },
                 },
             },
         )
     self.assertIn('Interest False is not a string', str(e.exception))
コード例 #11
0
 def test_publish_should_fail_if_interest_too_long(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with self.assertRaises(ValueError) as e:
         pn_client.publish(
             interests=['A'*200],
             publish_body={
                 'apns': {
                     'aps': {
                         'alert': 'Hello World!',
                     },
                 },
             },
         )
     self.assertIn('longer than the maximum of 164 chars', str(e.exception))
コード例 #12
0
def push_notify(title,vahicleNo,timedate):    
    from pusher_push_notifications import PushNotifications
    pn_client = PushNotifications(
    instance_id='8518a068-3e7f-4520-8b59-2799cb76b86c',
    secret_key='9A1A920184592A9F281E7635D340E2C9C6D45C27156C7F1F742E6EF69662D67E',
    )
    response = pn_client.publish(
    interests=['hello'],
    publish_body={'apns': {'aps': {'alert': 'Report Created'}},
    'fcm': {'notification': {'title': str(title), 'body': 'Black List Vehicle: '+str(vahicleNo) +'has entered'
                             }
            }}
    )
    print(response['publishId'])
コード例 #13
0
 def test_publish_should_succeed_if_100_interests_passed(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with requests_mock.Mocker() as http_mock:
         http_mock.register_uri(
             requests_mock.ANY,
             requests_mock.ANY,
             status_code=200,
             json={
                 'publishId': '1234',
             },
         )
         pn_client.publish(
             interests=['interest-' + str(i) for i in range(0, 100)],
             publish_body={
                 'apns': {
                     'aps': {
                         'alert': 'Hello World!',
                     },
                 },
             },
         )
コード例 #14
0
 def test_publish_should_error_correctly_if_error_not_json(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with requests_mock.Mocker() as http_mock:
         http_mock.register_uri(
             requests_mock.ANY,
             requests_mock.ANY,
             status_code=500,
             text='<notjson></notjson>',
         )
         with self.assertRaises(PusherServerError) as e:
             pn_client.publish(
                 interests=['donuts'],
                 publish_body={
                     'apns': {
                         'aps': {
                             'alert': 'Hello World!',
                         },
                     },
                 },
             )
         self.assertIn('Unknown error: no description', str(e.exception))
コード例 #15
0
 def test_publish_should_raise_on_http_404_error(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with requests_mock.Mocker() as http_mock:
         http_mock.register_uri(
             requests_mock.ANY,
             requests_mock.ANY,
             status_code=404,
             json={'error': 'Instance not found', 'description': 'blah'},
         )
         with self.assertRaises(PusherMissingInstanceError) as e:
             pn_client.publish(
                 interests=['donuts'],
                 publish_body={
                     'apns': {
                         'aps': {
                             'alert': 'Hello World!',
                         },
                     },
                 },
             )
         self.assertIn('Instance not found: blah', str(e.exception))
コード例 #16
0
def push_notification(currency, value):
    pn_client = PushNotifications(
        instance_id='776e8433-c7b8-4aa9-bf62-5c23650b37c7',
        secret_key=
        'C15FB9EFB61976F1F09BC463F3265EBD3A2A801E612CE717257A576472F9FEAE',
    )

    response = pn_client.publish(
        interests=['hello'],
        publish_body={
            'fcm': {
                'notification': {
                    'body': currency + ' ma nowy kurs: ' + value,
                },
            },
        },
    )

    print(response['publishId'])
コード例 #17
0
    def student_android_notify(title, studentName, alert, timedate):

        pn_client = PushNotifications(
            instance_id='8518a068-3e7f-4520-8b59-2799cb76b86c',
            secret_key=
            '9A1A920184592A9F281E7635D340E2C9C6D45C27156C7F1F742E6EF69662D67E',
        )
        response = pn_client.publish(interests=['hello'],
                                     publish_body={
                                         'apns': {
                                             'aps': {
                                                 'alert': 'Report Created'
                                             }
                                         },
                                         'fcm': {
                                             'notification': {
                                                 'title': 'FRS Camera',
                                                 'body': alert
                                             }
                                         }
                                     })
コード例 #18
0
ファイル: views.py プロジェクト: ElvinEga/timeappdjango
def push_notify(title, message):

    pn_client = PushNotifications(
        instance_id='3ab849d3-463b-4bea-b81e-86b25542a590',
        secret_key='C2C5AA3DEBBA3C415AF5FA21404A654',
    )
    response = pn_client.publish(interests=['hello'],
                                 publish_body={
                                     'apns': {
                                         'aps': {
                                             'alert': 'Transaction'
                                         }
                                     },
                                     'fcm': {
                                         'notification': {
                                             'title': str(title),
                                             'body': str(message)
                                         }
                                     }
                                 })

    print(response['publishId'])
コード例 #19
0
    def sendNotification(message, targetInterests):
        try:
            #pusher instance
            pn_client = PushNotifications(
                instance_id="e26036a3-7c7e-4de1-a782-a8aee792f3c4",
                secret_key="AE5D352C43A1139E2587312C231A478",
            )
            #send notification
            response = pn_client.publish(
                interests=['hello'],
                publish_body={
                    'apns': {
                        'aps': {
                            'alert': message
                        },
                    },
                },
            )

        except Exception as e:
            print("error while trying to send notification. Error: " + str(e))
            return "error while trying to send notification. Error: " + str(
                e), 200
コード例 #20
0
def push_notify(name, progress, work):

    pn_client = PushNotifications(
        instance_id='d01b2036-e93f-4125-9842-599b86adf848',
        secret_key=
        'A3A80F519C3087269057B0660CD7DF4ED50E6F63EA413983BEA26B31297AE7D3')
    response = pn_client.publish(interests=['hello'],
                                 publish_body={
                                     'apns': {
                                         'aps': {
                                             'alert': 'Report Created'
                                         }
                                     },
                                     'fcm': {
                                         'notification': {
                                             'title':
                                             str(name),
                                             'body':
                                             'Progress: ' + str(progress) +
                                             " work: " + str(work)
                                         }
                                     }
                                 })
    print(response['publishId'])
コード例 #21
0
    def test_publish_should_fail_if_interest_contains_invalid_chars(self):
        pn_client = PushNotifications(
            'INSTANCE_ID',
            'SECRET_KEY'
        )
        with self.assertRaises(ValueError) as e:
            pn_client.publish(
                interests=['bad:interest'],
                publish_body={
                    'apns': {
                        'aps': {
                            'alert': 'Hello World!',
                        },
                    },
                },
            )
        self.assertIn('"bad:interest" contains a forbidden character', str(e.exception))

        with self.assertRaises(ValueError) as e:
            pn_client.publish(
                interests=['bad|interest'],
                publish_body={
                    'apns': {
                        'aps': {
                            'alert': 'Hello World!',
                        },
                    },
                },
            )
        self.assertIn('"bad|interest" contains a forbidden character', str(e.exception))

        with self.assertRaises(ValueError) as e:
            pn_client.publish(
                interests=['bad(interest)'],
                publish_body={
                    'apns': {
                        'aps': {
                            'alert': 'Hello World!',
                        },
                    },
                },
            )
        self.assertIn('"bad(interest)" contains a forbidden character', str(e.exception))
コード例 #22
0
    def test_deprecated_alias_still_works(self):
        pn_client = PushNotifications('INSTANCE_ID', 'SECRET_KEY')
        with requests_mock.Mocker() as http_mock:
            http_mock.register_uri(
                requests_mock.ANY,
                requests_mock.ANY,
                status_code=200,
                json={
                    'publishId': '1234',
                },
            )
            response = pn_client.publish(
                interests=['donuts'],
                publish_body={
                    'apns': {
                        'aps': {
                            'alert': 'Hello World!',
                        },
                    },
                },
            )
            req = http_mock.request_history[0]

        method = req.method
        path = req.path
        headers = dict(req._request.headers.lower_items())
        body = req.json()

        self.assertEqual(
            method,
            'POST',
        )
        self.assertEqual(
            path,
            '/publish_api/v1/instances/instance_id/publishes/interests',
        )
        self.assertDictEqual(
            headers,
            {
                'content-type': 'application/json',
                'content-length': '69',
                'authorization': 'Bearer SECRET_KEY',
                'x-pusher-library': 'pusher-push-notifications-python 2.0.1',
                'host': 'instance_id.pushnotifications.pusher.com',
            },
        )
        self.assertDictEqual(
            body,
            {
                'interests': ['donuts'],
                'apns': {
                    'aps': {
                        'alert': 'Hello World!',
                    },
                },
            },
        )
        self.assertDictEqual(
            response,
            {
                'publishId': '1234',
            },
        )
コード例 #23
0
from pusher_push_notifications import PushNotifications

pn_client = PushNotifications(
    instance_id="5fb00808-3b8d-4533-9079-9fec45c7d781",
    secret_key='11027CDC0A5627F5F6EE83961C72D34',
)

response = pn_client.publish(
    interests=['debug-hello'],
    publish_body={
        'apns': {
            'aps': {
                'alert': 'Hello!',
            },
        },
        'fcm': {
            'notification': {
                'title': 'Hello',
                'body': 'Hello, world!',
                'sound': 'default',
            },
        },
    },
)

print(response['publishId'])
コード例 #24
0
            print('///////////')
            print('checking notifications for ' + username)
            print('last timestamp: ' + str(last_timestamp))
            response = requests.get(
                'https://heraldapp.herokuapp.com/backendConfig/' + username +
                '&' + token + '/notification/' + str(last_timestamp))
            print(response)
            print(response.json())
            notification = response.json()['notification']
            if notification != 'NA':
                #new commits added, so send push notification
                new_time = response.json()['new_timestamp']
                data = {'last_commit_timestamp': new_time, 'token': token}
                db.child('users').child(username).set(data)
                pn_client = PushNotifications(
                    instance_id='3205f451-bb8e-400c-ac13-88d5750a6bfc',
                    secret_key=
                    '78C3B49B6A8C52FD8A7392C8794CE43CC4562B4C1D71288F8F4CBEA58DB8E7AF',
                )
                response = pn_client.publish(
                    interests=[username],
                    publish_body={
                        'apns': {
                            'aps': {
                                'alert': notification,
                            },
                        },
                    },
                )
                print(response)