Skip to content

Commit bb6671d

Browse files
authored
Merge pull request #68 from appwrite/dev
fix: pong response & chunked upload
2 parents 19bb779 + 645f2a2 commit bb6671d

File tree

7 files changed

+68
-33
lines changed

7 files changed

+68
-33
lines changed

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors.
1+
Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors.
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-android.svg?color=green&style=flat-square)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-android.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-1.6.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.6.1-blue.svg?style=flat-square)
66
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
77
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
88
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
@@ -38,7 +38,7 @@ repositories {
3838
Next, add the dependency to your project's `build.gradle(.kts)` file:
3939

4040
```groovy
41-
implementation("io.appwrite:sdk-for-android:6.1.0")
41+
implementation("io.appwrite:sdk-for-android:7.0.0")
4242
```
4343

4444
### Maven
@@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file:
4949
<dependency>
5050
<groupId>io.appwrite</groupId>
5151
<artifactId>sdk-for-android</artifactId>
52-
<version>6.1.0</version>
52+
<version>7.0.0</version>
5353
</dependency>
5454
</dependencies>
5555
```

library/src/main/java/io/appwrite/Client.kt

+46-19
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Client @JvmOverloads constructor(
6060
internal lateinit var http: OkHttpClient
6161

6262
internal val headers: MutableMap<String, String>
63-
63+
6464
val config: MutableMap<String, String>
6565

6666
internal val cookieJar = ListenableCookieJar(CookieManager(
@@ -86,11 +86,11 @@ class Client @JvmOverloads constructor(
8686
"x-sdk-name" to "Android",
8787
"x-sdk-platform" to "client",
8888
"x-sdk-language" to "android",
89-
"x-sdk-version" to "6.1.0",
89+
"x-sdk-version" to "7.0.0",
9090
"x-appwrite-response-format" to "1.6.0"
9191
)
9292
config = mutableMapOf()
93-
93+
9494
setSelfSigned(selfSigned)
9595
}
9696

@@ -154,10 +154,10 @@ class Client @JvmOverloads constructor(
154154

155155
/**
156156
* Set self Signed
157-
*
157+
*
158158
* @param status
159159
*
160-
* @return this
160+
* @return this
161161
*/
162162
fun setSelfSigned(status: Boolean): Client {
163163
selfSigned = status
@@ -206,10 +206,10 @@ class Client @JvmOverloads constructor(
206206

207207
/**
208208
* Set endpoint and realtime endpoint.
209-
*
209+
*
210210
* @param endpoint
211211
*
212-
* @return this
212+
* @return this
213213
*/
214214
fun setEndpoint(endpoint: String): Client {
215215
this.endpoint = endpoint
@@ -235,32 +235,51 @@ class Client @JvmOverloads constructor(
235235

236236
/**
237237
* Add Header
238-
*
238+
*
239239
* @param key
240240
* @param value
241241
*
242-
* @return this
242+
* @return this
243243
*/
244244
fun addHeader(key: String, value: String): Client {
245245
headers[key] = value
246246
return this
247247
}
248248

249+
/**
250+
* Sends a "ping" request to Appwrite to verify connectivity.
251+
*
252+
* @return String
253+
*/
254+
suspend fun ping(): String {
255+
val apiPath = "/ping"
256+
val apiParams = mutableMapOf<String, Any?>()
257+
val apiHeaders = mutableMapOf("content-type" to "application/json")
258+
259+
return call(
260+
"GET",
261+
apiPath,
262+
apiHeaders,
263+
apiParams,
264+
responseType = String::class.java
265+
)
266+
}
267+
249268
/**
250269
* Send the HTTP request
251-
*
270+
*
252271
* @param method
253272
* @param path
254273
* @param headers
255274
* @param params
256275
*
257-
* @return [T]
276+
* @return [T]
258277
*/
259278
@Throws(AppwriteException::class)
260279
suspend fun <T> call(
261-
method: String,
262-
path: String,
263-
headers: Map<String, String> = mapOf(),
280+
method: String,
281+
path: String,
282+
headers: Map<String, String> = mapOf(),
264283
params: Map<String, Any?> = mapOf(),
265284
responseType: Class<T>,
266285
converter: ((Any) -> T)? = null
@@ -398,7 +417,7 @@ class Client @JvmOverloads constructor(
398417
var offset = 0L
399418
var result: Map<*, *>? = null
400419

401-
if (idParamName?.isNotEmpty() == true && params[idParamName] != "unique()") {
420+
if (idParamName?.isNotEmpty() == true) {
402421
// Make a request to check if a file already exists
403422
val current = call(
404423
method = "GET",
@@ -495,14 +514,14 @@ class Client @JvmOverloads constructor(
495514
.charStream()
496515
.buffered()
497516
.use(BufferedReader::readText)
498-
517+
499518
val error = if (response.headers["content-type"]?.contains("application/json") == true) {
500519
val map = body.fromJson<Map<String, Any>>()
501520

502521
AppwriteException(
503-
map["message"] as? String ?: "",
522+
map["message"] as? String ?: "",
504523
(map["code"] as Number).toInt(),
505-
map["type"] as? String ?: "",
524+
map["type"] as? String ?: "",
506525
body
507526
)
508527
} else {
@@ -524,6 +543,14 @@ class Client @JvmOverloads constructor(
524543
it.resume(true as T)
525544
return
526545
}
546+
responseType == String::class.java -> {
547+
val body = response.body!!
548+
.charStream()
549+
.buffered()
550+
.use(BufferedReader::readText)
551+
it.resume(body as T)
552+
return
553+
}
527554
responseType == ByteArray::class.java -> {
528555
it.resume(response.body!!
529556
.byteStream()
@@ -554,4 +581,4 @@ class Client @JvmOverloads constructor(
554581
}
555582
})
556583
}
557-
}
584+
}

library/src/main/java/io/appwrite/enums/ImageFormat.kt

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ enum class ImageFormat(val value: String) {
1313
PNG("png"),
1414
@SerializedName("webp")
1515
WEBP("webp"),
16+
@SerializedName("heic")
17+
HEIC("heic"),
1618
@SerializedName("avif")
1719
AVIF("avif");
1820

library/src/main/java/io/appwrite/models/RealtimeModels.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ data class RealtimeCallback(
1717

1818
open class RealtimeResponse(
1919
val type: String,
20-
val data: Any
20+
val data: Any?
2121
)
2222

2323
data class RealtimeResponseEvent<T>(

library/src/main/java/io/appwrite/services/Account.kt

+12-7
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,12 @@ class Account(client: Client) : Service(client) {
529529
*
530530
* @param challengeId ID of the challenge.
531531
* @param otp Valid verification token.
532-
* @return [Any]
532+
* @return [io.appwrite.models.Session]
533533
*/
534534
suspend fun updateMfaChallenge(
535535
challengeId: String,
536536
otp: String,
537-
): Any {
537+
): io.appwrite.models.Session {
538538
val apiPath = "/account/mfa/challenge"
539539

540540
val apiParams = mutableMapOf<String, Any?>(
@@ -544,12 +544,17 @@ class Account(client: Client) : Service(client) {
544544
val apiHeaders = mutableMapOf(
545545
"content-type" to "application/json",
546546
)
547+
val converter: (Any) -> io.appwrite.models.Session = {
548+
@Suppress("UNCHECKED_CAST")
549+
io.appwrite.models.Session.from(map = it as Map<String, Any>)
550+
}
547551
return client.call(
548552
"PUT",
549553
apiPath,
550554
apiHeaders,
551555
apiParams,
552-
responseType = Any::class.java,
556+
responseType = io.appwrite.models.Session::class.java,
557+
converter,
553558
)
554559
}
555560

@@ -1467,7 +1472,7 @@ class Account(client: Client) : Service(client) {
14671472
/**
14681473
* Create push target
14691474
*
1470-
*
1475+
* Use this endpoint to register a device for push notifications. Provide a target ID (custom or generated using ID.unique()), a device identifier (usually a device token), and optionally specify which provider should send notifications to this target. The target is automatically linked to the current session and includes device information like brand and model.
14711476
*
14721477
* @param targetId Target ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
14731478
* @param identifier The target identifier (token, email, phone etc.)
@@ -1508,7 +1513,7 @@ class Account(client: Client) : Service(client) {
15081513
/**
15091514
* Update push target
15101515
*
1511-
*
1516+
* Update the currently logged in user&#039;s push notification target. You can modify the target&#039;s identifier (device token) and provider ID (token, email, phone etc.). The target must exist and belong to the current user. If you change the provider ID, notifications will be sent through the new messaging provider instead.
15121517
*
15131518
* @param targetId Target ID.
15141519
* @param identifier The target identifier (token, email, phone etc.)
@@ -1545,7 +1550,7 @@ class Account(client: Client) : Service(client) {
15451550
/**
15461551
* Delete push target
15471552
*
1548-
*
1553+
* Delete a push notification target for the currently logged in user. After deletion, the device will no longer receive push notifications. The target must exist and belong to the current user.
15491554
*
15501555
* @param targetId Target ID.
15511556
* @return [Any]
@@ -1615,7 +1620,7 @@ class Account(client: Client) : Service(client) {
16151620
/**
16161621
* Create magic URL token
16171622
*
1618-
* Sends the user an email with a secret key for creating a session. If the provided user ID has not been registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The link sent to the user&#039;s email address is valid for 1 hour. If you are on a mobile device you can leave the URL parameter empty, so that the login completion will be handled by your Appwrite instance by default.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).
1623+
* Sends the user an email with a secret key for creating a session. If the provided user ID has not been registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The link sent to the user&#039;s email address is valid for 1 hour.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).
16191624
*
16201625
* @param userId Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
16211626
* @param email User email.

library/src/main/java/io/appwrite/services/Realtime.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,17 @@ class Realtime(client: Client) : Service(client), CoroutineScope {
175175
when (message.type) {
176176
TYPE_ERROR -> handleResponseError(message)
177177
TYPE_EVENT -> handleResponseEvent(message)
178+
TYPE_PONG -> {}
178179
}
179180
}
180181
}
181182

182183
private fun handleResponseError(message: RealtimeResponse) {
183-
throw message.data.jsonCast<AppwriteException>()
184+
throw message.data?.jsonCast<AppwriteException>() ?: RuntimeException("Data is not present")
184185
}
185186

186187
private suspend fun handleResponseEvent(message: RealtimeResponse) {
187-
val event = message.data.jsonCast<RealtimeResponseEvent<Any>>()
188+
val event = message.data?.jsonCast<RealtimeResponseEvent<Any>>() ?: return
188189
if (event.channels.isEmpty()) {
189190
return
190191
}

0 commit comments

Comments
 (0)