Ejemplo n.º 1
0
def example_push_batch2():
    """An example on how to use push_batch with many parameters
    directly to method.
    In the following example sound, badge (iOS only), schedule
    and devices with specifed tags to exclude are
    defined for the push_batch().
    """

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define all fields
    platform = Pushbots.PLATFORM_IOS
    msg = 'My super cool msg'
    sound = 'mysound'
    badge = '16'
    schedule = '2016-08-12T11:33:00'
    except_tags = ['tag4', 'tag5', 'tag6']
    payload = {'custom_field1': 'My field1 value',
               'custom_field2': 'My field2 value'}
    # Finally make the call
    code, msg = pushbots.push_batch(platform=platform, msg=msg, sound=sound,
                                    badge=badge, schedule=schedule,
                                    except_tags=except_tags, payload=payload)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(msg))
Ejemplo n.º 2
0
def example_push_batch2():
    """An example on how to use push_batch with many parameters
    directly to method.
    In the following example sound, badge (iOS only), schedule
    and devices with specifed tags to exclude are
    defined for the push_batch().
    """

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define all fields
    platform = Pushbots.PLATFORM_IOS
    msg = 'My super cool msg'
    sound = 'mysound'
    badge = '16'
    schedule = '2016-08-12T11:33:00'
    except_tags = ['tag4', 'tag5', 'tag6']
    payload = {'custom_field1': 'My field1 value',
               'custom_field2': 'My field2 value'}
    # Finally make the call
    code, msg = pushbots.push_batch(platform=platform, msg=msg, sound=sound,
                                    badge=badge, schedule=schedule,
                                    except_tags=except_tags, payload=payload)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(msg))
Ejemplo n.º 3
0
def example_get_analytics():
    """Get analytics by calling Pushbots.get_analytics()"""

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    code, message = pushbots.get_analytics()
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 4
0
def example_unregister_from_alias():
    app_id = 'my_app_id'
    secret = 'my_secret'
    alias = 'my_alias'
    pushbots = Pushbots(app_id=app_id, secret=secret)
    devices = get_token_and_platform_from_alias(pushbots, alias)
    if not devices:
        print('No devices found with alias {0}'.format(alias))
    for (token, platform) in devices:
        c, d = pushbots.unregister(token=token, platform=platform)
        print('{0}:{1}'.format(c, d))
Ejemplo n.º 5
0
def example_get_analytics():
    """Get analytics by calling Pushbots.get_analytics()"""

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    code, message = pushbots.get_analytics()
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 6
0
def example_unregister_from_alias():
    app_id = 'my_app_id'
    secret = 'my_secret'
    alias = 'my_alias'
    pushbots = Pushbots(app_id=app_id, secret=secret)
    devices = get_token_and_platform_from_alias(pushbots, alias)
    if not devices:
        print('No devices found with alias {0}'.format(alias))
    for (token, platform) in devices:
        c, d = pushbots.unregister(token=token, platform=platform)
        print('{0}:{1}'.format(c, d))
Ejemplo n.º 7
0
def example_location_from_alias():
    app_id = "my_app_id"
    secret = "my_secret"
    alias = "my_alias"
    lng = 12.212
    lat = 56.123
    pushbots = Pushbots(app_id=app_id, secret=secret)
    devices = get_token_and_platform_from_alias(pushbots, alias)
    if not devices:
        print("No devices found with alias {0}".format(alias))
    for (token, platform) in devices:
        c, d = pushbots.device_location(token=token, platform=platform, lat=lat, lng=lng)
        print("{0}:{1}".format(c, d))
Ejemplo n.º 8
0
def example_alias2():
    """Alternatively you can change alias by passing values defined by you."""

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define data
    data = {'platform': Pushbots.PLATFORM_ANDROID, 'alias': 'my_new_alias',
            'current_alias': 'my_current_alias'}
    code, message = pushbots.alias(data=data)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 9
0
def example_untag2():
    """Alternatively you can remove a tag by passing values defined by you."""

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define data
    data = {'platform': Pushbots.PLATFORM_ANDROID,
            'alias': 'alias_to_remove_tag', 'tag': 'tag_to_be_removed'}
    code, message = pushbots.untag(data=data)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 10
0
def example_untag1():
    """Remove tag by passing values directly to Pushbots.untag()"""

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define alias, tag and platform
    alias = 'alias_to_remove_tag'
    tag = 'tag_to_be_removed'
    platform = Pushbots.PLATFORM_ANDROID
    code, message = pushbots.untag(platform=platform, alias=alias, tag=tag)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 11
0
def example_record_analytics1():
    """Record analytics by passing platform directly to
    Pushbots.record_analytics()
    """

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define platform
    platform = Pushbots.PLATFORM_IOS
    code, message = pushbots.record_analytics(platform=platform)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 12
0
def example_untag1():
    """Remove tag by passing values directly to Pushbots.untag()"""

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define alias, tag and platform
    alias = 'alias_to_remove_tag'
    tag = 'tag_to_be_removed'
    platform = Pushbots.PLATFORM_ANDROID
    code, message = pushbots.untag(platform=platform, alias=alias, tag=tag)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 13
0
def example_generic_get():
    """Example api call using get request"""

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define the API url
    api_url = 'poshbots_api_url'
    # Define your headers manually or use the one's from Pushbots module
    headers = pushbots.headers  # or define yours as a python dict
    code, msg = pushbots.get(api_url=api_url, headers=headers)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(msg))
Ejemplo n.º 14
0
def example_record_analytics2():
    """Record analytics by passing data defined by you to
    Pushbots.record_analytics()
    """

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define data
    data = {'platform': '0'}  # '0' is Equivalent to Pushbots.PLATFORM_IOS
    code, message = pushbots.record_analytics(data=data)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 15
0
def example_record_analytics1():
    """Record analytics by passing platform directly to
    Pushbots.record_analytics()
    """

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define platform
    platform = Pushbots.PLATFORM_IOS
    code, message = pushbots.record_analytics(platform=platform)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 16
0
def example_record_analytics2():
    """Record analytics by passing data defined by you to
    Pushbots.record_analytics()
    """

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define data
    data = {'platform': '0'}  # '0' is Equivalent to Pushbots.PLATFORM_IOS
    code, message = pushbots.record_analytics(data=data)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 17
0
def example_location_from_alias():
    app_id = 'my_app_id'
    secret = 'my_secret'
    alias = 'my_alias'
    lng = 12.212
    lat = 56.123
    pushbots = Pushbots(app_id=app_id, secret=secret)
    devices = get_token_and_platform_from_alias(pushbots, alias)
    if not devices:
        print('No devices found with alias {0}'.format(alias))
    for (token, platform) in devices:
        c, d = pushbots.device_location(token=token,
                                        platform=platform,
                                        lat=lat,
                                        lng=lng)
        print('{0}:{1}'.format(c, d))
Ejemplo n.º 18
0
def example_alias1():
    """Change alias by passing values directly to Pushbots.alias()"""

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define new and current alias and platform
    new_alias = 'my_new_alias'
    old_alias = 'my_current_alias'
    platform = Pushbots.PLATFORM_ANDROID
    code, message = pushbots.alias(platform=platform, alias=new_alias,
                                   current_alias=old_alias)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 19
0
def example_generic_post():
    """Example api call using post request"""

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define the API url
    api_url = 'poshbots_api_url'
    # Define your headers manually or use the one's from Pushbots module
    headers = pushbots.headers  # or define yours as a python dict
    # Define your data accordingly, or define no data
    data = {'platform': '1', 'alias': 'superjohn123'}
    code, msg = pushbots.post(api_url=api_url, headers=headers, data=data)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(msg))
Ejemplo n.º 20
0
def example_alias1():
    """Change alias by passing values directly to Pushbots.alias()"""

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define new and current alias and platform
    new_alias = 'my_new_alias'
    old_alias = 'my_current_alias'
    platform = Pushbots.PLATFORM_ANDROID
    code, message = pushbots.alias(platform=platform,
                                   alias=new_alias,
                                   current_alias=old_alias)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 21
0
def example_alias2():
    """Alternatively you can change alias by passing values defined by you."""

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define data
    data = {
        'platform': Pushbots.PLATFORM_ANDROID,
        'alias': 'my_new_alias',
        'current_alias': 'my_current_alias'
    }
    code, message = pushbots.alias(data=data)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 22
0
def example_untag2():
    """Alternatively you can remove a tag by passing values defined by you."""

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define data
    data = {
        'platform': Pushbots.PLATFORM_ANDROID,
        'alias': 'alias_to_remove_tag',
        'tag': 'tag_to_be_removed'
    }
    code, message = pushbots.untag(data=data)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(message))
Ejemplo n.º 23
0
def example_generic_put():
    """Example api call using put request"""

    # Define app_id and secret
    my_app_id = "my_app_id"
    my_secret = "my_secret"
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define the API url
    api_url = "poshbots_api_url"
    # Define your headers manually or use the one's from Pushbots module
    headers = pushbots.headers  # or define yours as a python dict
    # Define your data accordingly, or define no data
    data = {"platform": "1", "alias": "superjohn123"}
    code, msg = pushbots.put(api_url=api_url, headers=headers, data=data)
    print("Returned code: {0}".format(code))
    print("Returned message: {0}".format(msg))
Ejemplo n.º 24
0
def example_push_batch3():
    """An example on how to use push_batch with data defined by you
    In this example alias is used for push_batch(), along with a payload
    with 1 custom field.
    """

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define data
    data = {'platform': Pushbots.PLATFORM_ANDROID, 'msg': 'Hello there',
            'alias': 'superjohn123', 'payload': {'custom_field': 'Custom val'}}
    # Alternatively you can set 'except_alias' : 'superjohn123' to exclude
    # "superjohn123" from getting that push
    code, msg = pushbots.push_batch(data=data)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(msg))
Ejemplo n.º 25
0
def example_push_batch1():
    """An example on how to use push_batch with some parameters
    directly to method. In this example a notification will be sent,
    to all iOS devices, that are tagged with "News" or "Politics"
    using push_batch().
    """

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define all fields
    platform = Pushbots.PLATFORM_ANDROID  # Required
    msg = 'My super cool msg'  # Required
    tags = ['News', 'Politics']  # Single tags, must also be in a list.
    code, msg = pushbots.push_batch(platform=platform, msg=msg, tags=tags)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(msg))
Ejemplo n.º 26
0
def example_push_batch1():
    """An example on how to use push_batch with some parameters
    directly to method. In this example a notification will be sent,
    to all iOS devices, that are tagged with "News" or "Politics"
    using push_batch().
    """

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define all fields
    platform = Pushbots.PLATFORM_ANDROID  # Required
    msg = 'My super cool msg'  # Required
    tags = ['News', 'Politics']  # Single tags, must also be in a list.
    code, msg = pushbots.push_batch(platform=platform, msg=msg, tags=tags)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(msg))
Ejemplo n.º 27
0
def example_push_batch3():
    """An example on how to use push_batch with data defined by you
    In this example alias is used for push_batch(), along with a payload
    with 1 custom field.
    """

    # Define app_id and secret
    my_app_id = 'my_app_id'
    my_secret = 'my_secret'
    # Create a Pushbots instance
    pushbots = Pushbots(app_id=my_app_id, secret=my_secret)
    # Define data
    data = {'platform': Pushbots.PLATFORM_ANDROID, 'msg': 'Hello there',
            'alias': 'superjohn123', 'payload': {'custom_field': 'Custom val'}}
    # Alternatively you can set 'except_alias' : 'superjohn123' to exclude
    # "superjohn123" from getting that push
    code, msg = pushbots.push_batch(data=data)
    print('Returned code: {0}'.format(code))
    print('Returned message: {0}'.format(msg))
Ejemplo n.º 28
0
def main():
    parse_args()
    print('Warning!!!')
    print('Tests are going to create virtual devices to test api calls'
          ' for platform: {0}'.format(platform))
    print('Virtual devices are going to have the following tokens:'
          '{0}, {1}, {2}, {3}, {4}. {5}. {6}'.format(token1, token2, token3,
                                                     token4, token5, token6,
                                                     token7))
    print('Also the following random testing tags will be created:'
          '{0}, {1}'.format(tag1, tag2))
    print('And the following random testing aliases will be created:'
          '{0}, {1}, {2}'.format(alias1, alias2, alias3))
    print('If you have conflicing aliases or tags open tests/run.py and define'
          ' them manually')
    # The following try catch is for python 2 - python 3 compatibility.
    try:
        read_str = raw_input
    except NameError:
        read_str = input
    choice = read_str('Do you want to continue? (y/n):')
    if choice.lower() != 'y':
        return
    pushbots = Pushbots(app_id=APP_ID, secret=SECRET)
    try:
        unregister_all(pushbots)  # Do this for clean testing.
        debug('\nStarting tests...')
        test_register(pushbots)
        test_register_batch(pushbots)
        test_alias(pushbots)
        test_tag(pushbots)
        test_untag(pushbots)
        test_device_location(pushbots)
        test_device(pushbots)
        test_badge(pushbots)
        test_analytics(pushbots)
        test_push(pushbots)
        test_push_batch(pushbots)
        test_unregister(pushbots)
        debug('\nDone testing!')
    except KeyboardInterrupt:
        return
    except Exception as e:
        debug('Exception found:{0}:{1}'.format(type(e), e), error=True)
    finally:
        unregister_all(pushbots)  # Unregister all tokens
        pass