From c7827ae31b148ec80aebebe199414e1ed9f653b5 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 1 Mar 2022 19:53:42 +1300 Subject: [PATCH] 0.13 support snapshot --- README.md | 6 +- build.gradle | 2 +- docs/examples/java/account/update-session.md | 48 +++++ docs/examples/java/functions/retry-build.md | 50 ++++++ docs/examples/java/storage/create-file.md | 1 + docs/examples/java/storage/delete-file.md | 1 + .../java/storage/get-file-download.md | 1 + .../examples/java/storage/get-file-preview.md | 1 + docs/examples/java/storage/get-file-view.md | 1 + docs/examples/java/storage/get-file.md | 1 + docs/examples/java/storage/list-files.md | 1 + docs/examples/java/storage/update-file.md | 3 +- .../examples/kotlin/account/update-session.md | 26 +++ docs/examples/kotlin/functions/retry-build.md | 28 +++ docs/examples/kotlin/storage/create-file.md | 1 + docs/examples/kotlin/storage/delete-file.md | 1 + .../kotlin/storage/get-file-download.md | 1 + .../kotlin/storage/get-file-preview.md | 1 + docs/examples/kotlin/storage/get-file-view.md | 1 + docs/examples/kotlin/storage/get-file.md | 1 + docs/examples/kotlin/storage/list-files.md | 1 + docs/examples/kotlin/storage/update-file.md | 3 +- gradlew | 0 library/build.gradle | 2 + library/src/main/java/io/appwrite/Client.kt | 89 +++++++++- .../appwrite/exceptions/AppwriteException.kt | 1 + .../main/java/io/appwrite/models/Execution.kt | 10 +- .../src/main/java/io/appwrite/models/File.kt | 33 +++- .../java/io/appwrite/models/RealtimeModels.kt | 1 + .../main/java/io/appwrite/models/Session.kt | 28 ++- .../main/java/io/appwrite/services/Account.kt | 167 +++++++++++------- .../main/java/io/appwrite/services/Avatars.kt | 14 +- .../java/io/appwrite/services/Database.kt | 30 ++-- .../java/io/appwrite/services/Functions.kt | 55 ++++-- .../main/java/io/appwrite/services/Locale.kt | 42 ++--- .../main/java/io/appwrite/services/Storage.kt | 108 +++++++---- .../main/java/io/appwrite/services/Teams.kt | 68 +++---- 37 files changed, 612 insertions(+), 216 deletions(-) create mode 100644 docs/examples/java/account/update-session.md create mode 100644 docs/examples/java/functions/retry-build.md create mode 100644 docs/examples/kotlin/account/update-session.md create mode 100644 docs/examples/kotlin/functions/retry-build.md mode change 100644 => 100755 gradlew diff --git a/README.md b/README.md index 6656d46..76409b2 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ ![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-0.12.1-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-0.12.3-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) -**This SDK is compatible with Appwrite server version 0.12.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).** +**This SDK is compatible with Appwrite server version 0.13.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).** Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Android SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) @@ -158,4 +158,4 @@ This library is auto-generated by Appwrite custom [SDK Generator](https://github ## License -Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information. +Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information. \ No newline at end of file diff --git a/build.gradle b/build.gradle index 42d442d..79f6b0b 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'io.github.gradle-nexus.publish-plugin' // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = "1.5.31" - version "0.3.3" + version System.getenv("SDK_VERSION") repositories { maven { url "https://plugins.gradle.org/m2/" } google() diff --git a/docs/examples/java/account/update-session.md b/docs/examples/java/account/update-session.md new file mode 100644 index 0000000..80aff11 --- /dev/null +++ b/docs/examples/java/account/update-session.md @@ -0,0 +1,48 @@ +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import io.appwrite.Client +import io.appwrite.services.Account + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + Client client = new Client(getApplicationContext()) + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + + Account account = new Account(client); + + account.updateSession( + "[SESSION_ID]" + new Continuation() { + @NotNull + @Override + public CoroutineContext getContext() { + return EmptyCoroutineContext.INSTANCE; + } + + @Override + public void resumeWith(@NotNull Object o) { + String json = ""; + try { + if (o instanceof Result.Failure) { + Result.Failure failure = (Result.Failure) o; + throw failure.exception; + } else { + Response response = (Response) o; + json = response.body().string(); + } + } catch (Throwable th) { + Log.e("ERROR", th.toString()); + } + } + } + ); + } +} \ No newline at end of file diff --git a/docs/examples/java/functions/retry-build.md b/docs/examples/java/functions/retry-build.md new file mode 100644 index 0000000..96501a0 --- /dev/null +++ b/docs/examples/java/functions/retry-build.md @@ -0,0 +1,50 @@ +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import io.appwrite.Client +import io.appwrite.services.Functions + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + Client client = new Client(getApplicationContext()) + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + + Functions functions = new Functions(client); + + functions.retryBuild( + "[FUNCTION_ID]", + "[DEPLOYMENT_ID]", + "[BUILD_ID]" + new Continuation() { + @NotNull + @Override + public CoroutineContext getContext() { + return EmptyCoroutineContext.INSTANCE; + } + + @Override + public void resumeWith(@NotNull Object o) { + String json = ""; + try { + if (o instanceof Result.Failure) { + Result.Failure failure = (Result.Failure) o; + throw failure.exception; + } else { + Response response = (Response) o; + json = response.body().string(); + } + } catch (Throwable th) { + Log.e("ERROR", th.toString()); + } + } + } + ); + } +} \ No newline at end of file diff --git a/docs/examples/java/storage/create-file.md b/docs/examples/java/storage/create-file.md index 420ca3c..bc1df1a 100644 --- a/docs/examples/java/storage/create-file.md +++ b/docs/examples/java/storage/create-file.md @@ -19,6 +19,7 @@ public class MainActivity extends AppCompatActivity { Storage storage = new Storage(client); storage.createFile( + "[BUCKET_ID]", "[FILE_ID]", File("./path-to-files/image.jpg"), new Continuation() { diff --git a/docs/examples/java/storage/delete-file.md b/docs/examples/java/storage/delete-file.md index aafae2c..585593a 100644 --- a/docs/examples/java/storage/delete-file.md +++ b/docs/examples/java/storage/delete-file.md @@ -19,6 +19,7 @@ public class MainActivity extends AppCompatActivity { Storage storage = new Storage(client); storage.deleteFile( + "[BUCKET_ID]", "[FILE_ID]" new Continuation() { @NotNull diff --git a/docs/examples/java/storage/get-file-download.md b/docs/examples/java/storage/get-file-download.md index d56f293..b162248 100644 --- a/docs/examples/java/storage/get-file-download.md +++ b/docs/examples/java/storage/get-file-download.md @@ -19,6 +19,7 @@ public class MainActivity extends AppCompatActivity { Storage storage = new Storage(client); storage.getFileDownload( + "[BUCKET_ID]", "[FILE_ID]" new Continuation() { @NotNull diff --git a/docs/examples/java/storage/get-file-preview.md b/docs/examples/java/storage/get-file-preview.md index 00b54f2..583c1a0 100644 --- a/docs/examples/java/storage/get-file-preview.md +++ b/docs/examples/java/storage/get-file-preview.md @@ -19,6 +19,7 @@ public class MainActivity extends AppCompatActivity { Storage storage = new Storage(client); storage.getFilePreview( + "[BUCKET_ID]", "[FILE_ID]", new Continuation() { @NotNull diff --git a/docs/examples/java/storage/get-file-view.md b/docs/examples/java/storage/get-file-view.md index 087a48b..21a5074 100644 --- a/docs/examples/java/storage/get-file-view.md +++ b/docs/examples/java/storage/get-file-view.md @@ -19,6 +19,7 @@ public class MainActivity extends AppCompatActivity { Storage storage = new Storage(client); storage.getFileView( + "[BUCKET_ID]", "[FILE_ID]" new Continuation() { @NotNull diff --git a/docs/examples/java/storage/get-file.md b/docs/examples/java/storage/get-file.md index 9473cab..61740a9 100644 --- a/docs/examples/java/storage/get-file.md +++ b/docs/examples/java/storage/get-file.md @@ -19,6 +19,7 @@ public class MainActivity extends AppCompatActivity { Storage storage = new Storage(client); storage.getFile( + "[BUCKET_ID]", "[FILE_ID]" new Continuation() { @NotNull diff --git a/docs/examples/java/storage/list-files.md b/docs/examples/java/storage/list-files.md index e2eab69..a7ea06e 100644 --- a/docs/examples/java/storage/list-files.md +++ b/docs/examples/java/storage/list-files.md @@ -19,6 +19,7 @@ public class MainActivity extends AppCompatActivity { Storage storage = new Storage(client); storage.listFiles( + "[BUCKET_ID]", new Continuation() { @NotNull @Override diff --git a/docs/examples/java/storage/update-file.md b/docs/examples/java/storage/update-file.md index 1477615..b3e8e90 100644 --- a/docs/examples/java/storage/update-file.md +++ b/docs/examples/java/storage/update-file.md @@ -19,9 +19,8 @@ public class MainActivity extends AppCompatActivity { Storage storage = new Storage(client); storage.updateFile( + "[BUCKET_ID]", "[FILE_ID]", - listOf(), - listOf() new Continuation() { @NotNull @Override diff --git a/docs/examples/kotlin/account/update-session.md b/docs/examples/kotlin/account/update-session.md new file mode 100644 index 0000000..465320d --- /dev/null +++ b/docs/examples/kotlin/account/update-session.md @@ -0,0 +1,26 @@ +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import io.appwrite.Client +import io.appwrite.services.Account + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val client = Client(applicationContext) + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + + val account = Account(client) + + GlobalScope.launch { + val response = account.updateSession( + sessionId = "[SESSION_ID]" + ) + val json = response.body?.string() + } + } +} \ No newline at end of file diff --git a/docs/examples/kotlin/functions/retry-build.md b/docs/examples/kotlin/functions/retry-build.md new file mode 100644 index 0000000..597421c --- /dev/null +++ b/docs/examples/kotlin/functions/retry-build.md @@ -0,0 +1,28 @@ +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import io.appwrite.Client +import io.appwrite.services.Functions + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val client = Client(applicationContext) + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + + val functions = Functions(client) + + GlobalScope.launch { + val response = functions.retryBuild( + functionId = "[FUNCTION_ID]", + deploymentId = "[DEPLOYMENT_ID]", + buildId = "[BUILD_ID]" + ) + val json = response.body?.string() + } + } +} \ No newline at end of file diff --git a/docs/examples/kotlin/storage/create-file.md b/docs/examples/kotlin/storage/create-file.md index 1261bda..437bdeb 100644 --- a/docs/examples/kotlin/storage/create-file.md +++ b/docs/examples/kotlin/storage/create-file.md @@ -18,6 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = storage.createFile( + bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]", file = File("./path-to-files/image.jpg"), ) diff --git a/docs/examples/kotlin/storage/delete-file.md b/docs/examples/kotlin/storage/delete-file.md index f26acac..1a4a5b9 100644 --- a/docs/examples/kotlin/storage/delete-file.md +++ b/docs/examples/kotlin/storage/delete-file.md @@ -18,6 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = storage.deleteFile( + bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]" ) val json = response.body?.string() diff --git a/docs/examples/kotlin/storage/get-file-download.md b/docs/examples/kotlin/storage/get-file-download.md index b7d3d4a..3970fb8 100644 --- a/docs/examples/kotlin/storage/get-file-download.md +++ b/docs/examples/kotlin/storage/get-file-download.md @@ -18,6 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val result = storage.getFileDownload( + bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]" ) println(result); // Resource URL diff --git a/docs/examples/kotlin/storage/get-file-preview.md b/docs/examples/kotlin/storage/get-file-preview.md index 9f1d459..7804527 100644 --- a/docs/examples/kotlin/storage/get-file-preview.md +++ b/docs/examples/kotlin/storage/get-file-preview.md @@ -18,6 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val result = storage.getFilePreview( + bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]", ) println(result); // Resource URL diff --git a/docs/examples/kotlin/storage/get-file-view.md b/docs/examples/kotlin/storage/get-file-view.md index 0b4fe07..107ad45 100644 --- a/docs/examples/kotlin/storage/get-file-view.md +++ b/docs/examples/kotlin/storage/get-file-view.md @@ -18,6 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val result = storage.getFileView( + bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]" ) println(result); // Resource URL diff --git a/docs/examples/kotlin/storage/get-file.md b/docs/examples/kotlin/storage/get-file.md index b534d3b..30f640b 100644 --- a/docs/examples/kotlin/storage/get-file.md +++ b/docs/examples/kotlin/storage/get-file.md @@ -18,6 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = storage.getFile( + bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]" ) val json = response.body?.string() diff --git a/docs/examples/kotlin/storage/list-files.md b/docs/examples/kotlin/storage/list-files.md index 7d63837..20a253a 100644 --- a/docs/examples/kotlin/storage/list-files.md +++ b/docs/examples/kotlin/storage/list-files.md @@ -18,6 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = storage.listFiles( + bucketId = "[BUCKET_ID]", ) val json = response.body?.string() } diff --git a/docs/examples/kotlin/storage/update-file.md b/docs/examples/kotlin/storage/update-file.md index 31dfb38..35b1afb 100644 --- a/docs/examples/kotlin/storage/update-file.md +++ b/docs/examples/kotlin/storage/update-file.md @@ -18,9 +18,8 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = storage.updateFile( + bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]", - read = listOf(), - write = listOf() ) val json = response.body?.string() } diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/library/build.gradle b/library/build.gradle index cb15537..ee98757 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -19,6 +19,8 @@ ext { GITHUB_SCM_CONNECTION = 'scm:git:git://github.com/appwrite/sdk-for-android.git' } +version PUBLISH_VERSION + android { compileSdkVersion(31) diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 312dddd..806e048 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -42,6 +42,10 @@ class Client @JvmOverloads constructor( private var selfSigned: Boolean = false ) : CoroutineScope { + companion object { + const val CHUNK_SIZE = 5*1024*1024; // 5MB + } + override val coroutineContext: CoroutineContext get() = Dispatchers.Main + job @@ -231,7 +235,7 @@ class Client @JvmOverloads constructor( * @param headers * @param params * - * @return [Response] + * @return [T] */ @Throws(AppwriteException::class) suspend fun call( @@ -285,8 +289,7 @@ class Client @JvmOverloads constructor( filteredParams.forEach { when { it.key == "file" -> { - val file = it.value as File - builder.addFormDataPart(it.key, file.name, file.asRequestBody()) + builder.addPart(it.value as MultipartBody.Part) } it.value is List<*> -> { val list = it.value as List<*> @@ -317,6 +320,83 @@ class Client @JvmOverloads constructor( return awaitResponse(request, responseType, convert) } + /** + * Upload a file in chunks + * + * @param path + * @param headers + * @param params + * + * @return [T] + */ + @Throws(AppwriteException::class) + suspend fun chunkedUpload( + path: String, + headers: MutableMap, + params: MutableMap, + responseType: Class, + convert: ((Map) -> T), + paramName: String, + onProgress: ((Double) -> Unit)? = null, + ): T { + val file = params[paramName] as File + val size = file.length() + + if (size < CHUNK_SIZE) { + params[paramName] = MultipartBody.Part.createFormData( + paramName, + file.name, + file.asRequestBody() + ) + return call( + "POST", + path, + headers, + params, + responseType, + convert + ) + } + + val input = file.inputStream().buffered() + val buffer = ByteArray(CHUNK_SIZE) + var offset = 0L + var result: Map<*, *>? = null + + generateSequence { + val readBytes = input.read(buffer) + if (readBytes >= 0) { + buffer.copyOf(readBytes) + } else { + input.close() + null + } + }.forEach { + params[paramName] = MultipartBody.Part.createFormData( + paramName, + file.name, + it.toRequestBody() + ) + + headers["Content-Range"] = + "bytes $offset-${((offset + CHUNK_SIZE) - 1).coerceAtMost(size)}/$size" + + result = call( + "POST", + path, + headers, + params, + Map::class.java + ) + + offset += CHUNK_SIZE + headers["x-appwrite-id"] = result!!["\$id"].toString() + onProgress?.invoke(offset.coerceAtMost(size).toDouble()/size * 100) + } + + return convert(result as Map) + } + /** * Await Response * @@ -355,7 +435,8 @@ class Client @JvmOverloads constructor( ) AppwriteException( map["message"] as? String ?: "", - (map["code"] as Number).toInt(), + (map["code"] as Number).toInt(), + map["type"] as? String ?: "", body ) } else { diff --git a/library/src/main/java/io/appwrite/exceptions/AppwriteException.kt b/library/src/main/java/io/appwrite/exceptions/AppwriteException.kt index 1d22595..105f5ee 100644 --- a/library/src/main/java/io/appwrite/exceptions/AppwriteException.kt +++ b/library/src/main/java/io/appwrite/exceptions/AppwriteException.kt @@ -5,5 +5,6 @@ import java.lang.Exception class AppwriteException( override val message: String? = null, val code: Int? = null, + val type: String? = null, val response: String? = null ) : Exception(message) \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Execution.kt b/library/src/main/java/io/appwrite/models/Execution.kt index f03925d..c8f2ae2 100644 --- a/library/src/main/java/io/appwrite/models/Execution.kt +++ b/library/src/main/java/io/appwrite/models/Execution.kt @@ -49,11 +49,11 @@ data class Execution( val status: String, /** - * The script exit code. + * The script status code. * */ - @SerializedName("exitCode") - val exitCode: Long, + @SerializedName("statusCode") + val statusCode: Long, /** * The script stdout output string. Logs the last 4,000 characters of the execution stdout output. @@ -85,7 +85,7 @@ data class Execution( dateCreated = (map["dateCreated"] as Number).toLong(), trigger = map["trigger"] as String, status = map["status"] as String, - exitCode = (map["exitCode"] as Number).toLong(), + statusCode = (map["statusCode"] as Number).toLong(), stdout = map["stdout"] as String, stderr = map["stderr"] as String, time = (map["time"] as Number).toDouble() @@ -99,7 +99,7 @@ data class Execution( "dateCreated" to dateCreated as Any, "trigger" to trigger as Any, "status" to status as Any, - "exitCode" to exitCode as Any, + "statusCode" to statusCode as Any, "stdout" to stdout as Any, "stderr" to stderr as Any, "time" to time as Any diff --git a/library/src/main/java/io/appwrite/models/File.kt b/library/src/main/java/io/appwrite/models/File.kt index 1f9e734..2faa1e4 100644 --- a/library/src/main/java/io/appwrite/models/File.kt +++ b/library/src/main/java/io/appwrite/models/File.kt @@ -13,6 +13,13 @@ data class File( @SerializedName("\$id") val id: String, + /** + * Bucket ID. + * + */ + @SerializedName("bucketId") + val bucketId: String, + /** * File read permissions. * @@ -60,30 +67,50 @@ data class File( * */ @SerializedName("sizeOriginal") - val sizeOriginal: Long + val sizeOriginal: Long, + + /** + * Total number of chunks available + * + */ + @SerializedName("chunksTotal") + val chunksTotal: Long, + + /** + * Total number of chunks uploaded + * + */ + @SerializedName("chunksUploaded") + val chunksUploaded: Long ) { companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = File( id = map["\$id"] as String, + bucketId = map["bucketId"] as String, read = map["\$read"] as List, write = map["\$write"] as List, name = map["name"] as String, dateCreated = (map["dateCreated"] as Number).toLong(), signature = map["signature"] as String, mimeType = map["mimeType"] as String, - sizeOriginal = (map["sizeOriginal"] as Number).toLong() + sizeOriginal = (map["sizeOriginal"] as Number).toLong(), + chunksTotal = (map["chunksTotal"] as Number).toLong(), + chunksUploaded = (map["chunksUploaded"] as Number).toLong() ) } fun toMap(): Map = mapOf( "\$id" to id as Any, + "bucketId" to bucketId as Any, "\$read" to read as Any, "\$write" to write as Any, "name" to name as Any, "dateCreated" to dateCreated as Any, "signature" to signature as Any, "mimeType" to mimeType as Any, - "sizeOriginal" to sizeOriginal as Any + "sizeOriginal" to sizeOriginal as Any, + "chunksTotal" to chunksTotal as Any, + "chunksUploaded" to chunksUploaded as Any ) } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/RealtimeModels.kt b/library/src/main/java/io/appwrite/models/RealtimeModels.kt index e2b012a..4237638 100644 --- a/library/src/main/java/io/appwrite/models/RealtimeModels.kt +++ b/library/src/main/java/io/appwrite/models/RealtimeModels.kt @@ -1,5 +1,6 @@ package io.appwrite.models +import kotlin.collections.Collection import java.io.Closeable data class RealtimeSubscription( diff --git a/library/src/main/java/io/appwrite/models/Session.kt b/library/src/main/java/io/appwrite/models/Session.kt index 1ee5187..1abd909 100644 --- a/library/src/main/java/io/appwrite/models/Session.kt +++ b/library/src/main/java/io/appwrite/models/Session.kt @@ -42,11 +42,25 @@ data class Session( val providerUid: String, /** - * Session Provider Token. + * Session Provider Access Token. * */ - @SerializedName("providerToken") - val providerToken: String, + @SerializedName("providerAccessToken") + val providerAccessToken: String, + + /** + * Date, the Unix timestamp of when the access token expires. + * + */ + @SerializedName("providerAccessTokenExpiry") + val providerAccessTokenExpiry: Long, + + /** + * Session Provider Refresh Token. + * + */ + @SerializedName("providerRefreshToken") + val providerRefreshToken: String, /** * IP in use when the session was created. @@ -168,7 +182,9 @@ data class Session( expire = (map["expire"] as Number).toLong(), provider = map["provider"] as String, providerUid = map["providerUid"] as String, - providerToken = map["providerToken"] as String, + providerAccessToken = map["providerAccessToken"] as String, + providerAccessTokenExpiry = (map["providerAccessTokenExpiry"] as Number).toLong(), + providerRefreshToken = map["providerRefreshToken"] as String, ip = map["ip"] as String, osCode = map["osCode"] as String, osName = map["osName"] as String, @@ -194,7 +210,9 @@ data class Session( "expire" to expire as Any, "provider" to provider as Any, "providerUid" to providerUid as Any, - "providerToken" to providerToken as Any, + "providerAccessToken" to providerAccessToken as Any, + "providerAccessTokenExpiry" to providerAccessTokenExpiry as Any, + "providerRefreshToken" to providerRefreshToken as Any, "ip" to ip as Any, "osCode" to osCode as Any, "osName" to osName as Any, diff --git a/library/src/main/java/io/appwrite/services/Account.kt b/library/src/main/java/io/appwrite/services/Account.kt index 2c1b6a1..997b7c7 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -25,9 +25,9 @@ class Account(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun get(): io.appwrite.models.User { val path = "/account" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.User = { @@ -39,7 +39,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.User::class.java, - convert = convert + convert = convert, ) } @@ -53,7 +53,7 @@ class Account(client: Client) : Service(client) { * login to their new account, you need to create a new [account * session](/docs/client/account#accountCreateSession). * - * @param userId Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. 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. + * @param userId Unique Id. Choose your own unique ID or pass the string "unique()" to auto generate it. 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. * @param email User email. * @param password User password. Must be at least 8 chars. * @param name User name. Max length: 128 chars. @@ -68,13 +68,13 @@ class Account(client: Client) : Service(client) { name: String? = null ): io.appwrite.models.User { val path = "/account" - val params = mapOf( + val params = mutableMapOf( "userId" to userId, "email" to email, "password" to password, "name" to name ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.User = { @@ -86,7 +86,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.User::class.java, - convert = convert + convert = convert, ) } @@ -105,9 +105,9 @@ class Account(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun delete(): Any { val path = "/account" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) return client.call( @@ -142,11 +142,11 @@ class Account(client: Client) : Service(client) { password: String ): io.appwrite.models.User { val path = "/account/email" - val params = mapOf( + val params = mutableMapOf( "email" to email, "password" to password ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.User = { @@ -158,7 +158,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.User::class.java, - convert = convert + convert = convert, ) } @@ -177,9 +177,9 @@ class Account(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun createJWT(): io.appwrite.models.Jwt { val path = "/account/jwt" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Jwt = { @@ -191,7 +191,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Jwt::class.java, - convert = convert + convert = convert, ) } @@ -212,11 +212,11 @@ class Account(client: Client) : Service(client) { offset: Long? = null ): io.appwrite.models.LogList { val path = "/account/logs" - val params = mapOf( + val params = mutableMapOf( "limit" to limit, "offset" to offset ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.LogList = { @@ -228,7 +228,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.LogList::class.java, - convert = convert + convert = convert, ) } @@ -246,10 +246,10 @@ class Account(client: Client) : Service(client) { name: String ): io.appwrite.models.User { val path = "/account/name" - val params = mapOf( + val params = mutableMapOf( "name" to name ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.User = { @@ -261,7 +261,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.User::class.java, - convert = convert + convert = convert, ) } @@ -283,11 +283,11 @@ class Account(client: Client) : Service(client) { oldPassword: String? = null ): io.appwrite.models.User { val path = "/account/password" - val params = mapOf( + val params = mutableMapOf( "password" to password, "oldPassword" to oldPassword ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.User = { @@ -299,7 +299,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.User::class.java, - convert = convert + convert = convert, ) } @@ -314,9 +314,9 @@ class Account(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun getPrefs(): io.appwrite.models.Preferences { val path = "/account/prefs" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Preferences = { @@ -328,7 +328,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Preferences::class.java, - convert = convert + convert = convert, ) } @@ -348,10 +348,10 @@ class Account(client: Client) : Service(client) { prefs: Any ): io.appwrite.models.User { val path = "/account/prefs" - val params = mapOf( + val params = mutableMapOf( "prefs" to prefs ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.User = { @@ -363,7 +363,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.User::class.java, - convert = convert + convert = convert, ) } @@ -390,11 +390,11 @@ class Account(client: Client) : Service(client) { url: String ): io.appwrite.models.Token { val path = "/account/recovery" - val params = mapOf( + val params = mutableMapOf( "email" to email, "url" to url ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Token = { @@ -406,7 +406,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Token::class.java, - convert = convert + convert = convert, ) } @@ -438,13 +438,13 @@ class Account(client: Client) : Service(client) { passwordAgain: String ): io.appwrite.models.Token { val path = "/account/recovery" - val params = mapOf( + val params = mutableMapOf( "userId" to userId, "secret" to secret, "password" to password, "passwordAgain" to passwordAgain ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Token = { @@ -456,7 +456,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Token::class.java, - convert = convert + convert = convert, ) } @@ -472,9 +472,9 @@ class Account(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun getSessions(): io.appwrite.models.SessionList { val path = "/account/sessions" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.SessionList = { @@ -486,7 +486,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.SessionList::class.java, - convert = convert + convert = convert, ) } @@ -507,11 +507,11 @@ class Account(client: Client) : Service(client) { password: String ): io.appwrite.models.Session { val path = "/account/sessions" - val params = mapOf( + val params = mutableMapOf( "email" to email, "password" to password ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Session = { @@ -523,7 +523,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Session::class.java, - convert = convert + convert = convert, ) } @@ -539,9 +539,9 @@ class Account(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun deleteSessions(): Any { val path = "/account/sessions" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) return client.call( @@ -569,9 +569,9 @@ class Account(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun createAnonymousSession(): io.appwrite.models.Session { val path = "/account/sessions/anonymous" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Session = { @@ -583,7 +583,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Session::class.java, - convert = convert + convert = convert, ) } @@ -601,7 +601,7 @@ class Account(client: Client) : Service(client) { * the URL parameter empty, so that the login completion will be handled by * your Appwrite instance by default. * - * @param userId Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. 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. + * @param userId Unique Id. Choose your own unique ID or pass the string "unique()" to auto generate it. 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. * @param email User email. * @param url URL to redirect the user back to your app from the magic URL login. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @return [io.appwrite.models.Token] @@ -614,12 +614,12 @@ class Account(client: Client) : Service(client) { url: String? = null ): io.appwrite.models.Token { val path = "/account/sessions/magic-url" - val params = mapOf( + val params = mutableMapOf( "userId" to userId, "email" to email, "url" to url ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Token = { @@ -631,7 +631,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Token::class.java, - convert = convert + convert = convert, ) } @@ -661,11 +661,11 @@ class Account(client: Client) : Service(client) { secret: String ): io.appwrite.models.Session { val path = "/account/sessions/magic-url" - val params = mapOf( + val params = mutableMapOf( "userId" to userId, "secret" to secret ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Session = { @@ -677,7 +677,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Session::class.java, - convert = convert + convert = convert, ) } @@ -697,7 +697,7 @@ class Account(client: Client) : Service(client) { * user.. * * - * @param provider OAuth2 Provider. Currently, supported providers are: amazon, apple, bitbucket, bitly, box, discord, dropbox, facebook, github, gitlab, google, linkedin, microsoft, paypal, paypalSandbox, salesforce, slack, spotify, tradeshift, tradeshiftBox, twitch, vk, yahoo, yammer, yandex, wordpress. + * @param provider OAuth2 Provider. Currently, supported providers are: amazon, apple, bitbucket, bitly, box, discord, dropbox, facebook, github, gitlab, google, linkedin, microsoft, notion, paypal, paypalSandbox, salesforce, slack, spotify, tradeshift, tradeshiftBox, twitch, vk, yahoo, yammer, yandex, wordpress, stripe. * @param success URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param failure URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param scopes A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. @@ -713,7 +713,7 @@ class Account(client: Client) : Service(client) { scopes: List? = null ) { val path = "/account/sessions/oauth2/{provider}".replace("{provider}", provider) - val params = mapOf( + val params = mutableMapOf( "success" to success, "failure" to failure, "scopes" to scopes, @@ -778,9 +778,9 @@ class Account(client: Client) : Service(client) { sessionId: String ): io.appwrite.models.Session { val path = "/account/sessions/{sessionId}".replace("{sessionId}", sessionId) - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Session = { @@ -792,7 +792,37 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Session::class.java, - convert = convert + convert = convert, + ) + } + + /** + * Update Session (Refresh Tokens) + * + * @param sessionId Session ID. Use the string 'current' to update the current device session. + * @return [io.appwrite.models.Session] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun updateSession( + sessionId: String + ): io.appwrite.models.Session { + val path = "/account/sessions/{sessionId}".replace("{sessionId}", sessionId) + val params = mutableMapOf( + ) + val headers = mutableMapOf( + "content-type" to "application/json" + ) + val convert: (Map) -> io.appwrite.models.Session = { + io.appwrite.models.Session.from(map = it) + } + return client.call( + "PATCH", + path, + headers, + params, + responseType = io.appwrite.models.Session::class.java, + convert = convert, ) } @@ -801,7 +831,8 @@ class Account(client: Client) : Service(client) { * * Use this endpoint to log out the currently logged in user from all their * account sessions across all of their different devices. When using the - * option id argument, only the session unique ID provider will be deleted. + * Session ID argument, only the unique session ID provided is deleted. + * * * @param sessionId Session ID. Use the string 'current' to delete the current device session. * @return [Any] @@ -812,9 +843,9 @@ class Account(client: Client) : Service(client) { sessionId: String ): Any { val path = "/account/sessions/{sessionId}".replace("{sessionId}", sessionId) - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) return client.call( @@ -854,10 +885,10 @@ class Account(client: Client) : Service(client) { url: String ): io.appwrite.models.Token { val path = "/account/verification" - val params = mapOf( + val params = mutableMapOf( "url" to url ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Token = { @@ -869,7 +900,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Token::class.java, - convert = convert + convert = convert, ) } @@ -892,11 +923,11 @@ class Account(client: Client) : Service(client) { secret: String ): io.appwrite.models.Token { val path = "/account/verification" - val params = mapOf( + val params = mutableMapOf( "userId" to userId, "secret" to secret ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Token = { @@ -908,7 +939,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Token::class.java, - convert = convert + convert = convert, ) } diff --git a/library/src/main/java/io/appwrite/services/Avatars.kt b/library/src/main/java/io/appwrite/services/Avatars.kt index 912b1e5..09afbc6 100644 --- a/library/src/main/java/io/appwrite/services/Avatars.kt +++ b/library/src/main/java/io/appwrite/services/Avatars.kt @@ -35,7 +35,7 @@ class Avatars(client: Client) : Service(client) { quality: Long? = null ): ByteArray { val path = "/avatars/browsers/{code}".replace("{code}", code) - val params = mapOf( + val params = mutableMapOf( "width" to width, "height" to height, "quality" to quality, @@ -71,7 +71,7 @@ class Avatars(client: Client) : Service(client) { quality: Long? = null ): ByteArray { val path = "/avatars/credit-cards/{code}".replace("{code}", code) - val params = mapOf( + val params = mutableMapOf( "width" to width, "height" to height, "quality" to quality, @@ -101,7 +101,7 @@ class Avatars(client: Client) : Service(client) { url: String ): ByteArray { val path = "/avatars/favicon" - val params = mapOf( + val params = mutableMapOf( "url" to url, "project" to client.config["project"] ) @@ -135,7 +135,7 @@ class Avatars(client: Client) : Service(client) { quality: Long? = null ): ByteArray { val path = "/avatars/flags/{code}".replace("{code}", code) - val params = mapOf( + val params = mutableMapOf( "width" to width, "height" to height, "quality" to quality, @@ -170,7 +170,7 @@ class Avatars(client: Client) : Service(client) { height: Long? = null ): ByteArray { val path = "/avatars/image" - val params = mapOf( + val params = mutableMapOf( "url" to url, "width" to width, "height" to height, @@ -215,7 +215,7 @@ class Avatars(client: Client) : Service(client) { background: String? = null ): ByteArray { val path = "/avatars/initials" - val params = mapOf( + val params = mutableMapOf( "name" to name, "width" to width, "height" to height, @@ -252,7 +252,7 @@ class Avatars(client: Client) : Service(client) { download: Boolean? = null ): ByteArray { val path = "/avatars/qr" - val params = mapOf( + val params = mutableMapOf( "text" to text, "size" to size, "margin" to margin, diff --git a/library/src/main/java/io/appwrite/services/Database.kt b/library/src/main/java/io/appwrite/services/Database.kt index 7b43505..8db1ac2 100644 --- a/library/src/main/java/io/appwrite/services/Database.kt +++ b/library/src/main/java/io/appwrite/services/Database.kt @@ -41,7 +41,7 @@ class Database(client: Client) : Service(client) { orderTypes: List? = null ): io.appwrite.models.DocumentList { val path = "/database/collections/{collectionId}/documents".replace("{collectionId}", collectionId) - val params = mapOf( + val params = mutableMapOf( "queries" to queries, "limit" to limit, "offset" to offset, @@ -50,7 +50,7 @@ class Database(client: Client) : Service(client) { "orderAttributes" to orderAttributes, "orderTypes" to orderTypes ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.DocumentList = { @@ -62,7 +62,7 @@ class Database(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.DocumentList::class.java, - convert = convert + convert = convert, ) } @@ -75,7 +75,7 @@ class Database(client: Client) : Service(client) { * directly from your database console. * * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection). Make sure to define attributes before creating documents. - * @param documentId Document ID. Choose your own unique ID or pass the string `unique()` to auto generate it. 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. + * @param documentId Document ID. Choose your own unique ID or pass the string "unique()" to auto generate it. 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. * @param data Document data as JSON object. * @param read An array of strings with read permissions. By default only the current user is granted with read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. * @param write An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. @@ -91,13 +91,13 @@ class Database(client: Client) : Service(client) { write: List? = null ): io.appwrite.models.Document { val path = "/database/collections/{collectionId}/documents".replace("{collectionId}", collectionId) - val params = mapOf( + val params = mutableMapOf( "documentId" to documentId, "data" to data, "read" to read, "write" to write ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Document = { @@ -109,7 +109,7 @@ class Database(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Document::class.java, - convert = convert + convert = convert, ) } @@ -130,9 +130,9 @@ class Database(client: Client) : Service(client) { documentId: String ): io.appwrite.models.Document { val path = "/database/collections/{collectionId}/documents/{documentId}".replace("{collectionId}", collectionId).replace("{documentId}", documentId) - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Document = { @@ -144,7 +144,7 @@ class Database(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Document::class.java, - convert = convert + convert = convert, ) } @@ -171,12 +171,12 @@ class Database(client: Client) : Service(client) { write: List? = null ): io.appwrite.models.Document { val path = "/database/collections/{collectionId}/documents/{documentId}".replace("{collectionId}", collectionId).replace("{documentId}", documentId) - val params = mapOf( + val params = mutableMapOf( "data" to data, "read" to read, "write" to write ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Document = { @@ -188,7 +188,7 @@ class Database(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Document::class.java, - convert = convert + convert = convert, ) } @@ -210,9 +210,9 @@ class Database(client: Client) : Service(client) { documentId: String ): Any { val path = "/database/collections/{collectionId}/documents/{documentId}".replace("{collectionId}", collectionId).replace("{documentId}", documentId) - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) return client.call( diff --git a/library/src/main/java/io/appwrite/services/Functions.kt b/library/src/main/java/io/appwrite/services/Functions.kt index 132e753..36f6b33 100644 --- a/library/src/main/java/io/appwrite/services/Functions.kt +++ b/library/src/main/java/io/appwrite/services/Functions.kt @@ -10,6 +10,36 @@ import java.io.File class Functions(client: Client) : Service(client) { + /** + * Retry Build + * + * @param functionId Function ID. + * @param deploymentId Deployment ID. + * @param buildId Build unique ID. + * @return [Any] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun retryBuild( + functionId: String, + deploymentId: String, + buildId: String + ): Any { + val path = "/functions/{functionId}/deployments/{deploymentId}/builds/{buildId}".replace("{functionId}", functionId).replace("{deploymentId}", deploymentId).replace("{buildId}", buildId) + val params = mutableMapOf( + ) + val headers = mutableMapOf( + "content-type" to "application/json" + ) + return client.call( + "POST", + path, + headers, + params, + responseType = Any::class.java, + ) + } + /** * List Executions * @@ -37,14 +67,14 @@ class Functions(client: Client) : Service(client) { cursorDirection: String? = null ): io.appwrite.models.ExecutionList { val path = "/functions/{functionId}/executions".replace("{functionId}", functionId) - val params = mapOf( + val params = mutableMapOf( "limit" to limit, "offset" to offset, "search" to search, "cursor" to cursor, "cursorDirection" to cursorDirection ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.ExecutionList = { @@ -56,7 +86,7 @@ class Functions(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.ExecutionList::class.java, - convert = convert + convert = convert, ) } @@ -70,19 +100,22 @@ class Functions(client: Client) : Service(client) { * * @param functionId Function ID. * @param data String of custom data to send to function. + * @param async Execute code asynchronously. Default value is true. * @return [io.appwrite.models.Execution] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun createExecution( functionId: String, - data: String? = null + data: String? = null, + async: Boolean? = null ): io.appwrite.models.Execution { val path = "/functions/{functionId}/executions".replace("{functionId}", functionId) - val params = mapOf( - "data" to data + val params = mutableMapOf( + "data" to data, + "async" to async ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Execution = { @@ -94,7 +127,7 @@ class Functions(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Execution::class.java, - convert = convert + convert = convert, ) } @@ -114,9 +147,9 @@ class Functions(client: Client) : Service(client) { executionId: String ): io.appwrite.models.Execution { val path = "/functions/{functionId}/executions/{executionId}".replace("{functionId}", functionId).replace("{executionId}", executionId) - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Execution = { @@ -128,7 +161,7 @@ class Functions(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Execution::class.java, - convert = convert + convert = convert, ) } diff --git a/library/src/main/java/io/appwrite/services/Locale.kt b/library/src/main/java/io/appwrite/services/Locale.kt index 423a323..c8837b4 100644 --- a/library/src/main/java/io/appwrite/services/Locale.kt +++ b/library/src/main/java/io/appwrite/services/Locale.kt @@ -26,9 +26,9 @@ class Locale(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun get(): io.appwrite.models.Locale { val path = "/locale" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Locale = { @@ -40,7 +40,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Locale::class.java, - convert = convert + convert = convert, ) } @@ -56,9 +56,9 @@ class Locale(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun getContinents(): io.appwrite.models.ContinentList { val path = "/locale/continents" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.ContinentList = { @@ -70,7 +70,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.ContinentList::class.java, - convert = convert + convert = convert, ) } @@ -86,9 +86,9 @@ class Locale(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun getCountries(): io.appwrite.models.CountryList { val path = "/locale/countries" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.CountryList = { @@ -100,7 +100,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.CountryList::class.java, - convert = convert + convert = convert, ) } @@ -116,9 +116,9 @@ class Locale(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun getCountriesEU(): io.appwrite.models.CountryList { val path = "/locale/countries/eu" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.CountryList = { @@ -130,7 +130,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.CountryList::class.java, - convert = convert + convert = convert, ) } @@ -146,9 +146,9 @@ class Locale(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun getCountriesPhones(): io.appwrite.models.PhoneList { val path = "/locale/countries/phones" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.PhoneList = { @@ -160,7 +160,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.PhoneList::class.java, - convert = convert + convert = convert, ) } @@ -177,9 +177,9 @@ class Locale(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun getCurrencies(): io.appwrite.models.CurrencyList { val path = "/locale/currencies" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.CurrencyList = { @@ -191,7 +191,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.CurrencyList::class.java, - convert = convert + convert = convert, ) } @@ -207,9 +207,9 @@ class Locale(client: Client) : Service(client) { @Throws(AppwriteException::class) suspend fun getLanguages(): io.appwrite.models.LanguageList { val path = "/locale/languages" - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.LanguageList = { @@ -221,7 +221,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.LanguageList::class.java, - convert = convert + convert = convert, ) } diff --git a/library/src/main/java/io/appwrite/services/Storage.kt b/library/src/main/java/io/appwrite/services/Storage.kt index 42a0958..4a8d3b3 100644 --- a/library/src/main/java/io/appwrite/services/Storage.kt +++ b/library/src/main/java/io/appwrite/services/Storage.kt @@ -19,6 +19,7 @@ class Storage(client: Client) : Service(client) { * your results. On admin mode, this endpoint will return a list of all of the * project's files. [Learn more about different API modes](/docs/admin). * + * @param bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket). * @param search Search term to filter your list results. Max length: 256 chars. * @param limit Maximum number of files to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request. * @param offset Offset value. The default value is 0. Use this param to manage pagination. [learn more about pagination](https://appwrite.io/docs/pagination) @@ -30,6 +31,7 @@ class Storage(client: Client) : Service(client) { @JvmOverloads @Throws(AppwriteException::class) suspend fun listFiles( + bucketId: String, search: String? = null, limit: Long? = null, offset: Long? = null, @@ -37,8 +39,8 @@ class Storage(client: Client) : Service(client) { cursorDirection: String? = null, orderType: String? = null ): io.appwrite.models.FileList { - val path = "/storage/files" - val params = mapOf( + val path = "/storage/buckets/{bucketId}/files".replace("{bucketId}", bucketId) + val params = mutableMapOf( "search" to search, "limit" to limit, "offset" to offset, @@ -46,7 +48,7 @@ class Storage(client: Client) : Service(client) { "cursorDirection" to cursorDirection, "orderType" to orderType ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.FileList = { @@ -58,18 +60,34 @@ class Storage(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.FileList::class.java, - convert = convert + convert = convert, ) } /** * Create File * - * Create a new file. The user who creates the file will automatically be - * assigned to read and write access unless he has passed custom values for - * read and write arguments. + * Create a new file. Before using this route, you should create a new bucket + * resource using either a [server + * integration](/docs/server/database#storageCreateBucket) API or directly + * from your Appwrite console. + * + * Larger files should be uploaded using multiple requests with the + * [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range) + * header to send a partial request with a maximum supported chunk of `5MB`. + * The `content-range` header values should always be in bytes. + * + * When the first request is sent, the server will return the **File** object, + * and the subsequent part request must include the file's **id** in + * `x-appwrite-id` header to allow the server to know that the partial upload + * is for the existing file and not for a new one. + * + * If you're creating a new file using one of the Appwrite SDKs, all the + * chunking logic will be managed by the SDK internally. + * * - * @param fileId File ID. Choose your own unique ID or pass the string `unique()` to auto generate it. 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. + * @param bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket). + * @param fileId File ID. Choose your own unique ID or pass the string "unique()" to auto generate it. 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. * @param file Binary file. * @param read An array of strings with read permissions. By default only the current user is granted with read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. * @param write An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. @@ -78,31 +96,34 @@ class Storage(client: Client) : Service(client) { @JvmOverloads @Throws(AppwriteException::class) suspend fun createFile( + bucketId: String, fileId: String, file: File, read: List? = null, - write: List? = null + write: List? = null, onProgress: ((Double) -> Unit)? = null ): io.appwrite.models.File { - val path = "/storage/files" - val params = mapOf( + val path = "/storage/buckets/{bucketId}/files".replace("{bucketId}", bucketId) + val params = mutableMapOf( "fileId" to fileId, "file" to file, "read" to read, "write" to write ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "multipart/form-data" ) val convert: (Map) -> io.appwrite.models.File = { io.appwrite.models.File.from(map = it) } - return client.call( - "POST", + val paramName = "file" + return client.chunkedUpload( path, headers, params, responseType = io.appwrite.models.File::class.java, - convert = convert + convert = convert, + paramName, + onProgress, ) } @@ -112,18 +133,20 @@ class Storage(client: Client) : Service(client) { * Get a file by its unique ID. This endpoint response returns a JSON object * with the file metadata. * + * @param bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket). * @param fileId File ID. * @return [io.appwrite.models.File] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getFile( + bucketId: String, fileId: String ): io.appwrite.models.File { - val path = "/storage/files/{fileId}".replace("{fileId}", fileId) - val params = mapOf( + val path = "/storage/buckets/{bucketId}/files/{fileId}".replace("{bucketId}", bucketId).replace("{fileId}", fileId) + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.File = { @@ -135,7 +158,7 @@ class Storage(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.File::class.java, - convert = convert + convert = convert, ) } @@ -145,7 +168,8 @@ class Storage(client: Client) : Service(client) { * Update a file by its unique ID. Only users with write permissions have * access to update this resource. * - * @param fileId File ID. + * @param bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket). + * @param fileId File unique ID. * @param read An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. * @param write An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. * @return [io.appwrite.models.File] @@ -153,16 +177,17 @@ class Storage(client: Client) : Service(client) { @JvmOverloads @Throws(AppwriteException::class) suspend fun updateFile( + bucketId: String, fileId: String, - read: List, - write: List + read: List? = null, + write: List? = null ): io.appwrite.models.File { - val path = "/storage/files/{fileId}".replace("{fileId}", fileId) - val params = mapOf( + val path = "/storage/buckets/{bucketId}/files/{fileId}".replace("{bucketId}", bucketId).replace("{fileId}", fileId) + val params = mutableMapOf( "read" to read, "write" to write ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.File = { @@ -174,7 +199,7 @@ class Storage(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.File::class.java, - convert = convert + convert = convert, ) } @@ -184,18 +209,20 @@ class Storage(client: Client) : Service(client) { * Delete a file by its unique ID. Only users with write permissions have * access to delete this resource. * + * @param bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket). * @param fileId File ID. * @return [Any] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun deleteFile( + bucketId: String, fileId: String ): Any { - val path = "/storage/files/{fileId}".replace("{fileId}", fileId) - val params = mapOf( + val path = "/storage/buckets/{bucketId}/files/{fileId}".replace("{bucketId}", bucketId).replace("{fileId}", fileId) + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) return client.call( @@ -214,16 +241,18 @@ class Storage(client: Client) : Service(client) { * 'Content-Disposition: attachment' header that tells the browser to start * downloading the file to user downloads directory. * + * @param bucketId Storage bucket ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket). * @param fileId File ID. * @return [ByteArray] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getFileDownload( + bucketId: String, fileId: String ): ByteArray { - val path = "/storage/files/{fileId}/download".replace("{fileId}", fileId) - val params = mapOf( + val path = "/storage/buckets/{bucketId}/files/{fileId}/download".replace("{bucketId}", bucketId).replace("{fileId}", fileId) + val params = mutableMapOf( "project" to client.config["project"] ) return client.call( @@ -240,9 +269,11 @@ class Storage(client: Client) : Service(client) { * Get a file preview image. Currently, this method supports preview for image * files (jpg, png, and gif), other supported formats, like pdf, docs, slides, * and spreadsheets, will return the file icon image. You can also pass query - * string arguments for cutting and resizing your preview image. + * string arguments for cutting and resizing your preview image. Preview is + * supported only for image files smaller than 10MB. * - * @param fileId File ID. + * @param bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket). + * @param fileId File ID * @param width Resize preview image width, Pass an integer between 0 to 4000. * @param height Resize preview image height, Pass an integer between 0 to 4000. * @param gravity Image crop gravity. Can be one of center,top-left,top,top-right,left,right,bottom-left,bottom,bottom-right @@ -259,6 +290,7 @@ class Storage(client: Client) : Service(client) { @JvmOverloads @Throws(AppwriteException::class) suspend fun getFilePreview( + bucketId: String, fileId: String, width: Long? = null, height: Long? = null, @@ -272,8 +304,8 @@ class Storage(client: Client) : Service(client) { background: String? = null, output: String? = null ): ByteArray { - val path = "/storage/files/{fileId}/preview".replace("{fileId}", fileId) - val params = mapOf( + val path = "/storage/buckets/{bucketId}/files/{fileId}/preview".replace("{bucketId}", bucketId).replace("{fileId}", fileId) + val params = mutableMapOf( "width" to width, "height" to height, "gravity" to gravity, @@ -302,16 +334,18 @@ class Storage(client: Client) : Service(client) { * download method but returns with no 'Content-Disposition: attachment' * header. * + * @param bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket). * @param fileId File ID. * @return [ByteArray] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getFileView( + bucketId: String, fileId: String ): ByteArray { - val path = "/storage/files/{fileId}/view".replace("{fileId}", fileId) - val params = mapOf( + val path = "/storage/buckets/{bucketId}/files/{fileId}/view".replace("{bucketId}", bucketId).replace("{fileId}", fileId) + val params = mutableMapOf( "project" to client.config["project"] ) return client.call( diff --git a/library/src/main/java/io/appwrite/services/Teams.kt b/library/src/main/java/io/appwrite/services/Teams.kt index cc08040..f58df7c 100644 --- a/library/src/main/java/io/appwrite/services/Teams.kt +++ b/library/src/main/java/io/appwrite/services/Teams.kt @@ -38,7 +38,7 @@ class Teams(client: Client) : Service(client) { orderType: String? = null ): io.appwrite.models.TeamList { val path = "/teams" - val params = mapOf( + val params = mutableMapOf( "search" to search, "limit" to limit, "offset" to offset, @@ -46,7 +46,7 @@ class Teams(client: Client) : Service(client) { "cursorDirection" to cursorDirection, "orderType" to orderType ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.TeamList = { @@ -58,7 +58,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.TeamList::class.java, - convert = convert + convert = convert, ) } @@ -69,7 +69,7 @@ class Teams(client: Client) : Service(client) { * assigned as the owner of the team. Only the users with the owner role can * invite new members, add new owners and delete or update the team. * - * @param teamId Team ID. Choose your own unique ID or pass the string `unique()` to auto generate it. 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. + * @param teamId Team ID. Choose your own unique ID or pass the string "unique()" to auto generate it. 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. * @param name Team name. Max length: 128 chars. * @param roles Array of strings. Use this param to set the roles in the team for the user who created it. The default role is **owner**. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Max length for each role is 32 chars. * @return [io.appwrite.models.Team] @@ -82,12 +82,12 @@ class Teams(client: Client) : Service(client) { roles: List? = null ): io.appwrite.models.Team { val path = "/teams" - val params = mapOf( + val params = mutableMapOf( "teamId" to teamId, "name" to name, "roles" to roles ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Team = { @@ -99,7 +99,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Team::class.java, - convert = convert + convert = convert, ) } @@ -117,9 +117,9 @@ class Teams(client: Client) : Service(client) { teamId: String ): io.appwrite.models.Team { val path = "/teams/{teamId}".replace("{teamId}", teamId) - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Team = { @@ -131,7 +131,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Team::class.java, - convert = convert + convert = convert, ) } @@ -152,10 +152,10 @@ class Teams(client: Client) : Service(client) { name: String ): io.appwrite.models.Team { val path = "/teams/{teamId}".replace("{teamId}", teamId) - val params = mapOf( + val params = mutableMapOf( "name" to name ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Team = { @@ -167,7 +167,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Team::class.java, - convert = convert + convert = convert, ) } @@ -186,9 +186,9 @@ class Teams(client: Client) : Service(client) { teamId: String ): Any { val path = "/teams/{teamId}".replace("{teamId}", teamId) - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) return client.call( @@ -227,7 +227,7 @@ class Teams(client: Client) : Service(client) { orderType: String? = null ): io.appwrite.models.MembershipList { val path = "/teams/{teamId}/memberships".replace("{teamId}", teamId) - val params = mapOf( + val params = mutableMapOf( "search" to search, "limit" to limit, "offset" to offset, @@ -235,7 +235,7 @@ class Teams(client: Client) : Service(client) { "cursorDirection" to cursorDirection, "orderType" to orderType ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.MembershipList = { @@ -247,7 +247,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.MembershipList::class.java, - convert = convert + convert = convert, ) } @@ -287,13 +287,13 @@ class Teams(client: Client) : Service(client) { name: String? = null ): io.appwrite.models.Membership { val path = "/teams/{teamId}/memberships".replace("{teamId}", teamId) - val params = mapOf( + val params = mutableMapOf( "email" to email, "roles" to roles, "url" to url, "name" to name ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Membership = { @@ -305,7 +305,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Membership::class.java, - convert = convert + convert = convert, ) } @@ -326,9 +326,9 @@ class Teams(client: Client) : Service(client) { membershipId: String ): io.appwrite.models.MembershipList { val path = "/teams/{teamId}/memberships/{membershipId}".replace("{teamId}", teamId).replace("{membershipId}", membershipId) - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.MembershipList = { @@ -340,7 +340,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.MembershipList::class.java, - convert = convert + convert = convert, ) } @@ -364,10 +364,10 @@ class Teams(client: Client) : Service(client) { roles: List ): io.appwrite.models.Membership { val path = "/teams/{teamId}/memberships/{membershipId}".replace("{teamId}", teamId).replace("{membershipId}", membershipId) - val params = mapOf( + val params = mutableMapOf( "roles" to roles ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Membership = { @@ -379,7 +379,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Membership::class.java, - convert = convert + convert = convert, ) } @@ -401,9 +401,9 @@ class Teams(client: Client) : Service(client) { membershipId: String ): Any { val path = "/teams/{teamId}/memberships/{membershipId}".replace("{teamId}", teamId).replace("{membershipId}", membershipId) - val params = mapOf( + val params = mutableMapOf( ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) return client.call( @@ -421,6 +421,10 @@ class Teams(client: Client) : Service(client) { * Use this endpoint to allow a user to accept an invitation to join a team * after being redirected back to your app from the invitation email received * by the user. + * + * If the request is successful, a session for the user is automatically + * created. + * * * @param teamId Team ID. * @param membershipId Membership ID. @@ -437,11 +441,11 @@ class Teams(client: Client) : Service(client) { secret: String ): io.appwrite.models.Membership { val path = "/teams/{teamId}/memberships/{membershipId}/status".replace("{teamId}", teamId).replace("{membershipId}", membershipId) - val params = mapOf( + val params = mutableMapOf( "userId" to userId, "secret" to secret ) - val headers = mapOf( + val headers = mutableMapOf( "content-type" to "application/json" ) val convert: (Map) -> io.appwrite.models.Membership = { @@ -453,7 +457,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Membership::class.java, - convert = convert + convert = convert, ) }