Skip to content

Commit c93a6a0

Browse files
authored
Add GetHttpsCallableFromURL to Functions (#313)
* Add GetHttpsCallableFromURL to Functions * Update the Cpp version to include functions * Formatting comments
1 parent 80bf31e commit c93a6a0

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

cmake/firebase_unity_version.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ set(FIREBASE_UNITY_JAR_RESOLVER_VERSION "1.2.171"
2727
)
2828

2929
# https://github.com/firebase/firebase-cpp-sdk
30-
set(FIREBASE_CPP_SDK_PRESET_VERSION "origin/unity-v9.0.0"
30+
set(FIREBASE_CPP_SDK_PRESET_VERSION "a192efbda2c22d5c336db00999ac919eb22e5157"
3131
CACHE STRING
3232
"Version tag of Firebase CPP SDK to download (if no local or not passed in) and use (no trailing .0)"
3333
)

docs/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ Release Notes
158158
### Upcoming
159159
- Changes
160160
- General: Added a missing namespace to the Google.MiniJson.dll.
161+
- Functions: Add a new method `GetHttpsCallableFromURL`, to create callables
162+
with URLs other than cloudfunctions.net.
161163

162164
### 9.0.0
163165
- Changes

functions/src/FirebaseFunctions.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,29 @@ private void ThrowIfNull() {
212212
}
213213

214214
/// <summary>
215-
/// Creates a
216-
/// <see cref="HttpsCallableReference" />
217-
/// given a name.
215+
/// Creates a <see cref="HttpsCallableReference" /> given a name.
218216
/// </summary>
219217
public HttpsCallableReference GetHttpsCallable(string name) {
220218
ThrowIfNull();
221219
return new HttpsCallableReference(this, functionsInternal.GetHttpsCallable(name));
222220
}
223221

222+
/// <summary>
223+
/// Creates a <see cref="HttpsCallableReference" /> given a URL.
224+
/// </summary>
225+
public HttpsCallableReference GetHttpsCallableFromURL(string url) {
226+
ThrowIfNull();
227+
return new HttpsCallableReference(this, functionsInternal.GetHttpsCallableFromURL(url));
228+
}
229+
230+
/// <summary>
231+
/// Creates a <see cref="HttpsCallableReference" /> given a URL.
232+
/// </summary>
233+
public HttpsCallableReference GetHttpsCallableFromURL(Uri url) {
234+
ThrowIfNull();
235+
return GetHttpsCallableFromURL(url.ToString());
236+
}
237+
224238
/// <summary>
225239
/// Sets an origin of a Cloud Functions Emulator instance to use.
226240
/// </summary>

functions/testapp/Assets/Firebase/Sample/Functions/TestCase.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ public TestCase(string name, object input, object expectedResult,
4040
ExpectedError = expectedError;
4141
}
4242

43+
// Returns the CallableReference to be used by the test. Overridable to allow
44+
// different ways to generate the CallableReference.
45+
public virtual HttpsCallableReference GetReference(FirebaseFunctions functions) {
46+
return functions.GetHttpsCallable(Name);
47+
}
48+
4349
// Runs the given test and returns whether it passed.
4450
public Task RunAsync(FirebaseFunctions functions,
4551
Utils.Reporter reporter) {
46-
var func = functions.GetHttpsCallable(Name);
52+
var func = GetReference(functions);
4753
return func.CallAsync(Input).ContinueWithOnMainThread((task) => {
4854
if (ExpectedError == FunctionsErrorCode.None) {
4955
// We expected no error.
@@ -82,4 +88,21 @@ public Task RunAsync(FirebaseFunctions functions,
8288
});
8389
}
8490
}
91+
92+
// TestCase that uses a URL to call the function directly.
93+
public class TestCaseWithURL : TestCase {
94+
// The URL of the function to call
95+
System.Uri URL { get; set; }
96+
97+
public TestCaseWithURL(string name, System.Uri url, object input, object expectedResult,
98+
FunctionsErrorCode expectedError = FunctionsErrorCode.None)
99+
: base(name, input, expectedResult, expectedError) {
100+
URL = url;
101+
}
102+
103+
// Generate the CallableReference using the URL
104+
public override HttpsCallableReference GetReference(FirebaseFunctions functions) {
105+
return functions.GetHttpsCallableFromURL(URL);
106+
}
107+
}
85108
}

functions/testapp/Assets/Firebase/Sample/Functions/UIHandlerAutomated.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public static IEnumerable<TestCase> AllTests() {
5454
FunctionsErrorCode.Internal);
5555
yield return new TestCase("explicitErrorTest", null, null,
5656
FunctionsErrorCode.OutOfRange);
57+
58+
// Test calling via Url
59+
string projectId = FirebaseApp.DefaultInstance.Options.ProjectId;
60+
yield return new TestCaseWithURL("scalarTest via Url",
61+
new System.Uri("https://us-central1-" + projectId + ".cloudfunctions.net/scalarTest"),
62+
17, 76L);
5763
}
5864

5965
protected override void Start() {

0 commit comments

Comments
 (0)