File tree Expand file tree Collapse file tree 5 files changed +49
-0
lines changed
templates/kotlin/src/main/kotlin/io/appwrite Expand file tree Collapse file tree 5 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,25 @@ class Client @JvmOverloads constructor(
170
170
return this
171
171
}
172
172
173
+ /**
174
+ * Sends a "ping" request to Appwrite to verify connectivity.
175
+ *
176
+ * @return String
177
+ */
178
+ suspend fun ping(): String {
179
+ val apiPath = "/ping"
180
+ val apiParams = mutableMapOf<String , Any ?>()
181
+ val apiHeaders = mutableMapOf("content-type" to "application/json")
182
+
183
+ return call(
184
+ "GET",
185
+ apiPath,
186
+ apiHeaders,
187
+ apiParams,
188
+ responseType = String::class.java
189
+ )
190
+ }
191
+
173
192
/**
174
193
* Prepare the HTTP request
175
194
*
@@ -536,6 +555,14 @@ class Client @JvmOverloads constructor(
536
555
it.resume(true as T)
537
556
return
538
557
}
558
+ responseType == String::class.java -> {
559
+ val body = response.body!!
560
+ .charStream()
561
+ .buffered()
562
+ .use(BufferedReader::readText)
563
+ it.resume(body as T)
564
+ return
565
+ }
539
566
responseType == ByteArray::class.java -> {
540
567
it.resume(response.body!!
541
568
.byteStream()
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class KotlinJava11Test extends Base
20
20
'docker run --network="mockapi" -v $(pwd):/app -w /app/tests/sdks/kotlin openjdk:11-jdk-slim sh -c "./gradlew test -q && cat 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 KotlinJava17Test extends Base
20
20
'docker run --network="mockapi" -v $(pwd):/app -w /app/tests/sdks/kotlin openjdk:17-jdk-slim sh -c "./gradlew test -q && cat 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 KotlinJava8Test extends Base
20
20
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/kotlin openjdk:8-jdk-slim sh -c "./gradlew test -q && cat 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 @@ -19,6 +19,7 @@ import kotlinx.coroutines.runBlocking
19
19
import okhttp3.Response
20
20
import org.junit.Before
21
21
import org.junit.Test
22
+ import org.json.JSONObject
22
23
import java.io.File
23
24
import java.io.IOException
24
25
import java.nio.file.Files
@@ -38,8 +39,19 @@ class ServiceTest {
38
39
@Throws(IOException ::class )
39
40
fun test () {
40
41
val client = Client ()
42
+ .setProject(" 123456" )
41
43
.addHeader(" Origin" , " http://localhost" )
42
44
.setSelfSigned(true )
45
+
46
+ runBlocking {
47
+ val ping = client.ping()
48
+ val pingResponse = parse(ping)
49
+ writeToFile(pingResponse)
50
+ }
51
+
52
+ // reset project
53
+ client.setProject(" 123456" )
54
+
43
55
val foo = Foo (client)
44
56
val bar = Bar (client)
45
57
val general = General (client)
@@ -185,4 +197,11 @@ class ServiceTest {
185
197
File (" result.txt" ).appendText(text)
186
198
}
187
199
200
+ private fun parse (json : String ): String? {
201
+ return try {
202
+ JSONObject (json).getString(" result" )
203
+ } catch (exception: Exception ) {
204
+ null
205
+ }
206
+ }
188
207
}
You can’t perform that action at this time.
0 commit comments