From 6ac931bbb6d536316b9795e94c4a60ce32b07117 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Sat, 16 Apr 2022 21:32:41 -0700 Subject: [PATCH 1/5] Initial commit; don't know how to run formatter or integration tests --- .../firebase/functions/FirebaseFunctions.java | 33 ++++++++++++++++--- .../functions/HttpsCallableReference.java | 27 +++++++++++++-- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java index 100e6929f8e..21967d0a816 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java +++ b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java @@ -204,6 +204,11 @@ public HttpsCallableReference getHttpsCallable(@NonNull String name) { return new HttpsCallableReference(this, name); } + @NonNull + public HttpsCallableReference getHttpsCallableFromUrl(@NonNull String url) throws MalformedURLException { + return new HttpsCallableReference(this, new URL(url)); + } + /** * Returns the URL for a particular function. * @@ -270,9 +275,30 @@ Task call(String name, @Nullable Object data, HttpsCallOpti return Tasks.forException(task.getException()); } HttpsCallableContext context = task.getResult(); - return call(name, data, context, options); + URL url = getURL(name); + return call(url, data, context, options); }); } + /** + * Calls a Callable HTTPS trigger endpoint. + * + * @param url The url of the HTTPS trigger + * @param data Parameters to pass to the function. Can be anything encodable as JSON. + * @return A Task that will be completed when the request is complete. + */ + Task call(URL url, @Nullable Object data, HttpsCallOptions options) { + return providerInstalled + .getTask() + .continueWithTask(task -> contextProvider.getContext()) + .continueWithTask( + task -> { + if (!task.isSuccessful()) { + return Tasks.forException(task.getException()); + } + HttpsCallableContext context = task.getResult(); + return call(url, data, context, options); + }); + } /** * Calls a Callable HTTPS trigger endpoint. @@ -283,12 +309,11 @@ Task call(String name, @Nullable Object data, HttpsCallOpti * @return A Task that will be completed when the request is complete. */ private Task call( - @NonNull String name, + @NonNull URL url, @Nullable Object data, HttpsCallableContext context, HttpsCallOptions options) { - Preconditions.checkNotNull(name, "name cannot be null"); - URL url = getURL(name); + Preconditions.checkNotNull(url, "url cannot be null"); Map body = new HashMap<>(); diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.java b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.java index d212775200f..be9feb0fe4b 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.java +++ b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.java @@ -17,6 +17,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.google.android.gms.tasks.Task; + +import java.net.URL; import java.util.concurrent.TimeUnit; /** A reference to a particular Callable HTTPS trigger in Cloud Functions. */ @@ -26,8 +28,13 @@ public class HttpsCallableReference { private final FirebaseFunctions functionsClient; // The name of the HTTPS endpoint this reference refers to. + // Is null if url is set. private final String name; + // The url of the HTTPS endpoint this reference refers to. + // Is null if name is set. + private final URL url; + // Options for how to do the HTTPS call. HttpsCallOptions options = new HttpsCallOptions(); @@ -35,6 +42,14 @@ public class HttpsCallableReference { HttpsCallableReference(FirebaseFunctions functionsClient, String name) { this.functionsClient = functionsClient; this.name = name; + this.url = null; + } + + /** Creates a new reference with the given options. */ + HttpsCallableReference(FirebaseFunctions functionsClient, URL url) { + this.functionsClient = functionsClient; + this.name = null; + this.url = url; } /** @@ -80,7 +95,11 @@ public class HttpsCallableReference { */ @NonNull public Task call(@Nullable Object data) { - return functionsClient.call(name, data, options); + if (name != null) { + return functionsClient.call(name, data, options); + } else { + return functionsClient.call(url, data, options); + } } /** @@ -99,7 +118,11 @@ public Task call(@Nullable Object data) { */ @NonNull public Task call() { - return functionsClient.call(name, null, options); + if (name != null) { + return functionsClient.call(name, null, options); + } else { + return functionsClient.call(url, null, options); + } } /** From 0256f3e4d22f808e71dc7e33c4b16db107a35587 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Mon, 18 Apr 2022 08:54:52 -0700 Subject: [PATCH 2/5] Add api.txt --- firebase-functions/api.txt | 1 + .../java/com/google/firebase/functions/FirebaseFunctions.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/firebase-functions/api.txt b/firebase-functions/api.txt index 25df5fab60a..25050a7eac6 100644 --- a/firebase-functions/api.txt +++ b/firebase-functions/api.txt @@ -3,6 +3,7 @@ package com.google.firebase.functions { public class FirebaseFunctions { method @NonNull public com.google.firebase.functions.HttpsCallableReference getHttpsCallable(@NonNull String); + method @NonNull public com.google.firebase.functions.HttpsCallableReference getHttpsCallableFromUrl(@NonNull URL url); method @NonNull public static com.google.firebase.functions.FirebaseFunctions getInstance(@NonNull com.google.firebase.FirebaseApp, @NonNull String); method @NonNull public static com.google.firebase.functions.FirebaseFunctions getInstance(@NonNull com.google.firebase.FirebaseApp); method @NonNull public static com.google.firebase.functions.FirebaseFunctions getInstance(@NonNull String); diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java index 21967d0a816..cea0801f08e 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java +++ b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java @@ -205,8 +205,8 @@ public HttpsCallableReference getHttpsCallable(@NonNull String name) { } @NonNull - public HttpsCallableReference getHttpsCallableFromUrl(@NonNull String url) throws MalformedURLException { - return new HttpsCallableReference(this, new URL(url)); + public HttpsCallableReference getHttpsCallableFromUrl(@NonNull URL url) { + return new HttpsCallableReference(this, url); } /** From e7083fd1380e359375eee1568e9c711e6c4f99c8 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Mon, 18 Apr 2022 09:08:52 -0700 Subject: [PATCH 3/5] Generate api.txt file --- firebase-functions/api.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-functions/api.txt b/firebase-functions/api.txt index 25050a7eac6..4b07ac34ce6 100644 --- a/firebase-functions/api.txt +++ b/firebase-functions/api.txt @@ -3,7 +3,7 @@ package com.google.firebase.functions { public class FirebaseFunctions { method @NonNull public com.google.firebase.functions.HttpsCallableReference getHttpsCallable(@NonNull String); - method @NonNull public com.google.firebase.functions.HttpsCallableReference getHttpsCallableFromUrl(@NonNull URL url); + method @NonNull public com.google.firebase.functions.HttpsCallableReference getHttpsCallableFromUrl(@NonNull java.net.URL); method @NonNull public static com.google.firebase.functions.FirebaseFunctions getInstance(@NonNull com.google.firebase.FirebaseApp, @NonNull String); method @NonNull public static com.google.firebase.functions.FirebaseFunctions getInstance(@NonNull com.google.firebase.FirebaseApp); method @NonNull public static com.google.firebase.functions.FirebaseFunctions getInstance(@NonNull String); From 48b23114573b46225bdd661c50a04326376064d5 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Mon, 18 Apr 2022 14:42:14 -0700 Subject: [PATCH 4/5] Fix bad formatting --- .../java/com/google/firebase/functions/FirebaseFunctions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java index cea0801f08e..26956972a41 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java +++ b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java @@ -275,7 +275,7 @@ Task call(String name, @Nullable Object data, HttpsCallOpti return Tasks.forException(task.getException()); } HttpsCallableContext context = task.getResult(); - URL url = getURL(name); + URL url = getURL(name); return call(url, data, context, options); }); } From 4b173f8444dab55fe421d65bc0d9d53ba3d0772e Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Tue, 19 Apr 2022 08:38:01 -0700 Subject: [PATCH 5/5] Finally fix style issues --- .../firebase/functions/FirebaseFunctions.java | 44 ++++++++++--------- .../functions/HttpsCallableReference.java | 1 - 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java index 26956972a41..ffc453bba15 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java +++ b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.java @@ -204,9 +204,10 @@ public HttpsCallableReference getHttpsCallable(@NonNull String name) { return new HttpsCallableReference(this, name); } + /** Returns a reference to the Callable HTTPS trigger with the provided url. */ @NonNull public HttpsCallableReference getHttpsCallableFromUrl(@NonNull URL url) { - return new HttpsCallableReference(this, url); + return new HttpsCallableReference(this, url); } /** @@ -279,26 +280,27 @@ Task call(String name, @Nullable Object data, HttpsCallOpti return call(url, data, context, options); }); } - /** - * Calls a Callable HTTPS trigger endpoint. - * - * @param url The url of the HTTPS trigger - * @param data Parameters to pass to the function. Can be anything encodable as JSON. - * @return A Task that will be completed when the request is complete. - */ - Task call(URL url, @Nullable Object data, HttpsCallOptions options) { - return providerInstalled - .getTask() - .continueWithTask(task -> contextProvider.getContext()) - .continueWithTask( - task -> { - if (!task.isSuccessful()) { - return Tasks.forException(task.getException()); - } - HttpsCallableContext context = task.getResult(); - return call(url, data, context, options); - }); - } + + /** + * Calls a Callable HTTPS trigger endpoint. + * + * @param url The url of the HTTPS trigger + * @param data Parameters to pass to the function. Can be anything encodable as JSON. + * @return A Task that will be completed when the request is complete. + */ + Task call(URL url, @Nullable Object data, HttpsCallOptions options) { + return providerInstalled + .getTask() + .continueWithTask(task -> contextProvider.getContext()) + .continueWithTask( + task -> { + if (!task.isSuccessful()) { + return Tasks.forException(task.getException()); + } + HttpsCallableContext context = task.getResult(); + return call(url, data, context, options); + }); + } /** * Calls a Callable HTTPS trigger endpoint. diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.java b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.java index be9feb0fe4b..26dfa4c498c 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.java +++ b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.java @@ -17,7 +17,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.google.android.gms.tasks.Task; - import java.net.URL; import java.util.concurrent.TimeUnit;