Skip to content

Commit 1a1c62b

Browse files
committed
add support for pojos in firebase functions call
1 parent 0563844 commit 1a1c62b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

firebase-functions/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ kotlin {
5050
val androidMain by getting {
5151
dependencies {
5252
api("com.google.firebase:firebase-functions:17.0.0")
53+
implementation("com.google.code.gson:gson:2.7")
5354
}
5455
}
5556
val jvmMain by getting {
5657
kotlin.srcDir("src/androidMain/kotlin")
58+
dependencies {
59+
implementation("com.google.code.gson:gson:2.7")
60+
}
5761
}
5862
}
5963
}

firebase-functions/src/androidMain/kotlin/dev/teamhub/firebase/functions/functions.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package dev.teamhub.firebase.functions
22

3+
import com.google.gson.Gson
34
import kotlinx.coroutines.tasks.await
5+
import org.json.JSONTokener
46
import java.util.concurrent.TimeUnit
57

8+
private val gson by lazy { Gson() }
9+
610
actual fun getFirebaseFunctions() = FirebaseFunctions.getInstance()
711

812
actual typealias FirebaseFunctions = com.google.firebase.functions.FirebaseFunctions
913

1014
actual typealias HttpsCallableReference = com.google.firebase.functions.HttpsCallableReference
1115

12-
actual suspend fun HttpsCallableReference.awaitCall(data: Any?) = call(data).await()
16+
actual suspend fun HttpsCallableReference.awaitCall(data: Any?) = call(JSONTokener(gson.toJson(data)).nextValue()).await()
1317
actual suspend fun HttpsCallableReference.awaitCall() = call().await()
1418

1519
actual typealias HttpsCallableResult = com.google.firebase.functions.HttpsCallableResult
@@ -20,4 +24,4 @@ actual val HttpsCallableResult.data: Any
2024
actual fun FirebaseFunctions.getHttpsCallable(name: String, timeout: Long?) =
2125
getHttpsCallable(name).apply { timeout?.let { setTimeout(it, TimeUnit.MILLISECONDS) } }
2226

23-
actual typealias FirebaseFunctionsException = com.google.firebase.functions.FirebaseFunctionsException
27+
actual typealias FirebaseFunctionsException = com.google.firebase.functions.FirebaseFunctionsException

0 commit comments

Comments
 (0)