18
18
from typing import Any , Callable , Dict , List , Optional , cast
19
19
import concurrent .futures
20
20
import json
21
- import warnings
22
21
import asyncio
23
22
import logging
24
23
import requests
25
24
import httpx
26
25
27
- from googleapiclient import http
28
- from googleapiclient import _auth
29
-
30
26
import firebase_admin
31
27
from firebase_admin import (
32
28
_http_client ,
33
29
_messaging_encoder ,
34
30
_messaging_utils ,
35
- _gapic_utils ,
36
31
_utils ,
37
32
exceptions ,
38
33
App
72
67
'WebpushNotificationAction' ,
73
68
74
69
'send' ,
75
- 'send_all' ,
76
- 'send_multicast' ,
77
70
'send_each' ,
78
71
'send_each_async' ,
79
72
'send_each_for_multicast' ,
@@ -246,64 +239,6 @@ def send_each_for_multicast(multicast_message, dry_run=False, app=None):
246
239
) for token in multicast_message .tokens ]
247
240
return _get_messaging_service (app ).send_each (messages , dry_run )
248
241
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
-
307
242
def subscribe_to_topic (tokens , topic , app = None ):
308
243
"""Subscribes a list of registration tokens to an FCM topic.
309
244
@@ -472,7 +407,6 @@ def __init__(self, app: App) -> None:
472
407
self ._client = _http_client .JsonHttpClient (credential = self ._credential , timeout = timeout )
473
408
self ._async_client = _http_client .HttpxAsyncClient (
474
409
credential = self ._credential , timeout = timeout )
475
- self ._build_transport = _auth .authorized_http
476
410
477
411
@classmethod
478
412
def encode_message (cls , message ):
@@ -555,45 +489,6 @@ async def send_data(data):
555
489
message = 'Unknown error while making remote service calls: {0}' .format (error ),
556
490
cause = error )
557
491
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
-
597
492
def make_topic_management_request (self , tokens , topic , operation ):
598
493
"""Invokes the IID service for topic management functionality."""
599
494
if isinstance (tokens , str ):
@@ -670,11 +565,6 @@ def _handle_iid_error(self, error):
670
565
671
566
return _utils .handle_requests_error (error , msg )
672
567
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
-
678
568
def close (self ) -> None :
679
569
asyncio .run (self ._async_client .aclose ())
680
570
@@ -700,14 +590,6 @@ def _build_fcm_error_httpx(
700
590
message , cause = error , http_response = error .response ) if exc_type else None
701
591
return exc_type (message , cause = error ) if exc_type else None
702
592
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
-
711
593
@classmethod
712
594
def _build_fcm_error (
713
595
cls ,
0 commit comments