Skip to content

Commit e19ca29

Browse files
authored
Implementing FCM sendAll and sendMulticast APIs (#247)
* Preliminary impl of FCM batch support * Added BatchMessage class and tests * Refactored the FCM send operation * Added unit tests for sendBatch() API * Refactored error handling * Refactored FCM logic into a new FirebaseMessagingClient class * Using a separate request factory for child requests * Added the InstanceIdClient class for handling topic mgt ops * Added license headers * Renamed BatchResponse as SendResponse * Added BatchResponse class; Renamed BatchMessage to MulticastMessage * Updated tests and docs * Updated documentation * Added documentation and tests * Updated docs, changelog and annotations * Updated integration test to use multiple topics; Updated docs * Removing a redundant whitespace * Reduced FCM batch size to 100 (#250) * Setting the X-Client-Version header for FCM (#252) * Snippets for FCM sendAll() and sendMulticast() (#249) * Snippets for FCM sendAll() and sendMulticast() * Reduced batch size to 100 in snippets * Addressing some documentation nits
1 parent 5ddf8fc commit e19ca29

24 files changed

+2350
-337
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ target/
55
.classpath
66
.project
77
.checkstyle
8+
.factorypath
9+
.vscode/
810
release.properties
911
integration_cert.json
1012
integration_apikey.txt

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- [added] Implemented new `sendAll()` and `sendMulticast()` APIs in
4+
`FirebaseMessaging`.
35
- [changed] Removed org.json dependency and replaced with com.google.code.gson.
46
- [changed] Upgraded Mockito dependency, and fixed the build on Java 11.
57

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2019 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.internal;
18+
19+
import com.google.api.client.http.HttpRequestFactory;
20+
import com.google.api.client.http.HttpResponse;
21+
import com.google.api.client.http.HttpTransport;
22+
import com.google.firebase.FirebaseApp;
23+
24+
import java.io.IOException;
25+
26+
/**
27+
* A set of shared utilities for using the Google API client.
28+
*/
29+
public class ApiClientUtils {
30+
31+
public static HttpRequestFactory newAuthorizedRequestFactory(FirebaseApp app) {
32+
HttpTransport transport = app.getOptions().getHttpTransport();
33+
return transport.createRequestFactory(new FirebaseRequestInitializer(app));
34+
}
35+
36+
public static HttpRequestFactory newUnauthorizedRequestFactory(FirebaseApp app) {
37+
HttpTransport transport = app.getOptions().getHttpTransport();
38+
return transport.createRequestFactory();
39+
}
40+
41+
public static void disconnectQuietly(HttpResponse response) {
42+
if (response != null) {
43+
try {
44+
response.disconnect();
45+
} catch (IOException ignored) {
46+
// ignored
47+
}
48+
}
49+
}
50+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2019 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.messaging;
18+
19+
import com.google.common.collect.ImmutableList;
20+
import com.google.firebase.internal.NonNull;
21+
import java.util.List;
22+
23+
/**
24+
* Response from an operation that sends FCM messages to multiple recipients.
25+
* See {@link FirebaseMessaging#sendAll(List)} and {@link
26+
* FirebaseMessaging#sendMulticast(MulticastMessage)}.
27+
*/
28+
public final class BatchResponse {
29+
30+
private final List<SendResponse> responses;
31+
private final int successCount;
32+
33+
BatchResponse(List<SendResponse> responses) {
34+
this.responses = ImmutableList.copyOf(responses);
35+
int successCount = 0;
36+
for (SendResponse response : this.responses) {
37+
if (response.isSuccessful()) {
38+
successCount++;
39+
}
40+
}
41+
this.successCount = successCount;
42+
}
43+
44+
@NonNull
45+
public List<SendResponse> getResponses() {
46+
return responses;
47+
}
48+
49+
public int getSuccessCount() {
50+
return successCount;
51+
}
52+
53+
public int getFailureCount() {
54+
return responses.size() - successCount;
55+
}
56+
}

0 commit comments

Comments
 (0)