Skip to content

Commit

Permalink
Precommit done
Browse files Browse the repository at this point in the history
  • Loading branch information
eighthcolor22 committed Mar 19, 2024
1 parent b877ac2 commit ea109eb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 43 deletions.
25 changes: 8 additions & 17 deletions async_firebase/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from email.mime.nonmultipart import MIMENonMultipart
from importlib.metadata import version
from pathlib import PurePath
from typing import Any, Coroutine
from urllib.parse import urlencode

import httpx
Expand All @@ -20,11 +19,11 @@
from async_firebase._config import DEFAULT_REQUEST_LIMITS, DEFAULT_REQUEST_TIMEOUT, RequestLimits, RequestTimeout
from async_firebase.messages import FCMBatchResponse, FCMResponse, TopicManagementResponse
from async_firebase.utils import (
FCMBatchResponseHandler,
FCMBatchResponseHandler,
FCMResponseHandler,
TopicManagementResponseHandler,
join_url,
serialize_mime_message
join_url,
serialize_mime_message,
)


Expand Down Expand Up @@ -172,7 +171,7 @@ async def prepare_headers(self) -> t.Dict[str, str]:
"X-GOOG-API-FORMAT-VERSION": "2",
"X-FIREBASE-CLIENT": "async-firebase/{0}".format(version("async-firebase")),
}

async def _send_request(
self,
url: str,
Expand Down Expand Up @@ -227,12 +226,8 @@ async def send_request(
:return: HTTP response
"""
url = join_url(self.BASE_URL, uri)
return await self._send_request( # type: ignore
url=url,
response_handler=response_handler,
json_payload=json_payload,
headers=headers,
content=content
return await self._send_request( # type: ignore
url=url, response_handler=response_handler, json_payload=json_payload, headers=headers, content=content
)

async def send_iid_request(
Expand All @@ -256,10 +251,6 @@ async def send_iid_request(
url = join_url(self.IID_URL, uri)
headers = headers or await self.prepare_headers()
headers.update(self.IID_HEADERS)
return await self._send_request( # type: ignore
url=url,
response_handler=response_handler,
json_payload=json_payload,
headers=headers,
content=content
return await self._send_request( # type: ignore
url=url, response_handler=response_handler, json_payload=json_payload, headers=headers, content=content
)
23 changes: 5 additions & 18 deletions async_firebase/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,7 @@ async def send_each_for_multicast(
return await self.send_each(messages, dry_run=dry_run)

async def _make_topic_management_request(
self,
device_tokens: t.List[str],
topic_name: str,
action: str
self, device_tokens: t.List[str], topic_name: str, action: str
) -> TopicManagementResponse:
payload = {
"to": f"/topics/{topic_name}",
Expand All @@ -567,11 +564,7 @@ async def _make_topic_management_request(
)
return response

async def subscribe_devices_to_topic(
self,
device_tokens: t.List[str],
topic_name: str
) -> TopicManagementResponse:
async def subscribe_devices_to_topic(self, device_tokens: t.List[str], topic_name: str) -> TopicManagementResponse:
"""
Subscribes devices to the topic.
Expand All @@ -580,15 +573,11 @@ async def subscribe_devices_to_topic(
:returns: Instance of messages.TopicManagementResponse.
"""
return await self._make_topic_management_request(
device_tokens=device_tokens,
topic_name=topic_name,
action=self.TOPIC_ADD_ACTION
device_tokens=device_tokens, topic_name=topic_name, action=self.TOPIC_ADD_ACTION
)

async def unsubscribe_devices_from_topic(
self,
device_tokens: t.List[str],
topic_name: str
self, device_tokens: t.List[str], topic_name: str
) -> TopicManagementResponse:
"""
Unsubscribes devices from the topic.
Expand All @@ -598,7 +587,5 @@ async def unsubscribe_devices_from_topic(
:returns: Instance of messages.TopicManagementResponse.
"""
return await self._make_topic_management_request(
device_tokens=device_tokens,
topic_name=topic_name,
action=self.TOPIC_REMOVE_ACTION
device_tokens=device_tokens, topic_name=topic_name, action=self.TOPIC_REMOVE_ACTION
)
5 changes: 2 additions & 3 deletions async_firebase/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class FcmOptions:
Arguments:
analytics_label: Label associated with the message's analytics data.
"""

analytics_label: str


Expand Down Expand Up @@ -432,9 +433,7 @@ def reason(self):
class TopicManagementResponse:
"""The response received from a topic management operation."""

def __init__(
self, resp: t.Optional[httpx.Response] = None, exception: t.Optional[AsyncFirebaseError] = None
):
def __init__(self, resp: t.Optional[httpx.Response] = None, exception: t.Optional[AsyncFirebaseError] = None):
self.exception = exception
self._success_count = 0
self._failure_count = 0
Expand Down
6 changes: 1 addition & 5 deletions async_firebase/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
UnknownError,
UnregisteredError,
)
from async_firebase.messages import (
FCMBatchResponse,
FCMResponse,
TopicManagementResponse,
)
from async_firebase.messages import FCMBatchResponse, FCMResponse, TopicManagementResponse


def join_url(
Expand Down

0 comments on commit ea109eb

Please sign in to comment.