Skip to content

Commit 6ac931b

Browse files
committed
Initial commit; don't know how to run formatter or integration tests
1 parent 7f0bff1 commit 6ac931b

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ public HttpsCallableReference getHttpsCallable(@NonNull String name) {
204204
return new HttpsCallableReference(this, name);
205205
}
206206

207+
@NonNull
208+
public HttpsCallableReference getHttpsCallableFromUrl(@NonNull String url) throws MalformedURLException {
209+
return new HttpsCallableReference(this, new URL(url));
210+
}
211+
207212
/**
208213
* Returns the URL for a particular function.
209214
*
@@ -270,9 +275,30 @@ Task<HttpsCallableResult> call(String name, @Nullable Object data, HttpsCallOpti
270275
return Tasks.forException(task.getException());
271276
}
272277
HttpsCallableContext context = task.getResult();
273-
return call(name, data, context, options);
278+
URL url = getURL(name);
279+
return call(url, data, context, options);
274280
});
275281
}
282+
/**
283+
* Calls a Callable HTTPS trigger endpoint.
284+
*
285+
* @param url The url of the HTTPS trigger
286+
* @param data Parameters to pass to the function. Can be anything encodable as JSON.
287+
* @return A Task that will be completed when the request is complete.
288+
*/
289+
Task<HttpsCallableResult> call(URL url, @Nullable Object data, HttpsCallOptions options) {
290+
return providerInstalled
291+
.getTask()
292+
.continueWithTask(task -> contextProvider.getContext())
293+
.continueWithTask(
294+
task -> {
295+
if (!task.isSuccessful()) {
296+
return Tasks.forException(task.getException());
297+
}
298+
HttpsCallableContext context = task.getResult();
299+
return call(url, data, context, options);
300+
});
301+
}
276302

277303
/**
278304
* Calls a Callable HTTPS trigger endpoint.
@@ -283,12 +309,11 @@ Task<HttpsCallableResult> call(String name, @Nullable Object data, HttpsCallOpti
283309
* @return A Task that will be completed when the request is complete.
284310
*/
285311
private Task<HttpsCallableResult> call(
286-
@NonNull String name,
312+
@NonNull URL url,
287313
@Nullable Object data,
288314
HttpsCallableContext context,
289315
HttpsCallOptions options) {
290-
Preconditions.checkNotNull(name, "name cannot be null");
291-
URL url = getURL(name);
316+
Preconditions.checkNotNull(url, "url cannot be null");
292317

293318
Map<String, Object> body = new HashMap<>();
294319

firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import androidx.annotation.NonNull;
1818
import androidx.annotation.Nullable;
1919
import com.google.android.gms.tasks.Task;
20+
21+
import java.net.URL;
2022
import java.util.concurrent.TimeUnit;
2123

2224
/** A reference to a particular Callable HTTPS trigger in Cloud Functions. */
@@ -26,15 +28,28 @@ public class HttpsCallableReference {
2628
private final FirebaseFunctions functionsClient;
2729

2830
// The name of the HTTPS endpoint this reference refers to.
31+
// Is null if url is set.
2932
private final String name;
3033

34+
// The url of the HTTPS endpoint this reference refers to.
35+
// Is null if name is set.
36+
private final URL url;
37+
3138
// Options for how to do the HTTPS call.
3239
HttpsCallOptions options = new HttpsCallOptions();
3340

3441
/** Creates a new reference with the given options. */
3542
HttpsCallableReference(FirebaseFunctions functionsClient, String name) {
3643
this.functionsClient = functionsClient;
3744
this.name = name;
45+
this.url = null;
46+
}
47+
48+
/** Creates a new reference with the given options. */
49+
HttpsCallableReference(FirebaseFunctions functionsClient, URL url) {
50+
this.functionsClient = functionsClient;
51+
this.name = null;
52+
this.url = url;
3853
}
3954

4055
/**
@@ -80,7 +95,11 @@ public class HttpsCallableReference {
8095
*/
8196
@NonNull
8297
public Task<HttpsCallableResult> call(@Nullable Object data) {
83-
return functionsClient.call(name, data, options);
98+
if (name != null) {
99+
return functionsClient.call(name, data, options);
100+
} else {
101+
return functionsClient.call(url, data, options);
102+
}
84103
}
85104

86105
/**
@@ -99,7 +118,11 @@ public Task<HttpsCallableResult> call(@Nullable Object data) {
99118
*/
100119
@NonNull
101120
public Task<HttpsCallableResult> call() {
102-
return functionsClient.call(name, null, options);
121+
if (name != null) {
122+
return functionsClient.call(name, null, options);
123+
} else {
124+
return functionsClient.call(url, null, options);
125+
}
103126
}
104127

105128
/**

0 commit comments

Comments
 (0)