Skip to content
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

fix: multipart testing #43

Closed
wants to merge 4 commits into from
Closed
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-kotlin.svg?color=green&style=flat-square)
![License](https://img.shields.io/github/license/appwrite/sdk-for-kotlin.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.6.0-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.6.1-blue.svg?style=flat-square)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

Expand Down 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.1.0")
implementation("io.appwrite:sdk-for-kotlin:6.2.1")
```

### 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.1.0</version>
<version>6.2.1</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/java/databases/update-string-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ databases.updateStringAttribute(
"", // key
false, // required
"<DEFAULT>", // default
0, // size (optional)
1, // size (optional)
"", // newKey (optional)
new CoroutineCallback<>((result, error) -> {
if (error != null) {
Expand Down
9 changes: 6 additions & 3 deletions docs/examples/java/messaging/create-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Messaging messaging = new Messaging(client);

messaging.createPush(
"<MESSAGE_ID>", // messageId
"<TITLE>", // title
"<BODY>", // body
"<TITLE>", // title (optional)
"<BODY>", // body (optional)
listOf(), // topics (optional)
listOf(), // users (optional)
listOf(), // targets (optional)
Expand All @@ -23,9 +23,12 @@ messaging.createPush(
"<SOUND>", // sound (optional)
"<COLOR>", // color (optional)
"<TAG>", // tag (optional)
"<BADGE>", // badge (optional)
0, // badge (optional)
false, // draft (optional)
"", // scheduledAt (optional)
false, // contentAvailable (optional)
false, // critical (optional)
MessagePriority.NORMAL, // priority (optional)
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
Expand Down
3 changes: 3 additions & 0 deletions docs/examples/java/messaging/update-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ messaging.updatePush(
0, // badge (optional)
false, // draft (optional)
"", // scheduledAt (optional)
false, // contentAvailable (optional)
false, // critical (optional)
MessagePriority.NORMAL, // priority (optional)
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/kotlin/databases/update-string-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ val response = databases.updateStringAttribute(
key = "",
required = false,
default = "<DEFAULT>",
size = 0, // optional
size = 1, // optional
newKey = "" // optional
)
11 changes: 7 additions & 4 deletions docs/examples/kotlin/messaging/create-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ val messaging = Messaging(client)

val response = messaging.createPush(
messageId = "<MESSAGE_ID>",
title = "<TITLE>",
body = "<BODY>",
title = "<TITLE>", // optional
body = "<BODY>", // optional
topics = listOf(), // optional
users = listOf(), // optional
targets = listOf(), // optional
Expand All @@ -23,7 +23,10 @@ val response = messaging.createPush(
sound = "<SOUND>", // optional
color = "<COLOR>", // optional
tag = "<TAG>", // optional
badge = "<BADGE>", // optional
badge = 0, // optional
draft = false, // optional
scheduledAt = "" // optional
scheduledAt = "", // optional
contentAvailable = false, // optional
critical = false, // optional
priority = "normal" // optional
)
5 changes: 4 additions & 1 deletion docs/examples/kotlin/messaging/update-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ val response = messaging.updatePush(
tag = "<TAG>", // optional
badge = 0, // optional
draft = false, // optional
scheduledAt = "" // optional
scheduledAt = "", // optional
contentAvailable = false, // optional
critical = false, // optional
priority = "normal" // optional
)
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.1.0 ${System.getProperty("http.agent")}",
"user-agent" to "AppwriteKotlinSDK/6.2.1 ${System.getProperty("http.agent")}",
"x-sdk-name" to "Kotlin",
"x-sdk-platform" to "server",
"x-sdk-language" to "kotlin",
"x-sdk-version" to "6.1.0",
"x-sdk-version" to "6.2.1",
"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(
}
})
}
}
}
6 changes: 5 additions & 1 deletion src/main/kotlin/io/appwrite/enums/ImageFormat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ enum class ImageFormat(val value: String) {
@SerializedName("png")
PNG("png"),
@SerializedName("webp")
WEBP("webp");
WEBP("webp"),
@SerializedName("heic")
HEIC("heic"),
@SerializedName("avif")
AVIF("avif");

override fun toString() = value
}
12 changes: 12 additions & 0 deletions src/main/kotlin/io/appwrite/enums/MessagePriority.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.appwrite.enums

import com.google.gson.annotations.SerializedName

enum class MessagePriority(val value: String) {
@SerializedName("normal")
NORMAL("normal"),
@SerializedName("high")
HIGH("high");

override fun toString() = value
}
32 changes: 29 additions & 3 deletions src/main/kotlin/io/appwrite/enums/Runtime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ enum class Runtime(val value: String) {
NODE_20_0("node-20.0"),
@SerializedName("node-21.0")
NODE_21_0("node-21.0"),
@SerializedName("node-22")
NODE_22("node-22"),
@SerializedName("php-8.0")
PHP_8_0("php-8.0"),
@SerializedName("php-8.1")
Expand Down Expand Up @@ -43,8 +45,18 @@ enum class Runtime(val value: String) {
PYTHON_3_12("python-3.12"),
@SerializedName("python-ml-3.11")
PYTHON_ML_3_11("python-ml-3.11"),
@SerializedName("deno-1.21")
DENO_1_21("deno-1.21"),
@SerializedName("deno-1.24")
DENO_1_24("deno-1.24"),
@SerializedName("deno-1.35")
DENO_1_35("deno-1.35"),
@SerializedName("deno-1.40")
DENO_1_40("deno-1.40"),
@SerializedName("deno-1.46")
DENO_1_46("deno-1.46"),
@SerializedName("deno-2.0")
DENO_2_0("deno-2.0"),
@SerializedName("dart-2.15")
DART_2_15("dart-2.15"),
@SerializedName("dart-2.16")
Expand All @@ -59,12 +71,14 @@ enum class Runtime(val value: String) {
DART_3_1("dart-3.1"),
@SerializedName("dart-3.3")
DART_3_3("dart-3.3"),
@SerializedName("dotnet-3.1")
DOTNET_3_1("dotnet-3.1"),
@SerializedName("dart-3.5")
DART_3_5("dart-3.5"),
@SerializedName("dotnet-6.0")
DOTNET_6_0("dotnet-6.0"),
@SerializedName("dotnet-7.0")
DOTNET_7_0("dotnet-7.0"),
@SerializedName("dotnet-8.0")
DOTNET_8_0("dotnet-8.0"),
@SerializedName("java-8.0")
JAVA_8_0("java-8.0"),
@SerializedName("java-11.0")
Expand All @@ -75,26 +89,38 @@ enum class Runtime(val value: String) {
JAVA_18_0("java-18.0"),
@SerializedName("java-21.0")
JAVA_21_0("java-21.0"),
@SerializedName("java-22")
JAVA_22("java-22"),
@SerializedName("swift-5.5")
SWIFT_5_5("swift-5.5"),
@SerializedName("swift-5.8")
SWIFT_5_8("swift-5.8"),
@SerializedName("swift-5.9")
SWIFT_5_9("swift-5.9"),
@SerializedName("swift-5.10")
SWIFT_5_10("swift-5.10"),
@SerializedName("kotlin-1.6")
KOTLIN_1_6("kotlin-1.6"),
@SerializedName("kotlin-1.8")
KOTLIN_1_8("kotlin-1.8"),
@SerializedName("kotlin-1.9")
KOTLIN_1_9("kotlin-1.9"),
@SerializedName("kotlin-2.0")
KOTLIN_2_0("kotlin-2.0"),
@SerializedName("cpp-17")
CPP_17("cpp-17"),
@SerializedName("cpp-20")
CPP_20("cpp-20"),
@SerializedName("bun-1.0")
BUN_1_0("bun-1.0"),
@SerializedName("bun-1.1")
BUN_1_1("bun-1.1"),
@SerializedName("go-1.23")
GO_1_23("go-1.23");
GO_1_23("go-1.23"),
@SerializedName("static-1")
STATIC_1("static-1"),
@SerializedName("flutter-3.24")
FLUTTER_3_24("flutter-3.24");

override fun toString() = value
}
Loading