How to use the pyfcm.baseapi.BaseAPI function in pyfcm

To help you get started, we’ve selected a few pyfcm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github olucurious / PyFCM / tests / test_baseapi.py View on Github external
def base_api():
    api_key = os.getenv("FCM_TEST_API_KEY", None)
    assert api_key, "Please set the environment variables for testing according to CONTRIBUTING.rst"

    return BaseAPI(api_key=api_key)
github olucurious / PyFCM / tests / test_baseapi.py View on Github external
def test_init_baseapi():
    try:
        BaseAPI()
        assert False, "Should raise AuthenticationError"
    except errors.AuthenticationError:
        pass
github olucurious / PyFCM / pyfcm / fcm.py View on Github external
from .baseapi import BaseAPI
from .errors import InvalidDataError


class FCMNotification(BaseAPI):
    def notify_single_device(self,
                             registration_id=None,
                             message_body=None,
                             message_title=None,
                             message_icon=None,
                             sound=None,
                             condition=None,
                             collapse_key=None,
                             delay_while_idle=False,
                             time_to_live=None,
                             restricted_package_name=None,
                             low_priority=False,
                             dry_run=False,
                             data_message=None,
                             click_action=None,
                             badge=None,
github olucurious / PyFCM / pyfcm / extensions / tornado.py View on Github external
from tornado import escape
from tornado import gen
from tornado.httpclient import AsyncHTTPClient, HTTPRequest

from ..baseapi import BaseAPI
from ..errors import AuthenticationError, InternalPackageError, FCMServerError
from ..fcm import FCMNotification


class TornadoBaseAPI(BaseAPI):
    def __init__(self, *args, **kwargs):
        super(TornadoBaseAPI, self).__init__(*args, **kwargs)
        self.http_client = AsyncHTTPClient()

    @gen.coroutine
    def send_request(self, payloads=None):
        for payload in payloads:
            request = HTTPRequest(
                url=self.FCM_END_POINT,
                method='POST',
                headers=self.request_headers(),
                body=payload
            )

            response = yield self.http_client.fetch(request)