1818from typing import Any , Callable , Dict , List , Optional , cast
1919import concurrent .futures
2020import json
21- import warnings
2221import asyncio
2322import logging
2423import requests
2524import httpx
2625
27- from googleapiclient import http
28- from googleapiclient import _auth
29-
3026import firebase_admin
3127from firebase_admin import (
3228 _http_client ,
3329 _messaging_encoder ,
3430 _messaging_utils ,
35- _gapic_utils ,
3631 _utils ,
3732 exceptions ,
3833 App
7267 'WebpushNotificationAction' ,
7368
7469 'send' ,
75- 'send_all' ,
76- 'send_multicast' ,
7770 'send_each' ,
7871 'send_each_async' ,
7972 'send_each_for_multicast' ,
@@ -246,64 +239,6 @@ def send_each_for_multicast(multicast_message, dry_run=False, app=None):
246239 ) for token in multicast_message .tokens ]
247240 return _get_messaging_service (app ).send_each (messages , dry_run )
248241
249- def send_all (messages , dry_run = False , app = None ):
250- """Sends the given list of messages via Firebase Cloud Messaging as a single batch.
251-
252- If the ``dry_run`` mode is enabled, the message will not be actually delivered to the
253- recipients. Instead, FCM performs all the usual validations and emulates the send operation.
254-
255- Args:
256- messages: A list of ``messaging.Message`` instances.
257- dry_run: A boolean indicating whether to run the operation in dry run mode (optional).
258- app: An App instance (optional).
259-
260- Returns:
261- BatchResponse: A ``messaging.BatchResponse`` instance.
262-
263- Raises:
264- FirebaseError: If an error occurs while sending the message to the FCM service.
265- ValueError: If the input arguments are invalid.
266-
267- send_all() is deprecated. Use send_each() instead.
268- """
269- warnings .warn ('send_all() is deprecated. Use send_each() instead.' , DeprecationWarning )
270- return _get_messaging_service (app ).send_all (messages , dry_run )
271-
272- def send_multicast (multicast_message , dry_run = False , app = None ):
273- """Sends the given mutlicast message to all tokens via Firebase Cloud Messaging (FCM).
274-
275- If the ``dry_run`` mode is enabled, the message will not be actually delivered to the
276- recipients. Instead, FCM performs all the usual validations and emulates the send operation.
277-
278- Args:
279- multicast_message: An instance of ``messaging.MulticastMessage``.
280- dry_run: A boolean indicating whether to run the operation in dry run mode (optional).
281- app: An App instance (optional).
282-
283- Returns:
284- BatchResponse: A ``messaging.BatchResponse`` instance.
285-
286- Raises:
287- FirebaseError: If an error occurs while sending the message to the FCM service.
288- ValueError: If the input arguments are invalid.
289-
290- send_multicast() is deprecated. Use send_each_for_multicast() instead.
291- """
292- warnings .warn ('send_multicast() is deprecated. Use send_each_for_multicast() instead.' ,
293- DeprecationWarning )
294- if not isinstance (multicast_message , MulticastMessage ):
295- raise ValueError ('Message must be an instance of messaging.MulticastMessage class.' )
296- messages = [Message (
297- data = multicast_message .data ,
298- notification = multicast_message .notification ,
299- android = multicast_message .android ,
300- webpush = multicast_message .webpush ,
301- apns = multicast_message .apns ,
302- fcm_options = multicast_message .fcm_options ,
303- token = token
304- ) for token in multicast_message .tokens ]
305- return _get_messaging_service (app ).send_all (messages , dry_run )
306-
307242def subscribe_to_topic (tokens , topic , app = None ):
308243 """Subscribes a list of registration tokens to an FCM topic.
309244
@@ -472,7 +407,6 @@ def __init__(self, app: App) -> None:
472407 self ._client = _http_client .JsonHttpClient (credential = self ._credential , timeout = timeout )
473408 self ._async_client = _http_client .HttpxAsyncClient (
474409 credential = self ._credential , timeout = timeout )
475- self ._build_transport = _auth .authorized_http
476410
477411 @classmethod
478412 def encode_message (cls , message ):
@@ -555,45 +489,6 @@ async def send_data(data):
555489 message = 'Unknown error while making remote service calls: {0}' .format (error ),
556490 cause = error )
557491
558-
559- def send_all (self , messages , dry_run = False ):
560- """Sends the given messages to FCM via the batch API."""
561- if not isinstance (messages , list ):
562- raise ValueError ('messages must be a list of messaging.Message instances.' )
563- if len (messages ) > 500 :
564- raise ValueError ('messages must not contain more than 500 elements.' )
565-
566- responses = []
567-
568- def batch_callback (_ , response , error ):
569- exception = None
570- if error :
571- exception = self ._handle_batch_error (error )
572- send_response = SendResponse (response , exception )
573- responses .append (send_response )
574-
575- batch = http .BatchHttpRequest (
576- callback = batch_callback , batch_uri = _MessagingService .FCM_BATCH_URL )
577- transport = self ._build_transport (self ._credential )
578- for message in messages :
579- body = json .dumps (self ._message_data (message , dry_run ))
580- req = http .HttpRequest (
581- http = transport ,
582- postproc = self ._postproc ,
583- uri = self ._fcm_url ,
584- method = 'POST' ,
585- body = body ,
586- headers = self ._fcm_headers
587- )
588- batch .add (req )
589-
590- try :
591- batch .execute ()
592- except Exception as error :
593- raise self ._handle_batch_error (error )
594- else :
595- return BatchResponse (responses )
596-
597492 def make_topic_management_request (self , tokens , topic , operation ):
598493 """Invokes the IID service for topic management functionality."""
599494 if isinstance (tokens , str ):
@@ -670,11 +565,6 @@ def _handle_iid_error(self, error):
670565
671566 return _utils .handle_requests_error (error , msg )
672567
673- def _handle_batch_error (self , error ):
674- """Handles errors received from the googleapiclient while making batch requests."""
675- return _gapic_utils .handle_platform_error_from_googleapiclient (
676- error , _MessagingService ._build_fcm_error_googleapiclient )
677-
678568 def close (self ) -> None :
679569 asyncio .run (self ._async_client .aclose ())
680570
@@ -700,14 +590,6 @@ def _build_fcm_error_httpx(
700590 message , cause = error , http_response = error .response ) if exc_type else None
701591 return exc_type (message , cause = error ) if exc_type else None
702592
703-
704- @classmethod
705- def _build_fcm_error_googleapiclient (cls , error , message , error_dict , http_response ):
706- """Parses an error response from the FCM API and creates a FCM-specific exception if
707- appropriate."""
708- exc_type = cls ._build_fcm_error (error_dict )
709- return exc_type (message , cause = error , http_response = http_response ) if exc_type else None
710-
711593 @classmethod
712594 def _build_fcm_error (
713595 cls ,
0 commit comments