File tree Expand file tree Collapse file tree 6 files changed +51
-2
lines changed
templates/android/library/src/main/java/io/package Expand file tree Collapse file tree 6 files changed +51
-2
lines changed Original file line number Diff line number Diff line change @@ -211,6 +211,25 @@ class Client @JvmOverloads constructor(
211
211
return this
212
212
}
213
213
214
+ /**
215
+ * Sends a "ping" request to Appwrite to verify connectivity.
216
+ *
217
+ * @return String
218
+ */
219
+ suspend fun ping(): String {
220
+ val apiPath = "/ping"
221
+ val apiParams = mutableMapOf<String , Any ?>()
222
+ val apiHeaders = mutableMapOf("content-type" to "application/json")
223
+
224
+ return call(
225
+ "GET",
226
+ apiPath,
227
+ apiHeaders,
228
+ apiParams,
229
+ responseType = String::class.java
230
+ )
231
+ }
232
+
214
233
/**
215
234
* Send the HTTP request
216
235
*
@@ -489,6 +508,14 @@ class Client @JvmOverloads constructor(
489
508
it.resume(true as T)
490
509
return
491
510
}
511
+ responseType == String::class.java -> {
512
+ val body = response.body!!
513
+ .charStream()
514
+ .buffered()
515
+ .use(BufferedReader::readText)
516
+ it.resume(body as T)
517
+ return
518
+ }
492
519
responseType == ByteArray::class.java -> {
493
520
it.resume(response.body!!
494
521
.byteStream()
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class Android14Java11Test extends Base
20
20
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-34-jdk11 sh -c "./gradlew :library:testReleaseUnitTest --stacktrace -q && cat library/result.txt" ' ;
21
21
22
22
protected array $ expectedOutput = [
23
+ ...Base::PING_RESPONSE ,
23
24
...Base::FOO_RESPONSES ,
24
25
...Base::BAR_RESPONSES ,
25
26
...Base::GENERAL_RESPONSES ,
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class Android14Java17Test extends Base
20
20
'docker run --rm --network="mockapi" -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-34-jdk17 sh -c "./gradlew :library:testReleaseUnitTest --stacktrace -q && cat library/result.txt" ' ;
21
21
22
22
protected array $ expectedOutput = [
23
+ ...Base::PING_RESPONSE ,
23
24
...Base::FOO_RESPONSES ,
24
25
...Base::BAR_RESPONSES ,
25
26
...Base::GENERAL_RESPONSES ,
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class Android14Java8Test extends Base
20
20
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-34-jdk8 sh -c "./gradlew :library:testReleaseUnitTest --stacktrace -q && cat library/result.txt" ' ;
21
21
22
22
protected array $ expectedOutput = [
23
+ ...Base::PING_RESPONSE ,
23
24
...Base::FOO_RESPONSES ,
24
25
...Base::BAR_RESPONSES ,
25
26
...Base::GENERAL_RESPONSES ,
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class Android5Java17Test extends Base
20
20
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-21-jdk17 sh -c "./gradlew :library:testReleaseUnitTest --stacktrace -q && cat library/result.txt" ' ;
21
21
22
22
protected array $ expectedOutput = [
23
+ ...Base::PING_RESPONSE ,
23
24
...Base::FOO_RESPONSES ,
24
25
...Base::BAR_RESPONSES ,
25
26
...Base::GENERAL_RESPONSES ,
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import org.junit.After
29
29
import org.junit.Before
30
30
import org.junit.Test
31
31
import org.junit.runner.RunWith
32
+ import org.json.JSONObject
32
33
import org.robolectric.annotation.Config
33
34
import java.io.File
34
35
import java.io.IOException
@@ -61,10 +62,20 @@ class ServiceTest {
61
62
@Throws(IOException ::class )
62
63
fun test () {
63
64
val client = Client (ApplicationProvider .getApplicationContext())
64
- .setEndpointRealtime(" wss://cloud.appwrite.io/v1" )
65
- .setProject(" console" )
65
+ .setProject(" 123456" )
66
66
.addHeader(" Origin" , " http://localhost" )
67
67
.setSelfSigned(true )
68
+
69
+ runBlocking {
70
+ val ping = client.ping()
71
+ val pingResponse = parse(ping)
72
+ writeToFile(pingResponse)
73
+ }
74
+
75
+ // reset configs
76
+ client.setProject(" console" )
77
+ .setEndpointRealtime(" wss://cloud.appwrite.io/v1" )
78
+
68
79
val foo = Foo (client)
69
80
val bar = Bar (client)
70
81
val general = General (client)
@@ -219,4 +230,11 @@ class ServiceTest {
219
230
File (" result.txt" ).appendText(text)
220
231
}
221
232
233
+ private fun parse (json : String ): String? {
234
+ return try {
235
+ JSONObject (json).getString(" result" )
236
+ } catch (exception: Exception ) {
237
+ null
238
+ }
239
+ }
222
240
}
You can’t perform that action at this time.
0 commit comments