Skip to content

Commit

Permalink
Merge pull request #322 from Subhrans/bugfix-pyfcm-v1
Browse files Browse the repository at this point in the history
Fixed tests for async
  • Loading branch information
olucurious authored Jun 8, 2024
2 parents bee89b1 + 0066c09 commit d2321b3
Show file tree
Hide file tree
Showing 14 changed files with 640 additions and 516 deletions.
12 changes: 9 additions & 3 deletions pyfcm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
__version__,
__author__,
__email__,
__license__
__license__,
)
from .fcm import FCMNotification

__all__ = [
"FCMNotification", "__title__", "__summary__",
"__url__", "__version__", "__author__", "__email__", "__license__"
"FCMNotification",
"__title__",
"__summary__",
"__url__",
"__version__",
"__author__",
"__email__",
"__license__",
]
14 changes: 7 additions & 7 deletions pyfcm/__meta__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
__title__ = 'pyfcm'
__summary__ = 'Python client for FCM - Firebase Cloud Messaging (Android, iOS and Web)'
__url__ = 'https://github.com/olucurious/pyfcm'
__title__ = "pyfcm"
__summary__ = "Python client for FCM - Firebase Cloud Messaging (Android, iOS and Web)"
__url__ = "https://github.com/olucurious/pyfcm"

__version__ = '1.5.2'
__version__ = "1.5.2"

__author__ = 'Emmanuel Adegbite'
__email__ = '[email protected]'
__author__ = "Emmanuel Adegbite"
__email__ = "[email protected]"

__license__ = 'MIT License'
__license__ = "MIT License"
18 changes: 13 additions & 5 deletions pyfcm/async_fcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import aiohttp
import json

async def fetch_tasks(end_point,headers,payloads,timeout):

async def fetch_tasks(end_point, headers, payloads, timeout):
"""
:param end_point (str) : FCM endpoint
Expand All @@ -11,11 +12,18 @@ async def fetch_tasks(end_point,headers,payloads,timeout):
:param timeout (int) : FCM timeout
:return:
"""
fetches = [asyncio.Task(send_request(end_point=end_point,headers=headers,payload=payload,timeout=timeout)) for payload in payloads]
fetches = [
asyncio.Task(
send_request(
end_point=end_point, headers=headers, payload=payload, timeout=timeout
)
)
for payload in payloads
]
return await asyncio.gather(*fetches)


async def send_request(end_point,headers,payload,timeout=5):
async def send_request(end_point, headers, payload, timeout=5):
"""
:param end_point (str) : FCM endpoint
Expand All @@ -26,9 +34,9 @@ async def send_request(end_point,headers,payload,timeout=5):
"""
timeout = aiohttp.ClientTimeout(total=timeout)

async with aiohttp.ClientSession(headers=headers,timeout=timeout) as session:
async with aiohttp.ClientSession(headers=headers, timeout=timeout) as session:

async with session.post(end_point,data=payload) as res:
async with session.post(end_point, data=payload) as res:
result = await res.text()
result = json.loads(result)
return result
Loading

0 comments on commit d2321b3

Please sign in to comment.