GithubHelp home page GithubHelp logo

isabella232 / expo-server-sdk-asyncio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from expo-community/expo-server-sdk-python

0.0 0.0 0.0 44 KB

Exponent Server SDK

License: MIT License

Python 100.00%

expo-server-sdk-asyncio's Introduction

aioexponent

If you have problems with the code in this repository, please file an issue or a pull-request. Thanks!

Installation

pip install aioexponent

Usage

Use to send push notifications to Exponent Experiences from a Python server.

Full documentation on the API is available if you want to dive into the details.

Here's an example on how to use this with retries and reporting via pyrollbar.

from aioexponent import DeviceNotRegisteredError
from aioexponent import PushClient
from aioexponent import PushMessage
from aioexponent import PushResponseError
from aioexponent import PushServerError
from aiohttp import ClientError


# Basic arguments. You should extend this function with the push features you
# want to use, or simply pass in a `PushMessage` object.
async def send_push_message(tokens, message, extra=None):
    client = PushClient()
    try:
        response = await client.publish_multiple([
            PushMessage(to=token,
                        body=message,
                        data=extra) for token in tokens])
    except PushServerError as exc:
        # Encountered some likely formatting/validation error.
        rollbar.report_exc_info(
            extra_data={
                'tokens': tokens, 'message': message, 'extra': extra
                'errors': exc.errors,
                'response_data': exc.response_data,
            })
        raise
    except (ClientError) as exc:
        # Encountered some Connection or HTTP error - retry a few times in
        # case it is transient.
        rollbar.report_exc_info(
            extra_data={'tokens': tokens, 'message': message, 'extra': extra})
        raise retry(exc=exc)

    try:
        # We got a response back, but we don't know whether it's an error yet.
        # This call raises errors so we can handle them with normal exception
        # flows.
        response.validate_response()
    except DeviceNotRegisteredError:
        # Mark the push token as inactive
        from notifications.models import PushToken
        PushToken.objects.filter(token=token).update(active=False)
    except PushResponseError as exc:
        # Encountered some other per-notification error.
        rollbar.report_exc_info(
            extra_data={
                'tokens': tokens,
                'message': message,
                'extra': extra,
                'push_response': exc.push_response._asdict(),
            })
        raise retry(exc=exc)

expo-server-sdk-asyncio's People

Contributors

anp avatar ccheever avatar greysteil avatar ide avatar odero avatar raphaelrk avatar wli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.