Skip to content

Commit

Permalink
Merge pull request #310 from SuppliedOrange/patch-1
Browse files Browse the repository at this point in the history
Improve README.rst's readablility
  • Loading branch information
olucurious authored Apr 7, 2023
2 parents f5c4e4d + 2e0559c commit 69c754b
Showing 1 changed file with 49 additions and 23 deletions.
72 changes: 49 additions & 23 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ Updates (Breaking Changes)
- MAJOR UPDATES (AUGUST 2017): https://github.com/olucurious/PyFCM/releases/tag/1.4.0


Quickstart
Installation
==========

Install using pip:


::

pip install pyfcm
Expand All @@ -45,17 +44,20 @@ Install using pip:

PyFCM supports Android, iOS and Web.


Features
--------
========

- All FCM functionality covered
- Tornado support


Examples
--------
========
|
Send notifications using the ``FCMNotification`` class:
Send notifications using the ``FCMNotification`` class
-------------------------------------------------------

.. code-block:: python
Expand Down Expand Up @@ -87,7 +89,10 @@ Send notifications using the ``FCMNotification`` class:
print result
Send a data message.
|
Send a data message
--------------------

.. code-block:: python
Expand Down Expand Up @@ -131,40 +136,48 @@ Send a data message.
'mutable_content': True
}
# and then write a NotificationService Extension in your app
# Use notification messages when you want FCM to handle displaying a notification on your app's behalf.
# Use data messages when you just want to process the messages only in your app.
# PyFCM can send a message including both notification and data payloads.
# In such cases, FCM handles displaying the notification payload, and the client app handles the data payload.
Send a low priority message.
|
Send a low priority message
----------------------------

.. code-block:: python
# The default is low_priority == False
result = push_service.notify_multiple_devices(registration_ids=registration_ids, message_body=message, low_priority=True)
|
Get valid registration ids (useful for cleaning up invalid registration ids in your database)
---------------------------------------------------------------------------------------------

.. code-block:: python
registration_ids = ['reg id 1', 'reg id 2', 'reg id 3', 'reg id 4', ...]
valid_registration_ids = push_service.clean_registration_ids(registration_ids)
# Shoutout to @baali for this
|
Appengine users should define their environment
-----------------------------------------------

.. code-block:: python
push_service = FCMNotification(api_key="<api-key>", proxy_dict=proxy_dict, env='app_engine')
result = push_service.notify_multiple_devices(registration_ids=registration_ids, message_body=message, low_priority=True)
|
Manage subscriptions to a topic
-------------------------------

.. code-block:: python
Expand All @@ -180,8 +193,10 @@ Manage subscriptions to a topic
unsubscribed = push_service.unsubscribe_registration_ids_from_topic(tokens, 'test')
# returns True if successful, raises error if unsuccessful
Sending a message to a topic.
|
Sending a message to a topic
-----------------------------
.. code-block:: python
# Send a message to devices subscribed to a topic.
Expand All @@ -198,52 +213,63 @@ Sending a message to a topic.
# Conditions for topics support two operators per expression, and parentheses are supported.
# For more information, check: https://firebase.google.com/docs/cloud-messaging/topic-messaging
|
Other argument options
----------------------

::

collapse_key (str, optional): Identifier for a group of messages
that can be collapsed so that only the last message gets sent
when delivery can be resumed. Defaults to `None`.
delay_while_idle (bool, optional): If `True` indicates that the
message should not be sent until the device becomes active.
time_to_live (int, optional): How long (in seconds) the message
should be kept in FCM storage if the device is offline. The
maximum time to live supported is 4 weeks. Defaults to ``None``
which uses the FCM default of 4 weeks.
low_priority (boolean, optional): Whether to send notification with
the low priority flag. Defaults to `False`.
restricted_package_name (str, optional): Package name of the
application where the registration IDs must match in order to
receive the message. Defaults to `None`.
dry_run (bool, optional): If `True` no message will be sent but
request will be tested.

Get response data.
|
Get response data
------------------

.. code-block:: python
# Response from PyFCM.
response_dict = {
'multicast_ids': list(), # List of Unique ID (number) identifying the multicast message.
'success': 0, #Number of messages that were processed without an error.
'failure': 0, #Number of messages that could not be processed.
'canonical_ids': 0, #Number of results that contain a canonical registration token.
'results': list(), #Array of dict objects representing the status of the messages processed.
'topic_message_id': None or str
'multicast_ids': list, # List of Unique ID (number) identifying the multicast message.
'success': int, #Number of messages that were processed without an error.
'failure': int, #Number of messages that could not be processed.
'canonical_ids': int, #Number of results that contain a canonical registration token.
'results': list, #Array of dict objects representing the status of the messages processed.
'topic_message_id': None | str
}
# registration_id: Optional string specifying the canonical registration token for the client app that the message
# was processed and sent to. Sender should use this value as the registration token for future requests. Otherwise,
# the messages might be rejected.
# error: String specifying the error that occurred when processing the message for the recipient
|
.. |version| image:: http://img.shields.io/pypi/v/pyfcm.svg?style=flat-square
:target: https://pypi.python.org/pypi/pyfcm/

.. |license| image:: http://img.shields.io/pypi/l/pyfcm.svg?style=flat-square
:target: https://pypi.python.org/pypi/pyfcm/


0 comments on commit 69c754b

Please sign in to comment.