Skip to content

Commit

Permalink
chore: Assemble new version for Topic Management (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
akalex authored Mar 20, 2024
1 parent 5296976 commit e7d8b9c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## 3.7.0
* `async-firebase` has been allowed to perform basic topic management tasks from the server side. Given their registration token(s), you can now subscribe and unsubscribe client app instances in bulk using server logic. You can subscribe client app instances to any existing topic, or you can create a new topic.

## 3.6.3
* [FIX] The ``join_url`` util has been tuned to encode the URL properly when the path is present. That led to the invalid URL being built.

Expand Down
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Set priority for notifications
* Set collapse-key for notifications
* Dry-run mode for testing purpose
* Topic Management

## Installation
To install `async-firebase`, simply execute the following command in a terminal:
Expand Down Expand Up @@ -270,6 +271,51 @@ async def main():
print(response.success)


if __name__ == "__main__":
asyncio.run(main())
```

### Topic Management
You can subscribe and unsubscribe client app instances in bulk approach by passing a list of registration tokens to the subscription method to subscribe the corresponding devices to a topic:
```python3
import asyncio

from async_firebase import AsyncFirebaseClient


async def main():
device_tokens: list[str] = ["...", "..."]

client = AsyncFirebaseClient()
client.creds_from_service_account_info({...})
response = await client.subscribe_devices_to_topic(
device_tokens=device_tokens, topic_name="some-topic"
)
print(response)


if __name__ == "__main__":
asyncio.run(main())
```

To unsubscribe devices from a topic by passing registration tokens to the appropriate method:
```python3
import asyncio

from async_firebase import AsyncFirebaseClient


async def main():
device_tokens: list[str] = ["...", "..."]

client = AsyncFirebaseClient()
client.creds_from_service_account_info({...})
response = await client.unsubscribe_devices_from_topic(
device_tokens=device_tokens, topic_name="some-topic"
)
print(response)


if __name__ == "__main__":
asyncio.run(main())
```
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "async-firebase"
version = "3.6.3"
version = "3.7.0"
description = "Async Firebase Client - a Python asyncio client to interact with Firebase Cloud Messaging in an easy way."
license = "MIT"
authors = [
Expand Down
12 changes: 9 additions & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,9 @@ async def test_subscribe_to_topic(fake_async_fcm_client_w_creds, fake_multi_devi


@pytest.mark.parametrize("fake_multi_device_tokens", (3,), indirect=True)
async def test_subscribe_to_topic_with_incorrect(fake_async_fcm_client_w_creds, fake_multi_device_tokens, httpx_mock: HTTPXMock):
async def test_subscribe_to_topic_with_incorrect(
fake_async_fcm_client_w_creds, fake_multi_device_tokens, httpx_mock: HTTPXMock
):
fake_async_fcm_client_w_creds._get_access_token = fake__get_access_token

device_tokens = [*fake_multi_device_tokens, "incorrect"]
Expand Down Expand Up @@ -794,7 +796,9 @@ async def test_unsubscribe_to_topic(fake_async_fcm_client_w_creds, fake_multi_de


@pytest.mark.parametrize("fake_multi_device_tokens", (3,), indirect=True)
async def test_unsubscribe_to_topic_with_incorrect(fake_async_fcm_client_w_creds, fake_multi_device_tokens, httpx_mock: HTTPXMock):
async def test_unsubscribe_to_topic_with_incorrect(
fake_async_fcm_client_w_creds, fake_multi_device_tokens, httpx_mock: HTTPXMock
):
fake_async_fcm_client_w_creds._get_access_token = fake__get_access_token

device_tokens = [*fake_multi_device_tokens, "incorrect"]
Expand All @@ -816,7 +820,9 @@ async def test_unsubscribe_to_topic_with_incorrect(fake_async_fcm_client_w_creds


@pytest.mark.parametrize("fake_multi_device_tokens", (3,), indirect=True)
async def test_send_topic_management_unauthenticated(fake_async_fcm_client_w_creds, fake_multi_device_tokens, httpx_mock: HTTPXMock):
async def test_send_topic_management_unauthenticated(
fake_async_fcm_client_w_creds, fake_multi_device_tokens, httpx_mock: HTTPXMock
):
fake_async_fcm_client_w_creds._get_access_token = fake__get_access_token
httpx_mock.add_response(
status_code=401,
Expand Down

0 comments on commit e7d8b9c

Please sign in to comment.