Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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-android.svg?color=green&style=flat-square)
![License](https://img.shields.io/github/license/appwrite/sdk-for-android.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)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![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 @@ -38,7 +38,7 @@ repositories {
Next, add the dependency to your project's `build.gradle(.kts)` file:

```groovy
implementation("io.appwrite:sdk-for-android:6.0.0")
implementation("io.appwrite:sdk-for-android:6.1.1")
```

### Maven
Expand All @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file:
<dependency>
<groupId>io.appwrite</groupId>
<artifactId>sdk-for-android</artifactId>
<version>6.0.0</version>
<version>6.1.1</version>
</dependency>
</dependencies>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class AccountsViewModel : ViewModel() {
account.createOAuth2Session(
activity,
OAuthProvider.FACEBOOK,
"appwrite-callback-6070749e6acd4://demo.appwrite.io/auth/oauth2/success",
"appwrite-callback-6070749e6acd4://demo.appwrite.io/auth/oauth2/failure"
"appwrite-callback-6070749e6acd4://cloud.appwrite.io/auth/oauth2/success",
"appwrite-callback-6070749e6acd4://cloud.appwrite.io/auth/oauth2/failure"
)
} catch (e: Exception) {
_error.postValue(Event(e))
Expand Down
65 changes: 46 additions & 19 deletions library/src/main/java/io/appwrite/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Client @JvmOverloads constructor(
internal lateinit var http: OkHttpClient

internal val headers: MutableMap<String, String>

val config: MutableMap<String, String>

internal val cookieJar = ListenableCookieJar(CookieManager(
Expand All @@ -86,11 +86,11 @@ class Client @JvmOverloads constructor(
"x-sdk-name" to "Android",
"x-sdk-platform" to "client",
"x-sdk-language" to "android",
"x-sdk-version" to "6.0.0",
"x-sdk-version" to "6.1.1",
"x-appwrite-response-format" to "1.6.0"
)
config = mutableMapOf()

setSelfSigned(selfSigned)
}

Expand Down Expand Up @@ -154,10 +154,10 @@ class Client @JvmOverloads constructor(

/**
* Set self Signed
*
*
* @param status
*
* @return this
* @return this
*/
fun setSelfSigned(status: Boolean): Client {
selfSigned = status
Expand Down Expand Up @@ -206,10 +206,10 @@ class Client @JvmOverloads constructor(

/**
* Set endpoint and realtime endpoint.
*
*
* @param endpoint
*
* @return this
* @return this
*/
fun setEndpoint(endpoint: String): Client {
this.endpoint = endpoint
Expand All @@ -235,32 +235,51 @@ class Client @JvmOverloads constructor(

/**
* Add Header
*
*
* @param key
* @param value
*
* @return this
* @return this
*/
fun addHeader(key: String, value: String): Client {
headers[key] = value
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
)
}

/**
* Send the HTTP request
*
*
* @param method
* @param path
* @param headers
* @param params
*
* @return [T]
* @return [T]
*/
@Throws(AppwriteException::class)
suspend fun <T> call(
method: String,
path: String,
headers: Map<String, String> = mapOf(),
method: String,
path: String,
headers: Map<String, String> = mapOf(),
params: Map<String, Any?> = mapOf(),
responseType: Class<T>,
converter: ((Any) -> T)? = null
Expand Down Expand Up @@ -398,7 +417,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 @@ -495,14 +514,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 @@ -524,6 +543,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 @@ -554,4 +581,4 @@ class Client @JvmOverloads constructor(
}
})
}
}
}
6 changes: 5 additions & 1 deletion library/src/main/java/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
}
6 changes: 3 additions & 3 deletions library/src/main/java/io/appwrite/models/Document.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ data class Document<T>(
* Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).
*/
@SerializedName("\$permissions")
val permissions: List<Any>,
val permissions: List<String>,

/**
* Additional properties
Expand All @@ -66,7 +66,7 @@ data class Document<T>(
databaseId: String,
createdAt: String,
updatedAt: String,
permissions: List<Any>,
permissions: List<String>,
data: Map<String, Any>
) = Document<Map<String, Any>>(
id,
Expand All @@ -88,7 +88,7 @@ data class Document<T>(
databaseId = map["\$databaseId"] as String,
createdAt = map["\$createdAt"] as String,
updatedAt = map["\$updatedAt"] as String,
permissions = map["\$permissions"] as List<Any>,
permissions = map["\$permissions"] as List<String>,
data = map.jsonCast(to = nestedType)
)
}
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/io/appwrite/models/Execution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class Execution(
* Execution roles.
*/
@SerializedName("\$permissions")
val permissions: List<Any>,
val permissions: List<String>,

/**
* Function ID.
Expand Down Expand Up @@ -139,7 +139,7 @@ data class Execution(
id = map["\$id"] as String,
createdAt = map["\$createdAt"] as String,
updatedAt = map["\$updatedAt"] as String,
permissions = map["\$permissions"] as List<Any>,
permissions = map["\$permissions"] as List<String>,
functionId = map["functionId"] as String,
trigger = map["trigger"] as String,
status = map["status"] as String,
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/io/appwrite/models/File.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ data class File(
* File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).
*/
@SerializedName("\$permissions")
val permissions: List<Any>,
val permissions: List<String>,

/**
* File name.
Expand Down Expand Up @@ -98,7 +98,7 @@ data class File(
bucketId = map["bucketId"] as String,
createdAt = map["\$createdAt"] as String,
updatedAt = map["\$updatedAt"] as String,
permissions = map["\$permissions"] as List<Any>,
permissions = map["\$permissions"] as List<String>,
name = map["name"] as String,
signature = map["signature"] as String,
mimeType = map["mimeType"] as String,
Expand Down
10 changes: 5 additions & 5 deletions library/src/main/java/io/appwrite/models/Membership.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ data class Membership(
val userId: String,

/**
* User name.
* User name. Hide this attribute by toggling membership privacy in the Console.
*/
@SerializedName("userName")
val userName: String,

/**
* User email address.
* User email address. Hide this attribute by toggling membership privacy in the Console.
*/
@SerializedName("userEmail")
val userEmail: String,
Expand Down Expand Up @@ -74,7 +74,7 @@ data class Membership(
val confirm: Boolean,

/**
* Multi factor authentication status, true if the user has MFA enabled or false otherwise.
* Multi factor authentication status, true if the user has MFA enabled or false otherwise. Hide this attribute by toggling membership privacy in the Console.
*/
@SerializedName("mfa")
val mfa: Boolean,
Expand All @@ -83,7 +83,7 @@ data class Membership(
* User list of roles
*/
@SerializedName("roles")
val roles: List<Any>,
val roles: List<String>,

) {
fun toMap(): Map<String, Any> = mapOf(
Expand Down Expand Up @@ -120,7 +120,7 @@ data class Membership(
joined = map["joined"] as String,
confirm = map["confirm"] as Boolean,
mfa = map["mfa"] as Boolean,
roles = map["roles"] as List<Any>,
roles = map["roles"] as List<String>,
)
}
}
4 changes: 2 additions & 2 deletions library/src/main/java/io/appwrite/models/MfaRecoveryCodes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data class MfaRecoveryCodes(
* Recovery codes.
*/
@SerializedName("recoveryCodes")
val recoveryCodes: List<Any>,
val recoveryCodes: List<String>,

) {
fun toMap(): Map<String, Any> = mapOf(
Expand All @@ -24,7 +24,7 @@ data class MfaRecoveryCodes(
fun from(
map: Map<String, Any>,
) = MfaRecoveryCodes(
recoveryCodes = map["recoveryCodes"] as List<Any>,
recoveryCodes = map["recoveryCodes"] as List<String>,
)
}
}
2 changes: 1 addition & 1 deletion library/src/main/java/io/appwrite/models/RealtimeModels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data class RealtimeCallback(

open class RealtimeResponse(
val type: String,
val data: Any
val data: Any?
)

data class RealtimeResponseEvent<T>(
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/io/appwrite/models/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ data class Session(
* Returns a list of active session factors.
*/
@SerializedName("factors")
val factors: List<Any>,
val factors: List<String>,

/**
* Secret used to authenticate the user. Only included if the request was made with an API key
Expand Down Expand Up @@ -246,7 +246,7 @@ data class Session(
countryCode = map["countryCode"] as String,
countryName = map["countryName"] as String,
current = map["current"] as Boolean,
factors = map["factors"] as List<Any>,
factors = map["factors"] as List<String>,
secret = map["secret"] as String,
mfaUpdatedAt = map["mfaUpdatedAt"] as String,
)
Expand Down
8 changes: 8 additions & 0 deletions library/src/main/java/io/appwrite/models/Target.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ data class Target(
@SerializedName("identifier")
val identifier: String,

/**
* Is the target expired.
*/
@SerializedName("expired")
val expired: Boolean,

) {
fun toMap(): Map<String, Any> = mapOf(
"\$id" to id as Any,
Expand All @@ -65,6 +71,7 @@ data class Target(
"providerId" to providerId as Any,
"providerType" to providerType as Any,
"identifier" to identifier as Any,
"expired" to expired as Any,
)

companion object {
Expand All @@ -81,6 +88,7 @@ data class Target(
providerId = map["providerId"] as? String?,
providerType = map["providerType"] as String,
identifier = map["identifier"] as String,
expired = map["expired"] as Boolean,
)
}
}
Loading