Skip to content

fix: pong response & chunked upload #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors.
Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repositories {
Next, add the dependency to your project's `build.gradle(.kts)` file:

```groovy
implementation("io.appwrite:sdk-for-kotlin:6.2.0")
implementation("io.appwrite:sdk-for-kotlin:7.0.0")
```

### Maven
Expand All @@ -50,7 +50,7 @@ Add this to your project's `pom.xml` file:
<dependency>
<groupId>io.appwrite</groupId>
<artifactId>sdk-for-kotlin</artifactId>
<version>6.2.0</version>
<version>7.0.0</version>
</dependency>
</dependencies>
```
Expand Down
55 changes: 41 additions & 14 deletions src/main/kotlin/io/appwrite/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class Client @JvmOverloads constructor(
init {
headers = mutableMapOf(
"content-type" to "application/json",
"user-agent" to "AppwriteKotlinSDK/6.2.0 ${System.getProperty("http.agent")}",
"user-agent" to "AppwriteKotlinSDK/7.0.0 ${System.getProperty("http.agent")}",
"x-sdk-name" to "Kotlin",
"x-sdk-platform" to "server",
"x-sdk-language" to "kotlin",
"x-sdk-version" to "6.2.0",
"x-sdk-version" to "7.0.0",
"x-appwrite-response-format" to "1.6.0",
)

Expand Down Expand Up @@ -235,9 +235,28 @@ class Client @JvmOverloads constructor(
return this
}

/**
* Sends a "ping" request to Appwrite to verify connectivity.
*
* @return String
*/
suspend fun ping(): String {
val apiPath = "/ping"
val apiParams = mutableMapOf<String, Any?>()
val apiHeaders = mutableMapOf("content-type" to "application/json")

return call(
"GET",
apiPath,
apiHeaders,
apiParams,
responseType = String::class.java
)
}

/**
* Prepare the HTTP request
*
*
* @param method
* @param path
* @param headers
Expand Down Expand Up @@ -332,7 +351,7 @@ class Client @JvmOverloads constructor(
* @param headers
* @param params
*
* @return [T]
* @return [T]
*/
@Throws(AppwriteException::class)
suspend fun <T> call(
Expand All @@ -355,7 +374,7 @@ class Client @JvmOverloads constructor(
* @param headers
* @param params
*
* @return [T]
* @return [T]
*/
@Throws(AppwriteException::class)
suspend fun redirect(
Expand Down Expand Up @@ -427,7 +446,7 @@ class Client @JvmOverloads constructor(
var offset = 0L
var result: Map<*, *>? = null

if (idParamName?.isNotEmpty() == true && params[idParamName] != "unique()") {
if (idParamName?.isNotEmpty() == true) {
// Make a request to check if a file already exists
val current = call(
method = "GET",
Expand Down Expand Up @@ -494,7 +513,7 @@ class Client @JvmOverloads constructor(
return converter(result as Map<String, Any>)
}

/**
/**
* Await Redirect
*
* @param request
Expand All @@ -521,14 +540,14 @@ class Client @JvmOverloads constructor(
.charStream()
.buffered()
.use(BufferedReader::readText)

val error = if (response.headers["content-type"]?.contains("application/json") == true) {
val map = body.fromJson<Map<String, Any>>()

AppwriteException(
map["message"] as? String ?: "",
map["message"] as? String ?: "",
(map["code"] as Number).toInt(),
map["type"] as? String ?: "",
map["type"] as? String ?: "",
body
)
} else {
Expand Down Expand Up @@ -572,14 +591,14 @@ class Client @JvmOverloads constructor(
.charStream()
.buffered()
.use(BufferedReader::readText)

val error = if (response.headers["content-type"]?.contains("application/json") == true) {
val map = body.fromJson<Map<String, Any>>()

AppwriteException(
map["message"] as? String ?: "",
map["message"] as? String ?: "",
(map["code"] as Number).toInt(),
map["type"] as? String ?: "",
map["type"] as? String ?: "",
body
)
} else {
Expand All @@ -601,6 +620,14 @@ class Client @JvmOverloads constructor(
it.resume(true as T)
return
}
responseType == String::class.java -> {
val body = response.body!!
.charStream()
.buffered()
.use(BufferedReader::readText)
it.resume(body as T)
return
}
responseType == ByteArray::class.java -> {
it.resume(response.body!!
.byteStream()
Expand Down Expand Up @@ -629,4 +656,4 @@ class Client @JvmOverloads constructor(
}
})
}
}
}
2 changes: 2 additions & 0 deletions src/main/kotlin/io/appwrite/enums/ImageFormat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ enum class ImageFormat(val value: String) {
PNG("png"),
@SerializedName("webp")
WEBP("webp"),
@SerializedName("heic")
HEIC("heic"),
@SerializedName("avif")
AVIF("avif");

Expand Down
10 changes: 7 additions & 3 deletions src/main/kotlin/io/appwrite/services/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,13 @@ class Account(client: Client) : Service(client) {
*
* @param challengeId ID of the challenge.
* @param otp Valid verification token.
* @return [Any]
* @return [io.appwrite.models.Session]
*/
@Throws(AppwriteException::class)
suspend fun updateMfaChallenge(
challengeId: String,
otp: String,
): Any {
): io.appwrite.models.Session {
val apiPath = "/account/mfa/challenge"

val apiParams = mutableMapOf<String, Any?>(
Expand All @@ -534,12 +534,16 @@ class Account(client: Client) : Service(client) {
val apiHeaders = mutableMapOf(
"content-type" to "application/json",
)
val converter: (Any) -> io.appwrite.models.Session = {
io.appwrite.models.Session.from(map = it as Map<String, Any>)
}
return client.call(
"PUT",
apiPath,
apiHeaders,
apiParams,
responseType = Any::class.java,
responseType = io.appwrite.models.Session::class.java,
converter,
)
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/io/appwrite/services/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ class Functions(client: Client) : Service(client) {
/**
* Rebuild deployment
*
*
* Create a new build for an existing function deployment. This endpoint allows you to rebuild a deployment with the updated function configuration, including its entrypoint and build commands if they have been modified The build process will be queued and executed asynchronously. The original deployment&#039;s code will be preserved and used for the new build.
*
* @param functionId Function ID.
* @param deploymentId Deployment ID.
Expand Down Expand Up @@ -590,7 +590,7 @@ class Functions(client: Client) : Service(client) {
/**
* Cancel deployment
*
*
* Cancel an ongoing function deployment build. If the build is already in progress, it will be stopped and marked as canceled. If the build hasn&#039;t started yet, it will be marked as canceled without executing. You cannot cancel builds that have already completed (status &#039;ready&#039;) or failed. The response includes the final build status and details.
*
* @param functionId Function ID.
* @param deploymentId Deployment ID.
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/appwrite/services/Messaging.kt
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ class Messaging(client: Client) : Service(client) {
/**
* Update SMS
*
* Update an email message by its unique ID.
* Update an SMS message by its unique ID.
*
* @param messageId Message ID.
* @param topics List of Topic IDs.
Expand Down
32 changes: 4 additions & 28 deletions src/main/kotlin/io/appwrite/services/Users.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1121,14 +1121,13 @@ class Users(client: Client) : Service(client) {
*
* @param userId User ID.
* @param type Type of authenticator.
* @return [io.appwrite.models.User<T>]
* @return [Any]
*/
@Throws(AppwriteException::class)
suspend fun <T> deleteMfaAuthenticator(
suspend fun deleteMfaAuthenticator(
userId: String,
type: io.appwrite.enums.AuthenticatorType,
nestedType: Class<T>,
): io.appwrite.models.User<T> {
): Any {
val apiPath = "/users/{userId}/mfa/authenticators/{type}"
.replace("{userId}", userId)
.replace("{type}", type.value)
Expand All @@ -1138,38 +1137,15 @@ class Users(client: Client) : Service(client) {
val apiHeaders = mutableMapOf(
"content-type" to "application/json",
)
val converter: (Any) -> io.appwrite.models.User<T> = {
io.appwrite.models.User.from(map = it as Map<String, Any>, nestedType)
}
return client.call(
"DELETE",
apiPath,
apiHeaders,
apiParams,
responseType = classOf(),
converter,
responseType = Any::class.java,
)
}

/**
* Delete authenticator
*
* Delete an authenticator app.
*
* @param userId User ID.
* @param type Type of authenticator.
* @return [io.appwrite.models.User<T>]
*/
@Throws(AppwriteException::class)
suspend fun deleteMfaAuthenticator(
userId: String,
type: io.appwrite.enums.AuthenticatorType,
): io.appwrite.models.User<Map<String, Any>> = deleteMfaAuthenticator(
userId,
type,
nestedType = classOf(),
)

/**
* List factors
*
Expand Down