From c565d6d2348850b921397bfa57559c46dcaddcbb Mon Sep 17 00:00:00 2001 From: a-maurice Date: Mon, 23 May 2022 18:21:08 -0700 Subject: [PATCH 1/3] Add GetHttpsCallableFromURL to Functions --- docs/readme.md | 2 ++ functions/src/FirebaseFunctions.cs | 20 +++++++++++++++ .../Firebase/Sample/Functions/TestCase.cs | 25 ++++++++++++++++++- .../Sample/Functions/UIHandlerAutomated.cs | 6 +++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/docs/readme.md b/docs/readme.md index 7a96a860d..769f24da7 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -158,6 +158,8 @@ Release Notes ### Upcoming - Changes - General: Added a missing namespace to the Google.MiniJson.dll. + - Functions: Add a new method `GetHttpsCallableFromURL`, to create callables + with URLs other than cloudfunctions.net. ### 9.0.0 - Changes diff --git a/functions/src/FirebaseFunctions.cs b/functions/src/FirebaseFunctions.cs index 7dcf6b000..ed88a8d89 100644 --- a/functions/src/FirebaseFunctions.cs +++ b/functions/src/FirebaseFunctions.cs @@ -221,6 +221,26 @@ public HttpsCallableReference GetHttpsCallable(string name) { return new HttpsCallableReference(this, functionsInternal.GetHttpsCallable(name)); } + /// + /// Creates a + /// + /// given a URL. + /// + public HttpsCallableReference GetHttpsCallableFromURL(string url) { + ThrowIfNull(); + return new HttpsCallableReference(this, functionsInternal.GetHttpsCallableFromURL(url)); + } + + /// + /// Creates a + /// + /// given a URL. + /// + public HttpsCallableReference GetHttpsCallableFromURL(Uri url) { + ThrowIfNull(); + return GetHttpsCallableFromURL(url.ToString()); + } + /// /// Sets an origin of a Cloud Functions Emulator instance to use. /// diff --git a/functions/testapp/Assets/Firebase/Sample/Functions/TestCase.cs b/functions/testapp/Assets/Firebase/Sample/Functions/TestCase.cs index 29c61aafb..ddcaa26a0 100644 --- a/functions/testapp/Assets/Firebase/Sample/Functions/TestCase.cs +++ b/functions/testapp/Assets/Firebase/Sample/Functions/TestCase.cs @@ -40,10 +40,16 @@ public TestCase(string name, object input, object expectedResult, ExpectedError = expectedError; } + // Returns the CallableReference to be used by the test. Overridable to allow + // different ways to generate the CallableReference. + public virtual HttpsCallableReference GetReference(FirebaseFunctions functions) { + return functions.GetHttpsCallable(Name); + } + // Runs the given test and returns whether it passed. public Task RunAsync(FirebaseFunctions functions, Utils.Reporter reporter) { - var func = functions.GetHttpsCallable(Name); + var func = GetReference(functions); return func.CallAsync(Input).ContinueWithOnMainThread((task) => { if (ExpectedError == FunctionsErrorCode.None) { // We expected no error. @@ -82,4 +88,21 @@ public Task RunAsync(FirebaseFunctions functions, }); } } + + // TestCase that uses a URL to call the function directly. + public class TestCaseWithURL : TestCase { + // The URL of the function to call + System.Uri URL { get; set; } + + public TestCaseWithURL(string name, System.Uri url, object input, object expectedResult, + FunctionsErrorCode expectedError = FunctionsErrorCode.None) + : base(name, input, expectedResult, expectedError) { + URL = url; + } + + // Generate the CallableReference using the URL + public override HttpsCallableReference GetReference(FirebaseFunctions functions) { + return functions.GetHttpsCallableFromURL(URL); + } + } } diff --git a/functions/testapp/Assets/Firebase/Sample/Functions/UIHandlerAutomated.cs b/functions/testapp/Assets/Firebase/Sample/Functions/UIHandlerAutomated.cs index b3c918196..f4b377231 100644 --- a/functions/testapp/Assets/Firebase/Sample/Functions/UIHandlerAutomated.cs +++ b/functions/testapp/Assets/Firebase/Sample/Functions/UIHandlerAutomated.cs @@ -54,6 +54,12 @@ public static IEnumerable AllTests() { FunctionsErrorCode.Internal); yield return new TestCase("explicitErrorTest", null, null, FunctionsErrorCode.OutOfRange); + + // Test calling via Url + string projectId = FirebaseApp.DefaultInstance.Options.ProjectId; + yield return new TestCaseWithURL("scalarTest via Url", + new System.Uri("https://us-central1-" + projectId + ".cloudfunctions.net/scalarTest"), + 17, 76L); } protected override void Start() { From ccbae7ef8daba3a127df3b7244c3edf87d610b24 Mon Sep 17 00:00:00 2001 From: a-maurice Date: Tue, 24 May 2022 13:22:42 -0700 Subject: [PATCH 2/3] Update the Cpp version to include functions --- cmake/firebase_unity_version.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/firebase_unity_version.cmake b/cmake/firebase_unity_version.cmake index 5f03fbb11..731c906c7 100644 --- a/cmake/firebase_unity_version.cmake +++ b/cmake/firebase_unity_version.cmake @@ -27,7 +27,7 @@ set(FIREBASE_UNITY_JAR_RESOLVER_VERSION "1.2.171" ) # https://github.com/firebase/firebase-cpp-sdk -set(FIREBASE_CPP_SDK_PRESET_VERSION "origin/unity-v9.0.0" +set(FIREBASE_CPP_SDK_PRESET_VERSION "a192efbda2c22d5c336db00999ac919eb22e5157" CACHE STRING "Version tag of Firebase CPP SDK to download (if no local or not passed in) and use (no trailing .0)" ) From d32b596481544bff0fc829ed178e05e257287e70 Mon Sep 17 00:00:00 2001 From: a-maurice Date: Tue, 24 May 2022 17:05:47 -0700 Subject: [PATCH 3/3] Formatting comments --- functions/src/FirebaseFunctions.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/functions/src/FirebaseFunctions.cs b/functions/src/FirebaseFunctions.cs index ed88a8d89..3424e3c27 100644 --- a/functions/src/FirebaseFunctions.cs +++ b/functions/src/FirebaseFunctions.cs @@ -212,9 +212,7 @@ private void ThrowIfNull() { } /// - /// Creates a - /// - /// given a name. + /// Creates a given a name. /// public HttpsCallableReference GetHttpsCallable(string name) { ThrowIfNull(); @@ -222,9 +220,7 @@ public HttpsCallableReference GetHttpsCallable(string name) { } /// - /// Creates a - /// - /// given a URL. + /// Creates a given a URL. /// public HttpsCallableReference GetHttpsCallableFromURL(string url) { ThrowIfNull(); @@ -232,9 +228,7 @@ public HttpsCallableReference GetHttpsCallableFromURL(string url) { } /// - /// Creates a - /// - /// given a URL. + /// Creates a given a URL. /// public HttpsCallableReference GetHttpsCallableFromURL(Uri url) { ThrowIfNull();