14
14
15
15
"""Firebase Cloud Messaging module."""
16
16
17
- import json
18
17
import requests
19
18
import six
20
19
@@ -253,6 +252,7 @@ class _MessagingService(object):
253
252
IID_HEADERS = {'access_token_auth' : 'true' }
254
253
JSON_ENCODER = _messaging_utils .MessageEncoder ()
255
254
BATCH_ENCODER = _messaging_utils .BatchMessageEncoder ()
255
+ BATCH_DECODER = _messaging_utils .BatchMessageResponseDecoder ()
256
256
257
257
BATCH_PART_BOUNDARY = '__END_OF_PART__'
258
258
@@ -329,7 +329,7 @@ def sendAll(self, messages, dry_run=False):
329
329
'Content-Type' : 'multipart/mixed; boundary={}' .format (_MessagingService .BATCH_PART_BOUNDARY )
330
330
}
331
331
try :
332
- response = self ._client .request (
332
+ resp = self ._client .request (
333
333
'post' , url = _MessagingService .FCM_BATCH_URL , headers = headers , data = data , timeout = self ._timeout
334
334
)
335
335
except requests .exceptions .RequestException as error :
@@ -339,18 +339,7 @@ def sendAll(self, messages, dry_run=False):
339
339
msg = 'Failed to call messaging API: {0}' .format (error )
340
340
raise ApiCallError (self .INTERNAL_ERROR , msg , error )
341
341
else :
342
- import re
343
- # Split our batches responses in to groups
344
- response_regex = re .compile ('--batch.*?$\n (.*?)(?=--batch)' , re .DOTALL | re .MULTILINE )
345
- responses = response_regex .findall (response .content )
346
-
347
- # First section is headers related to the batch request
348
- # Second section is headers related to the batched request
349
- # Third section is data related to the batched request
350
- response_sections = [r .split ('\r \n \r \n ' ) for r in responses ]
351
- response_json = [json .loads (r [2 ]) for r in response_sections ]
352
-
353
- return response_json
342
+ return _MessagingService .BATCH_DECODER .decode (resp )
354
343
355
344
def make_topic_management_request (self , tokens , topic , operation ):
356
345
"""Invokes the IID service for topic management functionality."""
0 commit comments