Skip to content

Add GetHttpsCallableFromURL to Functions #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/firebase_unity_version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
)
2 changes: 2 additions & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 17 additions & 3 deletions functions/src/FirebaseFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,29 @@ private void ThrowIfNull() {
}

/// <summary>
/// Creates a
/// <see cref="HttpsCallableReference" />
/// given a name.
/// Creates a <see cref="HttpsCallableReference" /> given a name.
/// </summary>
public HttpsCallableReference GetHttpsCallable(string name) {
ThrowIfNull();
return new HttpsCallableReference(this, functionsInternal.GetHttpsCallable(name));
}

/// <summary>
/// Creates a <see cref="HttpsCallableReference" /> given a URL.
/// </summary>
public HttpsCallableReference GetHttpsCallableFromURL(string url) {
ThrowIfNull();
return new HttpsCallableReference(this, functionsInternal.GetHttpsCallableFromURL(url));
}

/// <summary>
/// Creates a <see cref="HttpsCallableReference" /> given a URL.
/// </summary>
public HttpsCallableReference GetHttpsCallableFromURL(Uri url) {
ThrowIfNull();
return GetHttpsCallableFromURL(url.ToString());
}

/// <summary>
/// Sets an origin of a Cloud Functions Emulator instance to use.
/// </summary>
Expand Down
25 changes: 24 additions & 1 deletion functions/testapp/Assets/Firebase/Sample/Functions/TestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public static IEnumerable<TestCase> 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() {
Expand Down