From df55095c54c96e6b9ee6911692db07a275bc0548 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 17 Dec 2021 17:28:28 +0545 Subject: [PATCH 01/21] update twitter link --- README.md | 2 +- build.gradle | 6 +- example-java/build.gradle | 7 +- example-java/src/main/AndroidManifest.xml | 2 +- .../appwrite/example_java/MainActivity.java | 13 +- example/build.gradle | 25 +- example/src/main/AndroidManifest.xml | 4 +- .../android/ui/accounts/AccountsViewModel.kt | 40 +- gradle/wrapper/gradle-wrapper.properties | 2 +- library/build.gradle | 11 +- library/src/main/java/io/appwrite/Client.kt | 106 +++-- .../appwrite/exceptions/AppwriteException.kt | 2 +- .../io/appwrite/json/PreciseNumberAdapter.kt | 64 +++ .../main/java/io/appwrite/models/Continent.kt | 31 ++ .../java/io/appwrite/models/ContinentList.kt | 31 ++ .../main/java/io/appwrite/models/Country.kt | 31 ++ .../java/io/appwrite/models/CountryList.kt | 31 ++ .../main/java/io/appwrite/models/Currency.kt | 71 +++ .../java/io/appwrite/models/CurrencyList.kt | 31 ++ .../main/java/io/appwrite/models/Document.kt | 47 ++ .../java/io/appwrite/models/DocumentList.kt | 34 ++ .../main/java/io/appwrite/models/Execution.kt | 95 ++++ .../java/io/appwrite/models/ExecutionList.kt | 31 ++ .../src/main/java/io/appwrite/models/File.kt | 71 +++ .../main/java/io/appwrite/models/FileList.kt | 31 ++ .../src/main/java/io/appwrite/models/Jwt.kt | 23 + .../main/java/io/appwrite/models/Language.kt | 39 ++ .../java/io/appwrite/models/LanguageList.kt | 31 ++ .../main/java/io/appwrite/models/Locale.kt | 71 +++ .../src/main/java/io/appwrite/models/Log.kt | 151 ++++++ .../main/java/io/appwrite/models/LogList.kt | 23 + .../java/io/appwrite/models/Membership.kt | 87 ++++ .../java/io/appwrite/models/MembershipList.kt | 31 ++ .../java/io/appwrite/models/Permissions.kt | 31 ++ .../src/main/java/io/appwrite/models/Phone.kt | 39 ++ .../main/java/io/appwrite/models/PhoneList.kt | 31 ++ .../java/io/appwrite/models/Preferences.kt | 23 + .../java/io/appwrite/models/RealtimeModels.kt | 1 + .../main/java/io/appwrite/models/Session.kt | 191 ++++++++ .../java/io/appwrite/models/SessionList.kt | 31 ++ .../src/main/java/io/appwrite/models/Team.kt | 47 ++ .../main/java/io/appwrite/models/TeamList.kt | 31 ++ .../src/main/java/io/appwrite/models/Token.kt | 47 ++ .../src/main/java/io/appwrite/models/User.kt | 79 ++++ .../main/java/io/appwrite/services/Account.kt | 447 ++++++++++++------ .../main/java/io/appwrite/services/Avatars.kt | 165 ++++--- .../java/io/appwrite/services/Database.kt | 139 ++++-- .../java/io/appwrite/services/Functions.kt | 77 ++- .../main/java/io/appwrite/services/Locale.kt | 127 +++-- .../java/io/appwrite/services/Realtime.kt | 106 +++-- .../main/java/io/appwrite/services/Storage.kt | 191 +++++--- .../main/java/io/appwrite/services/Teams.kt | 239 ++++++---- 52 files changed, 2710 insertions(+), 607 deletions(-) create mode 100644 library/src/main/java/io/appwrite/json/PreciseNumberAdapter.kt create mode 100644 library/src/main/java/io/appwrite/models/Continent.kt create mode 100644 library/src/main/java/io/appwrite/models/ContinentList.kt create mode 100644 library/src/main/java/io/appwrite/models/Country.kt create mode 100644 library/src/main/java/io/appwrite/models/CountryList.kt create mode 100644 library/src/main/java/io/appwrite/models/Currency.kt create mode 100644 library/src/main/java/io/appwrite/models/CurrencyList.kt create mode 100644 library/src/main/java/io/appwrite/models/Document.kt create mode 100644 library/src/main/java/io/appwrite/models/DocumentList.kt create mode 100644 library/src/main/java/io/appwrite/models/Execution.kt create mode 100644 library/src/main/java/io/appwrite/models/ExecutionList.kt create mode 100644 library/src/main/java/io/appwrite/models/File.kt create mode 100644 library/src/main/java/io/appwrite/models/FileList.kt create mode 100644 library/src/main/java/io/appwrite/models/Jwt.kt create mode 100644 library/src/main/java/io/appwrite/models/Language.kt create mode 100644 library/src/main/java/io/appwrite/models/LanguageList.kt create mode 100644 library/src/main/java/io/appwrite/models/Locale.kt create mode 100644 library/src/main/java/io/appwrite/models/Log.kt create mode 100644 library/src/main/java/io/appwrite/models/LogList.kt create mode 100644 library/src/main/java/io/appwrite/models/Membership.kt create mode 100644 library/src/main/java/io/appwrite/models/MembershipList.kt create mode 100644 library/src/main/java/io/appwrite/models/Permissions.kt create mode 100644 library/src/main/java/io/appwrite/models/Phone.kt create mode 100644 library/src/main/java/io/appwrite/models/PhoneList.kt create mode 100644 library/src/main/java/io/appwrite/models/Preferences.kt create mode 100644 library/src/main/java/io/appwrite/models/Session.kt create mode 100644 library/src/main/java/io/appwrite/models/SessionList.kt create mode 100644 library/src/main/java/io/appwrite/models/Team.kt create mode 100644 library/src/main/java/io/appwrite/models/TeamList.kt create mode 100644 library/src/main/java/io/appwrite/models/Token.kt create mode 100644 library/src/main/java/io/appwrite/models/User.kt diff --git a/README.md b/README.md index 862d6b8..0580a7a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ![License](https://img.shields.io/github/license/appwrite/sdk-for-android.svg?style=flat-square) ![Version](https://img.shields.io/badge/api%20version-0.11.0-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_io?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite_io) +[![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.11.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).** diff --git a/build.gradle b/build.gradle index 4df4d35..d2f3361 100644 --- a/build.gradle +++ b/build.gradle @@ -2,15 +2,15 @@ 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.4.31" - version '0.2.1' + ext.kotlin_version = "1.5.31" + version "0.2.1" repositories { maven { url "https://plugins.gradle.org/m2/" } google() mavenCentral() } dependencies { - classpath "com.android.tools.build:gradle:4.2.0" + classpath "com.android.tools.build:gradle:7.0.3" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'io.github.gradle-nexus:publish-plugin:1.1.0' diff --git a/example-java/build.gradle b/example-java/build.gradle index fb49677..fb916fa 100644 --- a/example-java/build.gradle +++ b/example-java/build.gradle @@ -3,13 +3,12 @@ plugins { } android { - compileSdkVersion 30 - buildToolsVersion "30.0.3" + compileSdkVersion 31 defaultConfig { applicationId "io.appwrite.example_java" minSdkVersion 23 - targetSdkVersion 30 + targetSdkVersion 31 versionCode 1 versionName "1.0" @@ -29,8 +28,8 @@ android { } dependencies { - implementation project(path: ':library') + implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' diff --git a/example-java/src/main/AndroidManifest.xml b/example-java/src/main/AndroidManifest.xml index 1fd3789..0276c9c 100644 --- a/example-java/src/main/AndroidManifest.xml +++ b/example-java/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.AppwriteAndroidSDK"> - + diff --git a/example-java/src/main/java/io/appwrite/example_java/MainActivity.java b/example-java/src/main/java/io/appwrite/example_java/MainActivity.java index 5b0d09b..28e3222 100644 --- a/example-java/src/main/java/io/appwrite/example_java/MainActivity.java +++ b/example-java/src/main/java/io/appwrite/example_java/MainActivity.java @@ -4,15 +4,15 @@ import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; import io.appwrite.Client; import io.appwrite.exceptions.AppwriteException; +import io.appwrite.extensions.JsonExtensionsKt; +import io.appwrite.models.Session; import io.appwrite.services.Account; import kotlin.Result; import kotlin.coroutines.Continuation; import kotlin.coroutines.CoroutineContext; import kotlin.coroutines.EmptyCoroutineContext; -import okhttp3.Response; public class MainActivity extends AppCompatActivity { @@ -28,7 +28,7 @@ public class MainActivity extends AppCompatActivity { Account account = new Account(client); try { - account.createSession("test7@test.com","password", new Continuation() { + account.createSession("test7@test.com","password", new Continuation() { @NotNull @Override public CoroutineContext getContext() { @@ -37,16 +37,13 @@ public class MainActivity extends AppCompatActivity { @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(); - json = new JSONObject(json).toString(8); - Log.d("RESPONSE", json); + Session session = (Session) o; + Log.d("RESPONSE", JsonExtensionsKt.toJson(session)); } } catch (Throwable th) { Log.e("ERROR", th.toString()); diff --git a/example/build.gradle b/example/build.gradle index 6057427..6c5e1f5 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -4,13 +4,12 @@ plugins { } android { - compileSdkVersion 30 - buildToolsVersion "30.0.3" + compileSdkVersion 31 defaultConfig { applicationId "io.appwrite.android" minSdkVersion 21 - targetSdkVersion 30 + targetSdkVersion 31 versionCode 1 versionName "1.0" @@ -37,23 +36,23 @@ android { } dependencies { - implementation project(path: ':library') + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.core:core-ktx:1.5.0' - implementation 'androidx.appcompat:appcompat:1.3.0' - implementation 'com.google.android.material:material:1.3.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.core:core-ktx:1.6.0' + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.1' implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' - implementation "androidx.fragment:fragment-ktx:1.3.2" + implementation "androidx.fragment:fragment-ktx:1.3.6" implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2" testImplementation 'junit:junit:4.+' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' } \ No newline at end of file diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml index 91f2179..e3c2421 100644 --- a/example/src/main/AndroidManifest.xml +++ b/example/src/main/AndroidManifest.xml @@ -9,14 +9,14 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.AppwriteAndroidSDK"> - + - + diff --git a/example/src/main/java/io/appwrite/android/ui/accounts/AccountsViewModel.kt b/example/src/main/java/io/appwrite/android/ui/accounts/AccountsViewModel.kt index 2d812e8..1e7b084 100644 --- a/example/src/main/java/io/appwrite/android/ui/accounts/AccountsViewModel.kt +++ b/example/src/main/java/io/appwrite/android/ui/accounts/AccountsViewModel.kt @@ -6,10 +6,9 @@ import androidx.lifecycle.* import io.appwrite.android.utils.Client.client import io.appwrite.android.utils.Event import io.appwrite.exceptions.AppwriteException +import io.appwrite.extensions.toJson import io.appwrite.services.Account import kotlinx.coroutines.launch -import org.json.JSONObject - class AccountsViewModel : ViewModel() { @@ -27,13 +26,11 @@ class AccountsViewModel : ViewModel() { Account(client) } - fun onLogin(email: Editable , password : Editable) { + fun onLogin(email: Editable, password: Editable) { viewModelScope.launch { try { - var response = accountService.createSession(email.toString(), password.toString()) - var json = response.body?.string() ?: "" - json = JSONObject(json).toString(8) - _response.postValue(Event(json)) + val session = accountService.createSession(email.toString(), password.toString()) + _response.postValue(Event(session.toJson())) } catch (e: AppwriteException) { _error.postValue(Event(e)) } @@ -41,13 +38,12 @@ class AccountsViewModel : ViewModel() { } - fun onSignup(email: Editable , password : Editable, name: Editable) { + fun onSignup(email: Editable, password: Editable, name: Editable) { viewModelScope.launch { try { - var response = accountService.create(email.toString(), password.toString(), name.toString()) - var json = response.body?.string() ?: "" - json = JSONObject(json).toString(2) - _response.postValue(Event(json)) + val user = + accountService.create(email.toString(), password.toString(), name.toString()) + _response.postValue(Event(user.toJson())) } catch (e: AppwriteException) { _error.postValue(Event(e)) } @@ -58,7 +54,12 @@ class AccountsViewModel : ViewModel() { fun oAuthLogin(activity: ComponentActivity) { viewModelScope.launch { try { - accountService.createOAuth2Session(activity, "facebook", "appwrite-callback-6070749e6acd4://demo.appwrite.io/auth/oauth2/success", "appwrite-callback-6070749e6acd4://demo.appwrite.io/auth/oauth2/failure") + accountService.createOAuth2Session( + activity, + "facebook", + "appwrite-callback-6070749e6acd4://demo.appwrite.io/auth/oauth2/success", + "appwrite-callback-6070749e6acd4://demo.appwrite.io/auth/oauth2/failure" + ) } catch (e: Exception) { _error.postValue(Event(e)) } catch (e: AppwriteException) { @@ -70,10 +71,8 @@ class AccountsViewModel : ViewModel() { fun getUser() { viewModelScope.launch { try { - var response = accountService.get() - var json = response.body?.string() ?: "" - json = JSONObject(json).toString(2) - _response.postValue(Event(json)) + val account = accountService.get() + _response.postValue(Event(account.toJson())) } catch (e: AppwriteException) { _error.postValue(Event(e)) } @@ -83,14 +82,11 @@ class AccountsViewModel : ViewModel() { fun logout() { viewModelScope.launch { try { - var response = accountService.deleteSession("current") - var json = response.body?.string()?.ifEmpty { "{}" } - json = JSONObject(json).toString(4) - _response.postValue(Event(json)) + val result = accountService.deleteSession("current") + _response.postValue(Event(result.toJson())) } catch (e: AppwriteException) { _error.postValue(Event(e)) } } } - } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2dadb9d..710f6bd 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Tue Jun 01 15:55:54 IST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/library/build.gradle b/library/build.gradle index 9ae290e..cb15537 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,4 +1,3 @@ -import org.jetbrains.kotlin.config.KotlinCompilerVersion plugins { id("com.android.library") id("kotlin-android") @@ -21,11 +20,11 @@ ext { } android { - compileSdkVersion(30) + compileSdkVersion(31) defaultConfig { minSdkVersion(21) - targetSdkVersion(30) + targetSdkVersion(31) versionCode = 1 versionName = "1.0" buildConfigField "String", "SDK_VERSION", "\"${PUBLISH_VERSION}\"" @@ -52,9 +51,9 @@ android { } dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${KotlinCompilerVersion.VERSION}") - api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1") - api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION}") + api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2") + api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2") api(platform("com.squareup.okhttp3:okhttp-bom:4.9.0")) api("com.squareup.okhttp3:okhttp") diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 4dba7e5..162357e 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -2,10 +2,12 @@ package io.appwrite import android.content.Context import android.content.pm.PackageManager -import com.google.gson.Gson +import com.google.gson.GsonBuilder +import com.google.gson.reflect.TypeToken import io.appwrite.appwrite.BuildConfig import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.fromJson +import io.appwrite.json.PreciseNumberAdapter import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -17,6 +19,7 @@ import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.MediaType.Companion.toMediaType import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody +import java.io.BufferedInputStream import java.io.BufferedReader import java.io.File import java.io.IOException @@ -44,6 +47,11 @@ class Client @JvmOverloads constructor( private val job = Job() + private val gson = GsonBuilder().registerTypeAdapter( + object : TypeToken>(){}.type, + PreciseNumberAdapter() + ).create() + lateinit var http: OkHttpClient private val headers: MutableMap @@ -143,9 +151,12 @@ class Client @JvmOverloads constructor( try { // Create a trust manager that does not validate certificate chains val trustAllCerts = arrayOf( + @Suppress("CustomX509TrustManager") object : X509TrustManager { + @Suppress("TrustAllX509TrustManager") override fun checkClientTrusted(chain: Array, authType: String) { } + @Suppress("TrustAllX509TrustManager") override fun checkServerTrusted(chain: Array, authType: String) { } override fun getAcceptedIssuers(): Array { @@ -223,13 +234,14 @@ class Client @JvmOverloads constructor( * @return [Response] */ @Throws(AppwriteException::class) - suspend fun call( + suspend fun call( method: String, path: String, headers: Map = mapOf(), - params: Map = mapOf() - ): Response { - + params: Map = mapOf(), + responseType: Class, + convert: ((Map) -> T)? = null + ): T { val filteredParams = params.filterValues { it != null } val requestHeaders = this.headers.toHeaders().newBuilder() @@ -264,7 +276,7 @@ class Client @JvmOverloads constructor( .get() .build() - return awaitResponse(request) + return awaitResponse(request, responseType, convert) } val body = if (MultipartBody.FORM.toString() == headers["content-type"]) { @@ -292,7 +304,7 @@ class Client @JvmOverloads constructor( } builder.build() } else { - Gson().toJson(filteredParams) + gson.toJson(filteredParams) .toRequestBody("application/json".toMediaType()) } @@ -302,21 +314,24 @@ class Client @JvmOverloads constructor( .method(method, body) .build() - return awaitResponse(request) + return awaitResponse(request, responseType, convert) } /** * Await Response - * - * @param method - * @param path - * @param headers - * @param params * - * @return [Response] + * @param request + * @param responseType + * @param convert + * + * @return [T] */ @Throws(AppwriteException::class) - private suspend fun awaitResponse(request: Request) = suspendCancellableCoroutine { + private suspend fun awaitResponse( + request: Request, + responseType: Class, + convert: ((Map) -> T)? = null + ) = suspendCancellableCoroutine { http.newCall(request).enqueue(object : Callback { override fun onFailure(call: Call, e: IOException) { if (it.isCancelled) { @@ -325,27 +340,54 @@ class Client @JvmOverloads constructor( it.cancel(e) } + @Suppress("UNCHECKED_CAST") override fun onResponse(call: Call, response: Response) { - if (response.code >= 400) { - val bodyString = response.body - ?.charStream() - ?.buffered() - ?.use(BufferedReader::readText) ?: "" - - val contentType: String = response.headers["content-type"] ?: "" - val error = if (contentType.contains("application/json", ignoreCase = true)) { - bodyString.fromJson() + if (!response.isSuccessful) { + val body = response.body!! + .charStream() + .buffered() + .use(BufferedReader::readText) + val error = if (response.headers["content-type"]?.contains("application/json") == true) { + body.fromJson() } else { - AppwriteException(bodyString, response.code) + AppwriteException(body, response.code) } - - it.cancel(AppwriteException( - error.message, - error.code, - bodyString - )) + it.cancel(error) + return } - it.resume(response) + when { + responseType == Boolean::class.java -> { + it.resume(true as T) + return + } + responseType == ByteArray::class.java -> { + it.resume(response.body!! + .byteStream() + .buffered() + .use(BufferedInputStream::readBytes) as T + ) + return + } + response.body == null -> { + it.resume(true as T) + return + } + } + val body = response.body!! + .charStream() + .buffered() + .use(BufferedReader::readText) + if (body.isEmpty()) { + it.resume(true as T) + return + } + val map = gson.fromJson>( + body, + object : TypeToken>(){}.type + ) + it.resume( + convert?.invoke(map) ?: map as T + ) } }) } diff --git a/library/src/main/java/io/appwrite/exceptions/AppwriteException.kt b/library/src/main/java/io/appwrite/exceptions/AppwriteException.kt index d7d4fbc..1d22595 100644 --- a/library/src/main/java/io/appwrite/exceptions/AppwriteException.kt +++ b/library/src/main/java/io/appwrite/exceptions/AppwriteException.kt @@ -3,7 +3,7 @@ package io.appwrite.exceptions import java.lang.Exception class AppwriteException( - message: String? = null, + override val message: String? = null, val code: Int? = null, val response: String? = null ) : Exception(message) \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/json/PreciseNumberAdapter.kt b/library/src/main/java/io/appwrite/json/PreciseNumberAdapter.kt new file mode 100644 index 0000000..6d408ac --- /dev/null +++ b/library/src/main/java/io/appwrite/json/PreciseNumberAdapter.kt @@ -0,0 +1,64 @@ +package io.appwrite.json + +import com.google.gson.Gson +import com.google.gson.TypeAdapter +import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonToken.* +import com.google.gson.stream.JsonWriter +import java.io.IOException + +internal class PreciseNumberAdapter : TypeAdapter() { + + private val delegate = Gson() + .getAdapter(Any::class.java) + + @Throws(IOException::class) + override fun write(out: JsonWriter?, value: Any?) { + delegate.write(out, value) + } + + @Throws(IOException::class) + override fun read(input: JsonReader): Any? { + return when (input.peek()) { + BEGIN_ARRAY -> { + val list = mutableListOf() + input.beginArray() + while (input.hasNext()) { + list.add(read(input)) + } + input.endArray() + list + } + BEGIN_OBJECT -> { + val map = mutableMapOf() + input.beginObject() + while (input.hasNext()) { + map[input.nextName()] = read(input) + } + input.endObject() + map + } + STRING -> { + input.nextString() + } + NUMBER -> { + val numberString = input.nextString() + if (numberString.indexOf('.') != -1) { + numberString.toDouble() + } else { + numberString.toLong() + } + } + BOOLEAN -> { + input.nextBoolean() + } + NULL -> { + input.nextNull() + null + } + else -> { + throw IllegalStateException() + } + } + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Continent.kt b/library/src/main/java/io/appwrite/models/Continent.kt new file mode 100644 index 0000000..da6eca6 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Continent.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Continent + */ +data class Continent( + /** + * Continent name. + * + */ + val name: String, + + /** + * Continent two letter code. + * + */ + val code: String +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Continent( + name = map["name"] as String, + code = map["code"] as String + ) + } + + fun toMap(): Map = mapOf( + "name" to name as Any, + "code" to code as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/ContinentList.kt b/library/src/main/java/io/appwrite/models/ContinentList.kt new file mode 100644 index 0000000..9b076c4 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/ContinentList.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Continents List + */ +data class ContinentList( + /** + * Total number of items available on the server. + * + */ + val sum: Long, + + /** + * List of continents. + * + */ + val continents: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = ContinentList( + sum = map["sum"] as Long, + continents = (map["continents"] as List>).map { Continent.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "sum" to sum as Any, + "continents" to continents.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Country.kt b/library/src/main/java/io/appwrite/models/Country.kt new file mode 100644 index 0000000..8c1d608 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Country.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Country + */ +data class Country( + /** + * Country name. + * + */ + val name: String, + + /** + * Country two-character ISO 3166-1 alpha code. + * + */ + val code: String +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Country( + name = map["name"] as String, + code = map["code"] as String + ) + } + + fun toMap(): Map = mapOf( + "name" to name as Any, + "code" to code as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/CountryList.kt b/library/src/main/java/io/appwrite/models/CountryList.kt new file mode 100644 index 0000000..a1476a1 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/CountryList.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Countries List + */ +data class CountryList( + /** + * Total number of items available on the server. + * + */ + val sum: Long, + + /** + * List of countries. + * + */ + val countries: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = CountryList( + sum = map["sum"] as Long, + countries = (map["countries"] as List>).map { Country.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "sum" to sum as Any, + "countries" to countries.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Currency.kt b/library/src/main/java/io/appwrite/models/Currency.kt new file mode 100644 index 0000000..58002c2 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Currency.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * Currency + */ +data class Currency( + /** + * Currency symbol. + * + */ + val symbol: String, + + /** + * Currency name. + * + */ + val name: String, + + /** + * Currency native symbol. + * + */ + val symbolNative: String, + + /** + * Number of decimal digits. + * + */ + val decimalDigits: Long, + + /** + * Currency digit rounding. + * + */ + val rounding: Double, + + /** + * Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format. + * + */ + val code: String, + + /** + * Currency plural name + * + */ + val namePlural: String +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Currency( + symbol = map["symbol"] as String, + name = map["name"] as String, + symbolNative = map["symbolNative"] as String, + decimalDigits = map["decimalDigits"] as Long, + rounding = map["rounding"] as Double, + code = map["code"] as String, + namePlural = map["namePlural"] as String + ) + } + + fun toMap(): Map = mapOf( + "symbol" to symbol as Any, + "name" to name as Any, + "symbolNative" to symbolNative as Any, + "decimalDigits" to decimalDigits as Any, + "rounding" to rounding as Any, + "code" to code as Any, + "namePlural" to namePlural as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/CurrencyList.kt b/library/src/main/java/io/appwrite/models/CurrencyList.kt new file mode 100644 index 0000000..d2863d9 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/CurrencyList.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Currencies List + */ +data class CurrencyList( + /** + * Total number of items available on the server. + * + */ + val sum: Long, + + /** + * List of currencies. + * + */ + val currencies: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = CurrencyList( + sum = map["sum"] as Long, + currencies = (map["currencies"] as List>).map { Currency.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "sum" to sum as Any, + "currencies" to currencies.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Document.kt b/library/src/main/java/io/appwrite/models/Document.kt new file mode 100644 index 0000000..0941dfe --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Document.kt @@ -0,0 +1,47 @@ +package io.appwrite.models + +/** + * Document + */ +data class Document( + /** + * Document ID. + * + */ + val id: String, + + /** + * Collection ID. + * + */ + val collection: String, + + /** + * Document permissions. + * + */ + val permissions: Permissions, + + val data: Map +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Document( + id = map["\$id"] as String, + collection = map["\$collection"] as String, + permissions = Permissions.from(map = map["\$permissions"] as Map), + data = map + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "\$collection" to collection as Any, + "\$permissions" to permissions.toMap() as Any, + "data" to data + ) + + fun convertTo(fromJson: (Map) -> T): T { + return fromJson(data) + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/DocumentList.kt b/library/src/main/java/io/appwrite/models/DocumentList.kt new file mode 100644 index 0000000..c05899f --- /dev/null +++ b/library/src/main/java/io/appwrite/models/DocumentList.kt @@ -0,0 +1,34 @@ +package io.appwrite.models + +/** + * Documents List + */ +data class DocumentList( + /** + * Total number of items available on the server. + * + */ + val sum: Long, + + /** + * List of documents. + * + */ + val documents: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = DocumentList( + sum = map["sum"] as Long, + documents = (map["documents"] as List>).map { Document.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "sum" to sum as Any, + "documents" to documents.map { it.toMap() } as Any + ) + + fun convertTo(fromJson: (Map) -> T) = + documents.map { it.convertTo(fromJson = fromJson) } +} \ 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 new file mode 100644 index 0000000..e9e8d8f --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Execution.kt @@ -0,0 +1,95 @@ +package io.appwrite.models + +/** + * Execution + */ +data class Execution( + /** + * Execution ID. + * + */ + val id: String, + + /** + * Execution permissions. + * + */ + val permissions: Permissions, + + /** + * Function ID. + * + */ + val functionId: String, + + /** + * The execution creation date in Unix timestamp. + * + */ + val dateCreated: Long, + + /** + * The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. + * + */ + val trigger: String, + + /** + * The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. + * + */ + val status: String, + + /** + * The script exit code. + * + */ + val exitCode: Long, + + /** + * The script stdout output string. Logs the last 4,000 characters of the execution stdout output. + * + */ + val stdout: String, + + /** + * The script stderr output string. Logs the last 4,000 characters of the execution stderr output + * + */ + val stderr: String, + + /** + * The script execution time in seconds. + * + */ + val time: Double +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Execution( + id = map["\$id"] as String, + permissions = Permissions.from(map = map["\$permissions"] as Map), + functionId = map["functionId"] as String, + dateCreated = map["dateCreated"] as Long, + trigger = map["trigger"] as String, + status = map["status"] as String, + exitCode = map["exitCode"] as Long, + stdout = map["stdout"] as String, + stderr = map["stderr"] as String, + time = map["time"] as Double + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "\$permissions" to permissions.toMap() as Any, + "functionId" to functionId as Any, + "dateCreated" to dateCreated as Any, + "trigger" to trigger as Any, + "status" to status as Any, + "exitCode" to exitCode as Any, + "stdout" to stdout as Any, + "stderr" to stderr as Any, + "time" to time as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/ExecutionList.kt b/library/src/main/java/io/appwrite/models/ExecutionList.kt new file mode 100644 index 0000000..5ab06b7 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/ExecutionList.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Executions List + */ +data class ExecutionList( + /** + * Total number of items available on the server. + * + */ + val sum: Long, + + /** + * List of executions. + * + */ + val executions: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = ExecutionList( + sum = map["sum"] as Long, + executions = (map["executions"] as List>).map { Execution.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "sum" to sum as Any, + "executions" to executions.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/File.kt b/library/src/main/java/io/appwrite/models/File.kt new file mode 100644 index 0000000..daa35c2 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/File.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * File + */ +data class File( + /** + * File ID. + * + */ + val id: String, + + /** + * File permissions. + * + */ + val permissions: Permissions, + + /** + * File name. + * + */ + val name: String, + + /** + * File creation date in Unix timestamp. + * + */ + val dateCreated: Long, + + /** + * File MD5 signature. + * + */ + val signature: String, + + /** + * File mime type. + * + */ + val mimeType: String, + + /** + * File original size in bytes. + * + */ + val sizeOriginal: Long +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = File( + id = map["\$id"] as String, + permissions = Permissions.from(map = map["\$permissions"] as Map), + name = map["name"] as String, + dateCreated = map["dateCreated"] as Long, + signature = map["signature"] as String, + mimeType = map["mimeType"] as String, + sizeOriginal = map["sizeOriginal"] as Long + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "\$permissions" to permissions.toMap() 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 + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/FileList.kt b/library/src/main/java/io/appwrite/models/FileList.kt new file mode 100644 index 0000000..4c9cf1c --- /dev/null +++ b/library/src/main/java/io/appwrite/models/FileList.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Files List + */ +data class FileList( + /** + * Total number of items available on the server. + * + */ + val sum: Long, + + /** + * List of files. + * + */ + val files: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = FileList( + sum = map["sum"] as Long, + files = (map["files"] as List>).map { File.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "sum" to sum as Any, + "files" to files.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Jwt.kt b/library/src/main/java/io/appwrite/models/Jwt.kt new file mode 100644 index 0000000..4012643 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Jwt.kt @@ -0,0 +1,23 @@ +package io.appwrite.models + +/** + * JWT + */ +data class Jwt( + /** + * JWT encoded string. + * + */ + val jwt: String +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Jwt( + jwt = map["jwt"] as String + ) + } + + fun toMap(): Map = mapOf( + "jwt" to jwt as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Language.kt b/library/src/main/java/io/appwrite/models/Language.kt new file mode 100644 index 0000000..0f050a8 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Language.kt @@ -0,0 +1,39 @@ +package io.appwrite.models + +/** + * Language + */ +data class Language( + /** + * Language name. + * + */ + val name: String, + + /** + * Language two-character ISO 639-1 codes. + * + */ + val code: String, + + /** + * Language native name. + * + */ + val nativeName: String +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Language( + name = map["name"] as String, + code = map["code"] as String, + nativeName = map["nativeName"] as String + ) + } + + fun toMap(): Map = mapOf( + "name" to name as Any, + "code" to code as Any, + "nativeName" to nativeName as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/LanguageList.kt b/library/src/main/java/io/appwrite/models/LanguageList.kt new file mode 100644 index 0000000..813c99b --- /dev/null +++ b/library/src/main/java/io/appwrite/models/LanguageList.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Languages List + */ +data class LanguageList( + /** + * Total number of items available on the server. + * + */ + val sum: Long, + + /** + * List of languages. + * + */ + val languages: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = LanguageList( + sum = map["sum"] as Long, + languages = (map["languages"] as List>).map { Language.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "sum" to sum as Any, + "languages" to languages.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Locale.kt b/library/src/main/java/io/appwrite/models/Locale.kt new file mode 100644 index 0000000..6e812c5 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Locale.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * Locale + */ +data class Locale( + /** + * User IP address. + * + */ + val ip: String, + + /** + * Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format + * + */ + val countryCode: String, + + /** + * Country name. This field support localization. + * + */ + val country: String, + + /** + * Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America. + * + */ + val continentCode: String, + + /** + * Continent name. This field support localization. + * + */ + val continent: String, + + /** + * True if country is part of the Europian Union. + * + */ + val eu: Boolean, + + /** + * Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format + * + */ + val currency: String +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Locale( + ip = map["ip"] as String, + countryCode = map["countryCode"] as String, + country = map["country"] as String, + continentCode = map["continentCode"] as String, + continent = map["continent"] as String, + eu = map["eu"] as Boolean, + currency = map["currency"] as String + ) + } + + fun toMap(): Map = mapOf( + "ip" to ip as Any, + "countryCode" to countryCode as Any, + "country" to country as Any, + "continentCode" to continentCode as Any, + "continent" to continent as Any, + "eu" to eu as Any, + "currency" to currency as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Log.kt b/library/src/main/java/io/appwrite/models/Log.kt new file mode 100644 index 0000000..028aa71 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Log.kt @@ -0,0 +1,151 @@ +package io.appwrite.models + +/** + * Log + */ +data class Log( + /** + * Event name. + * + */ + val event: String, + + /** + * IP session in use when the session was created. + * + */ + val ip: String, + + /** + * Log creation time in Unix timestamp. + * + */ + val time: Long, + + /** + * Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + * + */ + val osCode: String, + + /** + * Operating system name. + * + */ + val osName: String, + + /** + * Operating system version. + * + */ + val osVersion: String, + + /** + * Client type. + * + */ + val clientType: String, + + /** + * Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + * + */ + val clientCode: String, + + /** + * Client name. + * + */ + val clientName: String, + + /** + * Client version. + * + */ + val clientVersion: String, + + /** + * Client engine name. + * + */ + val clientEngine: String, + + /** + * Client engine name. + * + */ + val clientEngineVersion: String, + + /** + * Device name. + * + */ + val deviceName: String, + + /** + * Device brand name. + * + */ + val deviceBrand: String, + + /** + * Device model name. + * + */ + val deviceModel: String, + + /** + * Country two-character ISO 3166-1 alpha code. + * + */ + val countryCode: String, + + /** + * Country name. + * + */ + val countryName: String +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Log( + event = map["event"] as String, + ip = map["ip"] as String, + time = map["time"] as Long, + osCode = map["osCode"] as String, + osName = map["osName"] as String, + osVersion = map["osVersion"] as String, + clientType = map["clientType"] as String, + clientCode = map["clientCode"] as String, + clientName = map["clientName"] as String, + clientVersion = map["clientVersion"] as String, + clientEngine = map["clientEngine"] as String, + clientEngineVersion = map["clientEngineVersion"] as String, + deviceName = map["deviceName"] as String, + deviceBrand = map["deviceBrand"] as String, + deviceModel = map["deviceModel"] as String, + countryCode = map["countryCode"] as String, + countryName = map["countryName"] as String + ) + } + + fun toMap(): Map = mapOf( + "event" to event as Any, + "ip" to ip as Any, + "time" to time as Any, + "osCode" to osCode as Any, + "osName" to osName as Any, + "osVersion" to osVersion as Any, + "clientType" to clientType as Any, + "clientCode" to clientCode as Any, + "clientName" to clientName as Any, + "clientVersion" to clientVersion as Any, + "clientEngine" to clientEngine as Any, + "clientEngineVersion" to clientEngineVersion as Any, + "deviceName" to deviceName as Any, + "deviceBrand" to deviceBrand as Any, + "deviceModel" to deviceModel as Any, + "countryCode" to countryCode as Any, + "countryName" to countryName as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/LogList.kt b/library/src/main/java/io/appwrite/models/LogList.kt new file mode 100644 index 0000000..a741ae4 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/LogList.kt @@ -0,0 +1,23 @@ +package io.appwrite.models + +/** + * Logs List + */ +data class LogList( + /** + * List of logs. + * + */ + val logs: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = LogList( + logs = (map["logs"] as List>).map { Log.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "logs" to logs.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Membership.kt b/library/src/main/java/io/appwrite/models/Membership.kt new file mode 100644 index 0000000..9e0266f --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Membership.kt @@ -0,0 +1,87 @@ +package io.appwrite.models + +/** + * Membership + */ +data class Membership( + /** + * Membership ID. + * + */ + val id: String, + + /** + * User ID. + * + */ + val userId: String, + + /** + * Team ID. + * + */ + val teamId: String, + + /** + * User name. + * + */ + val name: String, + + /** + * User email address. + * + */ + val email: String, + + /** + * Date, the user has been invited to join the team in Unix timestamp. + * + */ + val invited: Long, + + /** + * Date, the user has accepted the invitation to join the team in Unix timestamp. + * + */ + val joined: Long, + + /** + * User confirmation status, true if the user has joined the team or false otherwise. + * + */ + val confirm: Boolean, + + /** + * User list of roles + * + */ + val roles: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Membership( + id = map["\$id"] as String, + userId = map["userId"] as String, + teamId = map["teamId"] as String, + name = map["name"] as String, + email = map["email"] as String, + invited = map["invited"] as Long, + joined = map["joined"] as Long, + confirm = map["confirm"] as Boolean, + roles = map["roles"] as List + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "userId" to userId as Any, + "teamId" to teamId as Any, + "name" to name as Any, + "email" to email as Any, + "invited" to invited as Any, + "joined" to joined as Any, + "confirm" to confirm as Any, + "roles" to roles as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/MembershipList.kt b/library/src/main/java/io/appwrite/models/MembershipList.kt new file mode 100644 index 0000000..3935263 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/MembershipList.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Memberships List + */ +data class MembershipList( + /** + * Total number of items available on the server. + * + */ + val sum: Long, + + /** + * List of memberships. + * + */ + val memberships: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = MembershipList( + sum = map["sum"] as Long, + memberships = (map["memberships"] as List>).map { Membership.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "sum" to sum as Any, + "memberships" to memberships.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Permissions.kt b/library/src/main/java/io/appwrite/models/Permissions.kt new file mode 100644 index 0000000..81cd07d --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Permissions.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Permissions + */ +data class Permissions( + /** + * Read permissions. + * + */ + val read: List, + + /** + * Write permissions. + * + */ + val write: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Permissions( + read = map["read"] as List, + write = map["write"] as List + ) + } + + fun toMap(): Map = mapOf( + "read" to read as Any, + "write" to write as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Phone.kt b/library/src/main/java/io/appwrite/models/Phone.kt new file mode 100644 index 0000000..a11de9d --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Phone.kt @@ -0,0 +1,39 @@ +package io.appwrite.models + +/** + * Phone + */ +data class Phone( + /** + * Phone code. + * + */ + val code: String, + + /** + * Country two-character ISO 3166-1 alpha code. + * + */ + val countryCode: String, + + /** + * Country name. + * + */ + val countryName: String +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Phone( + code = map["code"] as String, + countryCode = map["countryCode"] as String, + countryName = map["countryName"] as String + ) + } + + fun toMap(): Map = mapOf( + "code" to code as Any, + "countryCode" to countryCode as Any, + "countryName" to countryName as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/PhoneList.kt b/library/src/main/java/io/appwrite/models/PhoneList.kt new file mode 100644 index 0000000..a7b92d0 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/PhoneList.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Phones List + */ +data class PhoneList( + /** + * Total number of items available on the server. + * + */ + val sum: Long, + + /** + * List of phones. + * + */ + val phones: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = PhoneList( + sum = map["sum"] as Long, + phones = (map["phones"] as List>).map { Phone.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "sum" to sum as Any, + "phones" to phones.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Preferences.kt b/library/src/main/java/io/appwrite/models/Preferences.kt new file mode 100644 index 0000000..a95850f --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Preferences.kt @@ -0,0 +1,23 @@ +package io.appwrite.models + +/** + * Preferences + */ +data class Preferences( + val data: Map +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Preferences( + data = map + ) + } + + fun toMap(): Map = mapOf( + "data" to data + ) + + fun convertTo(fromJson: (Map) -> T): T { + return fromJson(data) + } +} \ 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 b4990c8..e2b012a 100644 --- a/library/src/main/java/io/appwrite/models/RealtimeModels.kt +++ b/library/src/main/java/io/appwrite/models/RealtimeModels.kt @@ -9,6 +9,7 @@ data class RealtimeSubscription( } data class RealtimeCallback( + val channels: Collection, val payloadClass: Class<*>, val callback: (RealtimeResponseEvent<*>) -> Unit ) diff --git a/library/src/main/java/io/appwrite/models/Session.kt b/library/src/main/java/io/appwrite/models/Session.kt new file mode 100644 index 0000000..fa8a91f --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Session.kt @@ -0,0 +1,191 @@ +package io.appwrite.models + +/** + * Session + */ +data class Session( + /** + * Session ID. + * + */ + val id: String, + + /** + * User ID. + * + */ + val userId: String, + + /** + * Session expiration date in Unix timestamp. + * + */ + val expire: Long, + + /** + * Session Provider. + * + */ + val provider: String, + + /** + * Session Provider User ID. + * + */ + val providerUid: String, + + /** + * Session Provider Token. + * + */ + val providerToken: String, + + /** + * IP in use when the session was created. + * + */ + val ip: String, + + /** + * Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + * + */ + val osCode: String, + + /** + * Operating system name. + * + */ + val osName: String, + + /** + * Operating system version. + * + */ + val osVersion: String, + + /** + * Client type. + * + */ + val clientType: String, + + /** + * Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + * + */ + val clientCode: String, + + /** + * Client name. + * + */ + val clientName: String, + + /** + * Client version. + * + */ + val clientVersion: String, + + /** + * Client engine name. + * + */ + val clientEngine: String, + + /** + * Client engine name. + * + */ + val clientEngineVersion: String, + + /** + * Device name. + * + */ + val deviceName: String, + + /** + * Device brand name. + * + */ + val deviceBrand: String, + + /** + * Device model name. + * + */ + val deviceModel: String, + + /** + * Country two-character ISO 3166-1 alpha code. + * + */ + val countryCode: String, + + /** + * Country name. + * + */ + val countryName: String, + + /** + * Returns true if this the current user session. + * + */ + val current: Boolean +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Session( + id = map["\$id"] as String, + userId = map["userId"] as String, + expire = map["expire"] as Long, + provider = map["provider"] as String, + providerUid = map["providerUid"] as String, + providerToken = map["providerToken"] as String, + ip = map["ip"] as String, + osCode = map["osCode"] as String, + osName = map["osName"] as String, + osVersion = map["osVersion"] as String, + clientType = map["clientType"] as String, + clientCode = map["clientCode"] as String, + clientName = map["clientName"] as String, + clientVersion = map["clientVersion"] as String, + clientEngine = map["clientEngine"] as String, + clientEngineVersion = map["clientEngineVersion"] as String, + deviceName = map["deviceName"] as String, + deviceBrand = map["deviceBrand"] as String, + deviceModel = map["deviceModel"] as String, + countryCode = map["countryCode"] as String, + countryName = map["countryName"] as String, + current = map["current"] as Boolean + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "userId" to userId as Any, + "expire" to expire as Any, + "provider" to provider as Any, + "providerUid" to providerUid as Any, + "providerToken" to providerToken as Any, + "ip" to ip as Any, + "osCode" to osCode as Any, + "osName" to osName as Any, + "osVersion" to osVersion as Any, + "clientType" to clientType as Any, + "clientCode" to clientCode as Any, + "clientName" to clientName as Any, + "clientVersion" to clientVersion as Any, + "clientEngine" to clientEngine as Any, + "clientEngineVersion" to clientEngineVersion as Any, + "deviceName" to deviceName as Any, + "deviceBrand" to deviceBrand as Any, + "deviceModel" to deviceModel as Any, + "countryCode" to countryCode as Any, + "countryName" to countryName as Any, + "current" to current as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/SessionList.kt b/library/src/main/java/io/appwrite/models/SessionList.kt new file mode 100644 index 0000000..655701d --- /dev/null +++ b/library/src/main/java/io/appwrite/models/SessionList.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Sessions List + */ +data class SessionList( + /** + * Total number of items available on the server. + * + */ + val sum: Long, + + /** + * List of sessions. + * + */ + val sessions: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = SessionList( + sum = map["sum"] as Long, + sessions = (map["sessions"] as List>).map { Session.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "sum" to sum as Any, + "sessions" to sessions.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Team.kt b/library/src/main/java/io/appwrite/models/Team.kt new file mode 100644 index 0000000..414886a --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Team.kt @@ -0,0 +1,47 @@ +package io.appwrite.models + +/** + * Team + */ +data class Team( + /** + * Team ID. + * + */ + val id: String, + + /** + * Team name. + * + */ + val name: String, + + /** + * Team creation date in Unix timestamp. + * + */ + val dateCreated: Long, + + /** + * Total sum of team members. + * + */ + val sum: Long +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Team( + id = map["\$id"] as String, + name = map["name"] as String, + dateCreated = map["dateCreated"] as Long, + sum = map["sum"] as Long + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "name" to name as Any, + "dateCreated" to dateCreated as Any, + "sum" to sum as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/TeamList.kt b/library/src/main/java/io/appwrite/models/TeamList.kt new file mode 100644 index 0000000..3adca8d --- /dev/null +++ b/library/src/main/java/io/appwrite/models/TeamList.kt @@ -0,0 +1,31 @@ +package io.appwrite.models + +/** + * Teams List + */ +data class TeamList( + /** + * Total number of items available on the server. + * + */ + val sum: Long, + + /** + * List of teams. + * + */ + val teams: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = TeamList( + sum = map["sum"] as Long, + teams = (map["teams"] as List>).map { Team.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "sum" to sum as Any, + "teams" to teams.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Token.kt b/library/src/main/java/io/appwrite/models/Token.kt new file mode 100644 index 0000000..5041d1a --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Token.kt @@ -0,0 +1,47 @@ +package io.appwrite.models + +/** + * Token + */ +data class Token( + /** + * Token ID. + * + */ + val id: String, + + /** + * User ID. + * + */ + val userId: String, + + /** + * Token secret key. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + * + */ + val secret: String, + + /** + * Token expiration date in Unix timestamp. + * + */ + val expire: Long +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Token( + id = map["\$id"] as String, + userId = map["userId"] as String, + secret = map["secret"] as String, + expire = map["expire"] as Long + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "userId" to userId as Any, + "secret" to secret as Any, + "expire" to expire as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/User.kt b/library/src/main/java/io/appwrite/models/User.kt new file mode 100644 index 0000000..82039e4 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/User.kt @@ -0,0 +1,79 @@ +package io.appwrite.models + +/** + * User + */ +data class User( + /** + * User ID. + * + */ + val id: String, + + /** + * User name. + * + */ + val name: String, + + /** + * User registration date in Unix timestamp. + * + */ + val registration: Long, + + /** + * User status. 0 for Unactivated, 1 for active and 2 is blocked. + * + */ + val status: Long, + + /** + * Unix timestamp of the most recent password update + * + */ + val passwordUpdate: Long, + + /** + * User email address. + * + */ + val email: String, + + /** + * Email verification status. + * + */ + val emailVerification: Boolean, + + /** + * User preferences as a key-value object + * + */ + val prefs: Preferences +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = User( + id = map["\$id"] as String, + name = map["name"] as String, + registration = map["registration"] as Long, + status = map["status"] as Long, + passwordUpdate = map["passwordUpdate"] as Long, + email = map["email"] as String, + emailVerification = map["emailVerification"] as Boolean, + prefs = Preferences.from(map = map["prefs"] as Map) + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "name" to name as Any, + "registration" to registration as Any, + "status" to status as Any, + "passwordUpdate" to passwordUpdate as Any, + "email" to email as Any, + "emailVerification" to emailVerification as Any, + "prefs" to prefs.toMap() as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/services/Account.kt b/library/src/main/java/io/appwrite/services/Account.kt index 89206d3..063d602 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -2,6 +2,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client +import io.appwrite.models.* import io.appwrite.WebAuthComponent import androidx.activity.ComponentActivity import io.appwrite.exceptions.AppwriteException @@ -18,20 +19,28 @@ class Account(client: Client) : Service(client) { * * Get currently logged in user data as JSON object. * - * @return [Response] + * @return [io.appwrite.models.User] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun get(): Response { + suspend fun get(): io.appwrite.models.User { val path = "/account" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.User::class.java, + convert = convert + ) } /** @@ -44,10 +53,10 @@ class Account(client: Client) : Service(client) { * login to their new account, you need to create a new [account * session](/docs/client/account#accountCreateSession). * - * @param email - * @param password - * @param name - * @return [Response] + * @param email User email. + * @param password User password. Must be between 6 to 32 chars. + * @param name User name. Max length: 128 chars. + * @return [io.appwrite.models.User] */ @JvmOverloads @Throws(AppwriteException::class) @@ -55,19 +64,27 @@ class Account(client: Client) : Service(client) { email: String, password: String, name: String? = null - ): Response { + ): io.appwrite.models.User { val path = "/account" val params = mapOf( "email" to email, "password" to password, "name" to name ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("POST", path, headers, params) + val convert: (Map) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it) + } + return client.call( + "POST", + path, + headers, + params, + responseType = io.appwrite.models.User::class.java, + convert = convert + ) } /** @@ -79,20 +96,24 @@ class Account(client: Client) : Service(client) { * address. Any user-related resources like documents or storage files should * be deleted separately. * - * @return [Response] + * @return [Any] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun delete(): Response { + suspend fun delete(): Any { val path = "/account" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("DELETE", path, headers, params) + return client.call( + "DELETE", + path, + headers, + params, + responseType = Any::class.java, + ) } /** @@ -105,27 +126,35 @@ class Account(client: Client) : Service(client) { * This endpoint can also be used to convert an anonymous account to a normal * one, by passing an email address and a new password. * - * @param email - * @param password - * @return [Response] + * @param email User email. + * @param password User password. Must be between 6 to 32 chars. + * @return [io.appwrite.models.User] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun updateEmail( email: String, password: String - ): Response { + ): io.appwrite.models.User { val path = "/account/email" val params = mapOf( "email" to email, "password" to password ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("PATCH", path, headers, params) + val convert: (Map) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it) + } + return client.call( + "PATCH", + path, + headers, + params, + responseType = io.appwrite.models.User::class.java, + convert = convert + ) } /** @@ -137,20 +166,28 @@ class Account(client: Client) : Service(client) { * from its creation and will be invalid if the user will logout in that time * frame. * - * @return [Response] + * @return [io.appwrite.models.Jwt] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun createJWT(): Response { + suspend fun createJWT(): io.appwrite.models.Jwt { val path = "/account/jwt" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("POST", path, headers, params) + val convert: (Map) -> io.appwrite.models.Jwt = { + io.appwrite.models.Jwt.from(map = it) + } + return client.call( + "POST", + path, + headers, + params, + responseType = io.appwrite.models.Jwt::class.java, + convert = convert + ) } /** @@ -159,20 +196,28 @@ class Account(client: Client) : Service(client) { * Get currently logged in user list of latest security activity logs. Each * log returns user IP address, location and date and time of log. * - * @return [Response] + * @return [io.appwrite.models.LogList] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun getLogs(): Response { + suspend fun getLogs(): io.appwrite.models.LogList { val path = "/account/logs" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.LogList = { + io.appwrite.models.LogList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.LogList::class.java, + convert = convert + ) } /** @@ -180,24 +225,32 @@ class Account(client: Client) : Service(client) { * * Update currently logged in user account name. * - * @param name - * @return [Response] + * @param name User name. Max length: 128 chars. + * @return [io.appwrite.models.User] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun updateName( name: String - ): Response { + ): io.appwrite.models.User { val path = "/account/name" val params = mapOf( "name" to name ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("PATCH", path, headers, params) + val convert: (Map) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it) + } + return client.call( + "PATCH", + path, + headers, + params, + responseType = io.appwrite.models.User::class.java, + convert = convert + ) } /** @@ -207,27 +260,35 @@ class Account(client: Client) : Service(client) { * to pass in the new password, and the old password. For users created with * OAuth and Team Invites, oldPassword is optional. * - * @param password - * @param oldPassword - * @return [Response] + * @param password New user password. Must be between 6 to 32 chars. + * @param oldPassword Old user password. Must be between 6 to 32 chars. + * @return [io.appwrite.models.User] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun updatePassword( password: String, oldPassword: String? = null - ): Response { + ): io.appwrite.models.User { val path = "/account/password" val params = mapOf( "password" to password, "oldPassword" to oldPassword ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("PATCH", path, headers, params) + val convert: (Map) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it) + } + return client.call( + "PATCH", + path, + headers, + params, + responseType = io.appwrite.models.User::class.java, + convert = convert + ) } /** @@ -235,20 +296,28 @@ class Account(client: Client) : Service(client) { * * Get currently logged in user preferences as a key-value object. * - * @return [Response] + * @return [io.appwrite.models.Preferences] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun getPrefs(): Response { + suspend fun getPrefs(): io.appwrite.models.Preferences { val path = "/account/prefs" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.Preferences = { + io.appwrite.models.Preferences.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.Preferences::class.java, + convert = convert + ) } /** @@ -257,24 +326,32 @@ class Account(client: Client) : Service(client) { * Update currently logged in user account preferences. You can pass only the * specific settings you wish to update. * - * @param prefs - * @return [Response] + * @param prefs Prefs key-value JSON object. + * @return [io.appwrite.models.User] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun updatePrefs( prefs: Any - ): Response { + ): io.appwrite.models.User { val path = "/account/prefs" val params = mapOf( "prefs" to prefs ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("PATCH", path, headers, params) + val convert: (Map) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it) + } + return client.call( + "PATCH", + path, + headers, + params, + responseType = io.appwrite.models.User::class.java, + convert = convert + ) } /** @@ -289,27 +366,35 @@ class Account(client: Client) : Service(client) { * complete the process. The verification link sent to the user's email * address is valid for 1 hour. * - * @param email - * @param url - * @return [Response] + * @param email User email. + * @param url URL to redirect the user back to your app from the recovery email. 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] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun createRecovery( email: String, url: String - ): Response { + ): io.appwrite.models.Token { val path = "/account/recovery" val params = mapOf( "email" to email, "url" to url ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("POST", path, headers, params) + val convert: (Map) -> io.appwrite.models.Token = { + io.appwrite.models.Token.from(map = it) + } + return client.call( + "POST", + path, + headers, + params, + responseType = io.appwrite.models.Token::class.java, + convert = convert + ) } /** @@ -325,11 +410,11 @@ class Account(client: Client) : Service(client) { * the only valid redirect URLs are the ones from domains you have set when * adding your platforms in the console interface. * - * @param userId - * @param secret - * @param password - * @param passwordAgain - * @return [Response] + * @param userId User account UID address. + * @param secret Valid reset token. + * @param password New password. Must be between 6 to 32 chars. + * @param passwordAgain New password again. Must be between 6 to 32 chars. + * @return [io.appwrite.models.Token] */ @JvmOverloads @Throws(AppwriteException::class) @@ -338,7 +423,7 @@ class Account(client: Client) : Service(client) { secret: String, password: String, passwordAgain: String - ): Response { + ): io.appwrite.models.Token { val path = "/account/recovery" val params = mapOf( "userId" to userId, @@ -346,12 +431,20 @@ class Account(client: Client) : Service(client) { "password" to password, "passwordAgain" to passwordAgain ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("PUT", path, headers, params) + val convert: (Map) -> io.appwrite.models.Token = { + io.appwrite.models.Token.from(map = it) + } + return client.call( + "PUT", + path, + headers, + params, + responseType = io.appwrite.models.Token::class.java, + convert = convert + ) } /** @@ -360,20 +453,28 @@ class Account(client: Client) : Service(client) { * Get currently logged in user list of active sessions across different * devices. * - * @return [Response] + * @return [io.appwrite.models.SessionList] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun getSessions(): Response { + suspend fun getSessions(): io.appwrite.models.SessionList { val path = "/account/sessions" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.SessionList = { + io.appwrite.models.SessionList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.SessionList::class.java, + convert = convert + ) } /** @@ -382,27 +483,35 @@ class Account(client: Client) : Service(client) { * Allow the user to login into their account by providing a valid email and * password combination. This route will create a new session for the user. * - * @param email - * @param password - * @return [Response] + * @param email User email. + * @param password User password. Must be between 6 to 32 chars. + * @return [io.appwrite.models.Session] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun createSession( email: String, password: String - ): Response { + ): io.appwrite.models.Session { val path = "/account/sessions" val params = mapOf( "email" to email, "password" to password ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("POST", path, headers, params) + val convert: (Map) -> io.appwrite.models.Session = { + io.appwrite.models.Session.from(map = it) + } + return client.call( + "POST", + path, + headers, + params, + responseType = io.appwrite.models.Session::class.java, + convert = convert + ) } /** @@ -411,20 +520,24 @@ class Account(client: Client) : Service(client) { * Delete all sessions from the user account and remove any sessions cookies * from the end client. * - * @return [Response] + * @return [Any] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun deleteSessions(): Response { + suspend fun deleteSessions(): Any { val path = "/account/sessions" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("DELETE", path, headers, params) + return client.call( + "DELETE", + path, + headers, + params, + responseType = Any::class.java, + ) } /** @@ -437,20 +550,28 @@ class Account(client: Client) : Service(client) { * password](/docs/client/account#accountUpdateEmail) or create an [OAuth2 * session](/docs/client/account#accountCreateOAuth2Session). * - * @return [Response] + * @return [io.appwrite.models.Session] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun createAnonymousSession(): Response { + suspend fun createAnonymousSession(): io.appwrite.models.Session { val path = "/account/sessions/anonymous" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("POST", path, headers, params) + val convert: (Map) -> io.appwrite.models.Session = { + io.appwrite.models.Session.from(map = it) + } + return client.call( + "POST", + path, + headers, + params, + responseType = io.appwrite.models.Session::class.java, + convert = convert + ) } /** @@ -467,27 +588,35 @@ 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 email - * @param url - * @return [Response] + * @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] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun createMagicURLSession( email: String, url: String? = null - ): Response { + ): io.appwrite.models.Token { val path = "/account/sessions/magic-url" val params = mapOf( "email" to email, "url" to url ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("POST", path, headers, params) + val convert: (Map) -> io.appwrite.models.Token = { + io.appwrite.models.Token.from(map = it) + } + return client.call( + "POST", + path, + headers, + params, + responseType = io.appwrite.models.Token::class.java, + convert = convert + ) } /** @@ -505,27 +634,35 @@ class Account(client: Client) : Service(client) { * the only valid redirect URLs are the ones from domains you have set when * adding your platforms in the console interface. * - * @param userId - * @param secret - * @return [Response] + * @param userId User unique ID. + * @param secret Valid verification token. + * @return [io.appwrite.models.Session] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun updateMagicURLSession( userId: String, secret: String - ): Response { + ): io.appwrite.models.Session { val path = "/account/sessions/magic-url" val params = mapOf( "userId" to userId, "secret" to secret ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("PUT", path, headers, params) + val convert: (Map) -> io.appwrite.models.Session = { + io.appwrite.models.Session.from(map = it) + } + return client.call( + "PUT", + path, + headers, + params, + responseType = io.appwrite.models.Session::class.java, + convert = convert + ) } /** @@ -544,10 +681,10 @@ class Account(client: Client) : Service(client) { * user.. * * - * @param provider - * @param success - * @param failure - * @param scopes + * @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, yandex, wordpress. + * @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. * */ @JvmOverloads @@ -566,7 +703,6 @@ class Account(client: Client) : Service(client) { "scopes" to scopes, "project" to client.config["project"] ) - val query = mutableListOf() params.forEach { when (it.value) { @@ -609,7 +745,6 @@ class Account(client: Client) : Service(client) { listOf(cookie) ) } - } /** @@ -618,23 +753,31 @@ class Account(client: Client) : Service(client) { * Use this endpoint to get a logged in user's session using a Session ID. * Inputting 'current' will return the current session being used. * - * @param sessionId - * @return [Response] + * @param sessionId Session unique ID. Use the string 'current' to get the current device session. + * @return [io.appwrite.models.Session] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getSession( sessionId: String - ): Response { + ): io.appwrite.models.Session { val path = "/account/sessions/{sessionId}".replace("{sessionId}", sessionId) val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.Session = { + io.appwrite.models.Session.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.Session::class.java, + convert = convert + ) } /** @@ -644,23 +787,27 @@ class Account(client: Client) : Service(client) { * account sessions across all of their different devices. When using the * option id argument, only the session unique ID provider will be deleted. * - * @param sessionId - * @return [Response] + * @param sessionId Session unique ID. Use the string 'current' to delete the current device session. + * @return [Any] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun deleteSession( sessionId: String - ): Response { + ): Any { val path = "/account/sessions/{sessionId}".replace("{sessionId}", sessionId) val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("DELETE", path, headers, params) + return client.call( + "DELETE", + path, + headers, + params, + responseType = Any::class.java, + ) } /** @@ -682,24 +829,32 @@ class Account(client: Client) : Service(client) { * adding your platforms in the console interface. * * - * @param url - * @return [Response] + * @param url URL to redirect the user back to your app from the verification email. 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] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun createVerification( url: String - ): Response { + ): io.appwrite.models.Token { val path = "/account/verification" val params = mapOf( "url" to url ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("POST", path, headers, params) + val convert: (Map) -> io.appwrite.models.Token = { + io.appwrite.models.Token.from(map = it) + } + return client.call( + "POST", + path, + headers, + params, + responseType = io.appwrite.models.Token::class.java, + convert = convert + ) } /** @@ -710,27 +865,35 @@ class Account(client: Client) : Service(client) { * to verify the user email ownership. If confirmed this route will return a * 200 status code. * - * @param userId - * @param secret - * @return [Response] + * @param userId User unique ID. + * @param secret Valid verification token. + * @return [io.appwrite.models.Token] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun updateVerification( userId: String, secret: String - ): Response { + ): io.appwrite.models.Token { val path = "/account/verification" val params = mapOf( "userId" to userId, "secret" to secret ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("PUT", path, headers, params) + val convert: (Map) -> io.appwrite.models.Token = { + io.appwrite.models.Token.from(map = it) + } + return client.call( + "PUT", + path, + headers, + params, + responseType = io.appwrite.models.Token::class.java, + convert = convert + ) } } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/services/Avatars.kt b/library/src/main/java/io/appwrite/services/Avatars.kt index 3e0432f..912b1e5 100644 --- a/library/src/main/java/io/appwrite/services/Avatars.kt +++ b/library/src/main/java/io/appwrite/services/Avatars.kt @@ -2,6 +2,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client +import io.appwrite.models.* import io.appwrite.exceptions.AppwriteException import okhttp3.Cookie import okhttp3.Response @@ -19,20 +20,20 @@ class Avatars(client: Client) : Service(client) { * /account/sessions endpoint. Use width, height and quality arguments to * change the output settings. * - * @param code - * @param width - * @param height - * @param quality - * @return [Response] + * @param code Browser Code. + * @param width Image width. Pass an integer between 0 to 2000. Defaults to 100. + * @param height Image height. Pass an integer between 0 to 2000. Defaults to 100. + * @param quality Image quality. Pass an integer between 0 to 100. Defaults to 100. + * @return [ByteArray] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getBrowser( code: String, - width: Int? = null, - height: Int? = null, - quality: Int? = null - ): Response { + width: Long? = null, + height: Long? = null, + quality: Long? = null + ): ByteArray { val path = "/avatars/browsers/{code}".replace("{code}", code) val params = mapOf( "width" to width, @@ -40,8 +41,12 @@ class Avatars(client: Client) : Service(client) { "quality" to quality, "project" to client.config["project"] ) - - return client.call("GET", path, params = params) + return client.call( + "GET", + path, + params = params, + responseType = ByteArray::class.java + ) } /** @@ -51,20 +56,20 @@ class Avatars(client: Client) : Service(client) { * provider you need. Use width, height and quality arguments to change the * output settings. * - * @param code - * @param width - * @param height - * @param quality - * @return [Response] + * @param code Credit Card Code. Possible values: amex, argencard, cabal, censosud, diners, discover, elo, hipercard, jcb, mastercard, naranja, targeta-shopping, union-china-pay, visa, mir, maestro. + * @param width Image width. Pass an integer between 0 to 2000. Defaults to 100. + * @param height Image height. Pass an integer between 0 to 2000. Defaults to 100. + * @param quality Image quality. Pass an integer between 0 to 100. Defaults to 100. + * @return [ByteArray] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getCreditCard( code: String, - width: Int? = null, - height: Int? = null, - quality: Int? = null - ): Response { + width: Long? = null, + height: Long? = null, + quality: Long? = null + ): ByteArray { val path = "/avatars/credit-cards/{code}".replace("{code}", code) val params = mapOf( "width" to width, @@ -72,8 +77,12 @@ class Avatars(client: Client) : Service(client) { "quality" to quality, "project" to client.config["project"] ) - - return client.call("GET", path, params = params) + return client.call( + "GET", + path, + params = params, + responseType = ByteArray::class.java + ) } /** @@ -83,21 +92,25 @@ class Avatars(client: Client) : Service(client) { * website URL. * * - * @param url - * @return [Response] + * @param url Website URL which you want to fetch the favicon from. + * @return [ByteArray] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getFavicon( url: String - ): Response { + ): ByteArray { val path = "/avatars/favicon" val params = mapOf( "url" to url, "project" to client.config["project"] ) - - return client.call("GET", path, params = params) + return client.call( + "GET", + path, + params = params, + responseType = ByteArray::class.java + ) } /** @@ -107,20 +120,20 @@ class Avatars(client: Client) : Service(client) { * users. The code argument receives the 2 letter country code. Use width, * height and quality arguments to change the output settings. * - * @param code - * @param width - * @param height - * @param quality - * @return [Response] + * @param code Country Code. ISO Alpha-2 country code format. + * @param width Image width. Pass an integer between 0 to 2000. Defaults to 100. + * @param height Image height. Pass an integer between 0 to 2000. Defaults to 100. + * @param quality Image quality. Pass an integer between 0 to 100. Defaults to 100. + * @return [ByteArray] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getFlag( code: String, - width: Int? = null, - height: Int? = null, - quality: Int? = null - ): Response { + width: Long? = null, + height: Long? = null, + quality: Long? = null + ): ByteArray { val path = "/avatars/flags/{code}".replace("{code}", code) val params = mapOf( "width" to width, @@ -128,8 +141,12 @@ class Avatars(client: Client) : Service(client) { "quality" to quality, "project" to client.config["project"] ) - - return client.call("GET", path, params = params) + return client.call( + "GET", + path, + params = params, + responseType = ByteArray::class.java + ) } /** @@ -140,18 +157,18 @@ class Avatars(client: Client) : Service(client) { * remote images in your app or in case you want to make sure a 3rd party * image is properly served using a TLS protocol. * - * @param url - * @param width - * @param height - * @return [Response] + * @param url Image URL which you want to crop. + * @param width Resize preview image width, Pass an integer between 0 to 2000. + * @param height Resize preview image height, Pass an integer between 0 to 2000. + * @return [ByteArray] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getImage( url: String, - width: Int? = null, - height: Int? = null - ): Response { + width: Long? = null, + height: Long? = null + ): ByteArray { val path = "/avatars/image" val params = mapOf( "url" to url, @@ -159,8 +176,12 @@ class Avatars(client: Client) : Service(client) { "height" to height, "project" to client.config["project"] ) - - return client.call("GET", path, params = params) + return client.call( + "GET", + path, + params = params, + responseType = ByteArray::class.java + ) } /** @@ -177,22 +198,22 @@ class Avatars(client: Client) : Service(client) { * the user's initials when reloading the same theme will always return for * the same initials. * - * @param name - * @param width - * @param height - * @param color - * @param background - * @return [Response] + * @param name Full Name. When empty, current user name or email will be used. Max length: 128 chars. + * @param width Image width. Pass an integer between 0 to 2000. Defaults to 100. + * @param height Image height. Pass an integer between 0 to 2000. Defaults to 100. + * @param color Changes text color. By default a random color will be picked and stay will persistent to the given name. + * @param background Changes background color. By default a random color will be picked and stay will persistent to the given name. + * @return [ByteArray] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getInitials( name: String? = null, - width: Int? = null, - height: Int? = null, + width: Long? = null, + height: Long? = null, color: String? = null, background: String? = null - ): Response { + ): ByteArray { val path = "/avatars/initials" val params = mapOf( "name" to name, @@ -202,8 +223,12 @@ class Avatars(client: Client) : Service(client) { "background" to background, "project" to client.config["project"] ) - - return client.call("GET", path, params = params) + return client.call( + "GET", + path, + params = params, + responseType = ByteArray::class.java + ) } /** @@ -212,20 +237,20 @@ class Avatars(client: Client) : Service(client) { * Converts a given plain text to a QR code image. You can use the query * parameters to change the size and style of the resulting image. * - * @param text - * @param size - * @param margin - * @param download - * @return [Response] + * @param text Plain text to be converted to QR code image. + * @param size QR code size. Pass an integer between 0 to 1000. Defaults to 400. + * @param margin Margin from edge. Pass an integer between 0 to 10. Defaults to 1. + * @param download Return resulting image with 'Content-Disposition: attachment ' headers for the browser to start downloading it. Pass 0 for no header, or 1 for otherwise. Default value is set to 0. + * @return [ByteArray] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getQR( text: String, - size: Int? = null, - margin: Int? = null, + size: Long? = null, + margin: Long? = null, download: Boolean? = null - ): Response { + ): ByteArray { val path = "/avatars/qr" val params = mapOf( "text" to text, @@ -234,8 +259,12 @@ class Avatars(client: Client) : Service(client) { "download" to download, "project" to client.config["project"] ) - - return client.call("GET", path, params = params) + return client.call( + "GET", + path, + params = params, + responseType = ByteArray::class.java + ) } } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/services/Database.kt b/library/src/main/java/io/appwrite/services/Database.kt index 6333532..6baecdc 100644 --- a/library/src/main/java/io/appwrite/services/Database.kt +++ b/library/src/main/java/io/appwrite/services/Database.kt @@ -2,6 +2,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client +import io.appwrite.models.* import io.appwrite.exceptions.AppwriteException import okhttp3.Cookie import okhttp3.Response @@ -17,28 +18,28 @@ class Database(client: Client) : Service(client) { * of the project's documents. [Learn more about different API * modes](/docs/admin). * - * @param collectionId - * @param filters - * @param limit - * @param offset - * @param orderField - * @param orderType - * @param orderCast - * @param search - * @return [Response] + * @param collectionId Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection). + * @param filters Array of filter strings. Each filter is constructed from a key name, comparison operator (=, !=, >, <, <=, >=) and a value. You can also use a dot (.) separator in attribute names to filter by child document attributes. Examples: 'name=John Doe' or 'category.$id>=5bed2d152c362'. + * @param limit Maximum number of documents to return in response. Use this value to manage pagination. 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. + * @param orderField Document field that results will be sorted by. + * @param orderType Order direction. Possible values are DESC for descending order, or ASC for ascending order. + * @param orderCast Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string. + * @param search Search query. Enter any free text search. The database will try to find a match against all document attributes and children. Max length: 256 chars. + * @return [io.appwrite.models.DocumentList] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun listDocuments( collectionId: String, filters: List? = null, - limit: Int? = null, - offset: Int? = null, + limit: Long? = null, + offset: Long? = null, orderField: String? = null, orderType: String? = null, orderCast: String? = null, search: String? = null - ): Response { + ): io.appwrite.models.DocumentList { val path = "/database/collections/{collectionId}/documents".replace("{collectionId}", collectionId) val params = mapOf( "filters" to filters, @@ -49,12 +50,20 @@ class Database(client: Client) : Service(client) { "orderCast" to orderCast, "search" to search ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.DocumentList = { + io.appwrite.models.DocumentList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.DocumentList::class.java, + convert = convert + ) } /** @@ -65,14 +74,14 @@ class Database(client: Client) : Service(client) { * integration](/docs/server/database#databaseCreateCollection) API or * directly from your database console. * - * @param collectionId - * @param data - * @param read - * @param write - * @param parentDocument - * @param parentProperty - * @param parentPropertyType - * @return [Response] + * @param collectionId Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection). + * @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](/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](/docs/permissions) and get a full list of available permissions. + * @param parentDocument Parent document unique ID. Use when you want your new document to be a child of a parent document. + * @param parentProperty Parent document property name. Use when you want your new document to be a child of a parent document. + * @param parentPropertyType Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. Use when you want your new document to be a child of a parent document. + * @return [io.appwrite.models.Document] */ @JvmOverloads @Throws(AppwriteException::class) @@ -84,7 +93,7 @@ class Database(client: Client) : Service(client) { parentDocument: String? = null, parentProperty: String? = null, parentPropertyType: String? = null - ): Response { + ): io.appwrite.models.Document { val path = "/database/collections/{collectionId}/documents".replace("{collectionId}", collectionId) val params = mapOf( "data" to data, @@ -94,12 +103,20 @@ class Database(client: Client) : Service(client) { "parentProperty" to parentProperty, "parentPropertyType" to parentPropertyType ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("POST", path, headers, params) + val convert: (Map) -> io.appwrite.models.Document = { + io.appwrite.models.Document.from(map = it) + } + return client.call( + "POST", + path, + headers, + params, + responseType = io.appwrite.models.Document::class.java, + convert = convert + ) } /** @@ -108,25 +125,33 @@ class Database(client: Client) : Service(client) { * Get a document by its unique ID. This endpoint response returns a JSON * object with the document data. * - * @param collectionId - * @param documentId - * @return [Response] + * @param collectionId Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection). + * @param documentId Document unique ID. + * @return [io.appwrite.models.Document] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getDocument( collectionId: String, documentId: String - ): Response { + ): io.appwrite.models.Document { val path = "/database/collections/{collectionId}/documents/{documentId}".replace("{collectionId}", collectionId).replace("{documentId}", documentId) val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.Document = { + io.appwrite.models.Document.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.Document::class.java, + convert = convert + ) } /** @@ -135,12 +160,12 @@ class Database(client: Client) : Service(client) { * Update a document by its unique ID. Using the patch method you can pass * only specific fields that will get updated. * - * @param collectionId - * @param documentId - * @param data - * @param read - * @param write - * @return [Response] + * @param collectionId Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection). + * @param documentId Document unique ID. + * @param data Document data as JSON object. + * @param read An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. + * @param write An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. + * @return [io.appwrite.models.Document] */ @JvmOverloads @Throws(AppwriteException::class) @@ -150,19 +175,27 @@ class Database(client: Client) : Service(client) { data: Any, read: List? = null, write: List? = null - ): Response { + ): io.appwrite.models.Document { val path = "/database/collections/{collectionId}/documents/{documentId}".replace("{collectionId}", collectionId).replace("{documentId}", documentId) val params = mapOf( "data" to data, "read" to read, "write" to write ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("PATCH", path, headers, params) + val convert: (Map) -> io.appwrite.models.Document = { + io.appwrite.models.Document.from(map = it) + } + return client.call( + "PATCH", + path, + headers, + params, + responseType = io.appwrite.models.Document::class.java, + convert = convert + ) } /** @@ -172,25 +205,29 @@ class Database(client: Client) : Service(client) { * documents, its attributes and relations to other documents. Child documents * **will not** be deleted. * - * @param collectionId - * @param documentId - * @return [Response] + * @param collectionId Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection). + * @param documentId Document unique ID. + * @return [Any] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun deleteDocument( collectionId: String, documentId: String - ): Response { + ): Any { val path = "/database/collections/{collectionId}/documents/{documentId}".replace("{collectionId}", collectionId).replace("{documentId}", documentId) val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("DELETE", path, headers, params) + return client.call( + "DELETE", + path, + headers, + params, + responseType = Any::class.java, + ) } } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/services/Functions.kt b/library/src/main/java/io/appwrite/services/Functions.kt index 95a915f..83ac165 100644 --- a/library/src/main/java/io/appwrite/services/Functions.kt +++ b/library/src/main/java/io/appwrite/services/Functions.kt @@ -2,6 +2,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client +import io.appwrite.models.* import io.appwrite.exceptions.AppwriteException import okhttp3.Cookie import okhttp3.Response @@ -17,22 +18,22 @@ class Functions(client: Client) : Service(client) { * return a list of all of the project's executions. [Learn more about * different API modes](/docs/admin). * - * @param functionId - * @param search - * @param limit - * @param offset - * @param orderType - * @return [Response] + * @param functionId Function unique ID. + * @param search Search term to filter your list results. Max length: 256 chars. + * @param limit Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request. + * @param offset Results offset. The default value is 0. Use this param to manage pagination. + * @param orderType Order result by ASC or DESC order. + * @return [io.appwrite.models.ExecutionList] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun listExecutions( functionId: String, search: String? = null, - limit: Int? = null, - offset: Int? = null, + limit: Long? = null, + offset: Long? = null, orderType: String? = null - ): Response { + ): io.appwrite.models.ExecutionList { val path = "/functions/{functionId}/executions".replace("{functionId}", functionId) val params = mapOf( "search" to search, @@ -40,12 +41,20 @@ class Functions(client: Client) : Service(client) { "offset" to offset, "orderType" to orderType ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.ExecutionList = { + io.appwrite.models.ExecutionList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.ExecutionList::class.java, + convert = convert + ) } /** @@ -56,26 +65,34 @@ class Functions(client: Client) : Service(client) { * updates on the current execution status. Once this endpoint is called, your * function execution process will start asynchronously. * - * @param functionId - * @param data - * @return [Response] + * @param functionId Function unique ID. + * @param data String of custom data to send to function. + * @return [io.appwrite.models.Execution] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun createExecution( functionId: String, data: String? = null - ): Response { + ): io.appwrite.models.Execution { val path = "/functions/{functionId}/executions".replace("{functionId}", functionId) val params = mapOf( "data" to data ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("POST", path, headers, params) + val convert: (Map) -> io.appwrite.models.Execution = { + io.appwrite.models.Execution.from(map = it) + } + return client.call( + "POST", + path, + headers, + params, + responseType = io.appwrite.models.Execution::class.java, + convert = convert + ) } /** @@ -83,25 +100,33 @@ class Functions(client: Client) : Service(client) { * * Get a function execution log by its unique ID. * - * @param functionId - * @param executionId - * @return [Response] + * @param functionId Function unique ID. + * @param executionId Execution unique ID. + * @return [io.appwrite.models.Execution] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getExecution( functionId: String, executionId: String - ): Response { + ): io.appwrite.models.Execution { val path = "/functions/{functionId}/executions/{executionId}".replace("{functionId}", functionId).replace("{executionId}", executionId) val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.Execution = { + io.appwrite.models.Execution.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.Execution::class.java, + convert = convert + ) } } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/services/Locale.kt b/library/src/main/java/io/appwrite/services/Locale.kt index 415df78..423a323 100644 --- a/library/src/main/java/io/appwrite/services/Locale.kt +++ b/library/src/main/java/io/appwrite/services/Locale.kt @@ -2,6 +2,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client +import io.appwrite.models.* import io.appwrite.exceptions.AppwriteException import okhttp3.Cookie import okhttp3.Response @@ -19,20 +20,28 @@ class Locale(client: Client) : Service(client) { * * ([IP Geolocation by DB-IP](https://db-ip.com)) * - * @return [Response] + * @return [io.appwrite.models.Locale] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun get(): Response { + suspend fun get(): io.appwrite.models.Locale { val path = "/locale" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.Locale = { + io.appwrite.models.Locale.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.Locale::class.java, + convert = convert + ) } /** @@ -41,20 +50,28 @@ class Locale(client: Client) : Service(client) { * List of all continents. You can use the locale header to get the data in a * supported language. * - * @return [Response] + * @return [io.appwrite.models.ContinentList] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun getContinents(): Response { + suspend fun getContinents(): io.appwrite.models.ContinentList { val path = "/locale/continents" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.ContinentList = { + io.appwrite.models.ContinentList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.ContinentList::class.java, + convert = convert + ) } /** @@ -63,20 +80,28 @@ class Locale(client: Client) : Service(client) { * List of all countries. You can use the locale header to get the data in a * supported language. * - * @return [Response] + * @return [io.appwrite.models.CountryList] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun getCountries(): Response { + suspend fun getCountries(): io.appwrite.models.CountryList { val path = "/locale/countries" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.CountryList = { + io.appwrite.models.CountryList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.CountryList::class.java, + convert = convert + ) } /** @@ -85,20 +110,28 @@ class Locale(client: Client) : Service(client) { * List of all countries that are currently members of the EU. You can use the * locale header to get the data in a supported language. * - * @return [Response] + * @return [io.appwrite.models.CountryList] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun getCountriesEU(): Response { + suspend fun getCountriesEU(): io.appwrite.models.CountryList { val path = "/locale/countries/eu" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.CountryList = { + io.appwrite.models.CountryList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.CountryList::class.java, + convert = convert + ) } /** @@ -107,20 +140,28 @@ class Locale(client: Client) : Service(client) { * List of all countries phone codes. You can use the locale header to get the * data in a supported language. * - * @return [Response] + * @return [io.appwrite.models.PhoneList] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun getCountriesPhones(): Response { + suspend fun getCountriesPhones(): io.appwrite.models.PhoneList { val path = "/locale/countries/phones" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.PhoneList = { + io.appwrite.models.PhoneList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.PhoneList::class.java, + convert = convert + ) } /** @@ -130,20 +171,28 @@ class Locale(client: Client) : Service(client) { * decimal digits for all major and minor currencies. You can use the locale * header to get the data in a supported language. * - * @return [Response] + * @return [io.appwrite.models.CurrencyList] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun getCurrencies(): Response { + suspend fun getCurrencies(): io.appwrite.models.CurrencyList { val path = "/locale/currencies" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.CurrencyList = { + io.appwrite.models.CurrencyList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.CurrencyList::class.java, + convert = convert + ) } /** @@ -152,20 +201,28 @@ class Locale(client: Client) : Service(client) { * List of all languages classified by ISO 639-1 including 2-letter code, name * in English, and name in the respective language. * - * @return [Response] + * @return [io.appwrite.models.LanguageList] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun getLanguages(): Response { + suspend fun getLanguages(): io.appwrite.models.LanguageList { val path = "/locale/languages" val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.LanguageList = { + io.appwrite.models.LanguageList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.LanguageList::class.java, + convert = convert + ) } } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/services/Realtime.kt b/library/src/main/java/io/appwrite/services/Realtime.kt index cec1dad..316054a 100644 --- a/library/src/main/java/io/appwrite/services/Realtime.kt +++ b/library/src/main/java/io/appwrite/services/Realtime.kt @@ -15,6 +15,7 @@ import okhttp3.WebSocketListener import okhttp3.internal.concurrent.TaskRunner import okhttp3.internal.ws.RealWebSocket import java.util.* +import android.util.Log import kotlin.coroutines.CoroutineContext class Realtime(client: Client) : Service(client), CoroutineScope { @@ -31,17 +32,24 @@ class Realtime(client: Client) : Service(client), CoroutineScope { private const val DEBOUNCE_MILLIS = 1L private var socket: RealWebSocket? = null - private var channelCallbacks = mutableMapOf>() - private var errorCallbacks = mutableSetOf<(AppwriteException) -> Unit>() + private var activeChannels = mutableSetOf() + private var activeSubscriptions = mutableMapOf() private var subCallDepth = 0 + private var reconnectAttempts = 0 + private var subscriptionsCounter = 0 + private var reconnect = true } private fun createSocket() { + if (activeChannels.isEmpty()) { + return + } + val queryParamBuilder = StringBuilder() .append("project=${client.config["project"]}") - channelCallbacks.keys.forEach { + activeChannels.forEach { queryParamBuilder .append("&channels[]=$it") } @@ -51,6 +59,7 @@ class Realtime(client: Client) : Service(client), CoroutineScope { .build() if (socket != null) { + reconnect = false closeSocket() } @@ -71,6 +80,13 @@ class Realtime(client: Client) : Service(client), CoroutineScope { socket?.close(RealtimeCode.POLICY_VIOLATION.value, null) } + private fun getTimeout() = when { + reconnectAttempts < 5 -> 1000L + reconnectAttempts < 15 -> 5000L + reconnectAttempts < 100 -> 10000L + else -> 60000L + } + fun subscribe( vararg channels: String, callback: (RealtimeResponseEvent) -> Unit, @@ -85,20 +101,14 @@ class Realtime(client: Client) : Service(client), CoroutineScope { payloadType: Class, callback: (RealtimeResponseEvent) -> Unit, ): RealtimeSubscription { - channels.forEach { - if (!channelCallbacks.containsKey(it)) { - channelCallbacks[it] = mutableListOf( - RealtimeCallback( - payloadType, - callback as (RealtimeResponseEvent<*>) -> Unit - ) - ) - return@forEach - } - channelCallbacks[it]?.add( - RealtimeCallback(payloadType, callback as (RealtimeResponseEvent<*>) -> Unit) - ) - } + val counter = subscriptionsCounter++ + + activeChannels.addAll(channels) + activeSubscriptions[counter] = RealtimeCallback( + channels.toList(), + payloadType, + callback as (RealtimeResponseEvent<*>) -> Unit + ) launch { subCallDepth++ @@ -109,25 +119,31 @@ class Realtime(client: Client) : Service(client), CoroutineScope { subCallDepth-- } - return RealtimeSubscription { unsubscribe(*channels) } - } - - fun unsubscribe(vararg channels: String) { - channels.forEach { - channelCallbacks[it] = mutableListOf() - } - if (channelCallbacks.all { it.value.isEmpty() }) { - errorCallbacks = mutableSetOf() - closeSocket() + return RealtimeSubscription { + activeSubscriptions.remove(counter) + cleanUp(*channels) + createSocket() } } - fun doOnError(callback: (AppwriteException) -> Unit) { - errorCallbacks.add(callback) + private fun cleanUp(vararg channels: String) { + activeChannels.removeAll { channel -> + if (!channels.contains(channel)) { + return@removeAll false + } + activeSubscriptions.values.none { callback -> + callback.channels.contains(channel) + } + } } private inner class AppwriteWebSocketListener : WebSocketListener() { + override fun onOpen(webSocket: WebSocket, response: Response) { + super.onOpen(webSocket, response) + reconnectAttempts = 0 + } + override fun onMessage(webSocket: WebSocket, text: String) { super.onMessage(webSocket, text) @@ -141,27 +157,43 @@ class Realtime(client: Client) : Service(client), CoroutineScope { } private fun handleResponseError(message: RealtimeResponse) { - val error = message.data.jsonCast() - errorCallbacks.forEach { it.invoke(error) } + throw message.data.jsonCast() } private suspend fun handleResponseEvent(message: RealtimeResponse) { val event = message.data.jsonCast>() - event.channels.forEachAsync { channel -> - channelCallbacks[channel]?.forEachAsync { callbackWrapper -> - event.payload = event.payload.jsonCast(callbackWrapper.payloadClass) - callbackWrapper.callback.invoke(event) + if (event.channels.isEmpty()) { + return + } + if (!event.channels.any { activeChannels.contains(it) }) { + return + } + activeSubscriptions.values.forEachAsync { subscription -> + if (event.channels.any { subscription.channels.contains(it) }) { + event.payload = event.payload.jsonCast(subscription.payloadClass) + subscription.callback(event) } } } override fun onClosing(webSocket: WebSocket, code: Int, reason: String) { super.onClosing(webSocket, code, reason) - if (code == RealtimeCode.POLICY_VIOLATION.value) { + if (!reconnect || code == RealtimeCode.POLICY_VIOLATION.value) { + reconnect = true return } + + val timeout = getTimeout() + + Log.e( + this@Realtime::class.java.name, + "Realtime disconnected. Re-connecting in ${timeout / 1000} seconds.", + AppwriteException(reason, code) + ) + launch { - delay(1000) + delay(timeout) + reconnectAttempts++ createSocket() } } diff --git a/library/src/main/java/io/appwrite/services/Storage.kt b/library/src/main/java/io/appwrite/services/Storage.kt index 777b759..1b1941e 100644 --- a/library/src/main/java/io/appwrite/services/Storage.kt +++ b/library/src/main/java/io/appwrite/services/Storage.kt @@ -2,6 +2,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client +import io.appwrite.models.* import io.appwrite.exceptions.AppwriteException import okhttp3.Cookie import okhttp3.Response @@ -18,20 +19,20 @@ 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 search - * @param limit - * @param offset - * @param orderType - * @return [Response] + * @param search Search term to filter your list results. Max length: 256 chars. + * @param limit Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request. + * @param offset Results offset. The default value is 0. Use this param to manage pagination. + * @param orderType Order result by ASC or DESC order. + * @return [io.appwrite.models.FileList] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun listFiles( search: String? = null, - limit: Int? = null, - offset: Int? = null, + limit: Long? = null, + offset: Long? = null, orderType: String? = null - ): Response { + ): io.appwrite.models.FileList { val path = "/storage/files" val params = mapOf( "search" to search, @@ -39,12 +40,20 @@ class Storage(client: Client) : Service(client) { "offset" to offset, "orderType" to orderType ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.FileList = { + io.appwrite.models.FileList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.FileList::class.java, + convert = convert + ) } /** @@ -54,10 +63,10 @@ class Storage(client: Client) : Service(client) { * assigned to read and write access unless he has passed custom values for * read and write arguments. * - * @param file - * @param read - * @param write - * @return [Response] + * @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](/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](/docs/permissions) and get a full list of available permissions. + * @return [io.appwrite.models.File] */ @JvmOverloads @Throws(AppwriteException::class) @@ -65,19 +74,27 @@ class Storage(client: Client) : Service(client) { file: File, read: List? = null, write: List? = null - ): Response { + ): io.appwrite.models.File { val path = "/storage/files" val params = mapOf( "file" to file, "read" to read, "write" to write ) - val headers = mapOf( "content-type" to "multipart/form-data" ) - - return client.call("POST", path, headers, params) + val convert: (Map) -> io.appwrite.models.File = { + io.appwrite.models.File.from(map = it) + } + return client.call( + "POST", + path, + headers, + params, + responseType = io.appwrite.models.File::class.java, + convert = convert + ) } /** @@ -86,23 +103,31 @@ 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 fileId - * @return [Response] + * @param fileId File unique ID. + * @return [io.appwrite.models.File] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getFile( fileId: String - ): Response { + ): io.appwrite.models.File { val path = "/storage/files/{fileId}".replace("{fileId}", fileId) val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.File = { + io.appwrite.models.File.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.File::class.java, + convert = convert + ) } /** @@ -111,10 +136,10 @@ 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 - * @param read - * @param write - * @return [Response] + * @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](/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](/docs/permissions) and get a full list of available permissions. + * @return [io.appwrite.models.File] */ @JvmOverloads @Throws(AppwriteException::class) @@ -122,18 +147,26 @@ class Storage(client: Client) : Service(client) { fileId: String, read: List, write: List - ): Response { + ): io.appwrite.models.File { val path = "/storage/files/{fileId}".replace("{fileId}", fileId) val params = mapOf( "read" to read, "write" to write ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("PUT", path, headers, params) + val convert: (Map) -> io.appwrite.models.File = { + io.appwrite.models.File.from(map = it) + } + return client.call( + "PUT", + path, + headers, + params, + responseType = io.appwrite.models.File::class.java, + convert = convert + ) } /** @@ -142,23 +175,27 @@ 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 fileId - * @return [Response] + * @param fileId File unique ID. + * @return [Any] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun deleteFile( fileId: String - ): Response { + ): Any { val path = "/storage/files/{fileId}".replace("{fileId}", fileId) val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("DELETE", path, headers, params) + return client.call( + "DELETE", + path, + headers, + params, + responseType = Any::class.java, + ) } /** @@ -168,20 +205,24 @@ class Storage(client: Client) : Service(client) { * 'Content-Disposition: attachment' header that tells the browser to start * downloading the file to user downloads directory. * - * @param fileId - * @return [Response] + * @param fileId File unique ID. + * @return [ByteArray] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getFileDownload( fileId: String - ): Response { + ): ByteArray { val path = "/storage/files/{fileId}/download".replace("{fileId}", fileId) val params = mapOf( "project" to client.config["project"] ) - - return client.call("GET", path, params = params) + return client.call( + "GET", + path, + params = params, + responseType = ByteArray::class.java + ) } /** @@ -192,36 +233,36 @@ class Storage(client: Client) : Service(client) { * and spreadsheets, will return the file icon image. You can also pass query * string arguments for cutting and resizing your preview image. * - * @param fileId - * @param width - * @param height - * @param gravity - * @param quality - * @param borderWidth - * @param borderColor - * @param borderRadius - * @param opacity - * @param rotation - * @param background - * @param output - * @return [Response] + * @param fileId File unique 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 + * @param quality Preview image quality. Pass an integer between 0 to 100. Defaults to 100. + * @param borderWidth Preview image border in pixels. Pass an integer between 0 to 100. Defaults to 0. + * @param borderColor Preview image border color. Use a valid HEX color, no # is needed for prefix. + * @param borderRadius Preview image border radius in pixels. Pass an integer between 0 to 4000. + * @param opacity Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1. + * @param rotation Preview image rotation in degrees. Pass an integer between 0 and 360. + * @param background Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix. + * @param output Output format type (jpeg, jpg, png, gif and webp). + * @return [ByteArray] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getFilePreview( fileId: String, - width: Int? = null, - height: Int? = null, + width: Long? = null, + height: Long? = null, gravity: String? = null, - quality: Int? = null, - borderWidth: Int? = null, + quality: Long? = null, + borderWidth: Long? = null, borderColor: String? = null, - borderRadius: Int? = null, + borderRadius: Long? = null, opacity: Double? = null, - rotation: Int? = null, + rotation: Long? = null, background: String? = null, output: String? = null - ): Response { + ): ByteArray { val path = "/storage/files/{fileId}/preview".replace("{fileId}", fileId) val params = mapOf( "width" to width, @@ -237,8 +278,12 @@ class Storage(client: Client) : Service(client) { "output" to output, "project" to client.config["project"] ) - - return client.call("GET", path, params = params) + return client.call( + "GET", + path, + params = params, + responseType = ByteArray::class.java + ) } /** @@ -248,20 +293,24 @@ class Storage(client: Client) : Service(client) { * download method but returns with no 'Content-Disposition: attachment' * header. * - * @param fileId - * @return [Response] + * @param fileId File unique ID. + * @return [ByteArray] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getFileView( fileId: String - ): Response { + ): ByteArray { val path = "/storage/files/{fileId}/view".replace("{fileId}", fileId) val params = mapOf( "project" to client.config["project"] ) - - return client.call("GET", path, params = params) + return client.call( + "GET", + path, + params = params, + responseType = ByteArray::class.java + ) } } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/services/Teams.kt b/library/src/main/java/io/appwrite/services/Teams.kt index 741fd03..90dcba1 100644 --- a/library/src/main/java/io/appwrite/services/Teams.kt +++ b/library/src/main/java/io/appwrite/services/Teams.kt @@ -2,6 +2,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client +import io.appwrite.models.* import io.appwrite.exceptions.AppwriteException import okhttp3.Cookie import okhttp3.Response @@ -17,20 +18,20 @@ class Teams(client: Client) : Service(client) { * of the project's teams. [Learn more about different API * modes](/docs/admin). * - * @param search - * @param limit - * @param offset - * @param orderType - * @return [Response] + * @param search Search term to filter your list results. Max length: 256 chars. + * @param limit Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request. + * @param offset Results offset. The default value is 0. Use this param to manage pagination. + * @param orderType Order result by ASC or DESC order. + * @return [io.appwrite.models.TeamList] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun list( search: String? = null, - limit: Int? = null, - offset: Int? = null, + limit: Long? = null, + offset: Long? = null, orderType: String? = null - ): Response { + ): io.appwrite.models.TeamList { val path = "/teams" val params = mapOf( "search" to search, @@ -38,12 +39,20 @@ class Teams(client: Client) : Service(client) { "offset" to offset, "orderType" to orderType ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.TeamList = { + io.appwrite.models.TeamList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.TeamList::class.java, + convert = convert + ) } /** @@ -54,27 +63,35 @@ class Teams(client: Client) : Service(client) { * who will be able add new owners and update or delete the team from your * project. * - * @param name - * @param roles - * @return [Response] + * @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] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun create( name: String, roles: List? = null - ): Response { + ): io.appwrite.models.Team { val path = "/teams" val params = mapOf( "name" to name, "roles" to roles ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("POST", path, headers, params) + val convert: (Map) -> io.appwrite.models.Team = { + io.appwrite.models.Team.from(map = it) + } + return client.call( + "POST", + path, + headers, + params, + responseType = io.appwrite.models.Team::class.java, + convert = convert + ) } /** @@ -83,23 +100,31 @@ class Teams(client: Client) : Service(client) { * Get a team by its unique ID. All team members have read access for this * resource. * - * @param teamId - * @return [Response] + * @param teamId Team unique ID. + * @return [io.appwrite.models.Team] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun get( teamId: String - ): Response { + ): io.appwrite.models.Team { val path = "/teams/{teamId}".replace("{teamId}", teamId) val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.Team = { + io.appwrite.models.Team.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.Team::class.java, + convert = convert + ) } /** @@ -108,26 +133,34 @@ class Teams(client: Client) : Service(client) { * Update a team by its unique ID. Only team owners have write access for this * resource. * - * @param teamId - * @param name - * @return [Response] + * @param teamId Team unique ID. + * @param name Team name. Max length: 128 chars. + * @return [io.appwrite.models.Team] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun update( teamId: String, name: String - ): Response { + ): io.appwrite.models.Team { val path = "/teams/{teamId}".replace("{teamId}", teamId) val params = mapOf( "name" to name ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("PUT", path, headers, params) + val convert: (Map) -> io.appwrite.models.Team = { + io.appwrite.models.Team.from(map = it) + } + return client.call( + "PUT", + path, + headers, + params, + responseType = io.appwrite.models.Team::class.java, + convert = convert + ) } /** @@ -136,23 +169,27 @@ class Teams(client: Client) : Service(client) { * Delete a team by its unique ID. Only team owners have write access for this * resource. * - * @param teamId - * @return [Response] + * @param teamId Team unique ID. + * @return [Any] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun delete( teamId: String - ): Response { + ): Any { val path = "/teams/{teamId}".replace("{teamId}", teamId) val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("DELETE", path, headers, params) + return client.call( + "DELETE", + path, + headers, + params, + responseType = Any::class.java, + ) } /** @@ -161,22 +198,22 @@ class Teams(client: Client) : Service(client) { * Get a team members by the team unique ID. All team members have read access * for this list of resources. * - * @param teamId - * @param search - * @param limit - * @param offset - * @param orderType - * @return [Response] + * @param teamId Team unique ID. + * @param search Search term to filter your list results. Max length: 256 chars. + * @param limit Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request. + * @param offset Results offset. The default value is 0. Use this param to manage pagination. + * @param orderType Order result by ASC or DESC order. + * @return [io.appwrite.models.MembershipList] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun getMemberships( teamId: String, search: String? = null, - limit: Int? = null, - offset: Int? = null, + limit: Long? = null, + offset: Long? = null, orderType: String? = null - ): Response { + ): io.appwrite.models.MembershipList { val path = "/teams/{teamId}/memberships".replace("{teamId}", teamId) val params = mapOf( "search" to search, @@ -184,12 +221,20 @@ class Teams(client: Client) : Service(client) { "offset" to offset, "orderType" to orderType ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("GET", path, headers, params) + val convert: (Map) -> io.appwrite.models.MembershipList = { + io.appwrite.models.MembershipList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.MembershipList::class.java, + convert = convert + ) } /** @@ -212,12 +257,12 @@ class Teams(client: Client) : Service(client) { * the only valid redirect URL's are the once from domains you have set when * added your platforms in the console interface. * - * @param teamId - * @param email - * @param roles - * @param url - * @param name - * @return [Response] + * @param teamId Team unique ID. + * @param email New team member email. + * @param roles Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Max length for each role is 32 chars. + * @param url URL to redirect the user back to your app from the invitation email. 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 name New team member name. Max length: 128 chars. + * @return [io.appwrite.models.Membership] */ @JvmOverloads @Throws(AppwriteException::class) @@ -227,7 +272,7 @@ class Teams(client: Client) : Service(client) { roles: List, url: String, name: String? = null - ): Response { + ): io.appwrite.models.Membership { val path = "/teams/{teamId}/memberships".replace("{teamId}", teamId) val params = mapOf( "email" to email, @@ -235,21 +280,29 @@ class Teams(client: Client) : Service(client) { "url" to url, "name" to name ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("POST", path, headers, params) + val convert: (Map) -> io.appwrite.models.Membership = { + io.appwrite.models.Membership.from(map = it) + } + return client.call( + "POST", + path, + headers, + params, + responseType = io.appwrite.models.Membership::class.java, + convert = convert + ) } /** * Update Membership Roles * - * @param teamId - * @param membershipId - * @param roles - * @return [Response] + * @param teamId Team unique ID. + * @param membershipId Membership ID. + * @param roles Array of strings. Use this param to set the user roles in the team. 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.Membership] */ @JvmOverloads @Throws(AppwriteException::class) @@ -257,17 +310,25 @@ class Teams(client: Client) : Service(client) { teamId: String, membershipId: String, roles: List - ): Response { + ): io.appwrite.models.Membership { val path = "/teams/{teamId}/memberships/{membershipId}".replace("{teamId}", teamId).replace("{membershipId}", membershipId) val params = mapOf( "roles" to roles ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("PATCH", path, headers, params) + val convert: (Map) -> io.appwrite.models.Membership = { + io.appwrite.models.Membership.from(map = it) + } + return client.call( + "PATCH", + path, + headers, + params, + responseType = io.appwrite.models.Membership::class.java, + convert = convert + ) } /** @@ -277,25 +338,29 @@ class Teams(client: Client) : Service(client) { * the membership of any other team member. You can also use this endpoint to * delete a user membership even if it is not accepted. * - * @param teamId - * @param membershipId - * @return [Response] + * @param teamId Team unique ID. + * @param membershipId Membership ID. + * @return [Any] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun deleteMembership( teamId: String, membershipId: String - ): Response { + ): Any { val path = "/teams/{teamId}/memberships/{membershipId}".replace("{teamId}", teamId).replace("{membershipId}", membershipId) val params = mapOf( ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("DELETE", path, headers, params) + return client.call( + "DELETE", + path, + headers, + params, + responseType = Any::class.java, + ) } /** @@ -305,11 +370,11 @@ class Teams(client: Client) : Service(client) { * after being redirected back to your app from the invitation email recieved * by the user. * - * @param teamId - * @param membershipId - * @param userId - * @param secret - * @return [Response] + * @param teamId Team unique ID. + * @param membershipId Membership ID. + * @param userId User unique ID. + * @param secret Secret key. + * @return [io.appwrite.models.Membership] */ @JvmOverloads @Throws(AppwriteException::class) @@ -318,18 +383,26 @@ class Teams(client: Client) : Service(client) { membershipId: String, userId: String, secret: String - ): Response { + ): io.appwrite.models.Membership { val path = "/teams/{teamId}/memberships/{membershipId}/status".replace("{teamId}", teamId).replace("{membershipId}", membershipId) val params = mapOf( "userId" to userId, "secret" to secret ) - val headers = mapOf( "content-type" to "application/json" ) - - return client.call("PATCH", path, headers, params) + val convert: (Map) -> io.appwrite.models.Membership = { + io.appwrite.models.Membership.from(map = it) + } + return client.call( + "PATCH", + path, + headers, + params, + responseType = io.appwrite.models.Membership::class.java, + convert = convert + ) } } \ No newline at end of file From 3b0b656831e7cebea80e5bd405711b3b46015471 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 4 Jan 2022 15:18:09 +0545 Subject: [PATCH 02/21] feat(version): support 0.12.0 --- LICENSE.md | 2 +- README.md | 4 +- .../account/create-magic-u-r-l-session.md | 1 + docs/examples/java/account/create.md | 1 + docs/examples/java/account/get-logs.md | 35 ++--- .../account/update-magic-u-r-l-session.md | 2 +- .../examples/java/database/create-document.md | 1 + docs/examples/java/storage/create-file.md | 1 + docs/examples/java/teams/create.md | 1 + docs/examples/java/teams/get-membership.md | 49 ++++++ .../account/create-magic-u-r-l-session.md | 1 + docs/examples/kotlin/account/create.md | 1 + docs/examples/kotlin/account/get-logs.md | 3 +- .../account/update-magic-u-r-l-session.md | 2 +- .../kotlin/database/create-document.md | 1 + docs/examples/kotlin/storage/create-file.md | 1 + docs/examples/kotlin/teams/create.md | 1 + docs/examples/kotlin/teams/get-membership.md | 27 ++++ library/src/main/java/io/appwrite/Client.kt | 2 +- library/src/main/java/io/appwrite/Query.kt | 32 ++++ .../io/appwrite/models/AttributeBoolean.kt | 63 ++++++++ .../java/io/appwrite/models/AttributeEmail.kt | 71 +++++++++ .../java/io/appwrite/models/AttributeEnum.kt | 79 ++++++++++ .../java/io/appwrite/models/AttributeFloat.kt | 79 ++++++++++ .../io/appwrite/models/AttributeInteger.kt | 79 ++++++++++ .../java/io/appwrite/models/AttributeIp.kt | 71 +++++++++ .../io/appwrite/models/AttributeString.kt | 71 +++++++++ .../java/io/appwrite/models/AttributeUrl.kt | 71 +++++++++ .../java/io/appwrite/models/Collection.kt | 79 ++++++++++ .../main/java/io/appwrite/models/Document.kt | 16 +- .../main/java/io/appwrite/models/Execution.kt | 8 +- .../src/main/java/io/appwrite/models/File.kt | 16 +- .../main/java/io/appwrite/models/Function.kt | 127 ++++++++++++++++ .../src/main/java/io/appwrite/models/Index.kt | 55 +++++++ .../src/main/java/io/appwrite/models/Log.kt | 32 ++++ .../main/java/io/appwrite/models/LogList.kt | 8 + .../java/io/appwrite/models/Permissions.kt | 31 ---- .../main/java/io/appwrite/models/Runtime.kt | 71 +++++++++ .../src/main/java/io/appwrite/models/Tag.kt | 55 +++++++ .../src/main/java/io/appwrite/models/User.kt | 6 +- .../main/java/io/appwrite/services/Account.kt | 49 +++--- .../java/io/appwrite/services/Database.kt | 74 +++++---- .../java/io/appwrite/services/Functions.kt | 25 ++-- .../main/java/io/appwrite/services/Storage.kt | 35 +++-- .../main/java/io/appwrite/services/Teams.kt | 140 ++++++++++++------ 45 files changed, 1384 insertions(+), 195 deletions(-) create mode 100644 docs/examples/java/teams/get-membership.md create mode 100644 docs/examples/kotlin/teams/get-membership.md create mode 100644 library/src/main/java/io/appwrite/Query.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeBoolean.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeEmail.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeEnum.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeFloat.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeInteger.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeIp.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeString.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeUrl.kt create mode 100644 library/src/main/java/io/appwrite/models/Collection.kt create mode 100644 library/src/main/java/io/appwrite/models/Function.kt create mode 100644 library/src/main/java/io/appwrite/models/Index.kt delete mode 100644 library/src/main/java/io/appwrite/models/Permissions.kt create mode 100644 library/src/main/java/io/appwrite/models/Runtime.kt create mode 100644 library/src/main/java/io/appwrite/models/Tag.kt diff --git a/LICENSE.md b/LICENSE.md index d73a6e9..96201c4 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2021 Appwrite (https://appwrite.io) and individual contributors. +Copyright (c) 2022 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: diff --git a/README.md b/README.md index 0580a7a..66c0e17 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.11.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-0.12.0-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.11.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.12.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) diff --git a/docs/examples/java/account/create-magic-u-r-l-session.md b/docs/examples/java/account/create-magic-u-r-l-session.md index 36fc58a..de630ad 100644 --- a/docs/examples/java/account/create-magic-u-r-l-session.md +++ b/docs/examples/java/account/create-magic-u-r-l-session.md @@ -19,6 +19,7 @@ public class MainActivity extends AppCompatActivity { Account account = new Account(client); account.createMagicURLSession( + "", "email@example.com", new Continuation() { @NotNull diff --git a/docs/examples/java/account/create.md b/docs/examples/java/account/create.md index 3ff5ab9..1f10de2 100644 --- a/docs/examples/java/account/create.md +++ b/docs/examples/java/account/create.md @@ -19,6 +19,7 @@ public class MainActivity extends AppCompatActivity { Account account = new Account(client); account.create( + "", "email@example.com", "password", new Continuation() { diff --git a/docs/examples/java/account/get-logs.md b/docs/examples/java/account/get-logs.md index f2dea96..fb83c5d 100644 --- a/docs/examples/java/account/get-logs.md +++ b/docs/examples/java/account/get-logs.md @@ -18,29 +18,30 @@ public class MainActivity extends AppCompatActivity { Account account = new Account(client); - account.getLogs(new Continuation() { - @NotNull - @Override - public CoroutineContext getContext() { - return EmptyCoroutineContext.INSTANCE; - } + account.getLogs( + 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 { + @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()); } - } catch (Throwable th) { - Log.e("ERROR", th.toString()); } } - }); + ); } } \ No newline at end of file diff --git a/docs/examples/java/account/update-magic-u-r-l-session.md b/docs/examples/java/account/update-magic-u-r-l-session.md index d0734e1..f8375b9 100644 --- a/docs/examples/java/account/update-magic-u-r-l-session.md +++ b/docs/examples/java/account/update-magic-u-r-l-session.md @@ -19,7 +19,7 @@ public class MainActivity extends AppCompatActivity { Account account = new Account(client); account.updateMagicURLSession( - "[USER_ID]", + "", "[SECRET]" new Continuation() { @NotNull diff --git a/docs/examples/java/database/create-document.md b/docs/examples/java/database/create-document.md index b3a5b28..7f1ff4c 100644 --- a/docs/examples/java/database/create-document.md +++ b/docs/examples/java/database/create-document.md @@ -20,6 +20,7 @@ public class MainActivity extends AppCompatActivity { database.createDocument( "[COLLECTION_ID]", + "", mapOf( "a" to "b" ), new Continuation() { @NotNull diff --git a/docs/examples/java/storage/create-file.md b/docs/examples/java/storage/create-file.md index 172ef7e..f20ba26 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( + "", File("./path-to-files/image.jpg"), new Continuation() { @NotNull diff --git a/docs/examples/java/teams/create.md b/docs/examples/java/teams/create.md index a715c0a..c3e3093 100644 --- a/docs/examples/java/teams/create.md +++ b/docs/examples/java/teams/create.md @@ -19,6 +19,7 @@ public class MainActivity extends AppCompatActivity { Teams teams = new Teams(client); teams.create( + "", "[NAME]", new Continuation() { @NotNull diff --git a/docs/examples/java/teams/get-membership.md b/docs/examples/java/teams/get-membership.md new file mode 100644 index 0000000..87c0160 --- /dev/null +++ b/docs/examples/java/teams/get-membership.md @@ -0,0 +1,49 @@ +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.Teams + +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 + + Teams teams = new Teams(client); + + teams.getMembership( + "[TEAM_ID]", + "[MEMBERSHIP_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/kotlin/account/create-magic-u-r-l-session.md b/docs/examples/kotlin/account/create-magic-u-r-l-session.md index c803d1a..7ac9a30 100644 --- a/docs/examples/kotlin/account/create-magic-u-r-l-session.md +++ b/docs/examples/kotlin/account/create-magic-u-r-l-session.md @@ -18,6 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = account.createMagicURLSession( + userId = "", email = "email@example.com", ) val json = response.body?.string() diff --git a/docs/examples/kotlin/account/create.md b/docs/examples/kotlin/account/create.md index a8528ec..068fa5f 100644 --- a/docs/examples/kotlin/account/create.md +++ b/docs/examples/kotlin/account/create.md @@ -18,6 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = account.create( + userId = "", email = "email@example.com", password = "password", ) diff --git a/docs/examples/kotlin/account/get-logs.md b/docs/examples/kotlin/account/get-logs.md index 9f79f0a..b8c89f4 100644 --- a/docs/examples/kotlin/account/get-logs.md +++ b/docs/examples/kotlin/account/get-logs.md @@ -17,7 +17,8 @@ class MainActivity : AppCompatActivity() { val account = Account(client) GlobalScope.launch { - val response = account.getLogs() + val response = account.getLogs( + ) val json = response.body?.string() } } diff --git a/docs/examples/kotlin/account/update-magic-u-r-l-session.md b/docs/examples/kotlin/account/update-magic-u-r-l-session.md index 3fe1b7c..923574e 100644 --- a/docs/examples/kotlin/account/update-magic-u-r-l-session.md +++ b/docs/examples/kotlin/account/update-magic-u-r-l-session.md @@ -18,7 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = account.updateMagicURLSession( - userId = "[USER_ID]", + userId = "", secret = "[SECRET]" ) val json = response.body?.string() diff --git a/docs/examples/kotlin/database/create-document.md b/docs/examples/kotlin/database/create-document.md index 72ec7ad..89ada64 100644 --- a/docs/examples/kotlin/database/create-document.md +++ b/docs/examples/kotlin/database/create-document.md @@ -19,6 +19,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = database.createDocument( collectionId = "[COLLECTION_ID]", + documentId = "", data = mapOf( "a" to "b" ), ) val json = response.body?.string() diff --git a/docs/examples/kotlin/storage/create-file.md b/docs/examples/kotlin/storage/create-file.md index 92a5e95..f4f36c9 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( + fileId = "", file = File("./path-to-files/image.jpg"), ) val json = response.body?.string() diff --git a/docs/examples/kotlin/teams/create.md b/docs/examples/kotlin/teams/create.md index 068fbd6..fcce1e0 100644 --- a/docs/examples/kotlin/teams/create.md +++ b/docs/examples/kotlin/teams/create.md @@ -18,6 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = teams.create( + teamId = "", name = "[NAME]", ) val json = response.body?.string() diff --git a/docs/examples/kotlin/teams/get-membership.md b/docs/examples/kotlin/teams/get-membership.md new file mode 100644 index 0000000..aa3f29e --- /dev/null +++ b/docs/examples/kotlin/teams/get-membership.md @@ -0,0 +1,27 @@ +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.Teams + +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 teams = Teams(client) + + GlobalScope.launch { + val response = teams.getMembership( + teamId = "[TEAM_ID]", + membershipId = "[MEMBERSHIP_ID]" + ) + val json = response.body?.string() + } + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 162357e..352294d 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -79,7 +79,7 @@ class Client @JvmOverloads constructor( "origin" to "appwrite-android://${context.packageName}", "user-agent" to "${context.packageName}/${appVersion}, ${System.getProperty("http.agent")}", "x-sdk-version" to "appwrite:android:${BuildConfig.SDK_VERSION}", - "x-appwrite-response-format" to "0.11.0" + "x-appwrite-response-format" to "0.12.0" ) config = mutableMapOf() diff --git a/library/src/main/java/io/appwrite/Query.kt b/library/src/main/java/io/appwrite/Query.kt new file mode 100644 index 0000000..b86507b --- /dev/null +++ b/library/src/main/java/io/appwrite/Query.kt @@ -0,0 +1,32 @@ +package io.appwrite + +class Query { + companion object { + fun equal(attribute: String, value: Any) = addQuery(attribute, "equal", value) + + fun notEqual(attribute: String, value: Any) = Query.addQuery(attribute, "notEqual", value) + + fun lesser(attribute: String, value: Any) = Query.addQuery(attribute, "lesser", value) + + fun lesserEqual(attribute: String, value: Any) = Query.addQuery(attribute, "lesserEqual", value) + + fun greater(attribute: String, value: Any) = Query.addQuery(attribute, "greater", value) + + fun greaterEqual(attribute: String, value: Any) = Query.addQuery(attribute, "greaterEqual", value) + + fun search(attribute: String, value: String) = Query.addQuery(attribute, "search", value) + + private fun addQuery(attribute: String, oper: String, value: Any): String { + return when (value) { + is List<*> -> "${attribute}.${oper}(${value.map{it -> parseValues(it!!)}.joinToString(",")})" + else -> "${attribute}.${oper}(${Query.parseValues(value)})" + } + } + private fun parseValues(value: Any): String { + return when (value) { + is String -> "\"${value}\"" + else -> "${value}" + } + } + } +} diff --git a/library/src/main/java/io/appwrite/models/AttributeBoolean.kt b/library/src/main/java/io/appwrite/models/AttributeBoolean.kt new file mode 100644 index 0000000..dc1ea40 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeBoolean.kt @@ -0,0 +1,63 @@ +package io.appwrite.models + +/** + * AttributeBoolean + */ +data class AttributeBoolean( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: Boolean? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeBoolean( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + default = map["default"] as? Boolean + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeEmail.kt b/library/src/main/java/io/appwrite/models/AttributeEmail.kt new file mode 100644 index 0000000..890b40f --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeEmail.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * AttributeEmail + */ +data class AttributeEmail( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * String format. + * + */ + val format: String, + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: String? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeEmail( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + format = map["format"] as String, + default = map["default"] as? String + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "format" to format as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeEnum.kt b/library/src/main/java/io/appwrite/models/AttributeEnum.kt new file mode 100644 index 0000000..e700277 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeEnum.kt @@ -0,0 +1,79 @@ +package io.appwrite.models + +/** + * AttributeEnum + */ +data class AttributeEnum( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * Array of elements in enumerated type. + * + */ + val elements: List, + + /** + * String format. + * + */ + val format: String, + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: String? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeEnum( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + elements = map["elements"] as List, + format = map["format"] as String, + default = map["default"] as? String + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "elements" to elements as Any, + "format" to format as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeFloat.kt b/library/src/main/java/io/appwrite/models/AttributeFloat.kt new file mode 100644 index 0000000..ae7b985 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeFloat.kt @@ -0,0 +1,79 @@ +package io.appwrite.models + +/** + * AttributeFloat + */ +data class AttributeFloat( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * Minimum value to enforce for new documents. + * + */ + var min: Double? = , + + /** + * Maximum value to enforce for new documents. + * + */ + var max: Double? = , + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: Double? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeFloat( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + min = map["min"] as? Double, + max = map["max"] as? Double, + default = map["default"] as? Double + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "min" to min as Any, + "max" to max as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeInteger.kt b/library/src/main/java/io/appwrite/models/AttributeInteger.kt new file mode 100644 index 0000000..d00f804 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeInteger.kt @@ -0,0 +1,79 @@ +package io.appwrite.models + +/** + * AttributeInteger + */ +data class AttributeInteger( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * Minimum value to enforce for new documents. + * + */ + var min: Long? = , + + /** + * Maximum value to enforce for new documents. + * + */ + var max: Long? = , + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: Long? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeInteger( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + min = map["min"] as? Long, + max = map["max"] as? Long, + default = map["default"] as? Long + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "min" to min as Any, + "max" to max as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeIp.kt b/library/src/main/java/io/appwrite/models/AttributeIp.kt new file mode 100644 index 0000000..88c1c22 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeIp.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * AttributeIP + */ +data class AttributeIp( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * String format. + * + */ + val format: String, + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: String? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeIp( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + format = map["format"] as String, + default = map["default"] as? String + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "format" to format as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeString.kt b/library/src/main/java/io/appwrite/models/AttributeString.kt new file mode 100644 index 0000000..d383f4a --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeString.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * AttributeString + */ +data class AttributeString( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * Attribute size. + * + */ + val size: String, + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: String? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeString( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + size = map["size"] as String, + default = map["default"] as? String + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "size" to size as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeUrl.kt b/library/src/main/java/io/appwrite/models/AttributeUrl.kt new file mode 100644 index 0000000..5a8cd5f --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeUrl.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * AttributeURL + */ +data class AttributeUrl( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * String format. + * + */ + val format: String, + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: String? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeUrl( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + format = map["format"] as String, + default = map["default"] as? String + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "format" to format as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Collection.kt b/library/src/main/java/io/appwrite/models/Collection.kt new file mode 100644 index 0000000..c16018b --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Collection.kt @@ -0,0 +1,79 @@ +package io.appwrite.models + +/** + * Collection + */ +data class Collection( + /** + * Collection ID. + * + */ + val id: String, + + /** + * Collection read permissions. + * + */ + val read: List, + + /** + * Collection write permissions. + * + */ + val write: List, + + /** + * Collection name. + * + */ + val name: String, + + /** + * Collection enabled. + * + */ + val enabled: Boolean, + + /** + * Collection permission model. Possible values: `document` or `collection` + * + */ + val permission: String, + + /** + * Collection attributes. + * + */ + val attributes: List, + + /** + * Collection indexes. + * + */ + val indexes: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Collection( + id = map["\$id"] as String, + read = map["\$read"] as List, + write = map["\$write"] as List, + name = map["name"] as String, + enabled = map["enabled"] as Boolean, + permission = map["permission"] as String, + attributes = map["attributes"] as List, + indexes = (map["indexes"] as List>).map { Index.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "\$read" to read as Any, + "\$write" to write as Any, + "name" to name as Any, + "enabled" to enabled as Any, + "permission" to permission as Any, + "attributes" to attributes as Any, + "indexes" to indexes.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Document.kt b/library/src/main/java/io/appwrite/models/Document.kt index 0941dfe..f443676 100644 --- a/library/src/main/java/io/appwrite/models/Document.kt +++ b/library/src/main/java/io/appwrite/models/Document.kt @@ -17,10 +17,16 @@ data class Document( val collection: String, /** - * Document permissions. + * Document read permissions. * */ - val permissions: Permissions, + val read: List, + + /** + * Document write permissions. + * + */ + val write: List, val data: Map ) { @@ -29,7 +35,8 @@ data class Document( fun from(map: Map) = Document( id = map["\$id"] as String, collection = map["\$collection"] as String, - permissions = Permissions.from(map = map["\$permissions"] as Map), + read = map["\$read"] as List, + write = map["\$write"] as List, data = map ) } @@ -37,7 +44,8 @@ data class Document( fun toMap(): Map = mapOf( "\$id" to id as Any, "\$collection" to collection as Any, - "\$permissions" to permissions.toMap() as Any, + "\$read" to read as Any, + "\$write" to write as Any, "data" to data ) diff --git a/library/src/main/java/io/appwrite/models/Execution.kt b/library/src/main/java/io/appwrite/models/Execution.kt index e9e8d8f..2d25a73 100644 --- a/library/src/main/java/io/appwrite/models/Execution.kt +++ b/library/src/main/java/io/appwrite/models/Execution.kt @@ -11,10 +11,10 @@ data class Execution( val id: String, /** - * Execution permissions. + * Execution read permissions. * */ - val permissions: Permissions, + val read: List, /** * Function ID. @@ -68,7 +68,7 @@ data class Execution( @Suppress("UNCHECKED_CAST") fun from(map: Map) = Execution( id = map["\$id"] as String, - permissions = Permissions.from(map = map["\$permissions"] as Map), + read = map["\$read"] as List, functionId = map["functionId"] as String, dateCreated = map["dateCreated"] as Long, trigger = map["trigger"] as String, @@ -82,7 +82,7 @@ data class Execution( fun toMap(): Map = mapOf( "\$id" to id as Any, - "\$permissions" to permissions.toMap() as Any, + "\$read" to read as Any, "functionId" to functionId as Any, "dateCreated" to dateCreated as Any, "trigger" to trigger 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 daa35c2..1546c61 100644 --- a/library/src/main/java/io/appwrite/models/File.kt +++ b/library/src/main/java/io/appwrite/models/File.kt @@ -11,10 +11,16 @@ data class File( val id: String, /** - * File permissions. + * File read permissions. * */ - val permissions: Permissions, + val read: List, + + /** + * File write permissions. + * + */ + val write: List, /** * File name. @@ -50,7 +56,8 @@ data class File( @Suppress("UNCHECKED_CAST") fun from(map: Map) = File( id = map["\$id"] as String, - permissions = Permissions.from(map = map["\$permissions"] as Map), + read = map["\$read"] as List, + write = map["\$write"] as List, name = map["name"] as String, dateCreated = map["dateCreated"] as Long, signature = map["signature"] as String, @@ -61,7 +68,8 @@ data class File( fun toMap(): Map = mapOf( "\$id" to id as Any, - "\$permissions" to permissions.toMap() 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, diff --git a/library/src/main/java/io/appwrite/models/Function.kt b/library/src/main/java/io/appwrite/models/Function.kt new file mode 100644 index 0000000..bc46e83 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Function.kt @@ -0,0 +1,127 @@ +package io.appwrite.models + +/** + * Function + */ +data class Function( + /** + * Function ID. + * + */ + val id: String, + + /** + * Execution permissions. + * + */ + val execute: String, + + /** + * Function name. + * + */ + val name: String, + + /** + * Function creation date in Unix timestamp. + * + */ + val dateCreated: Long, + + /** + * Function update date in Unix timestamp. + * + */ + val dateUpdated: Long, + + /** + * Function status. Possible values: `disabled`, `enabled` + * + */ + val status: String, + + /** + * Function execution runtime. + * + */ + val runtime: String, + + /** + * Function active tag ID. + * + */ + val tag: String, + + /** + * Function environment variables. + * + */ + val vars: String, + + /** + * Function trigger events. + * + */ + val events: List, + + /** + * Function execution schedult in CRON format. + * + */ + val schedule: String, + + /** + * Function next scheduled execution date in Unix timestamp. + * + */ + val scheduleNext: Long, + + /** + * Function next scheduled execution date in Unix timestamp. + * + */ + val schedulePrevious: Long, + + /** + * Function execution timeout in seconds. + * + */ + val timeout: Long +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Function( + id = map["\$id"] as String, + execute = map["execute"] as String, + name = map["name"] as String, + dateCreated = map["dateCreated"] as Long, + dateUpdated = map["dateUpdated"] as Long, + status = map["status"] as String, + runtime = map["runtime"] as String, + tag = map["tag"] as String, + vars = map["vars"] as String, + events = map["events"] as List, + schedule = map["schedule"] as String, + scheduleNext = map["scheduleNext"] as Long, + schedulePrevious = map["schedulePrevious"] as Long, + timeout = map["timeout"] as Long + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "execute" to execute as Any, + "name" to name as Any, + "dateCreated" to dateCreated as Any, + "dateUpdated" to dateUpdated as Any, + "status" to status as Any, + "runtime" to runtime as Any, + "tag" to tag as Any, + "vars" to vars as Any, + "events" to events as Any, + "schedule" to schedule as Any, + "scheduleNext" to scheduleNext as Any, + "schedulePrevious" to schedulePrevious as Any, + "timeout" to timeout as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Index.kt b/library/src/main/java/io/appwrite/models/Index.kt new file mode 100644 index 0000000..5173b20 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Index.kt @@ -0,0 +1,55 @@ +package io.appwrite.models + +/** + * Index + */ +data class Index( + /** + * Index Key. + * + */ + val key: String, + + /** + * Index type. + * + */ + val type: String, + + /** + * Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Index attributes. + * + */ + val attributes: List, + + /** + * Index orders. + * + */ + val orders: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Index( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + attributes = map["attributes"] as List, + orders = map["orders"] as List + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "attributes" to attributes as Any, + "orders" to orders as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Log.kt b/library/src/main/java/io/appwrite/models/Log.kt index 028aa71..05a0786 100644 --- a/library/src/main/java/io/appwrite/models/Log.kt +++ b/library/src/main/java/io/appwrite/models/Log.kt @@ -10,6 +10,30 @@ data class Log( */ val event: String, + /** + * User ID. + * + */ + val userId: String, + + /** + * User Email. + * + */ + val userEmail: String, + + /** + * User Name. + * + */ + val userName: String, + + /** + * API mode when event triggered. + * + */ + val mode: String, + /** * IP session in use when the session was created. * @@ -110,6 +134,10 @@ data class Log( @Suppress("UNCHECKED_CAST") fun from(map: Map) = Log( event = map["event"] as String, + userId = map["userId"] as String, + userEmail = map["userEmail"] as String, + userName = map["userName"] as String, + mode = map["mode"] as String, ip = map["ip"] as String, time = map["time"] as Long, osCode = map["osCode"] as String, @@ -131,6 +159,10 @@ data class Log( fun toMap(): Map = mapOf( "event" to event as Any, + "userId" to userId as Any, + "userEmail" to userEmail as Any, + "userName" to userName as Any, + "mode" to mode as Any, "ip" to ip as Any, "time" to time as Any, "osCode" to osCode as Any, diff --git a/library/src/main/java/io/appwrite/models/LogList.kt b/library/src/main/java/io/appwrite/models/LogList.kt index a741ae4..a6bbd4a 100644 --- a/library/src/main/java/io/appwrite/models/LogList.kt +++ b/library/src/main/java/io/appwrite/models/LogList.kt @@ -4,6 +4,12 @@ package io.appwrite.models * Logs List */ data class LogList( + /** + * Total number of items available on the server. + * + */ + val sum: Long, + /** * List of logs. * @@ -13,11 +19,13 @@ data class LogList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = LogList( + sum = map["sum"] as Long, logs = (map["logs"] as List>).map { Log.from(map = it) } ) } fun toMap(): Map = mapOf( + "sum" to sum as Any, "logs" to logs.map { it.toMap() } as Any ) } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Permissions.kt b/library/src/main/java/io/appwrite/models/Permissions.kt deleted file mode 100644 index 81cd07d..0000000 --- a/library/src/main/java/io/appwrite/models/Permissions.kt +++ /dev/null @@ -1,31 +0,0 @@ -package io.appwrite.models - -/** - * Permissions - */ -data class Permissions( - /** - * Read permissions. - * - */ - val read: List, - - /** - * Write permissions. - * - */ - val write: List -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = Permissions( - read = map["read"] as List, - write = map["write"] as List - ) - } - - fun toMap(): Map = mapOf( - "read" to read as Any, - "write" to write as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Runtime.kt b/library/src/main/java/io/appwrite/models/Runtime.kt new file mode 100644 index 0000000..664467c --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Runtime.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * Runtime + */ +data class Runtime( + /** + * Runtime ID. + * + */ + val id: String, + + /** + * Runtime Name. + * + */ + val name: String, + + /** + * Runtime version. + * + */ + val version: String, + + /** + * Base Docker image used to build the runtime. + * + */ + val base: String, + + /** + * Image name of Docker Hub. + * + */ + val image: String, + + /** + * Name of the logo image. + * + */ + val logo: String, + + /** + * List of supported architectures. + * + */ + val supports: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Runtime( + id = map["\$id"] as String, + name = map["name"] as String, + version = map["version"] as String, + base = map["base"] as String, + image = map["image"] as String, + logo = map["logo"] as String, + supports = map["supports"] as List + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "name" to name as Any, + "version" to version as Any, + "base" to base as Any, + "image" to image as Any, + "logo" to logo as Any, + "supports" to supports as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Tag.kt b/library/src/main/java/io/appwrite/models/Tag.kt new file mode 100644 index 0000000..b2a69b9 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Tag.kt @@ -0,0 +1,55 @@ +package io.appwrite.models + +/** + * Tag + */ +data class Tag( + /** + * Tag ID. + * + */ + val id: String, + + /** + * Function ID. + * + */ + val functionId: String, + + /** + * The tag creation date in Unix timestamp. + * + */ + val dateCreated: Long, + + /** + * The entrypoint command in use to execute the tag code. + * + */ + val command: String, + + /** + * The code size in bytes. + * + */ + val size: String +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Tag( + id = map["\$id"] as String, + functionId = map["functionId"] as String, + dateCreated = map["dateCreated"] as Long, + command = map["command"] as String, + size = map["size"] as String + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "functionId" to functionId as Any, + "dateCreated" to dateCreated as Any, + "command" to command as Any, + "size" to size as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/User.kt b/library/src/main/java/io/appwrite/models/User.kt index 82039e4..0af27cc 100644 --- a/library/src/main/java/io/appwrite/models/User.kt +++ b/library/src/main/java/io/appwrite/models/User.kt @@ -23,10 +23,10 @@ data class User( val registration: Long, /** - * User status. 0 for Unactivated, 1 for active and 2 is blocked. + * User status. Pass `true` for enabled and `false` for disabled. * */ - val status: Long, + val status: Boolean, /** * Unix timestamp of the most recent password update @@ -58,7 +58,7 @@ data class User( id = map["\$id"] as String, name = map["name"] as String, registration = map["registration"] as Long, - status = map["status"] as Long, + status = map["status"] as Boolean, passwordUpdate = map["passwordUpdate"] as Long, email = map["email"] as String, emailVerification = map["emailVerification"] as Boolean, diff --git a/library/src/main/java/io/appwrite/services/Account.kt b/library/src/main/java/io/appwrite/services/Account.kt index 063d602..17344c4 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -53,20 +53,23 @@ 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 email User email. - * @param password User password. Must be between 6 to 32 chars. + * @param password User password. Must be at least 8 chars. * @param name User name. Max length: 128 chars. * @return [io.appwrite.models.User] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun create( + userId: String, email: String, password: String, name: String? = null ): io.appwrite.models.User { val path = "/account" val params = mapOf( + "userId" to userId, "email" to email, "password" to password, "name" to name @@ -120,14 +123,16 @@ class Account(client: Client) : Service(client) { * Update Account Email * * Update currently logged in user account email address. After changing user - * address, user confirmation status is being reset and a new confirmation - * mail is sent. For security measures, user password is required to complete - * this request. + * address, the user confirmation status will get reset. A new confirmation + * email is not sent automatically however you can use the send confirmation + * email endpoint again to send the confirmation email. For security measures, + * user password is required to complete this request. * This endpoint can also be used to convert an anonymous account to a normal * one, by passing an email address and a new password. + * * * @param email User email. - * @param password User password. Must be between 6 to 32 chars. + * @param password User password. Must be at least 8 chars. * @return [io.appwrite.models.User] */ @JvmOverloads @@ -196,13 +201,20 @@ class Account(client: Client) : Service(client) { * Get currently logged in user list of latest security activity logs. Each * log returns user IP address, location and date and time of log. * + * @param limit Maximum number of logs 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 value to manage pagination. [learn more about pagination](https://appwrite.io/docs/pagination) * @return [io.appwrite.models.LogList] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun getLogs(): io.appwrite.models.LogList { + suspend fun getLogs( + limit: Long? = null, + offset: Long? = null + ): io.appwrite.models.LogList { val path = "/account/logs" val params = mapOf( + "limit" to limit, + "offset" to offset ) val headers = mapOf( "content-type" to "application/json" @@ -260,8 +272,8 @@ class Account(client: Client) : Service(client) { * to pass in the new password, and the old password. For users created with * OAuth and Team Invites, oldPassword is optional. * - * @param password New user password. Must be between 6 to 32 chars. - * @param oldPassword Old user password. Must be between 6 to 32 chars. + * @param password New user password. Must be at least 8 chars. + * @param oldPassword Current user password. Must be at least 8 chars. * @return [io.appwrite.models.User] */ @JvmOverloads @@ -410,10 +422,10 @@ class Account(client: Client) : Service(client) { * the only valid redirect URLs are the ones from domains you have set when * adding your platforms in the console interface. * - * @param userId User account UID address. + * @param userId User ID. * @param secret Valid reset token. - * @param password New password. Must be between 6 to 32 chars. - * @param passwordAgain New password again. Must be between 6 to 32 chars. + * @param password New user password. Must be at least 8 chars. + * @param passwordAgain Repeat new user password. Must be at least 8 chars. * @return [io.appwrite.models.Token] */ @JvmOverloads @@ -484,7 +496,7 @@ class Account(client: Client) : Service(client) { * password combination. This route will create a new session for the user. * * @param email User email. - * @param password User password. Must be between 6 to 32 chars. + * @param password User password. Must be at least 8 chars. * @return [io.appwrite.models.Session] */ @JvmOverloads @@ -588,6 +600,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 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] @@ -595,11 +608,13 @@ class Account(client: Client) : Service(client) { @JvmOverloads @Throws(AppwriteException::class) suspend fun createMagicURLSession( + userId: String, email: String, url: String? = null ): io.appwrite.models.Token { val path = "/account/sessions/magic-url" val params = mapOf( + "userId" to userId, "email" to email, "url" to url ) @@ -634,7 +649,7 @@ class Account(client: Client) : Service(client) { * the only valid redirect URLs are the ones from domains you have set when * adding your platforms in the console interface. * - * @param userId User unique ID. + * @param userId User ID. * @param secret Valid verification token. * @return [io.appwrite.models.Session] */ @@ -681,7 +696,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, yandex, wordpress. + * @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 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. @@ -753,7 +768,7 @@ class Account(client: Client) : Service(client) { * Use this endpoint to get a logged in user's session using a Session ID. * Inputting 'current' will return the current session being used. * - * @param sessionId Session unique ID. Use the string 'current' to get the current device session. + * @param sessionId Session ID. Use the string 'current' to get the current device session. * @return [io.appwrite.models.Session] */ @JvmOverloads @@ -787,7 +802,7 @@ class Account(client: Client) : Service(client) { * account sessions across all of their different devices. When using the * option id argument, only the session unique ID provider will be deleted. * - * @param sessionId Session unique ID. Use the string 'current' to delete the current device session. + * @param sessionId Session ID. Use the string 'current' to delete the current device session. * @return [Any] */ @JvmOverloads @@ -865,7 +880,7 @@ class Account(client: Client) : Service(client) { * to verify the user email ownership. If confirmed this route will return a * 200 status code. * - * @param userId User unique ID. + * @param userId User ID. * @param secret Valid verification token. * @return [io.appwrite.models.Token] */ diff --git a/library/src/main/java/io/appwrite/services/Database.kt b/library/src/main/java/io/appwrite/services/Database.kt index 6baecdc..9e7a077 100644 --- a/library/src/main/java/io/appwrite/services/Database.kt +++ b/library/src/main/java/io/appwrite/services/Database.kt @@ -18,37 +18,37 @@ class Database(client: Client) : Service(client) { * of the project's documents. [Learn more about different API * modes](/docs/admin). * - * @param collectionId Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection). - * @param filters Array of filter strings. Each filter is constructed from a key name, comparison operator (=, !=, >, <, <=, >=) and a value. You can also use a dot (.) separator in attribute names to filter by child document attributes. Examples: 'name=John Doe' or 'category.$id>=5bed2d152c362'. - * @param limit Maximum number of documents to return in response. Use this value to manage pagination. 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. - * @param orderField Document field that results will be sorted by. - * @param orderType Order direction. Possible values are DESC for descending order, or ASC for ascending order. - * @param orderCast Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string. - * @param search Search query. Enter any free text search. The database will try to find a match against all document attributes and children. Max length: 256 chars. + * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection). + * @param queries Array of query strings. + * @param limit Maximum number of documents 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 value to manage pagination. [learn more about pagination](https://appwrite.io/docs/pagination) + * @param cursor ID of the document used as the starting point for the query, excluding the document itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](https://appwrite.io/docs/pagination) + * @param cursorDirection Direction of the cursor. + * @param orderAttributes Array of attributes used to sort results. + * @param orderTypes Array of order directions for sorting attribtues. Possible values are DESC for descending order, or ASC for ascending order. * @return [io.appwrite.models.DocumentList] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun listDocuments( collectionId: String, - filters: List? = null, + queries: List? = null, limit: Long? = null, offset: Long? = null, - orderField: String? = null, - orderType: String? = null, - orderCast: String? = null, - search: String? = null + cursor: String? = null, + cursorDirection: String? = null, + orderAttributes: List? = null, + orderTypes: List? = null ): io.appwrite.models.DocumentList { val path = "/database/collections/{collectionId}/documents".replace("{collectionId}", collectionId) val params = mapOf( - "filters" to filters, + "queries" to queries, "limit" to limit, "offset" to offset, - "orderField" to orderField, - "orderType" to orderType, - "orderCast" to orderCast, - "search" to search + "cursor" to cursor, + "cursorDirection" to cursorDirection, + "orderAttributes" to orderAttributes, + "orderTypes" to orderTypes ) val headers = mapOf( "content-type" to "application/json" @@ -74,34 +74,28 @@ class Database(client: Client) : Service(client) { * integration](/docs/server/database#databaseCreateCollection) API or * directly from your database console. * - * @param collectionId Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection). + * @param collectionId Collection ID. You can create a new collection with validation rules using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection). + * @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](/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](/docs/permissions) and get a full list of available permissions. - * @param parentDocument Parent document unique ID. Use when you want your new document to be a child of a parent document. - * @param parentProperty Parent document property name. Use when you want your new document to be a child of a parent document. - * @param parentPropertyType Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. Use when you want your new document to be a child of a parent document. + * @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. * @return [io.appwrite.models.Document] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun createDocument( collectionId: String, + documentId: String, data: Any, read: List? = null, - write: List? = null, - parentDocument: String? = null, - parentProperty: String? = null, - parentPropertyType: String? = null + write: List? = null ): io.appwrite.models.Document { val path = "/database/collections/{collectionId}/documents".replace("{collectionId}", collectionId) val params = mapOf( + "documentId" to documentId, "data" to data, "read" to read, - "write" to write, - "parentDocument" to parentDocument, - "parentProperty" to parentProperty, - "parentPropertyType" to parentPropertyType + "write" to write ) val headers = mapOf( "content-type" to "application/json" @@ -125,8 +119,8 @@ class Database(client: Client) : Service(client) { * Get a document by its unique ID. This endpoint response returns a JSON * object with the document data. * - * @param collectionId Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection). - * @param documentId Document unique ID. + * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection). + * @param documentId Document ID. * @return [io.appwrite.models.Document] */ @JvmOverloads @@ -160,11 +154,11 @@ class Database(client: Client) : Service(client) { * Update a document by its unique ID. Using the patch method you can pass * only specific fields that will get updated. * - * @param collectionId Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection). - * @param documentId Document unique ID. + * @param collectionId Collection ID. You can create a new collection with validation rules using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection). + * @param documentId Document ID. * @param data Document data as JSON object. - * @param read An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. - * @param write An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. + * @param read An array of strings with read permissions. By default inherits the existing 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 inherits the existing write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. * @return [io.appwrite.models.Document] */ @JvmOverloads @@ -205,8 +199,8 @@ class Database(client: Client) : Service(client) { * documents, its attributes and relations to other documents. Child documents * **will not** be deleted. * - * @param collectionId Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection). - * @param documentId Document unique ID. + * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection). + * @param documentId Document ID. * @return [Any] */ @JvmOverloads diff --git a/library/src/main/java/io/appwrite/services/Functions.kt b/library/src/main/java/io/appwrite/services/Functions.kt index 83ac165..132e753 100644 --- a/library/src/main/java/io/appwrite/services/Functions.kt +++ b/library/src/main/java/io/appwrite/services/Functions.kt @@ -18,28 +18,31 @@ class Functions(client: Client) : Service(client) { * return a list of all of the project's executions. [Learn more about * different API modes](/docs/admin). * - * @param functionId Function unique ID. + * @param functionId Function ID. + * @param limit Maximum number of executions 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 value to manage pagination. [learn more about pagination](https://appwrite.io/docs/pagination) * @param search Search term to filter your list results. Max length: 256 chars. - * @param limit Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request. - * @param offset Results offset. The default value is 0. Use this param to manage pagination. - * @param orderType Order result by ASC or DESC order. + * @param cursor ID of the execution used as the starting point for the query, excluding the execution itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](https://appwrite.io/docs/pagination) + * @param cursorDirection Direction of the cursor. * @return [io.appwrite.models.ExecutionList] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun listExecutions( functionId: String, - search: String? = null, limit: Long? = null, offset: Long? = null, - orderType: String? = null + search: String? = null, + cursor: String? = null, + cursorDirection: String? = null ): io.appwrite.models.ExecutionList { val path = "/functions/{functionId}/executions".replace("{functionId}", functionId) val params = mapOf( - "search" to search, "limit" to limit, "offset" to offset, - "orderType" to orderType + "search" to search, + "cursor" to cursor, + "cursorDirection" to cursorDirection ) val headers = mapOf( "content-type" to "application/json" @@ -65,7 +68,7 @@ class Functions(client: Client) : Service(client) { * updates on the current execution status. Once this endpoint is called, your * function execution process will start asynchronously. * - * @param functionId Function unique ID. + * @param functionId Function ID. * @param data String of custom data to send to function. * @return [io.appwrite.models.Execution] */ @@ -100,8 +103,8 @@ class Functions(client: Client) : Service(client) { * * Get a function execution log by its unique ID. * - * @param functionId Function unique ID. - * @param executionId Execution unique ID. + * @param functionId Function ID. + * @param executionId Execution ID. * @return [io.appwrite.models.Execution] */ @JvmOverloads diff --git a/library/src/main/java/io/appwrite/services/Storage.kt b/library/src/main/java/io/appwrite/services/Storage.kt index 1b1941e..42a0958 100644 --- a/library/src/main/java/io/appwrite/services/Storage.kt +++ b/library/src/main/java/io/appwrite/services/Storage.kt @@ -20,8 +20,10 @@ class Storage(client: Client) : Service(client) { * project's files. [Learn more about different API modes](/docs/admin). * * @param search Search term to filter your list results. Max length: 256 chars. - * @param limit Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request. - * @param offset Results offset. The default value is 0. Use this param to manage pagination. + * @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) + * @param cursor ID of the file used as the starting point for the query, excluding the file itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](https://appwrite.io/docs/pagination) + * @param cursorDirection Direction of the cursor. * @param orderType Order result by ASC or DESC order. * @return [io.appwrite.models.FileList] */ @@ -31,6 +33,8 @@ class Storage(client: Client) : Service(client) { search: String? = null, limit: Long? = null, offset: Long? = null, + cursor: String? = null, + cursorDirection: String? = null, orderType: String? = null ): io.appwrite.models.FileList { val path = "/storage/files" @@ -38,6 +42,8 @@ class Storage(client: Client) : Service(client) { "search" to search, "limit" to limit, "offset" to offset, + "cursor" to cursor, + "cursorDirection" to cursorDirection, "orderType" to orderType ) val headers = mapOf( @@ -63,20 +69,23 @@ class Storage(client: Client) : Service(client) { * assigned to read and write access unless he has passed custom values for * read and write arguments. * + * @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](/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](/docs/permissions) and get a full list of available permissions. + * @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. * @return [io.appwrite.models.File] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun createFile( + fileId: String, file: File, read: List? = null, write: List? = null ): io.appwrite.models.File { val path = "/storage/files" val params = mapOf( + "fileId" to fileId, "file" to file, "read" to read, "write" to write @@ -103,7 +112,7 @@ 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 fileId File unique ID. + * @param fileId File ID. * @return [io.appwrite.models.File] */ @JvmOverloads @@ -136,9 +145,9 @@ 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 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](/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](/docs/permissions) and get a full list of available permissions. + * @param fileId File 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] */ @JvmOverloads @@ -175,7 +184,7 @@ 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 fileId File unique ID. + * @param fileId File ID. * @return [Any] */ @JvmOverloads @@ -205,7 +214,7 @@ class Storage(client: Client) : Service(client) { * 'Content-Disposition: attachment' header that tells the browser to start * downloading the file to user downloads directory. * - * @param fileId File unique ID. + * @param fileId File ID. * @return [ByteArray] */ @JvmOverloads @@ -233,7 +242,7 @@ class Storage(client: Client) : Service(client) { * and spreadsheets, will return the file icon image. You can also pass query * string arguments for cutting and resizing your preview image. * - * @param fileId File unique ID + * @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 @@ -242,7 +251,7 @@ class Storage(client: Client) : Service(client) { * @param borderColor Preview image border color. Use a valid HEX color, no # is needed for prefix. * @param borderRadius Preview image border radius in pixels. Pass an integer between 0 to 4000. * @param opacity Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1. - * @param rotation Preview image rotation in degrees. Pass an integer between 0 and 360. + * @param rotation Preview image rotation in degrees. Pass an integer between -360 and 360. * @param background Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix. * @param output Output format type (jpeg, jpg, png, gif and webp). * @return [ByteArray] @@ -293,7 +302,7 @@ class Storage(client: Client) : Service(client) { * download method but returns with no 'Content-Disposition: attachment' * header. * - * @param fileId File unique ID. + * @param fileId File ID. * @return [ByteArray] */ @JvmOverloads diff --git a/library/src/main/java/io/appwrite/services/Teams.kt b/library/src/main/java/io/appwrite/services/Teams.kt index 90dcba1..cc08040 100644 --- a/library/src/main/java/io/appwrite/services/Teams.kt +++ b/library/src/main/java/io/appwrite/services/Teams.kt @@ -13,14 +13,17 @@ class Teams(client: Client) : Service(client) { /** * List Teams * - * Get a list of all the current user teams. You can use the query params to - * filter your results. On admin mode, this endpoint will return a list of all - * of the project's teams. [Learn more about different API - * modes](/docs/admin). + * Get a list of all the teams in which the current user is a member. You can + * use the parameters to filter your results. + * + * In admin mode, this endpoint returns a list of all the teams in the current + * project. [Learn more about different API modes](/docs/admin). * * @param search Search term to filter your list results. Max length: 256 chars. - * @param limit Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request. - * @param offset Results offset. The default value is 0. Use this param to manage pagination. + * @param limit Maximum number of teams 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) + * @param cursor ID of the team used as the starting point for the query, excluding the team itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](https://appwrite.io/docs/pagination) + * @param cursorDirection Direction of the cursor. * @param orderType Order result by ASC or DESC order. * @return [io.appwrite.models.TeamList] */ @@ -30,6 +33,8 @@ class Teams(client: Client) : Service(client) { search: String? = null, limit: Long? = null, offset: Long? = null, + cursor: String? = null, + cursorDirection: String? = null, orderType: String? = null ): io.appwrite.models.TeamList { val path = "/teams" @@ -37,6 +42,8 @@ class Teams(client: Client) : Service(client) { "search" to search, "limit" to limit, "offset" to offset, + "cursor" to cursor, + "cursorDirection" to cursorDirection, "orderType" to orderType ) val headers = mapOf( @@ -59,10 +66,10 @@ class Teams(client: Client) : Service(client) { * Create Team * * Create a new team. The user who creates the team will automatically be - * assigned as the owner of the team. The team owner can invite new members, - * who will be able add new owners and update or delete the team from your - * project. + * 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 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] @@ -70,11 +77,13 @@ class Teams(client: Client) : Service(client) { @JvmOverloads @Throws(AppwriteException::class) suspend fun create( + teamId: String, name: String, roles: List? = null ): io.appwrite.models.Team { val path = "/teams" val params = mapOf( + "teamId" to teamId, "name" to name, "roles" to roles ) @@ -97,10 +106,9 @@ class Teams(client: Client) : Service(client) { /** * Get Team * - * Get a team by its unique ID. All team members have read access for this - * resource. + * Get a team by its ID. All team members have read access for this resource. * - * @param teamId Team unique ID. + * @param teamId Team ID. * @return [io.appwrite.models.Team] */ @JvmOverloads @@ -130,11 +138,11 @@ class Teams(client: Client) : Service(client) { /** * Update Team * - * Update a team by its unique ID. Only team owners have write access for this - * resource. + * Update a team using its ID. Only members with the owner role can update the + * team. * - * @param teamId Team unique ID. - * @param name Team name. Max length: 128 chars. + * @param teamId Team ID. + * @param name New team name. Max length: 128 chars. * @return [io.appwrite.models.Team] */ @JvmOverloads @@ -166,10 +174,10 @@ class Teams(client: Client) : Service(client) { /** * Delete Team * - * Delete a team by its unique ID. Only team owners have write access for this - * resource. + * Delete a team using its ID. Only team members with the owner role can + * delete the team. * - * @param teamId Team unique ID. + * @param teamId Team ID. * @return [Any] */ @JvmOverloads @@ -195,13 +203,15 @@ class Teams(client: Client) : Service(client) { /** * Get Team Memberships * - * Get a team members by the team unique ID. All team members have read access - * for this list of resources. + * Use this endpoint to list a team's members using the team's ID. All team + * members have read access to this endpoint. * - * @param teamId Team unique ID. + * @param teamId Team ID. * @param search Search term to filter your list results. Max length: 256 chars. - * @param limit Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request. - * @param offset Results offset. The default value is 0. Use this param to manage pagination. + * @param limit Maximum number of memberships 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 value to manage pagination. [learn more about pagination](https://appwrite.io/docs/pagination) + * @param cursor ID of the membership used as the starting point for the query, excluding the membership itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](https://appwrite.io/docs/pagination) + * @param cursorDirection Direction of the cursor. * @param orderType Order result by ASC or DESC order. * @return [io.appwrite.models.MembershipList] */ @@ -212,6 +222,8 @@ class Teams(client: Client) : Service(client) { search: String? = null, limit: Long? = null, offset: Long? = null, + cursor: String? = null, + cursorDirection: String? = null, orderType: String? = null ): io.appwrite.models.MembershipList { val path = "/teams/{teamId}/memberships".replace("{teamId}", teamId) @@ -219,6 +231,8 @@ class Teams(client: Client) : Service(client) { "search" to search, "limit" to limit, "offset" to offset, + "cursor" to cursor, + "cursorDirection" to cursorDirection, "orderType" to orderType ) val headers = mapOf( @@ -240,28 +254,27 @@ class Teams(client: Client) : Service(client) { /** * Create Team Membership * - * Use this endpoint to invite a new member to join your team. If initiated - * from Client SDK, an email with a link to join the team will be sent to the - * new member's email address if the member doesn't exist in the project it - * will be created automatically. If initiated from server side SDKs, new - * member will automatically be added to the team. + * Invite a new member to join your team. If initiated from the client SDK, an + * email with a link to join the team will be sent to the member's email + * address and an account will be created for them should they not be signed + * up already. If initiated from server-side SDKs, the new member will + * automatically be added to the team. * - * Use the 'URL' parameter to redirect the user from the invitation email back + * Use the 'url' parameter to redirect the user from the invitation email back * to your app. When the user is redirected, use the [Update Team Membership * Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow - * the user to accept the invitation to the team. While calling from side - * SDKs the redirect url can be empty string. + * the user to accept the invitation to the team. * - * Please note that in order to avoid a [Redirect - * Attacks](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) + * Please note that to avoid a [Redirect + * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) * the only valid redirect URL's are the once from domains you have set when - * added your platforms in the console interface. + * adding your platforms in the console interface. * - * @param teamId Team unique ID. - * @param email New team member email. + * @param teamId Team ID. + * @param email Email of the new team member. * @param roles Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Max length for each role is 32 chars. * @param url URL to redirect the user back to your app from the invitation email. 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 name New team member name. Max length: 128 chars. + * @param name Name of the new team member. Max length: 128 chars. * @return [io.appwrite.models.Membership] */ @JvmOverloads @@ -296,12 +309,51 @@ class Teams(client: Client) : Service(client) { ) } + /** + * Get Team Membership + * + * Get a team member by the membership unique id. All team members have read + * access for this resource. + * + * @param teamId Team ID. + * @param membershipId Membership ID. + * @return [io.appwrite.models.MembershipList] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun getMembership( + teamId: String, + membershipId: String + ): io.appwrite.models.MembershipList { + val path = "/teams/{teamId}/memberships/{membershipId}".replace("{teamId}", teamId).replace("{membershipId}", membershipId) + val params = mapOf( + ) + val headers = mapOf( + "content-type" to "application/json" + ) + val convert: (Map) -> io.appwrite.models.MembershipList = { + io.appwrite.models.MembershipList.from(map = it) + } + return client.call( + "GET", + path, + headers, + params, + responseType = io.appwrite.models.MembershipList::class.java, + convert = convert + ) + } + /** * Update Membership Roles * - * @param teamId Team unique ID. + * Modify the roles of a team member. Only team members with the owner role + * have access to this endpoint. Learn more about [roles and + * permissions](/docs/permissions). + * + * @param teamId Team ID. * @param membershipId Membership ID. - * @param roles Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Max length for each role is 32 chars. + * @param roles An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Max length for each role is 32 chars. * @return [io.appwrite.models.Membership] */ @JvmOverloads @@ -338,7 +390,7 @@ class Teams(client: Client) : Service(client) { * the membership of any other team member. You can also use this endpoint to * delete a user membership even if it is not accepted. * - * @param teamId Team unique ID. + * @param teamId Team ID. * @param membershipId Membership ID. * @return [Any] */ @@ -367,12 +419,12 @@ class Teams(client: Client) : Service(client) { * Update Team Membership Status * * 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 recieved + * after being redirected back to your app from the invitation email received * by the user. * - * @param teamId Team unique ID. + * @param teamId Team ID. * @param membershipId Membership ID. - * @param userId User unique ID. + * @param userId User ID. * @param secret Secret key. * @return [io.appwrite.models.Membership] */ From 2320810b8f5db60ffdcfdbff71516997ef0b885a Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 4 Jan 2022 17:34:02 +0545 Subject: [PATCH 03/21] fix docs --- docs/examples/java/account/create-magic-u-r-l-session.md | 2 +- docs/examples/java/account/create.md | 2 +- docs/examples/java/account/update-magic-u-r-l-session.md | 2 +- docs/examples/java/database/create-document.md | 2 +- docs/examples/java/storage/create-file.md | 2 +- docs/examples/java/teams/create.md | 2 +- docs/examples/kotlin/account/create-magic-u-r-l-session.md | 2 +- docs/examples/kotlin/account/create.md | 2 +- docs/examples/kotlin/account/update-magic-u-r-l-session.md | 2 +- docs/examples/kotlin/database/create-document.md | 2 +- docs/examples/kotlin/storage/create-file.md | 2 +- docs/examples/kotlin/teams/create.md | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/examples/java/account/create-magic-u-r-l-session.md b/docs/examples/java/account/create-magic-u-r-l-session.md index de630ad..6c9fa7c 100644 --- a/docs/examples/java/account/create-magic-u-r-l-session.md +++ b/docs/examples/java/account/create-magic-u-r-l-session.md @@ -19,7 +19,7 @@ public class MainActivity extends AppCompatActivity { Account account = new Account(client); account.createMagicURLSession( - "", + "[USER_ID]", "email@example.com", new Continuation() { @NotNull diff --git a/docs/examples/java/account/create.md b/docs/examples/java/account/create.md index 1f10de2..11a5168 100644 --- a/docs/examples/java/account/create.md +++ b/docs/examples/java/account/create.md @@ -19,7 +19,7 @@ public class MainActivity extends AppCompatActivity { Account account = new Account(client); account.create( - "", + "[USER_ID]", "email@example.com", "password", new Continuation() { diff --git a/docs/examples/java/account/update-magic-u-r-l-session.md b/docs/examples/java/account/update-magic-u-r-l-session.md index f8375b9..d0734e1 100644 --- a/docs/examples/java/account/update-magic-u-r-l-session.md +++ b/docs/examples/java/account/update-magic-u-r-l-session.md @@ -19,7 +19,7 @@ public class MainActivity extends AppCompatActivity { Account account = new Account(client); account.updateMagicURLSession( - "", + "[USER_ID]", "[SECRET]" new Continuation() { @NotNull diff --git a/docs/examples/java/database/create-document.md b/docs/examples/java/database/create-document.md index 7f1ff4c..059a42e 100644 --- a/docs/examples/java/database/create-document.md +++ b/docs/examples/java/database/create-document.md @@ -20,7 +20,7 @@ public class MainActivity extends AppCompatActivity { database.createDocument( "[COLLECTION_ID]", - "", + "[DOCUMENT_ID]", mapOf( "a" to "b" ), new Continuation() { @NotNull diff --git a/docs/examples/java/storage/create-file.md b/docs/examples/java/storage/create-file.md index f20ba26..420ca3c 100644 --- a/docs/examples/java/storage/create-file.md +++ b/docs/examples/java/storage/create-file.md @@ -19,7 +19,7 @@ public class MainActivity extends AppCompatActivity { Storage storage = new Storage(client); storage.createFile( - "", + "[FILE_ID]", File("./path-to-files/image.jpg"), new Continuation() { @NotNull diff --git a/docs/examples/java/teams/create.md b/docs/examples/java/teams/create.md index c3e3093..3723b30 100644 --- a/docs/examples/java/teams/create.md +++ b/docs/examples/java/teams/create.md @@ -19,7 +19,7 @@ public class MainActivity extends AppCompatActivity { Teams teams = new Teams(client); teams.create( - "", + "[TEAM_ID]", "[NAME]", new Continuation() { @NotNull diff --git a/docs/examples/kotlin/account/create-magic-u-r-l-session.md b/docs/examples/kotlin/account/create-magic-u-r-l-session.md index 7ac9a30..15fa1c7 100644 --- a/docs/examples/kotlin/account/create-magic-u-r-l-session.md +++ b/docs/examples/kotlin/account/create-magic-u-r-l-session.md @@ -18,7 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = account.createMagicURLSession( - userId = "", + userId = "[USER_ID]", email = "email@example.com", ) val json = response.body?.string() diff --git a/docs/examples/kotlin/account/create.md b/docs/examples/kotlin/account/create.md index 068fa5f..ab2534f 100644 --- a/docs/examples/kotlin/account/create.md +++ b/docs/examples/kotlin/account/create.md @@ -18,7 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = account.create( - userId = "", + userId = "[USER_ID]", email = "email@example.com", password = "password", ) diff --git a/docs/examples/kotlin/account/update-magic-u-r-l-session.md b/docs/examples/kotlin/account/update-magic-u-r-l-session.md index 923574e..3fe1b7c 100644 --- a/docs/examples/kotlin/account/update-magic-u-r-l-session.md +++ b/docs/examples/kotlin/account/update-magic-u-r-l-session.md @@ -18,7 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = account.updateMagicURLSession( - userId = "", + userId = "[USER_ID]", secret = "[SECRET]" ) val json = response.body?.string() diff --git a/docs/examples/kotlin/database/create-document.md b/docs/examples/kotlin/database/create-document.md index 89ada64..d207383 100644 --- a/docs/examples/kotlin/database/create-document.md +++ b/docs/examples/kotlin/database/create-document.md @@ -19,7 +19,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = database.createDocument( collectionId = "[COLLECTION_ID]", - documentId = "", + documentId = "[DOCUMENT_ID]", data = mapOf( "a" to "b" ), ) val json = response.body?.string() diff --git a/docs/examples/kotlin/storage/create-file.md b/docs/examples/kotlin/storage/create-file.md index f4f36c9..1261bda 100644 --- a/docs/examples/kotlin/storage/create-file.md +++ b/docs/examples/kotlin/storage/create-file.md @@ -18,7 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = storage.createFile( - fileId = "", + fileId = "[FILE_ID]", file = File("./path-to-files/image.jpg"), ) val json = response.body?.string() diff --git a/docs/examples/kotlin/teams/create.md b/docs/examples/kotlin/teams/create.md index fcce1e0..73857b8 100644 --- a/docs/examples/kotlin/teams/create.md +++ b/docs/examples/kotlin/teams/create.md @@ -18,7 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = teams.create( - teamId = "", + teamId = "[TEAM_ID]", name = "[NAME]", ) val json = response.body?.string() From 596b8a2840dcd298a57078c2764588cbe6027368 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 4 Jan 2022 18:23:44 +0545 Subject: [PATCH 04/21] fix readmes and changes --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 66c0e17..91414f7 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ When trying to connect to Appwrite from an emulator or a mobile device, localhos // Register User val account = Account(client) val response = account.create( + "[USER_ID]", "email@example.com", "password" ) @@ -126,6 +127,7 @@ val client = Client(context) val account = Account(client) val response = account.create( + "[USER_ID]", "email@example.com", "password" ) @@ -136,7 +138,7 @@ The Appwrite Android SDK raises an `AppwriteException` object with `message`, `c ```kotlin try { - var response = account.create("email@example.com", "password") + var response = account.create("[USER_ID]", "email@example.com", "password") Log.d("Appwrite response", response.body?.string()) } catch(e : AppwriteException) { Log.e("AppwriteException",e.message.toString()) From 6c2dc0cd049263b11ab0321cf1ee53e5787b8725 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 4 Jan 2022 18:46:26 +0545 Subject: [PATCH 05/21] fix versions --- README.md | 4 ++-- build.gradle | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 91414f7..3dca835 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:0.2.1") +implementation("io.appwrite:sdk-for-android:0.3.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 0.2.1 + 0.3.0 ``` diff --git a/build.gradle b/build.gradle index d2f3361..be4a0fa 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.2.1" + version "0.3.0" repositories { maven { url "https://plugins.gradle.org/m2/" } google() From 664c8786e070653b7db02667f28214251b023f0e Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 5 Jan 2022 15:48:02 +0100 Subject: [PATCH 06/21] fix: add query builder --- README.md | 4 +- build.gradle | 2 +- .../io/appwrite/models/AttributeBoolean.kt | 63 --------- .../java/io/appwrite/models/AttributeEmail.kt | 71 ---------- .../java/io/appwrite/models/AttributeEnum.kt | 79 ----------- .../java/io/appwrite/models/AttributeFloat.kt | 79 ----------- .../io/appwrite/models/AttributeInteger.kt | 79 ----------- .../java/io/appwrite/models/AttributeIp.kt | 71 ---------- .../io/appwrite/models/AttributeString.kt | 71 ---------- .../java/io/appwrite/models/AttributeUrl.kt | 71 ---------- .../java/io/appwrite/models/Collection.kt | 79 ----------- .../main/java/io/appwrite/models/Function.kt | 127 ------------------ .../src/main/java/io/appwrite/models/Index.kt | 55 -------- .../main/java/io/appwrite/models/Runtime.kt | 71 ---------- .../src/main/java/io/appwrite/models/Tag.kt | 55 -------- 15 files changed, 3 insertions(+), 974 deletions(-) delete mode 100644 library/src/main/java/io/appwrite/models/AttributeBoolean.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeEmail.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeEnum.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeFloat.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeInteger.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeIp.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeString.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeUrl.kt delete mode 100644 library/src/main/java/io/appwrite/models/Collection.kt delete mode 100644 library/src/main/java/io/appwrite/models/Function.kt delete mode 100644 library/src/main/java/io/appwrite/models/Index.kt delete mode 100644 library/src/main/java/io/appwrite/models/Runtime.kt delete mode 100644 library/src/main/java/io/appwrite/models/Tag.kt diff --git a/README.md b/README.md index 3dca835..bc43724 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:0.3.0") +implementation("io.appwrite:sdk-for-android:0.3.1") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 0.3.0 + 0.3.1 ``` diff --git a/build.gradle b/build.gradle index be4a0fa..1c7defb 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.0" + version "0.3.1" repositories { maven { url "https://plugins.gradle.org/m2/" } google() diff --git a/library/src/main/java/io/appwrite/models/AttributeBoolean.kt b/library/src/main/java/io/appwrite/models/AttributeBoolean.kt deleted file mode 100644 index dc1ea40..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeBoolean.kt +++ /dev/null @@ -1,63 +0,0 @@ -package io.appwrite.models - -/** - * AttributeBoolean - */ -data class AttributeBoolean( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: Boolean? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeBoolean( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - default = map["default"] as? Boolean - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeEmail.kt b/library/src/main/java/io/appwrite/models/AttributeEmail.kt deleted file mode 100644 index 890b40f..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeEmail.kt +++ /dev/null @@ -1,71 +0,0 @@ -package io.appwrite.models - -/** - * AttributeEmail - */ -data class AttributeEmail( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * String format. - * - */ - val format: String, - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: String? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeEmail( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - format = map["format"] as String, - default = map["default"] as? String - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "format" to format as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeEnum.kt b/library/src/main/java/io/appwrite/models/AttributeEnum.kt deleted file mode 100644 index e700277..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeEnum.kt +++ /dev/null @@ -1,79 +0,0 @@ -package io.appwrite.models - -/** - * AttributeEnum - */ -data class AttributeEnum( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * Array of elements in enumerated type. - * - */ - val elements: List, - - /** - * String format. - * - */ - val format: String, - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: String? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeEnum( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - elements = map["elements"] as List, - format = map["format"] as String, - default = map["default"] as? String - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "elements" to elements as Any, - "format" to format as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeFloat.kt b/library/src/main/java/io/appwrite/models/AttributeFloat.kt deleted file mode 100644 index ae7b985..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeFloat.kt +++ /dev/null @@ -1,79 +0,0 @@ -package io.appwrite.models - -/** - * AttributeFloat - */ -data class AttributeFloat( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * Minimum value to enforce for new documents. - * - */ - var min: Double? = , - - /** - * Maximum value to enforce for new documents. - * - */ - var max: Double? = , - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: Double? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeFloat( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - min = map["min"] as? Double, - max = map["max"] as? Double, - default = map["default"] as? Double - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "min" to min as Any, - "max" to max as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeInteger.kt b/library/src/main/java/io/appwrite/models/AttributeInteger.kt deleted file mode 100644 index d00f804..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeInteger.kt +++ /dev/null @@ -1,79 +0,0 @@ -package io.appwrite.models - -/** - * AttributeInteger - */ -data class AttributeInteger( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * Minimum value to enforce for new documents. - * - */ - var min: Long? = , - - /** - * Maximum value to enforce for new documents. - * - */ - var max: Long? = , - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: Long? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeInteger( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - min = map["min"] as? Long, - max = map["max"] as? Long, - default = map["default"] as? Long - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "min" to min as Any, - "max" to max as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeIp.kt b/library/src/main/java/io/appwrite/models/AttributeIp.kt deleted file mode 100644 index 88c1c22..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeIp.kt +++ /dev/null @@ -1,71 +0,0 @@ -package io.appwrite.models - -/** - * AttributeIP - */ -data class AttributeIp( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * String format. - * - */ - val format: String, - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: String? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeIp( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - format = map["format"] as String, - default = map["default"] as? String - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "format" to format as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeString.kt b/library/src/main/java/io/appwrite/models/AttributeString.kt deleted file mode 100644 index d383f4a..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeString.kt +++ /dev/null @@ -1,71 +0,0 @@ -package io.appwrite.models - -/** - * AttributeString - */ -data class AttributeString( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * Attribute size. - * - */ - val size: String, - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: String? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeString( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - size = map["size"] as String, - default = map["default"] as? String - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "size" to size as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeUrl.kt b/library/src/main/java/io/appwrite/models/AttributeUrl.kt deleted file mode 100644 index 5a8cd5f..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeUrl.kt +++ /dev/null @@ -1,71 +0,0 @@ -package io.appwrite.models - -/** - * AttributeURL - */ -data class AttributeUrl( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * String format. - * - */ - val format: String, - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: String? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeUrl( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - format = map["format"] as String, - default = map["default"] as? String - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "format" to format as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Collection.kt b/library/src/main/java/io/appwrite/models/Collection.kt deleted file mode 100644 index c16018b..0000000 --- a/library/src/main/java/io/appwrite/models/Collection.kt +++ /dev/null @@ -1,79 +0,0 @@ -package io.appwrite.models - -/** - * Collection - */ -data class Collection( - /** - * Collection ID. - * - */ - val id: String, - - /** - * Collection read permissions. - * - */ - val read: List, - - /** - * Collection write permissions. - * - */ - val write: List, - - /** - * Collection name. - * - */ - val name: String, - - /** - * Collection enabled. - * - */ - val enabled: Boolean, - - /** - * Collection permission model. Possible values: `document` or `collection` - * - */ - val permission: String, - - /** - * Collection attributes. - * - */ - val attributes: List, - - /** - * Collection indexes. - * - */ - val indexes: List -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = Collection( - id = map["\$id"] as String, - read = map["\$read"] as List, - write = map["\$write"] as List, - name = map["name"] as String, - enabled = map["enabled"] as Boolean, - permission = map["permission"] as String, - attributes = map["attributes"] as List, - indexes = (map["indexes"] as List>).map { Index.from(map = it) } - ) - } - - fun toMap(): Map = mapOf( - "\$id" to id as Any, - "\$read" to read as Any, - "\$write" to write as Any, - "name" to name as Any, - "enabled" to enabled as Any, - "permission" to permission as Any, - "attributes" to attributes as Any, - "indexes" to indexes.map { it.toMap() } as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Function.kt b/library/src/main/java/io/appwrite/models/Function.kt deleted file mode 100644 index bc46e83..0000000 --- a/library/src/main/java/io/appwrite/models/Function.kt +++ /dev/null @@ -1,127 +0,0 @@ -package io.appwrite.models - -/** - * Function - */ -data class Function( - /** - * Function ID. - * - */ - val id: String, - - /** - * Execution permissions. - * - */ - val execute: String, - - /** - * Function name. - * - */ - val name: String, - - /** - * Function creation date in Unix timestamp. - * - */ - val dateCreated: Long, - - /** - * Function update date in Unix timestamp. - * - */ - val dateUpdated: Long, - - /** - * Function status. Possible values: `disabled`, `enabled` - * - */ - val status: String, - - /** - * Function execution runtime. - * - */ - val runtime: String, - - /** - * Function active tag ID. - * - */ - val tag: String, - - /** - * Function environment variables. - * - */ - val vars: String, - - /** - * Function trigger events. - * - */ - val events: List, - - /** - * Function execution schedult in CRON format. - * - */ - val schedule: String, - - /** - * Function next scheduled execution date in Unix timestamp. - * - */ - val scheduleNext: Long, - - /** - * Function next scheduled execution date in Unix timestamp. - * - */ - val schedulePrevious: Long, - - /** - * Function execution timeout in seconds. - * - */ - val timeout: Long -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = Function( - id = map["\$id"] as String, - execute = map["execute"] as String, - name = map["name"] as String, - dateCreated = map["dateCreated"] as Long, - dateUpdated = map["dateUpdated"] as Long, - status = map["status"] as String, - runtime = map["runtime"] as String, - tag = map["tag"] as String, - vars = map["vars"] as String, - events = map["events"] as List, - schedule = map["schedule"] as String, - scheduleNext = map["scheduleNext"] as Long, - schedulePrevious = map["schedulePrevious"] as Long, - timeout = map["timeout"] as Long - ) - } - - fun toMap(): Map = mapOf( - "\$id" to id as Any, - "execute" to execute as Any, - "name" to name as Any, - "dateCreated" to dateCreated as Any, - "dateUpdated" to dateUpdated as Any, - "status" to status as Any, - "runtime" to runtime as Any, - "tag" to tag as Any, - "vars" to vars as Any, - "events" to events as Any, - "schedule" to schedule as Any, - "scheduleNext" to scheduleNext as Any, - "schedulePrevious" to schedulePrevious as Any, - "timeout" to timeout as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Index.kt b/library/src/main/java/io/appwrite/models/Index.kt deleted file mode 100644 index 5173b20..0000000 --- a/library/src/main/java/io/appwrite/models/Index.kt +++ /dev/null @@ -1,55 +0,0 @@ -package io.appwrite.models - -/** - * Index - */ -data class Index( - /** - * Index Key. - * - */ - val key: String, - - /** - * Index type. - * - */ - val type: String, - - /** - * Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Index attributes. - * - */ - val attributes: List, - - /** - * Index orders. - * - */ - val orders: List -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = Index( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - attributes = map["attributes"] as List, - orders = map["orders"] as List - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "attributes" to attributes as Any, - "orders" to orders as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Runtime.kt b/library/src/main/java/io/appwrite/models/Runtime.kt deleted file mode 100644 index 664467c..0000000 --- a/library/src/main/java/io/appwrite/models/Runtime.kt +++ /dev/null @@ -1,71 +0,0 @@ -package io.appwrite.models - -/** - * Runtime - */ -data class Runtime( - /** - * Runtime ID. - * - */ - val id: String, - - /** - * Runtime Name. - * - */ - val name: String, - - /** - * Runtime version. - * - */ - val version: String, - - /** - * Base Docker image used to build the runtime. - * - */ - val base: String, - - /** - * Image name of Docker Hub. - * - */ - val image: String, - - /** - * Name of the logo image. - * - */ - val logo: String, - - /** - * List of supported architectures. - * - */ - val supports: List -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = Runtime( - id = map["\$id"] as String, - name = map["name"] as String, - version = map["version"] as String, - base = map["base"] as String, - image = map["image"] as String, - logo = map["logo"] as String, - supports = map["supports"] as List - ) - } - - fun toMap(): Map = mapOf( - "\$id" to id as Any, - "name" to name as Any, - "version" to version as Any, - "base" to base as Any, - "image" to image as Any, - "logo" to logo as Any, - "supports" to supports as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Tag.kt b/library/src/main/java/io/appwrite/models/Tag.kt deleted file mode 100644 index b2a69b9..0000000 --- a/library/src/main/java/io/appwrite/models/Tag.kt +++ /dev/null @@ -1,55 +0,0 @@ -package io.appwrite.models - -/** - * Tag - */ -data class Tag( - /** - * Tag ID. - * - */ - val id: String, - - /** - * Function ID. - * - */ - val functionId: String, - - /** - * The tag creation date in Unix timestamp. - * - */ - val dateCreated: Long, - - /** - * The entrypoint command in use to execute the tag code. - * - */ - val command: String, - - /** - * The code size in bytes. - * - */ - val size: String -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = Tag( - id = map["\$id"] as String, - functionId = map["functionId"] as String, - dateCreated = map["dateCreated"] as Long, - command = map["command"] as String, - size = map["size"] as String - ) - } - - fun toMap(): Map = mapOf( - "\$id" to id as Any, - "functionId" to functionId as Any, - "dateCreated" to dateCreated as Any, - "command" to command as Any, - "size" to size as Any - ) -} \ No newline at end of file From 7c1c0cff77b15c1acf43a84822fe496e8ebc7db4 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 6 Jan 2022 15:53:31 +0545 Subject: [PATCH 07/21] fix version --- README.md | 4 +- build.gradle | 2 +- .../io/appwrite/models/AttributeBoolean.kt | 63 +++++++++ .../java/io/appwrite/models/AttributeEmail.kt | 71 ++++++++++ .../java/io/appwrite/models/AttributeEnum.kt | 79 +++++++++++ .../java/io/appwrite/models/AttributeFloat.kt | 79 +++++++++++ .../io/appwrite/models/AttributeInteger.kt | 79 +++++++++++ .../java/io/appwrite/models/AttributeIp.kt | 71 ++++++++++ .../io/appwrite/models/AttributeString.kt | 71 ++++++++++ .../java/io/appwrite/models/AttributeUrl.kt | 71 ++++++++++ .../java/io/appwrite/models/Collection.kt | 79 +++++++++++ .../main/java/io/appwrite/models/Function.kt | 127 ++++++++++++++++++ .../src/main/java/io/appwrite/models/Index.kt | 55 ++++++++ .../main/java/io/appwrite/models/Runtime.kt | 71 ++++++++++ .../src/main/java/io/appwrite/models/Tag.kt | 55 ++++++++ 15 files changed, 974 insertions(+), 3 deletions(-) create mode 100644 library/src/main/java/io/appwrite/models/AttributeBoolean.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeEmail.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeEnum.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeFloat.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeInteger.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeIp.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeString.kt create mode 100644 library/src/main/java/io/appwrite/models/AttributeUrl.kt create mode 100644 library/src/main/java/io/appwrite/models/Collection.kt create mode 100644 library/src/main/java/io/appwrite/models/Function.kt create mode 100644 library/src/main/java/io/appwrite/models/Index.kt create mode 100644 library/src/main/java/io/appwrite/models/Runtime.kt create mode 100644 library/src/main/java/io/appwrite/models/Tag.kt diff --git a/README.md b/README.md index bc43724..3dca835 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:0.3.1") +implementation("io.appwrite:sdk-for-android:0.3.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 0.3.1 + 0.3.0 ``` diff --git a/build.gradle b/build.gradle index 1c7defb..be4a0fa 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.1" + version "0.3.0" repositories { maven { url "https://plugins.gradle.org/m2/" } google() diff --git a/library/src/main/java/io/appwrite/models/AttributeBoolean.kt b/library/src/main/java/io/appwrite/models/AttributeBoolean.kt new file mode 100644 index 0000000..dc1ea40 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeBoolean.kt @@ -0,0 +1,63 @@ +package io.appwrite.models + +/** + * AttributeBoolean + */ +data class AttributeBoolean( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: Boolean? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeBoolean( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + default = map["default"] as? Boolean + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeEmail.kt b/library/src/main/java/io/appwrite/models/AttributeEmail.kt new file mode 100644 index 0000000..890b40f --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeEmail.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * AttributeEmail + */ +data class AttributeEmail( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * String format. + * + */ + val format: String, + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: String? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeEmail( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + format = map["format"] as String, + default = map["default"] as? String + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "format" to format as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeEnum.kt b/library/src/main/java/io/appwrite/models/AttributeEnum.kt new file mode 100644 index 0000000..e700277 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeEnum.kt @@ -0,0 +1,79 @@ +package io.appwrite.models + +/** + * AttributeEnum + */ +data class AttributeEnum( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * Array of elements in enumerated type. + * + */ + val elements: List, + + /** + * String format. + * + */ + val format: String, + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: String? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeEnum( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + elements = map["elements"] as List, + format = map["format"] as String, + default = map["default"] as? String + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "elements" to elements as Any, + "format" to format as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeFloat.kt b/library/src/main/java/io/appwrite/models/AttributeFloat.kt new file mode 100644 index 0000000..ae7b985 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeFloat.kt @@ -0,0 +1,79 @@ +package io.appwrite.models + +/** + * AttributeFloat + */ +data class AttributeFloat( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * Minimum value to enforce for new documents. + * + */ + var min: Double? = , + + /** + * Maximum value to enforce for new documents. + * + */ + var max: Double? = , + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: Double? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeFloat( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + min = map["min"] as? Double, + max = map["max"] as? Double, + default = map["default"] as? Double + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "min" to min as Any, + "max" to max as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeInteger.kt b/library/src/main/java/io/appwrite/models/AttributeInteger.kt new file mode 100644 index 0000000..d00f804 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeInteger.kt @@ -0,0 +1,79 @@ +package io.appwrite.models + +/** + * AttributeInteger + */ +data class AttributeInteger( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * Minimum value to enforce for new documents. + * + */ + var min: Long? = , + + /** + * Maximum value to enforce for new documents. + * + */ + var max: Long? = , + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: Long? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeInteger( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + min = map["min"] as? Long, + max = map["max"] as? Long, + default = map["default"] as? Long + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "min" to min as Any, + "max" to max as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeIp.kt b/library/src/main/java/io/appwrite/models/AttributeIp.kt new file mode 100644 index 0000000..88c1c22 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeIp.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * AttributeIP + */ +data class AttributeIp( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * String format. + * + */ + val format: String, + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: String? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeIp( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + format = map["format"] as String, + default = map["default"] as? String + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "format" to format as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeString.kt b/library/src/main/java/io/appwrite/models/AttributeString.kt new file mode 100644 index 0000000..d383f4a --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeString.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * AttributeString + */ +data class AttributeString( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * Attribute size. + * + */ + val size: String, + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: String? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeString( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + size = map["size"] as String, + default = map["default"] as? String + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "size" to size as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeUrl.kt b/library/src/main/java/io/appwrite/models/AttributeUrl.kt new file mode 100644 index 0000000..5a8cd5f --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AttributeUrl.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * AttributeURL + */ +data class AttributeUrl( + /** + * Attribute Key. + * + */ + val key: String, + + /** + * Attribute type. + * + */ + val type: String, + + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Is attribute required? + * + */ + val required: Boolean, + + /** + * Is attribute an array? + * + */ + var array: Boolean? = , + + /** + * String format. + * + */ + val format: String, + + /** + * Default value for attribute when not provided. Cannot be set when attribute is required. + * + */ + var default: String? = +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = AttributeUrl( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + required = map["required"] as Boolean, + array = map["array"] as? Boolean, + format = map["format"] as String, + default = map["default"] as? String + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "required" to required as Any, + "array" to array as Any, + "format" to format as Any, + "default" to default as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Collection.kt b/library/src/main/java/io/appwrite/models/Collection.kt new file mode 100644 index 0000000..c16018b --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Collection.kt @@ -0,0 +1,79 @@ +package io.appwrite.models + +/** + * Collection + */ +data class Collection( + /** + * Collection ID. + * + */ + val id: String, + + /** + * Collection read permissions. + * + */ + val read: List, + + /** + * Collection write permissions. + * + */ + val write: List, + + /** + * Collection name. + * + */ + val name: String, + + /** + * Collection enabled. + * + */ + val enabled: Boolean, + + /** + * Collection permission model. Possible values: `document` or `collection` + * + */ + val permission: String, + + /** + * Collection attributes. + * + */ + val attributes: List, + + /** + * Collection indexes. + * + */ + val indexes: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Collection( + id = map["\$id"] as String, + read = map["\$read"] as List, + write = map["\$write"] as List, + name = map["name"] as String, + enabled = map["enabled"] as Boolean, + permission = map["permission"] as String, + attributes = map["attributes"] as List, + indexes = (map["indexes"] as List>).map { Index.from(map = it) } + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "\$read" to read as Any, + "\$write" to write as Any, + "name" to name as Any, + "enabled" to enabled as Any, + "permission" to permission as Any, + "attributes" to attributes as Any, + "indexes" to indexes.map { it.toMap() } as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Function.kt b/library/src/main/java/io/appwrite/models/Function.kt new file mode 100644 index 0000000..bc46e83 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Function.kt @@ -0,0 +1,127 @@ +package io.appwrite.models + +/** + * Function + */ +data class Function( + /** + * Function ID. + * + */ + val id: String, + + /** + * Execution permissions. + * + */ + val execute: String, + + /** + * Function name. + * + */ + val name: String, + + /** + * Function creation date in Unix timestamp. + * + */ + val dateCreated: Long, + + /** + * Function update date in Unix timestamp. + * + */ + val dateUpdated: Long, + + /** + * Function status. Possible values: `disabled`, `enabled` + * + */ + val status: String, + + /** + * Function execution runtime. + * + */ + val runtime: String, + + /** + * Function active tag ID. + * + */ + val tag: String, + + /** + * Function environment variables. + * + */ + val vars: String, + + /** + * Function trigger events. + * + */ + val events: List, + + /** + * Function execution schedult in CRON format. + * + */ + val schedule: String, + + /** + * Function next scheduled execution date in Unix timestamp. + * + */ + val scheduleNext: Long, + + /** + * Function next scheduled execution date in Unix timestamp. + * + */ + val schedulePrevious: Long, + + /** + * Function execution timeout in seconds. + * + */ + val timeout: Long +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Function( + id = map["\$id"] as String, + execute = map["execute"] as String, + name = map["name"] as String, + dateCreated = map["dateCreated"] as Long, + dateUpdated = map["dateUpdated"] as Long, + status = map["status"] as String, + runtime = map["runtime"] as String, + tag = map["tag"] as String, + vars = map["vars"] as String, + events = map["events"] as List, + schedule = map["schedule"] as String, + scheduleNext = map["scheduleNext"] as Long, + schedulePrevious = map["schedulePrevious"] as Long, + timeout = map["timeout"] as Long + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "execute" to execute as Any, + "name" to name as Any, + "dateCreated" to dateCreated as Any, + "dateUpdated" to dateUpdated as Any, + "status" to status as Any, + "runtime" to runtime as Any, + "tag" to tag as Any, + "vars" to vars as Any, + "events" to events as Any, + "schedule" to schedule as Any, + "scheduleNext" to scheduleNext as Any, + "schedulePrevious" to schedulePrevious as Any, + "timeout" to timeout as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Index.kt b/library/src/main/java/io/appwrite/models/Index.kt new file mode 100644 index 0000000..5173b20 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Index.kt @@ -0,0 +1,55 @@ +package io.appwrite.models + +/** + * Index + */ +data class Index( + /** + * Index Key. + * + */ + val key: String, + + /** + * Index type. + * + */ + val type: String, + + /** + * Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + * + */ + val status: String, + + /** + * Index attributes. + * + */ + val attributes: List, + + /** + * Index orders. + * + */ + val orders: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Index( + key = map["key"] as String, + type = map["type"] as String, + status = map["status"] as String, + attributes = map["attributes"] as List, + orders = map["orders"] as List + ) + } + + fun toMap(): Map = mapOf( + "key" to key as Any, + "type" to type as Any, + "status" to status as Any, + "attributes" to attributes as Any, + "orders" to orders as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Runtime.kt b/library/src/main/java/io/appwrite/models/Runtime.kt new file mode 100644 index 0000000..664467c --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Runtime.kt @@ -0,0 +1,71 @@ +package io.appwrite.models + +/** + * Runtime + */ +data class Runtime( + /** + * Runtime ID. + * + */ + val id: String, + + /** + * Runtime Name. + * + */ + val name: String, + + /** + * Runtime version. + * + */ + val version: String, + + /** + * Base Docker image used to build the runtime. + * + */ + val base: String, + + /** + * Image name of Docker Hub. + * + */ + val image: String, + + /** + * Name of the logo image. + * + */ + val logo: String, + + /** + * List of supported architectures. + * + */ + val supports: List +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Runtime( + id = map["\$id"] as String, + name = map["name"] as String, + version = map["version"] as String, + base = map["base"] as String, + image = map["image"] as String, + logo = map["logo"] as String, + supports = map["supports"] as List + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "name" to name as Any, + "version" to version as Any, + "base" to base as Any, + "image" to image as Any, + "logo" to logo as Any, + "supports" to supports as Any + ) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Tag.kt b/library/src/main/java/io/appwrite/models/Tag.kt new file mode 100644 index 0000000..b2a69b9 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Tag.kt @@ -0,0 +1,55 @@ +package io.appwrite.models + +/** + * Tag + */ +data class Tag( + /** + * Tag ID. + * + */ + val id: String, + + /** + * Function ID. + * + */ + val functionId: String, + + /** + * The tag creation date in Unix timestamp. + * + */ + val dateCreated: Long, + + /** + * The entrypoint command in use to execute the tag code. + * + */ + val command: String, + + /** + * The code size in bytes. + * + */ + val size: String +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun from(map: Map) = Tag( + id = map["\$id"] as String, + functionId = map["functionId"] as String, + dateCreated = map["dateCreated"] as Long, + command = map["command"] as String, + size = map["size"] as String + ) + } + + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "functionId" to functionId as Any, + "dateCreated" to dateCreated as Any, + "command" to command as Any, + "size" to size as Any + ) +} \ No newline at end of file From e582f73abbf3770bb1d39e04a81100e7bbd27434 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 6 Jan 2022 17:27:37 +0545 Subject: [PATCH 08/21] fix attribute models --- .../io/appwrite/models/AttributeBoolean.kt | 63 --------- .../java/io/appwrite/models/AttributeEmail.kt | 71 ---------- .../java/io/appwrite/models/AttributeEnum.kt | 79 ----------- .../java/io/appwrite/models/AttributeFloat.kt | 79 ----------- .../io/appwrite/models/AttributeInteger.kt | 79 ----------- .../java/io/appwrite/models/AttributeIp.kt | 71 ---------- .../io/appwrite/models/AttributeString.kt | 71 ---------- .../java/io/appwrite/models/AttributeUrl.kt | 71 ---------- .../java/io/appwrite/models/Collection.kt | 79 ----------- .../main/java/io/appwrite/models/Function.kt | 127 ------------------ .../src/main/java/io/appwrite/models/Index.kt | 55 -------- .../main/java/io/appwrite/models/Runtime.kt | 71 ---------- .../src/main/java/io/appwrite/models/Tag.kt | 55 -------- 13 files changed, 971 deletions(-) delete mode 100644 library/src/main/java/io/appwrite/models/AttributeBoolean.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeEmail.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeEnum.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeFloat.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeInteger.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeIp.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeString.kt delete mode 100644 library/src/main/java/io/appwrite/models/AttributeUrl.kt delete mode 100644 library/src/main/java/io/appwrite/models/Collection.kt delete mode 100644 library/src/main/java/io/appwrite/models/Function.kt delete mode 100644 library/src/main/java/io/appwrite/models/Index.kt delete mode 100644 library/src/main/java/io/appwrite/models/Runtime.kt delete mode 100644 library/src/main/java/io/appwrite/models/Tag.kt diff --git a/library/src/main/java/io/appwrite/models/AttributeBoolean.kt b/library/src/main/java/io/appwrite/models/AttributeBoolean.kt deleted file mode 100644 index dc1ea40..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeBoolean.kt +++ /dev/null @@ -1,63 +0,0 @@ -package io.appwrite.models - -/** - * AttributeBoolean - */ -data class AttributeBoolean( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: Boolean? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeBoolean( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - default = map["default"] as? Boolean - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeEmail.kt b/library/src/main/java/io/appwrite/models/AttributeEmail.kt deleted file mode 100644 index 890b40f..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeEmail.kt +++ /dev/null @@ -1,71 +0,0 @@ -package io.appwrite.models - -/** - * AttributeEmail - */ -data class AttributeEmail( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * String format. - * - */ - val format: String, - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: String? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeEmail( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - format = map["format"] as String, - default = map["default"] as? String - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "format" to format as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeEnum.kt b/library/src/main/java/io/appwrite/models/AttributeEnum.kt deleted file mode 100644 index e700277..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeEnum.kt +++ /dev/null @@ -1,79 +0,0 @@ -package io.appwrite.models - -/** - * AttributeEnum - */ -data class AttributeEnum( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * Array of elements in enumerated type. - * - */ - val elements: List, - - /** - * String format. - * - */ - val format: String, - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: String? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeEnum( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - elements = map["elements"] as List, - format = map["format"] as String, - default = map["default"] as? String - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "elements" to elements as Any, - "format" to format as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeFloat.kt b/library/src/main/java/io/appwrite/models/AttributeFloat.kt deleted file mode 100644 index ae7b985..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeFloat.kt +++ /dev/null @@ -1,79 +0,0 @@ -package io.appwrite.models - -/** - * AttributeFloat - */ -data class AttributeFloat( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * Minimum value to enforce for new documents. - * - */ - var min: Double? = , - - /** - * Maximum value to enforce for new documents. - * - */ - var max: Double? = , - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: Double? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeFloat( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - min = map["min"] as? Double, - max = map["max"] as? Double, - default = map["default"] as? Double - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "min" to min as Any, - "max" to max as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeInteger.kt b/library/src/main/java/io/appwrite/models/AttributeInteger.kt deleted file mode 100644 index d00f804..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeInteger.kt +++ /dev/null @@ -1,79 +0,0 @@ -package io.appwrite.models - -/** - * AttributeInteger - */ -data class AttributeInteger( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * Minimum value to enforce for new documents. - * - */ - var min: Long? = , - - /** - * Maximum value to enforce for new documents. - * - */ - var max: Long? = , - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: Long? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeInteger( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - min = map["min"] as? Long, - max = map["max"] as? Long, - default = map["default"] as? Long - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "min" to min as Any, - "max" to max as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeIp.kt b/library/src/main/java/io/appwrite/models/AttributeIp.kt deleted file mode 100644 index 88c1c22..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeIp.kt +++ /dev/null @@ -1,71 +0,0 @@ -package io.appwrite.models - -/** - * AttributeIP - */ -data class AttributeIp( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * String format. - * - */ - val format: String, - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: String? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeIp( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - format = map["format"] as String, - default = map["default"] as? String - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "format" to format as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeString.kt b/library/src/main/java/io/appwrite/models/AttributeString.kt deleted file mode 100644 index d383f4a..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeString.kt +++ /dev/null @@ -1,71 +0,0 @@ -package io.appwrite.models - -/** - * AttributeString - */ -data class AttributeString( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * Attribute size. - * - */ - val size: String, - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: String? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeString( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - size = map["size"] as String, - default = map["default"] as? String - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "size" to size as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AttributeUrl.kt b/library/src/main/java/io/appwrite/models/AttributeUrl.kt deleted file mode 100644 index 5a8cd5f..0000000 --- a/library/src/main/java/io/appwrite/models/AttributeUrl.kt +++ /dev/null @@ -1,71 +0,0 @@ -package io.appwrite.models - -/** - * AttributeURL - */ -data class AttributeUrl( - /** - * Attribute Key. - * - */ - val key: String, - - /** - * Attribute type. - * - */ - val type: String, - - /** - * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Is attribute required? - * - */ - val required: Boolean, - - /** - * Is attribute an array? - * - */ - var array: Boolean? = , - - /** - * String format. - * - */ - val format: String, - - /** - * Default value for attribute when not provided. Cannot be set when attribute is required. - * - */ - var default: String? = -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = AttributeUrl( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - required = map["required"] as Boolean, - array = map["array"] as? Boolean, - format = map["format"] as String, - default = map["default"] as? String - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "required" to required as Any, - "array" to array as Any, - "format" to format as Any, - "default" to default as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Collection.kt b/library/src/main/java/io/appwrite/models/Collection.kt deleted file mode 100644 index c16018b..0000000 --- a/library/src/main/java/io/appwrite/models/Collection.kt +++ /dev/null @@ -1,79 +0,0 @@ -package io.appwrite.models - -/** - * Collection - */ -data class Collection( - /** - * Collection ID. - * - */ - val id: String, - - /** - * Collection read permissions. - * - */ - val read: List, - - /** - * Collection write permissions. - * - */ - val write: List, - - /** - * Collection name. - * - */ - val name: String, - - /** - * Collection enabled. - * - */ - val enabled: Boolean, - - /** - * Collection permission model. Possible values: `document` or `collection` - * - */ - val permission: String, - - /** - * Collection attributes. - * - */ - val attributes: List, - - /** - * Collection indexes. - * - */ - val indexes: List -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = Collection( - id = map["\$id"] as String, - read = map["\$read"] as List, - write = map["\$write"] as List, - name = map["name"] as String, - enabled = map["enabled"] as Boolean, - permission = map["permission"] as String, - attributes = map["attributes"] as List, - indexes = (map["indexes"] as List>).map { Index.from(map = it) } - ) - } - - fun toMap(): Map = mapOf( - "\$id" to id as Any, - "\$read" to read as Any, - "\$write" to write as Any, - "name" to name as Any, - "enabled" to enabled as Any, - "permission" to permission as Any, - "attributes" to attributes as Any, - "indexes" to indexes.map { it.toMap() } as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Function.kt b/library/src/main/java/io/appwrite/models/Function.kt deleted file mode 100644 index bc46e83..0000000 --- a/library/src/main/java/io/appwrite/models/Function.kt +++ /dev/null @@ -1,127 +0,0 @@ -package io.appwrite.models - -/** - * Function - */ -data class Function( - /** - * Function ID. - * - */ - val id: String, - - /** - * Execution permissions. - * - */ - val execute: String, - - /** - * Function name. - * - */ - val name: String, - - /** - * Function creation date in Unix timestamp. - * - */ - val dateCreated: Long, - - /** - * Function update date in Unix timestamp. - * - */ - val dateUpdated: Long, - - /** - * Function status. Possible values: `disabled`, `enabled` - * - */ - val status: String, - - /** - * Function execution runtime. - * - */ - val runtime: String, - - /** - * Function active tag ID. - * - */ - val tag: String, - - /** - * Function environment variables. - * - */ - val vars: String, - - /** - * Function trigger events. - * - */ - val events: List, - - /** - * Function execution schedult in CRON format. - * - */ - val schedule: String, - - /** - * Function next scheduled execution date in Unix timestamp. - * - */ - val scheduleNext: Long, - - /** - * Function next scheduled execution date in Unix timestamp. - * - */ - val schedulePrevious: Long, - - /** - * Function execution timeout in seconds. - * - */ - val timeout: Long -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = Function( - id = map["\$id"] as String, - execute = map["execute"] as String, - name = map["name"] as String, - dateCreated = map["dateCreated"] as Long, - dateUpdated = map["dateUpdated"] as Long, - status = map["status"] as String, - runtime = map["runtime"] as String, - tag = map["tag"] as String, - vars = map["vars"] as String, - events = map["events"] as List, - schedule = map["schedule"] as String, - scheduleNext = map["scheduleNext"] as Long, - schedulePrevious = map["schedulePrevious"] as Long, - timeout = map["timeout"] as Long - ) - } - - fun toMap(): Map = mapOf( - "\$id" to id as Any, - "execute" to execute as Any, - "name" to name as Any, - "dateCreated" to dateCreated as Any, - "dateUpdated" to dateUpdated as Any, - "status" to status as Any, - "runtime" to runtime as Any, - "tag" to tag as Any, - "vars" to vars as Any, - "events" to events as Any, - "schedule" to schedule as Any, - "scheduleNext" to scheduleNext as Any, - "schedulePrevious" to schedulePrevious as Any, - "timeout" to timeout as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Index.kt b/library/src/main/java/io/appwrite/models/Index.kt deleted file mode 100644 index 5173b20..0000000 --- a/library/src/main/java/io/appwrite/models/Index.kt +++ /dev/null @@ -1,55 +0,0 @@ -package io.appwrite.models - -/** - * Index - */ -data class Index( - /** - * Index Key. - * - */ - val key: String, - - /** - * Index type. - * - */ - val type: String, - - /** - * Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - * - */ - val status: String, - - /** - * Index attributes. - * - */ - val attributes: List, - - /** - * Index orders. - * - */ - val orders: List -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = Index( - key = map["key"] as String, - type = map["type"] as String, - status = map["status"] as String, - attributes = map["attributes"] as List, - orders = map["orders"] as List - ) - } - - fun toMap(): Map = mapOf( - "key" to key as Any, - "type" to type as Any, - "status" to status as Any, - "attributes" to attributes as Any, - "orders" to orders as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Runtime.kt b/library/src/main/java/io/appwrite/models/Runtime.kt deleted file mode 100644 index 664467c..0000000 --- a/library/src/main/java/io/appwrite/models/Runtime.kt +++ /dev/null @@ -1,71 +0,0 @@ -package io.appwrite.models - -/** - * Runtime - */ -data class Runtime( - /** - * Runtime ID. - * - */ - val id: String, - - /** - * Runtime Name. - * - */ - val name: String, - - /** - * Runtime version. - * - */ - val version: String, - - /** - * Base Docker image used to build the runtime. - * - */ - val base: String, - - /** - * Image name of Docker Hub. - * - */ - val image: String, - - /** - * Name of the logo image. - * - */ - val logo: String, - - /** - * List of supported architectures. - * - */ - val supports: List -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = Runtime( - id = map["\$id"] as String, - name = map["name"] as String, - version = map["version"] as String, - base = map["base"] as String, - image = map["image"] as String, - logo = map["logo"] as String, - supports = map["supports"] as List - ) - } - - fun toMap(): Map = mapOf( - "\$id" to id as Any, - "name" to name as Any, - "version" to version as Any, - "base" to base as Any, - "image" to image as Any, - "logo" to logo as Any, - "supports" to supports as Any - ) -} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Tag.kt b/library/src/main/java/io/appwrite/models/Tag.kt deleted file mode 100644 index b2a69b9..0000000 --- a/library/src/main/java/io/appwrite/models/Tag.kt +++ /dev/null @@ -1,55 +0,0 @@ -package io.appwrite.models - -/** - * Tag - */ -data class Tag( - /** - * Tag ID. - * - */ - val id: String, - - /** - * Function ID. - * - */ - val functionId: String, - - /** - * The tag creation date in Unix timestamp. - * - */ - val dateCreated: Long, - - /** - * The entrypoint command in use to execute the tag code. - * - */ - val command: String, - - /** - * The code size in bytes. - * - */ - val size: String -) { - companion object { - @Suppress("UNCHECKED_CAST") - fun from(map: Map) = Tag( - id = map["\$id"] as String, - functionId = map["functionId"] as String, - dateCreated = map["dateCreated"] as Long, - command = map["command"] as String, - size = map["size"] as String - ) - } - - fun toMap(): Map = mapOf( - "\$id" to id as Any, - "functionId" to functionId as Any, - "dateCreated" to dateCreated as Any, - "command" to command as Any, - "size" to size as Any - ) -} \ No newline at end of file From 092b318eb8f9686b2941611162e91c74e32ca07a Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 7 Jan 2022 13:14:32 +0545 Subject: [PATCH 09/21] revert gradle --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index be4a0fa..60022df 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { mavenCentral() } dependencies { - classpath "com.android.tools.build:gradle:7.0.3" + classpath "com.android.tools.build:gradle:4.2.0" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'io.github.gradle-nexus:publish-plugin:1.1.0' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 710f6bd..2dadb9d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Tue Jun 01 15:55:54 IST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME From 67fe1d7ad92626257b8f407d96e099ed1a368c8f Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 21 Jan 2022 21:23:51 +1300 Subject: [PATCH 10/21] Fixes for number conversion and exceptions on Java 16+ --- README.md | 6 +++--- build.gradle | 2 +- .../java/account/update-magic-u-r-l-session.md | 2 +- .../kotlin/account/update-magic-u-r-l-session.md | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- library/src/main/java/io/appwrite/Client.kt | 11 ++++++++++- .../src/main/java/io/appwrite/models/ContinentList.kt | 2 +- .../src/main/java/io/appwrite/models/CountryList.kt | 2 +- library/src/main/java/io/appwrite/models/Currency.kt | 4 ++-- .../src/main/java/io/appwrite/models/CurrencyList.kt | 2 +- .../src/main/java/io/appwrite/models/DocumentList.kt | 2 +- library/src/main/java/io/appwrite/models/Execution.kt | 6 +++--- .../src/main/java/io/appwrite/models/ExecutionList.kt | 2 +- library/src/main/java/io/appwrite/models/File.kt | 4 ++-- library/src/main/java/io/appwrite/models/FileList.kt | 2 +- .../src/main/java/io/appwrite/models/LanguageList.kt | 2 +- library/src/main/java/io/appwrite/models/Log.kt | 2 +- library/src/main/java/io/appwrite/models/LogList.kt | 2 +- .../src/main/java/io/appwrite/models/Membership.kt | 4 ++-- .../main/java/io/appwrite/models/MembershipList.kt | 2 +- library/src/main/java/io/appwrite/models/PhoneList.kt | 2 +- library/src/main/java/io/appwrite/models/Session.kt | 2 +- .../src/main/java/io/appwrite/models/SessionList.kt | 2 +- library/src/main/java/io/appwrite/models/Team.kt | 4 ++-- library/src/main/java/io/appwrite/models/TeamList.kt | 2 +- library/src/main/java/io/appwrite/models/Token.kt | 2 +- library/src/main/java/io/appwrite/models/User.kt | 4 ++-- 27 files changed, 45 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 3dca835..5905436 100644 --- a/README.md +++ b/README.md @@ -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-0.12.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-0.12.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) @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:0.3.0") +implementation("io.appwrite:sdk-for-android:0.3.2") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 0.3.0 + 0.3.2 ``` diff --git a/build.gradle b/build.gradle index 60022df..751076f 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.0" + version "0.3.2" repositories { maven { url "https://plugins.gradle.org/m2/" } google() diff --git a/docs/examples/java/account/update-magic-u-r-l-session.md b/docs/examples/java/account/update-magic-u-r-l-session.md index f8375b9..d0734e1 100644 --- a/docs/examples/java/account/update-magic-u-r-l-session.md +++ b/docs/examples/java/account/update-magic-u-r-l-session.md @@ -19,7 +19,7 @@ public class MainActivity extends AppCompatActivity { Account account = new Account(client); account.updateMagicURLSession( - "", + "[USER_ID]", "[SECRET]" new Continuation() { @NotNull diff --git a/docs/examples/kotlin/account/update-magic-u-r-l-session.md b/docs/examples/kotlin/account/update-magic-u-r-l-session.md index 923574e..3fe1b7c 100644 --- a/docs/examples/kotlin/account/update-magic-u-r-l-session.md +++ b/docs/examples/kotlin/account/update-magic-u-r-l-session.md @@ -18,7 +18,7 @@ class MainActivity : AppCompatActivity() { GlobalScope.launch { val response = account.updateMagicURLSession( - userId = "", + userId = "[USER_ID]", secret = "[SECRET]" ) val json = response.body?.string() diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 710f6bd..2dadb9d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Tue Jun 01 15:55:54 IST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 352294d..312dddd 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -347,8 +347,17 @@ class Client @JvmOverloads constructor( .charStream() .buffered() .use(BufferedReader::readText) + val error = if (response.headers["content-type"]?.contains("application/json") == true) { - body.fromJson() + val map = gson.fromJson>( + body, + object : TypeToken>(){}.type + ) + AppwriteException( + map["message"] as? String ?: "", + (map["code"] as Number).toInt(), + body + ) } else { AppwriteException(body, response.code) } diff --git a/library/src/main/java/io/appwrite/models/ContinentList.kt b/library/src/main/java/io/appwrite/models/ContinentList.kt index 9b076c4..5ec4a01 100644 --- a/library/src/main/java/io/appwrite/models/ContinentList.kt +++ b/library/src/main/java/io/appwrite/models/ContinentList.kt @@ -19,7 +19,7 @@ data class ContinentList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = ContinentList( - sum = map["sum"] as Long, + sum = (map["sum"] as Number).toLong(), continents = (map["continents"] as List>).map { Continent.from(map = it) } ) } diff --git a/library/src/main/java/io/appwrite/models/CountryList.kt b/library/src/main/java/io/appwrite/models/CountryList.kt index a1476a1..fe9b804 100644 --- a/library/src/main/java/io/appwrite/models/CountryList.kt +++ b/library/src/main/java/io/appwrite/models/CountryList.kt @@ -19,7 +19,7 @@ data class CountryList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = CountryList( - sum = map["sum"] as Long, + sum = (map["sum"] as Number).toLong(), countries = (map["countries"] as List>).map { Country.from(map = it) } ) } diff --git a/library/src/main/java/io/appwrite/models/Currency.kt b/library/src/main/java/io/appwrite/models/Currency.kt index 58002c2..a35a7d6 100644 --- a/library/src/main/java/io/appwrite/models/Currency.kt +++ b/library/src/main/java/io/appwrite/models/Currency.kt @@ -52,8 +52,8 @@ data class Currency( symbol = map["symbol"] as String, name = map["name"] as String, symbolNative = map["symbolNative"] as String, - decimalDigits = map["decimalDigits"] as Long, - rounding = map["rounding"] as Double, + decimalDigits = (map["decimalDigits"] as Number).toLong(), + rounding = (map["rounding"] as Number).toDouble(), code = map["code"] as String, namePlural = map["namePlural"] as String ) diff --git a/library/src/main/java/io/appwrite/models/CurrencyList.kt b/library/src/main/java/io/appwrite/models/CurrencyList.kt index d2863d9..c50f951 100644 --- a/library/src/main/java/io/appwrite/models/CurrencyList.kt +++ b/library/src/main/java/io/appwrite/models/CurrencyList.kt @@ -19,7 +19,7 @@ data class CurrencyList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = CurrencyList( - sum = map["sum"] as Long, + sum = (map["sum"] as Number).toLong(), currencies = (map["currencies"] as List>).map { Currency.from(map = it) } ) } diff --git a/library/src/main/java/io/appwrite/models/DocumentList.kt b/library/src/main/java/io/appwrite/models/DocumentList.kt index c05899f..eab362f 100644 --- a/library/src/main/java/io/appwrite/models/DocumentList.kt +++ b/library/src/main/java/io/appwrite/models/DocumentList.kt @@ -19,7 +19,7 @@ data class DocumentList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = DocumentList( - sum = map["sum"] as Long, + sum = (map["sum"] as Number).toLong(), documents = (map["documents"] as List>).map { Document.from(map = it) } ) } diff --git a/library/src/main/java/io/appwrite/models/Execution.kt b/library/src/main/java/io/appwrite/models/Execution.kt index 2d25a73..52537f9 100644 --- a/library/src/main/java/io/appwrite/models/Execution.kt +++ b/library/src/main/java/io/appwrite/models/Execution.kt @@ -70,13 +70,13 @@ data class Execution( id = map["\$id"] as String, read = map["\$read"] as List, functionId = map["functionId"] as String, - dateCreated = map["dateCreated"] as Long, + dateCreated = (map["dateCreated"] as Number).toLong(), trigger = map["trigger"] as String, status = map["status"] as String, - exitCode = map["exitCode"] as Long, + exitCode = (map["exitCode"] as Number).toLong(), stdout = map["stdout"] as String, stderr = map["stderr"] as String, - time = map["time"] as Double + time = (map["time"] as Number).toDouble() ) } diff --git a/library/src/main/java/io/appwrite/models/ExecutionList.kt b/library/src/main/java/io/appwrite/models/ExecutionList.kt index 5ab06b7..597324e 100644 --- a/library/src/main/java/io/appwrite/models/ExecutionList.kt +++ b/library/src/main/java/io/appwrite/models/ExecutionList.kt @@ -19,7 +19,7 @@ data class ExecutionList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = ExecutionList( - sum = map["sum"] as Long, + sum = (map["sum"] as Number).toLong(), executions = (map["executions"] as List>).map { Execution.from(map = it) } ) } diff --git a/library/src/main/java/io/appwrite/models/File.kt b/library/src/main/java/io/appwrite/models/File.kt index 1546c61..ef3aade 100644 --- a/library/src/main/java/io/appwrite/models/File.kt +++ b/library/src/main/java/io/appwrite/models/File.kt @@ -59,10 +59,10 @@ data class File( read = map["\$read"] as List, write = map["\$write"] as List, name = map["name"] as String, - dateCreated = map["dateCreated"] as Long, + dateCreated = (map["dateCreated"] as Number).toLong(), signature = map["signature"] as String, mimeType = map["mimeType"] as String, - sizeOriginal = map["sizeOriginal"] as Long + sizeOriginal = (map["sizeOriginal"] as Number).toLong() ) } diff --git a/library/src/main/java/io/appwrite/models/FileList.kt b/library/src/main/java/io/appwrite/models/FileList.kt index 4c9cf1c..9160ac0 100644 --- a/library/src/main/java/io/appwrite/models/FileList.kt +++ b/library/src/main/java/io/appwrite/models/FileList.kt @@ -19,7 +19,7 @@ data class FileList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = FileList( - sum = map["sum"] as Long, + sum = (map["sum"] as Number).toLong(), files = (map["files"] as List>).map { File.from(map = it) } ) } diff --git a/library/src/main/java/io/appwrite/models/LanguageList.kt b/library/src/main/java/io/appwrite/models/LanguageList.kt index 813c99b..4346157 100644 --- a/library/src/main/java/io/appwrite/models/LanguageList.kt +++ b/library/src/main/java/io/appwrite/models/LanguageList.kt @@ -19,7 +19,7 @@ data class LanguageList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = LanguageList( - sum = map["sum"] as Long, + sum = (map["sum"] as Number).toLong(), languages = (map["languages"] as List>).map { Language.from(map = it) } ) } diff --git a/library/src/main/java/io/appwrite/models/Log.kt b/library/src/main/java/io/appwrite/models/Log.kt index 05a0786..87e2114 100644 --- a/library/src/main/java/io/appwrite/models/Log.kt +++ b/library/src/main/java/io/appwrite/models/Log.kt @@ -139,7 +139,7 @@ data class Log( userName = map["userName"] as String, mode = map["mode"] as String, ip = map["ip"] as String, - time = map["time"] as Long, + time = (map["time"] as Number).toLong(), osCode = map["osCode"] as String, osName = map["osName"] as String, osVersion = map["osVersion"] as String, diff --git a/library/src/main/java/io/appwrite/models/LogList.kt b/library/src/main/java/io/appwrite/models/LogList.kt index a6bbd4a..7fb5178 100644 --- a/library/src/main/java/io/appwrite/models/LogList.kt +++ b/library/src/main/java/io/appwrite/models/LogList.kt @@ -19,7 +19,7 @@ data class LogList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = LogList( - sum = map["sum"] as Long, + sum = (map["sum"] as Number).toLong(), logs = (map["logs"] as List>).map { Log.from(map = it) } ) } diff --git a/library/src/main/java/io/appwrite/models/Membership.kt b/library/src/main/java/io/appwrite/models/Membership.kt index 9e0266f..5375520 100644 --- a/library/src/main/java/io/appwrite/models/Membership.kt +++ b/library/src/main/java/io/appwrite/models/Membership.kt @@ -66,8 +66,8 @@ data class Membership( teamId = map["teamId"] as String, name = map["name"] as String, email = map["email"] as String, - invited = map["invited"] as Long, - joined = map["joined"] as Long, + invited = (map["invited"] as Number).toLong(), + joined = (map["joined"] as Number).toLong(), confirm = map["confirm"] as Boolean, roles = map["roles"] as List ) diff --git a/library/src/main/java/io/appwrite/models/MembershipList.kt b/library/src/main/java/io/appwrite/models/MembershipList.kt index 3935263..66563d8 100644 --- a/library/src/main/java/io/appwrite/models/MembershipList.kt +++ b/library/src/main/java/io/appwrite/models/MembershipList.kt @@ -19,7 +19,7 @@ data class MembershipList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = MembershipList( - sum = map["sum"] as Long, + sum = (map["sum"] as Number).toLong(), memberships = (map["memberships"] as List>).map { Membership.from(map = it) } ) } diff --git a/library/src/main/java/io/appwrite/models/PhoneList.kt b/library/src/main/java/io/appwrite/models/PhoneList.kt index a7b92d0..4331302 100644 --- a/library/src/main/java/io/appwrite/models/PhoneList.kt +++ b/library/src/main/java/io/appwrite/models/PhoneList.kt @@ -19,7 +19,7 @@ data class PhoneList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = PhoneList( - sum = map["sum"] as Long, + sum = (map["sum"] as Number).toLong(), phones = (map["phones"] as List>).map { Phone.from(map = it) } ) } diff --git a/library/src/main/java/io/appwrite/models/Session.kt b/library/src/main/java/io/appwrite/models/Session.kt index fa8a91f..6b5847b 100644 --- a/library/src/main/java/io/appwrite/models/Session.kt +++ b/library/src/main/java/io/appwrite/models/Session.kt @@ -141,7 +141,7 @@ data class Session( fun from(map: Map) = Session( id = map["\$id"] as String, userId = map["userId"] as String, - expire = map["expire"] as Long, + expire = (map["expire"] as Number).toLong(), provider = map["provider"] as String, providerUid = map["providerUid"] as String, providerToken = map["providerToken"] as String, diff --git a/library/src/main/java/io/appwrite/models/SessionList.kt b/library/src/main/java/io/appwrite/models/SessionList.kt index 655701d..2cf2df3 100644 --- a/library/src/main/java/io/appwrite/models/SessionList.kt +++ b/library/src/main/java/io/appwrite/models/SessionList.kt @@ -19,7 +19,7 @@ data class SessionList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = SessionList( - sum = map["sum"] as Long, + sum = (map["sum"] as Number).toLong(), sessions = (map["sessions"] as List>).map { Session.from(map = it) } ) } diff --git a/library/src/main/java/io/appwrite/models/Team.kt b/library/src/main/java/io/appwrite/models/Team.kt index 414886a..895791c 100644 --- a/library/src/main/java/io/appwrite/models/Team.kt +++ b/library/src/main/java/io/appwrite/models/Team.kt @@ -33,8 +33,8 @@ data class Team( fun from(map: Map) = Team( id = map["\$id"] as String, name = map["name"] as String, - dateCreated = map["dateCreated"] as Long, - sum = map["sum"] as Long + dateCreated = (map["dateCreated"] as Number).toLong(), + sum = (map["sum"] as Number).toLong() ) } diff --git a/library/src/main/java/io/appwrite/models/TeamList.kt b/library/src/main/java/io/appwrite/models/TeamList.kt index 3adca8d..db88ac3 100644 --- a/library/src/main/java/io/appwrite/models/TeamList.kt +++ b/library/src/main/java/io/appwrite/models/TeamList.kt @@ -19,7 +19,7 @@ data class TeamList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = TeamList( - sum = map["sum"] as Long, + sum = (map["sum"] as Number).toLong(), teams = (map["teams"] as List>).map { Team.from(map = it) } ) } diff --git a/library/src/main/java/io/appwrite/models/Token.kt b/library/src/main/java/io/appwrite/models/Token.kt index 5041d1a..c11cf3b 100644 --- a/library/src/main/java/io/appwrite/models/Token.kt +++ b/library/src/main/java/io/appwrite/models/Token.kt @@ -34,7 +34,7 @@ data class Token( id = map["\$id"] as String, userId = map["userId"] as String, secret = map["secret"] as String, - expire = map["expire"] as Long + expire = (map["expire"] as Number).toLong() ) } diff --git a/library/src/main/java/io/appwrite/models/User.kt b/library/src/main/java/io/appwrite/models/User.kt index 0af27cc..e852703 100644 --- a/library/src/main/java/io/appwrite/models/User.kt +++ b/library/src/main/java/io/appwrite/models/User.kt @@ -57,9 +57,9 @@ data class User( fun from(map: Map) = User( id = map["\$id"] as String, name = map["name"] as String, - registration = map["registration"] as Long, + registration = (map["registration"] as Number).toLong(), status = map["status"] as Boolean, - passwordUpdate = map["passwordUpdate"] as Long, + passwordUpdate = (map["passwordUpdate"] as Number).toLong(), email = map["email"] as String, emailVerification = map["emailVerification"] as Boolean, prefs = Preferences.from(map = map["prefs"] as Map) From 17c7a4b5542481af511c17c8a653e4d634234759 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 21 Jan 2022 21:24:33 +1300 Subject: [PATCH 11/21] Add snapshot tag --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 751076f..48f98e9 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.2" + version "0.3.2-SNAPSHOT" repositories { maven { url "https://plugins.gradle.org/m2/" } google() From 7c78fa58bdc97b913a959d6f326874423855f739 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 25 Jan 2022 23:24:16 +1300 Subject: [PATCH 12/21] Update generated SDK --- build.gradle | 2 +- library/src/main/java/io/appwrite/services/Account.kt | 5 +++-- library/src/main/java/io/appwrite/services/Database.kt | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 48f98e9..751076f 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.2-SNAPSHOT" + version "0.3.2" repositories { maven { url "https://plugins.gradle.org/m2/" } google() diff --git a/library/src/main/java/io/appwrite/services/Account.kt b/library/src/main/java/io/appwrite/services/Account.kt index 17344c4..2c1b6a1 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -335,8 +335,9 @@ class Account(client: Client) : Service(client) { /** * Update Account Preferences * - * Update currently logged in user account preferences. You can pass only the - * specific settings you wish to update. + * Update currently logged in user account preferences. The object you pass is + * stored as is, and replaces any previous value. The maximum allowed prefs + * size is 64kB and throws error if exceeded. * * @param prefs Prefs key-value JSON object. * @return [io.appwrite.models.User] diff --git a/library/src/main/java/io/appwrite/services/Database.kt b/library/src/main/java/io/appwrite/services/Database.kt index 9e7a077..7b43505 100644 --- a/library/src/main/java/io/appwrite/services/Database.kt +++ b/library/src/main/java/io/appwrite/services/Database.kt @@ -74,7 +74,7 @@ class Database(client: Client) : Service(client) { * integration](/docs/server/database#databaseCreateCollection) API or * directly from your database console. * - * @param collectionId Collection ID. You can create a new collection with validation rules using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection). + * @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 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. @@ -154,7 +154,7 @@ class Database(client: Client) : Service(client) { * Update a document by its unique ID. Using the patch method you can pass * only specific fields that will get updated. * - * @param collectionId Collection ID. You can create a new collection with validation rules using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection). + * @param collectionId Collection ID. * @param documentId Document ID. * @param data Document data as JSON object. * @param read An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. From 63f3795214590ace57917eceaa812b6550838c3d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 27 Jan 2022 23:18:57 +1300 Subject: [PATCH 13/21] Add serialized names to fix deserializing with realtime `payloadType` --- README.md | 6 ++--- build.gradle | 2 +- .../main/java/io/appwrite/models/Continent.kt | 4 ++++ .../java/io/appwrite/models/ContinentList.kt | 4 ++++ .../main/java/io/appwrite/models/Country.kt | 4 ++++ .../java/io/appwrite/models/CountryList.kt | 4 ++++ .../main/java/io/appwrite/models/Currency.kt | 9 +++++++ .../java/io/appwrite/models/CurrencyList.kt | 4 ++++ .../main/java/io/appwrite/models/Document.kt | 6 +++++ .../java/io/appwrite/models/DocumentList.kt | 4 ++++ .../main/java/io/appwrite/models/Execution.kt | 12 ++++++++++ .../java/io/appwrite/models/ExecutionList.kt | 4 ++++ .../src/main/java/io/appwrite/models/File.kt | 10 ++++++++ .../main/java/io/appwrite/models/FileList.kt | 4 ++++ .../src/main/java/io/appwrite/models/Jwt.kt | 3 +++ .../main/java/io/appwrite/models/Language.kt | 5 ++++ .../java/io/appwrite/models/LanguageList.kt | 4 ++++ .../main/java/io/appwrite/models/Locale.kt | 9 +++++++ .../src/main/java/io/appwrite/models/Log.kt | 23 ++++++++++++++++++ .../main/java/io/appwrite/models/LogList.kt | 4 ++++ .../java/io/appwrite/models/Membership.kt | 11 +++++++++ .../java/io/appwrite/models/MembershipList.kt | 4 ++++ .../src/main/java/io/appwrite/models/Phone.kt | 5 ++++ .../main/java/io/appwrite/models/PhoneList.kt | 4 ++++ .../java/io/appwrite/models/Preferences.kt | 2 ++ .../main/java/io/appwrite/models/Session.kt | 24 +++++++++++++++++++ .../java/io/appwrite/models/SessionList.kt | 4 ++++ .../src/main/java/io/appwrite/models/Team.kt | 6 +++++ .../main/java/io/appwrite/models/TeamList.kt | 4 ++++ .../src/main/java/io/appwrite/models/Token.kt | 6 +++++ .../src/main/java/io/appwrite/models/User.kt | 10 ++++++++ 31 files changed, 201 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5905436..6656d46 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:0.3.2") +implementation("io.appwrite:sdk-for-android:0.3.3") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 0.3.2 + 0.3.3 ``` @@ -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. \ No newline at end of file +Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information. diff --git a/build.gradle b/build.gradle index 751076f..42d442d 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.2" + version "0.3.3" repositories { maven { url "https://plugins.gradle.org/m2/" } google() diff --git a/library/src/main/java/io/appwrite/models/Continent.kt b/library/src/main/java/io/appwrite/models/Continent.kt index da6eca6..ba8b5ae 100644 --- a/library/src/main/java/io/appwrite/models/Continent.kt +++ b/library/src/main/java/io/appwrite/models/Continent.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Continent */ @@ -8,12 +10,14 @@ data class Continent( * Continent name. * */ + @SerializedName("name") val name: String, /** * Continent two letter code. * */ + @SerializedName("code") val code: String ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/ContinentList.kt b/library/src/main/java/io/appwrite/models/ContinentList.kt index 5ec4a01..0e7a052 100644 --- a/library/src/main/java/io/appwrite/models/ContinentList.kt +++ b/library/src/main/java/io/appwrite/models/ContinentList.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Continents List */ @@ -8,12 +10,14 @@ data class ContinentList( * Total number of items available on the server. * */ + @SerializedName("sum") val sum: Long, /** * List of continents. * */ + @SerializedName("continents") val continents: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Country.kt b/library/src/main/java/io/appwrite/models/Country.kt index 8c1d608..51fee8f 100644 --- a/library/src/main/java/io/appwrite/models/Country.kt +++ b/library/src/main/java/io/appwrite/models/Country.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Country */ @@ -8,12 +10,14 @@ data class Country( * Country name. * */ + @SerializedName("name") val name: String, /** * Country two-character ISO 3166-1 alpha code. * */ + @SerializedName("code") val code: String ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/CountryList.kt b/library/src/main/java/io/appwrite/models/CountryList.kt index fe9b804..7cbb9b4 100644 --- a/library/src/main/java/io/appwrite/models/CountryList.kt +++ b/library/src/main/java/io/appwrite/models/CountryList.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Countries List */ @@ -8,12 +10,14 @@ data class CountryList( * Total number of items available on the server. * */ + @SerializedName("sum") val sum: Long, /** * List of countries. * */ + @SerializedName("countries") val countries: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Currency.kt b/library/src/main/java/io/appwrite/models/Currency.kt index a35a7d6..df6e230 100644 --- a/library/src/main/java/io/appwrite/models/Currency.kt +++ b/library/src/main/java/io/appwrite/models/Currency.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Currency */ @@ -8,42 +10,49 @@ data class Currency( * Currency symbol. * */ + @SerializedName("symbol") val symbol: String, /** * Currency name. * */ + @SerializedName("name") val name: String, /** * Currency native symbol. * */ + @SerializedName("symbolNative") val symbolNative: String, /** * Number of decimal digits. * */ + @SerializedName("decimalDigits") val decimalDigits: Long, /** * Currency digit rounding. * */ + @SerializedName("rounding") val rounding: Double, /** * Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format. * */ + @SerializedName("code") val code: String, /** * Currency plural name * */ + @SerializedName("namePlural") val namePlural: String ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/CurrencyList.kt b/library/src/main/java/io/appwrite/models/CurrencyList.kt index c50f951..a311340 100644 --- a/library/src/main/java/io/appwrite/models/CurrencyList.kt +++ b/library/src/main/java/io/appwrite/models/CurrencyList.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Currencies List */ @@ -8,12 +10,14 @@ data class CurrencyList( * Total number of items available on the server. * */ + @SerializedName("sum") val sum: Long, /** * List of currencies. * */ + @SerializedName("currencies") val currencies: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Document.kt b/library/src/main/java/io/appwrite/models/Document.kt index f443676..a83a844 100644 --- a/library/src/main/java/io/appwrite/models/Document.kt +++ b/library/src/main/java/io/appwrite/models/Document.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Document */ @@ -8,24 +10,28 @@ data class Document( * Document ID. * */ + @SerializedName("\$id") val id: String, /** * Collection ID. * */ + @SerializedName("\$collection") val collection: String, /** * Document read permissions. * */ + @SerializedName("\$read") val read: List, /** * Document write permissions. * */ + @SerializedName("\$write") val write: List, val data: Map diff --git a/library/src/main/java/io/appwrite/models/DocumentList.kt b/library/src/main/java/io/appwrite/models/DocumentList.kt index eab362f..1807253 100644 --- a/library/src/main/java/io/appwrite/models/DocumentList.kt +++ b/library/src/main/java/io/appwrite/models/DocumentList.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Documents List */ @@ -8,12 +10,14 @@ data class DocumentList( * Total number of items available on the server. * */ + @SerializedName("sum") val sum: Long, /** * List of documents. * */ + @SerializedName("documents") val documents: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Execution.kt b/library/src/main/java/io/appwrite/models/Execution.kt index 52537f9..f03925d 100644 --- a/library/src/main/java/io/appwrite/models/Execution.kt +++ b/library/src/main/java/io/appwrite/models/Execution.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Execution */ @@ -8,60 +10,70 @@ data class Execution( * Execution ID. * */ + @SerializedName("\$id") val id: String, /** * Execution read permissions. * */ + @SerializedName("\$read") val read: List, /** * Function ID. * */ + @SerializedName("functionId") val functionId: String, /** * The execution creation date in Unix timestamp. * */ + @SerializedName("dateCreated") val dateCreated: Long, /** * The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. * */ + @SerializedName("trigger") val trigger: String, /** * The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. * */ + @SerializedName("status") val status: String, /** * The script exit code. * */ + @SerializedName("exitCode") val exitCode: Long, /** * The script stdout output string. Logs the last 4,000 characters of the execution stdout output. * */ + @SerializedName("stdout") val stdout: String, /** * The script stderr output string. Logs the last 4,000 characters of the execution stderr output * */ + @SerializedName("stderr") val stderr: String, /** * The script execution time in seconds. * */ + @SerializedName("time") val time: Double ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/ExecutionList.kt b/library/src/main/java/io/appwrite/models/ExecutionList.kt index 597324e..c771f57 100644 --- a/library/src/main/java/io/appwrite/models/ExecutionList.kt +++ b/library/src/main/java/io/appwrite/models/ExecutionList.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Executions List */ @@ -8,12 +10,14 @@ data class ExecutionList( * Total number of items available on the server. * */ + @SerializedName("sum") val sum: Long, /** * List of executions. * */ + @SerializedName("executions") val executions: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/File.kt b/library/src/main/java/io/appwrite/models/File.kt index ef3aade..1f9e734 100644 --- a/library/src/main/java/io/appwrite/models/File.kt +++ b/library/src/main/java/io/appwrite/models/File.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * File */ @@ -8,48 +10,56 @@ data class File( * File ID. * */ + @SerializedName("\$id") val id: String, /** * File read permissions. * */ + @SerializedName("\$read") val read: List, /** * File write permissions. * */ + @SerializedName("\$write") val write: List, /** * File name. * */ + @SerializedName("name") val name: String, /** * File creation date in Unix timestamp. * */ + @SerializedName("dateCreated") val dateCreated: Long, /** * File MD5 signature. * */ + @SerializedName("signature") val signature: String, /** * File mime type. * */ + @SerializedName("mimeType") val mimeType: String, /** * File original size in bytes. * */ + @SerializedName("sizeOriginal") val sizeOriginal: Long ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/FileList.kt b/library/src/main/java/io/appwrite/models/FileList.kt index 9160ac0..d000dfc 100644 --- a/library/src/main/java/io/appwrite/models/FileList.kt +++ b/library/src/main/java/io/appwrite/models/FileList.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Files List */ @@ -8,12 +10,14 @@ data class FileList( * Total number of items available on the server. * */ + @SerializedName("sum") val sum: Long, /** * List of files. * */ + @SerializedName("files") val files: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Jwt.kt b/library/src/main/java/io/appwrite/models/Jwt.kt index 4012643..c871237 100644 --- a/library/src/main/java/io/appwrite/models/Jwt.kt +++ b/library/src/main/java/io/appwrite/models/Jwt.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * JWT */ @@ -8,6 +10,7 @@ data class Jwt( * JWT encoded string. * */ + @SerializedName("jwt") val jwt: String ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Language.kt b/library/src/main/java/io/appwrite/models/Language.kt index 0f050a8..045202f 100644 --- a/library/src/main/java/io/appwrite/models/Language.kt +++ b/library/src/main/java/io/appwrite/models/Language.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Language */ @@ -8,18 +10,21 @@ data class Language( * Language name. * */ + @SerializedName("name") val name: String, /** * Language two-character ISO 639-1 codes. * */ + @SerializedName("code") val code: String, /** * Language native name. * */ + @SerializedName("nativeName") val nativeName: String ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/LanguageList.kt b/library/src/main/java/io/appwrite/models/LanguageList.kt index 4346157..6c688a6 100644 --- a/library/src/main/java/io/appwrite/models/LanguageList.kt +++ b/library/src/main/java/io/appwrite/models/LanguageList.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Languages List */ @@ -8,12 +10,14 @@ data class LanguageList( * Total number of items available on the server. * */ + @SerializedName("sum") val sum: Long, /** * List of languages. * */ + @SerializedName("languages") val languages: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Locale.kt b/library/src/main/java/io/appwrite/models/Locale.kt index 6e812c5..d8d3fcf 100644 --- a/library/src/main/java/io/appwrite/models/Locale.kt +++ b/library/src/main/java/io/appwrite/models/Locale.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Locale */ @@ -8,42 +10,49 @@ data class Locale( * User IP address. * */ + @SerializedName("ip") val ip: String, /** * Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format * */ + @SerializedName("countryCode") val countryCode: String, /** * Country name. This field support localization. * */ + @SerializedName("country") val country: String, /** * Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America. * */ + @SerializedName("continentCode") val continentCode: String, /** * Continent name. This field support localization. * */ + @SerializedName("continent") val continent: String, /** * True if country is part of the Europian Union. * */ + @SerializedName("eu") val eu: Boolean, /** * Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format * */ + @SerializedName("currency") val currency: String ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Log.kt b/library/src/main/java/io/appwrite/models/Log.kt index 87e2114..fb4de88 100644 --- a/library/src/main/java/io/appwrite/models/Log.kt +++ b/library/src/main/java/io/appwrite/models/Log.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Log */ @@ -8,126 +10,147 @@ data class Log( * Event name. * */ + @SerializedName("event") val event: String, /** * User ID. * */ + @SerializedName("userId") val userId: String, /** * User Email. * */ + @SerializedName("userEmail") val userEmail: String, /** * User Name. * */ + @SerializedName("userName") val userName: String, /** * API mode when event triggered. * */ + @SerializedName("mode") val mode: String, /** * IP session in use when the session was created. * */ + @SerializedName("ip") val ip: String, /** * Log creation time in Unix timestamp. * */ + @SerializedName("time") val time: Long, /** * Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). * */ + @SerializedName("osCode") val osCode: String, /** * Operating system name. * */ + @SerializedName("osName") val osName: String, /** * Operating system version. * */ + @SerializedName("osVersion") val osVersion: String, /** * Client type. * */ + @SerializedName("clientType") val clientType: String, /** * Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). * */ + @SerializedName("clientCode") val clientCode: String, /** * Client name. * */ + @SerializedName("clientName") val clientName: String, /** * Client version. * */ + @SerializedName("clientVersion") val clientVersion: String, /** * Client engine name. * */ + @SerializedName("clientEngine") val clientEngine: String, /** * Client engine name. * */ + @SerializedName("clientEngineVersion") val clientEngineVersion: String, /** * Device name. * */ + @SerializedName("deviceName") val deviceName: String, /** * Device brand name. * */ + @SerializedName("deviceBrand") val deviceBrand: String, /** * Device model name. * */ + @SerializedName("deviceModel") val deviceModel: String, /** * Country two-character ISO 3166-1 alpha code. * */ + @SerializedName("countryCode") val countryCode: String, /** * Country name. * */ + @SerializedName("countryName") val countryName: String ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/LogList.kt b/library/src/main/java/io/appwrite/models/LogList.kt index 7fb5178..d6666cf 100644 --- a/library/src/main/java/io/appwrite/models/LogList.kt +++ b/library/src/main/java/io/appwrite/models/LogList.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Logs List */ @@ -8,12 +10,14 @@ data class LogList( * Total number of items available on the server. * */ + @SerializedName("sum") val sum: Long, /** * List of logs. * */ + @SerializedName("logs") val logs: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Membership.kt b/library/src/main/java/io/appwrite/models/Membership.kt index 5375520..45b42c8 100644 --- a/library/src/main/java/io/appwrite/models/Membership.kt +++ b/library/src/main/java/io/appwrite/models/Membership.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Membership */ @@ -8,54 +10,63 @@ data class Membership( * Membership ID. * */ + @SerializedName("\$id") val id: String, /** * User ID. * */ + @SerializedName("userId") val userId: String, /** * Team ID. * */ + @SerializedName("teamId") val teamId: String, /** * User name. * */ + @SerializedName("name") val name: String, /** * User email address. * */ + @SerializedName("email") val email: String, /** * Date, the user has been invited to join the team in Unix timestamp. * */ + @SerializedName("invited") val invited: Long, /** * Date, the user has accepted the invitation to join the team in Unix timestamp. * */ + @SerializedName("joined") val joined: Long, /** * User confirmation status, true if the user has joined the team or false otherwise. * */ + @SerializedName("confirm") val confirm: Boolean, /** * User list of roles * */ + @SerializedName("roles") val roles: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/MembershipList.kt b/library/src/main/java/io/appwrite/models/MembershipList.kt index 66563d8..3171fae 100644 --- a/library/src/main/java/io/appwrite/models/MembershipList.kt +++ b/library/src/main/java/io/appwrite/models/MembershipList.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Memberships List */ @@ -8,12 +10,14 @@ data class MembershipList( * Total number of items available on the server. * */ + @SerializedName("sum") val sum: Long, /** * List of memberships. * */ + @SerializedName("memberships") val memberships: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Phone.kt b/library/src/main/java/io/appwrite/models/Phone.kt index a11de9d..bfa3113 100644 --- a/library/src/main/java/io/appwrite/models/Phone.kt +++ b/library/src/main/java/io/appwrite/models/Phone.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Phone */ @@ -8,18 +10,21 @@ data class Phone( * Phone code. * */ + @SerializedName("code") val code: String, /** * Country two-character ISO 3166-1 alpha code. * */ + @SerializedName("countryCode") val countryCode: String, /** * Country name. * */ + @SerializedName("countryName") val countryName: String ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/PhoneList.kt b/library/src/main/java/io/appwrite/models/PhoneList.kt index 4331302..d9338cb 100644 --- a/library/src/main/java/io/appwrite/models/PhoneList.kt +++ b/library/src/main/java/io/appwrite/models/PhoneList.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Phones List */ @@ -8,12 +10,14 @@ data class PhoneList( * Total number of items available on the server. * */ + @SerializedName("sum") val sum: Long, /** * List of phones. * */ + @SerializedName("phones") val phones: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Preferences.kt b/library/src/main/java/io/appwrite/models/Preferences.kt index a95850f..0b11e85 100644 --- a/library/src/main/java/io/appwrite/models/Preferences.kt +++ b/library/src/main/java/io/appwrite/models/Preferences.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Preferences */ diff --git a/library/src/main/java/io/appwrite/models/Session.kt b/library/src/main/java/io/appwrite/models/Session.kt index 6b5847b..1ee5187 100644 --- a/library/src/main/java/io/appwrite/models/Session.kt +++ b/library/src/main/java/io/appwrite/models/Session.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Session */ @@ -8,132 +10,154 @@ data class Session( * Session ID. * */ + @SerializedName("\$id") val id: String, /** * User ID. * */ + @SerializedName("userId") val userId: String, /** * Session expiration date in Unix timestamp. * */ + @SerializedName("expire") val expire: Long, /** * Session Provider. * */ + @SerializedName("provider") val provider: String, /** * Session Provider User ID. * */ + @SerializedName("providerUid") val providerUid: String, /** * Session Provider Token. * */ + @SerializedName("providerToken") val providerToken: String, /** * IP in use when the session was created. * */ + @SerializedName("ip") val ip: String, /** * Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). * */ + @SerializedName("osCode") val osCode: String, /** * Operating system name. * */ + @SerializedName("osName") val osName: String, /** * Operating system version. * */ + @SerializedName("osVersion") val osVersion: String, /** * Client type. * */ + @SerializedName("clientType") val clientType: String, /** * Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). * */ + @SerializedName("clientCode") val clientCode: String, /** * Client name. * */ + @SerializedName("clientName") val clientName: String, /** * Client version. * */ + @SerializedName("clientVersion") val clientVersion: String, /** * Client engine name. * */ + @SerializedName("clientEngine") val clientEngine: String, /** * Client engine name. * */ + @SerializedName("clientEngineVersion") val clientEngineVersion: String, /** * Device name. * */ + @SerializedName("deviceName") val deviceName: String, /** * Device brand name. * */ + @SerializedName("deviceBrand") val deviceBrand: String, /** * Device model name. * */ + @SerializedName("deviceModel") val deviceModel: String, /** * Country two-character ISO 3166-1 alpha code. * */ + @SerializedName("countryCode") val countryCode: String, /** * Country name. * */ + @SerializedName("countryName") val countryName: String, /** * Returns true if this the current user session. * */ + @SerializedName("current") val current: Boolean ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/SessionList.kt b/library/src/main/java/io/appwrite/models/SessionList.kt index 2cf2df3..2d6a4bd 100644 --- a/library/src/main/java/io/appwrite/models/SessionList.kt +++ b/library/src/main/java/io/appwrite/models/SessionList.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Sessions List */ @@ -8,12 +10,14 @@ data class SessionList( * Total number of items available on the server. * */ + @SerializedName("sum") val sum: Long, /** * List of sessions. * */ + @SerializedName("sessions") val sessions: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Team.kt b/library/src/main/java/io/appwrite/models/Team.kt index 895791c..d0eda4e 100644 --- a/library/src/main/java/io/appwrite/models/Team.kt +++ b/library/src/main/java/io/appwrite/models/Team.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Team */ @@ -8,24 +10,28 @@ data class Team( * Team ID. * */ + @SerializedName("\$id") val id: String, /** * Team name. * */ + @SerializedName("name") val name: String, /** * Team creation date in Unix timestamp. * */ + @SerializedName("dateCreated") val dateCreated: Long, /** * Total sum of team members. * */ + @SerializedName("sum") val sum: Long ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/TeamList.kt b/library/src/main/java/io/appwrite/models/TeamList.kt index db88ac3..af63825 100644 --- a/library/src/main/java/io/appwrite/models/TeamList.kt +++ b/library/src/main/java/io/appwrite/models/TeamList.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Teams List */ @@ -8,12 +10,14 @@ data class TeamList( * Total number of items available on the server. * */ + @SerializedName("sum") val sum: Long, /** * List of teams. * */ + @SerializedName("teams") val teams: List ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/Token.kt b/library/src/main/java/io/appwrite/models/Token.kt index c11cf3b..d555f45 100644 --- a/library/src/main/java/io/appwrite/models/Token.kt +++ b/library/src/main/java/io/appwrite/models/Token.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * Token */ @@ -8,24 +10,28 @@ data class Token( * Token ID. * */ + @SerializedName("\$id") val id: String, /** * User ID. * */ + @SerializedName("userId") val userId: String, /** * Token secret key. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. * */ + @SerializedName("secret") val secret: String, /** * Token expiration date in Unix timestamp. * */ + @SerializedName("expire") val expire: Long ) { companion object { diff --git a/library/src/main/java/io/appwrite/models/User.kt b/library/src/main/java/io/appwrite/models/User.kt index e852703..032391e 100644 --- a/library/src/main/java/io/appwrite/models/User.kt +++ b/library/src/main/java/io/appwrite/models/User.kt @@ -1,5 +1,7 @@ package io.appwrite.models +import com.google.gson.annotations.SerializedName + /** * User */ @@ -8,48 +10,56 @@ data class User( * User ID. * */ + @SerializedName("\$id") val id: String, /** * User name. * */ + @SerializedName("name") val name: String, /** * User registration date in Unix timestamp. * */ + @SerializedName("registration") val registration: Long, /** * User status. Pass `true` for enabled and `false` for disabled. * */ + @SerializedName("status") val status: Boolean, /** * Unix timestamp of the most recent password update * */ + @SerializedName("passwordUpdate") val passwordUpdate: Long, /** * User email address. * */ + @SerializedName("email") val email: String, /** * Email verification status. * */ + @SerializedName("emailVerification") val emailVerification: Boolean, /** * User preferences as a key-value object * */ + @SerializedName("prefs") val prefs: Preferences ) { companion object { From 5b9c43f8722b87cca302cd5bdfd3b66c463fcdf2 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 2 Mar 2022 12:23:43 +0100 Subject: [PATCH 14/21] feat: support for 0.13.0 --- 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 +- library/build.gradle | 2 + library/src/main/java/io/appwrite/Client.kt | 98 +++++++++- .../appwrite/exceptions/AppwriteException.kt | 1 + .../java/io/appwrite/models/ContinentList.kt | 10 +- .../java/io/appwrite/models/CountryList.kt | 10 +- .../java/io/appwrite/models/CurrencyList.kt | 10 +- .../java/io/appwrite/models/DocumentList.kt | 10 +- .../main/java/io/appwrite/models/Execution.kt | 10 +- .../java/io/appwrite/models/ExecutionList.kt | 10 +- .../src/main/java/io/appwrite/models/File.kt | 33 +++- .../main/java/io/appwrite/models/FileList.kt | 10 +- .../java/io/appwrite/models/LanguageList.kt | 10 +- .../main/java/io/appwrite/models/LogList.kt | 10 +- .../java/io/appwrite/models/MembershipList.kt | 10 +- .../main/java/io/appwrite/models/PhoneList.kt | 10 +- .../java/io/appwrite/models/RealtimeModels.kt | 1 + .../main/java/io/appwrite/models/Session.kt | 28 ++- .../java/io/appwrite/models/SessionList.kt | 10 +- .../src/main/java/io/appwrite/models/Team.kt | 10 +- .../main/java/io/appwrite/models/TeamList.kt | 10 +- .../java/io/appwrite/models/UploadProgress.kt | 9 + .../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 +++---- 50 files changed, 694 insertions(+), 282 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 create mode 100644 library/src/main/java/io/appwrite/models/UploadProgress.kt diff --git a/README.md b/README.md index 6656d46..8c463db 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.13.0-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/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..902fd7f 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -8,6 +8,7 @@ import io.appwrite.appwrite.BuildConfig import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.fromJson import io.appwrite.json.PreciseNumberAdapter +import io.appwrite.models.UploadProgress import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -42,6 +43,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 @@ -79,7 +84,7 @@ class Client @JvmOverloads constructor( "origin" to "appwrite-android://${context.packageName}", "user-agent" to "${context.packageName}/${appVersion}, ${System.getProperty("http.agent")}", "x-sdk-version" to "appwrite:android:${BuildConfig.SDK_VERSION}", - "x-appwrite-response-format" to "0.12.0" + "x-appwrite-response-format" to "0.13.0" ) config = mutableMapOf() @@ -231,7 +236,7 @@ class Client @JvmOverloads constructor( * @param headers * @param params * - * @return [Response] + * @return [T] */ @Throws(AppwriteException::class) suspend fun call( @@ -285,8 +290,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 +321,89 @@ 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: ((UploadProgress) -> 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(UploadProgress( + id = result!!["\$id"].toString(), + progress = offset.coerceAtMost(size).toDouble()/size * 100, + sizeUploaded = offset.coerceAtMost(size), + chunksTotal = result!!["chunksTotal"].toString().toInt(), + chunksUploaded = result!!["chunksUploaded"].toString().toInt(), + )) + } + + return convert(result as Map) + } + /** * Await Response * @@ -355,7 +442,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/ContinentList.kt b/library/src/main/java/io/appwrite/models/ContinentList.kt index 0e7a052..6a09c92 100644 --- a/library/src/main/java/io/appwrite/models/ContinentList.kt +++ b/library/src/main/java/io/appwrite/models/ContinentList.kt @@ -7,11 +7,11 @@ import com.google.gson.annotations.SerializedName */ data class ContinentList( /** - * Total number of items available on the server. + * Total number of continents documents that matched your query. * */ - @SerializedName("sum") - val sum: Long, + @SerializedName("total") + val total: Long, /** * List of continents. @@ -23,13 +23,13 @@ data class ContinentList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = ContinentList( - sum = (map["sum"] as Number).toLong(), + total = (map["total"] as Number).toLong(), continents = (map["continents"] as List>).map { Continent.from(map = it) } ) } fun toMap(): Map = mapOf( - "sum" to sum as Any, + "total" to total as Any, "continents" to continents.map { it.toMap() } as Any ) } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/CountryList.kt b/library/src/main/java/io/appwrite/models/CountryList.kt index 7cbb9b4..98dbfcd 100644 --- a/library/src/main/java/io/appwrite/models/CountryList.kt +++ b/library/src/main/java/io/appwrite/models/CountryList.kt @@ -7,11 +7,11 @@ import com.google.gson.annotations.SerializedName */ data class CountryList( /** - * Total number of items available on the server. + * Total number of countries documents that matched your query. * */ - @SerializedName("sum") - val sum: Long, + @SerializedName("total") + val total: Long, /** * List of countries. @@ -23,13 +23,13 @@ data class CountryList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = CountryList( - sum = (map["sum"] as Number).toLong(), + total = (map["total"] as Number).toLong(), countries = (map["countries"] as List>).map { Country.from(map = it) } ) } fun toMap(): Map = mapOf( - "sum" to sum as Any, + "total" to total as Any, "countries" to countries.map { it.toMap() } as Any ) } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/CurrencyList.kt b/library/src/main/java/io/appwrite/models/CurrencyList.kt index a311340..abc719d 100644 --- a/library/src/main/java/io/appwrite/models/CurrencyList.kt +++ b/library/src/main/java/io/appwrite/models/CurrencyList.kt @@ -7,11 +7,11 @@ import com.google.gson.annotations.SerializedName */ data class CurrencyList( /** - * Total number of items available on the server. + * Total number of currencies documents that matched your query. * */ - @SerializedName("sum") - val sum: Long, + @SerializedName("total") + val total: Long, /** * List of currencies. @@ -23,13 +23,13 @@ data class CurrencyList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = CurrencyList( - sum = (map["sum"] as Number).toLong(), + total = (map["total"] as Number).toLong(), currencies = (map["currencies"] as List>).map { Currency.from(map = it) } ) } fun toMap(): Map = mapOf( - "sum" to sum as Any, + "total" to total as Any, "currencies" to currencies.map { it.toMap() } as Any ) } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/DocumentList.kt b/library/src/main/java/io/appwrite/models/DocumentList.kt index 1807253..f8e41b5 100644 --- a/library/src/main/java/io/appwrite/models/DocumentList.kt +++ b/library/src/main/java/io/appwrite/models/DocumentList.kt @@ -7,11 +7,11 @@ import com.google.gson.annotations.SerializedName */ data class DocumentList( /** - * Total number of items available on the server. + * Total number of documents documents that matched your query. * */ - @SerializedName("sum") - val sum: Long, + @SerializedName("total") + val total: Long, /** * List of documents. @@ -23,13 +23,13 @@ data class DocumentList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = DocumentList( - sum = (map["sum"] as Number).toLong(), + total = (map["total"] as Number).toLong(), documents = (map["documents"] as List>).map { Document.from(map = it) } ) } fun toMap(): Map = mapOf( - "sum" to sum as Any, + "total" to total as Any, "documents" to documents.map { it.toMap() } as Any ) 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/ExecutionList.kt b/library/src/main/java/io/appwrite/models/ExecutionList.kt index c771f57..2131ffc 100644 --- a/library/src/main/java/io/appwrite/models/ExecutionList.kt +++ b/library/src/main/java/io/appwrite/models/ExecutionList.kt @@ -7,11 +7,11 @@ import com.google.gson.annotations.SerializedName */ data class ExecutionList( /** - * Total number of items available on the server. + * Total number of executions documents that matched your query. * */ - @SerializedName("sum") - val sum: Long, + @SerializedName("total") + val total: Long, /** * List of executions. @@ -23,13 +23,13 @@ data class ExecutionList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = ExecutionList( - sum = (map["sum"] as Number).toLong(), + total = (map["total"] as Number).toLong(), executions = (map["executions"] as List>).map { Execution.from(map = it) } ) } fun toMap(): Map = mapOf( - "sum" to sum as Any, + "total" to total as Any, "executions" to executions.map { it.toMap() } as Any ) } \ No newline at end of file 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/FileList.kt b/library/src/main/java/io/appwrite/models/FileList.kt index d000dfc..477bad2 100644 --- a/library/src/main/java/io/appwrite/models/FileList.kt +++ b/library/src/main/java/io/appwrite/models/FileList.kt @@ -7,11 +7,11 @@ import com.google.gson.annotations.SerializedName */ data class FileList( /** - * Total number of items available on the server. + * Total number of files documents that matched your query. * */ - @SerializedName("sum") - val sum: Long, + @SerializedName("total") + val total: Long, /** * List of files. @@ -23,13 +23,13 @@ data class FileList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = FileList( - sum = (map["sum"] as Number).toLong(), + total = (map["total"] as Number).toLong(), files = (map["files"] as List>).map { File.from(map = it) } ) } fun toMap(): Map = mapOf( - "sum" to sum as Any, + "total" to total as Any, "files" to files.map { it.toMap() } as Any ) } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/LanguageList.kt b/library/src/main/java/io/appwrite/models/LanguageList.kt index 6c688a6..8ca4f5f 100644 --- a/library/src/main/java/io/appwrite/models/LanguageList.kt +++ b/library/src/main/java/io/appwrite/models/LanguageList.kt @@ -7,11 +7,11 @@ import com.google.gson.annotations.SerializedName */ data class LanguageList( /** - * Total number of items available on the server. + * Total number of languages documents that matched your query. * */ - @SerializedName("sum") - val sum: Long, + @SerializedName("total") + val total: Long, /** * List of languages. @@ -23,13 +23,13 @@ data class LanguageList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = LanguageList( - sum = (map["sum"] as Number).toLong(), + total = (map["total"] as Number).toLong(), languages = (map["languages"] as List>).map { Language.from(map = it) } ) } fun toMap(): Map = mapOf( - "sum" to sum as Any, + "total" to total as Any, "languages" to languages.map { it.toMap() } as Any ) } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/LogList.kt b/library/src/main/java/io/appwrite/models/LogList.kt index d6666cf..47d5680 100644 --- a/library/src/main/java/io/appwrite/models/LogList.kt +++ b/library/src/main/java/io/appwrite/models/LogList.kt @@ -7,11 +7,11 @@ import com.google.gson.annotations.SerializedName */ data class LogList( /** - * Total number of items available on the server. + * Total number of logs documents that matched your query. * */ - @SerializedName("sum") - val sum: Long, + @SerializedName("total") + val total: Long, /** * List of logs. @@ -23,13 +23,13 @@ data class LogList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = LogList( - sum = (map["sum"] as Number).toLong(), + total = (map["total"] as Number).toLong(), logs = (map["logs"] as List>).map { Log.from(map = it) } ) } fun toMap(): Map = mapOf( - "sum" to sum as Any, + "total" to total as Any, "logs" to logs.map { it.toMap() } as Any ) } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/MembershipList.kt b/library/src/main/java/io/appwrite/models/MembershipList.kt index 3171fae..1b7549d 100644 --- a/library/src/main/java/io/appwrite/models/MembershipList.kt +++ b/library/src/main/java/io/appwrite/models/MembershipList.kt @@ -7,11 +7,11 @@ import com.google.gson.annotations.SerializedName */ data class MembershipList( /** - * Total number of items available on the server. + * Total number of memberships documents that matched your query. * */ - @SerializedName("sum") - val sum: Long, + @SerializedName("total") + val total: Long, /** * List of memberships. @@ -23,13 +23,13 @@ data class MembershipList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = MembershipList( - sum = (map["sum"] as Number).toLong(), + total = (map["total"] as Number).toLong(), memberships = (map["memberships"] as List>).map { Membership.from(map = it) } ) } fun toMap(): Map = mapOf( - "sum" to sum as Any, + "total" to total as Any, "memberships" to memberships.map { it.toMap() } as Any ) } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/PhoneList.kt b/library/src/main/java/io/appwrite/models/PhoneList.kt index d9338cb..6dee844 100644 --- a/library/src/main/java/io/appwrite/models/PhoneList.kt +++ b/library/src/main/java/io/appwrite/models/PhoneList.kt @@ -7,11 +7,11 @@ import com.google.gson.annotations.SerializedName */ data class PhoneList( /** - * Total number of items available on the server. + * Total number of phones documents that matched your query. * */ - @SerializedName("sum") - val sum: Long, + @SerializedName("total") + val total: Long, /** * List of phones. @@ -23,13 +23,13 @@ data class PhoneList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = PhoneList( - sum = (map["sum"] as Number).toLong(), + total = (map["total"] as Number).toLong(), phones = (map["phones"] as List>).map { Phone.from(map = it) } ) } fun toMap(): Map = mapOf( - "sum" to sum as Any, + "total" to total as Any, "phones" to phones.map { it.toMap() } 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/models/SessionList.kt b/library/src/main/java/io/appwrite/models/SessionList.kt index 2d6a4bd..9891102 100644 --- a/library/src/main/java/io/appwrite/models/SessionList.kt +++ b/library/src/main/java/io/appwrite/models/SessionList.kt @@ -7,11 +7,11 @@ import com.google.gson.annotations.SerializedName */ data class SessionList( /** - * Total number of items available on the server. + * Total number of sessions documents that matched your query. * */ - @SerializedName("sum") - val sum: Long, + @SerializedName("total") + val total: Long, /** * List of sessions. @@ -23,13 +23,13 @@ data class SessionList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = SessionList( - sum = (map["sum"] as Number).toLong(), + total = (map["total"] as Number).toLong(), sessions = (map["sessions"] as List>).map { Session.from(map = it) } ) } fun toMap(): Map = mapOf( - "sum" to sum as Any, + "total" to total as Any, "sessions" to sessions.map { it.toMap() } as Any ) } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Team.kt b/library/src/main/java/io/appwrite/models/Team.kt index d0eda4e..f502375 100644 --- a/library/src/main/java/io/appwrite/models/Team.kt +++ b/library/src/main/java/io/appwrite/models/Team.kt @@ -28,11 +28,11 @@ data class Team( val dateCreated: Long, /** - * Total sum of team members. + * Total number of team members. * */ - @SerializedName("sum") - val sum: Long + @SerializedName("total") + val total: Long ) { companion object { @Suppress("UNCHECKED_CAST") @@ -40,7 +40,7 @@ data class Team( id = map["\$id"] as String, name = map["name"] as String, dateCreated = (map["dateCreated"] as Number).toLong(), - sum = (map["sum"] as Number).toLong() + total = (map["total"] as Number).toLong() ) } @@ -48,6 +48,6 @@ data class Team( "\$id" to id as Any, "name" to name as Any, "dateCreated" to dateCreated as Any, - "sum" to sum as Any + "total" to total as Any ) } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/TeamList.kt b/library/src/main/java/io/appwrite/models/TeamList.kt index af63825..4f210b3 100644 --- a/library/src/main/java/io/appwrite/models/TeamList.kt +++ b/library/src/main/java/io/appwrite/models/TeamList.kt @@ -7,11 +7,11 @@ import com.google.gson.annotations.SerializedName */ data class TeamList( /** - * Total number of items available on the server. + * Total number of teams documents that matched your query. * */ - @SerializedName("sum") - val sum: Long, + @SerializedName("total") + val total: Long, /** * List of teams. @@ -23,13 +23,13 @@ data class TeamList( companion object { @Suppress("UNCHECKED_CAST") fun from(map: Map) = TeamList( - sum = (map["sum"] as Number).toLong(), + total = (map["total"] as Number).toLong(), teams = (map["teams"] as List>).map { Team.from(map = it) } ) } fun toMap(): Map = mapOf( - "sum" to sum as Any, + "total" to total as Any, "teams" to teams.map { it.toMap() } as Any ) } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/UploadProgress.kt b/library/src/main/java/io/appwrite/models/UploadProgress.kt new file mode 100644 index 0000000..4199694 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/UploadProgress.kt @@ -0,0 +1,9 @@ +package io.appwrite.models + +data class UploadProgress( + val id: String, + val progress: Double, + val sizeUploaded: Long, + val chunksTotal: Int, + val chunksUploaded: Int +) \ No newline at end of file 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..0117a62 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: ((UploadProgress) -> 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, ) } From 8fd751e9544f4cead06f6d20de7c1d5943b019fc Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 2 Mar 2022 12:26:58 +0100 Subject: [PATCH 15/21] feat: support for 0.13.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8c463db..f58d55b 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:0.3.3") +implementation("io.appwrite:sdk-for-android:0.4.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 0.3.3 + 0.4.0 ``` From 0a65a5548a62f6a2c4d7c0636da56e238e134ec6 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 12 Apr 2022 11:19:55 +0545 Subject: [PATCH 16/21] latest fixes --- README.md | 4 +- library/build.gradle | 1 - library/src/main/java/io/appwrite/Client.kt | 2 +- .../java/io/appwrite/cookies/Extensions.kt | 53 ++++ .../io/appwrite/cookies/InternalCookie.kt | 49 ++++ .../cookies/stores/InMemoryCookieStore.kt | 269 ++++++++++++++++++ .../stores/SharedPreferencesCookieStore.kt | 99 +++++++ 7 files changed, 473 insertions(+), 4 deletions(-) create mode 100644 library/src/main/java/io/appwrite/cookies/Extensions.kt create mode 100644 library/src/main/java/io/appwrite/cookies/InternalCookie.kt create mode 100644 library/src/main/java/io/appwrite/cookies/stores/InMemoryCookieStore.kt create mode 100644 library/src/main/java/io/appwrite/cookies/stores/SharedPreferencesCookieStore.kt diff --git a/README.md b/README.md index f58d55b..6051870 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:0.4.0") +implementation("io.appwrite:sdk-for-android:0.4.1") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 0.4.0 + 0.4.1 ``` diff --git a/library/build.gradle b/library/build.gradle index ee98757..7045591 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -63,7 +63,6 @@ dependencies { implementation("com.squareup.okhttp3:logging-interceptor") implementation("com.google.code.gson:gson:2.8.7") - implementation("net.gotev:cookie-store:1.3.5") implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1") implementation("androidx.lifecycle:lifecycle-common-java8:2.3.1") implementation("androidx.appcompat:appcompat:1.3.1") diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 902fd7f..fefa174 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -5,6 +5,7 @@ import android.content.pm.PackageManager import com.google.gson.GsonBuilder import com.google.gson.reflect.TypeToken import io.appwrite.appwrite.BuildConfig +import io.appwrite.cookies.stores.SharedPreferencesCookieStore import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.fromJson import io.appwrite.json.PreciseNumberAdapter @@ -13,7 +14,6 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.suspendCancellableCoroutine -import net.gotev.cookiestore.SharedPreferencesCookieStore import okhttp3.* import okhttp3.Headers.Companion.toHeaders import okhttp3.HttpUrl.Companion.toHttpUrl diff --git a/library/src/main/java/io/appwrite/cookies/Extensions.kt b/library/src/main/java/io/appwrite/cookies/Extensions.kt new file mode 100644 index 0000000..257c904 --- /dev/null +++ b/library/src/main/java/io/appwrite/cookies/Extensions.kt @@ -0,0 +1,53 @@ +package io.appwrite.cookies + +import android.os.Build +import java.net.CookieStore +import java.net.HttpCookie +import java.text.SimpleDateFormat +import java.util.Calendar +import java.util.Locale +import java.util.TimeZone + +fun HttpCookie.toSetCookieString(): String { + val expires = if (maxAge != -1L) { + val dateFormat = SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.UK).apply { + timeZone = TimeZone.getTimeZone("GMT") + } + + val calendar = Calendar.getInstance(Locale.UK).apply { set(Calendar.SECOND, maxAge.toInt()) } + + "; expires=${dateFormat.format(calendar.time)}" + } else { + "" + } + + val path = if (path != null) "; path=$path" else "" + val domain = if (domain != null) "; domain=$domain" else "" + val secure = if (secure) "; secure" else "" + val httpOnly = if (Build.VERSION.SDK_INT >= 24) { + if (isHttpOnly) "; httponly" else "" + } else { + "" + } + + return "$name=$value$expires$path$domain$secure$httpOnly" +} + +@Synchronized +fun CookieStore.syncToWebKitCookieManager() { + val webKitCookieManager = android.webkit.CookieManager.getInstance() + + cookies.forEach { + val hostUrl = "${if (it.secure) "https" else "http"}://${it.domain}" + webKitCookieManager.setCookie(hostUrl, it.toSetCookieString()) + } + + webKitCookieManager.flush() +} + +@Synchronized +@Suppress("DEPRECATION") +fun android.webkit.CookieManager.removeAll() { + removeAllCookies(null) + flush() +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/cookies/InternalCookie.kt b/library/src/main/java/io/appwrite/cookies/InternalCookie.kt new file mode 100644 index 0000000..c4ea22a --- /dev/null +++ b/library/src/main/java/io/appwrite/cookies/InternalCookie.kt @@ -0,0 +1,49 @@ +package io.appwrite.cookies + +import android.os.Build +import java.net.HttpCookie + +data class InternalCookie( + val comment: String?, + val commentURL: String?, + val discard: Boolean?, + val domain: String, + val maxAge: Long?, + val name: String, + val path: String?, + val portlist: String?, + val secure: Boolean?, + val value: String, + val version: Int?, + var httpOnly: Boolean? = null +) { + constructor(cookie: HttpCookie) : this( + cookie.comment, + cookie.commentURL, + cookie.discard, + cookie.domain, + cookie.maxAge, + cookie.name, + cookie.path, + cookie.portlist, + cookie.secure, + cookie.value, + cookie.version + ) + + fun toHttpCookie() = HttpCookie(name, value).apply { + comment = this@InternalCookie.comment + commentURL = this@InternalCookie.commentURL + discard = this@InternalCookie.discard == true + domain = this@InternalCookie.domain + maxAge = this@InternalCookie.maxAge ?: 0 + path = this@InternalCookie.path + portlist = this@InternalCookie.portlist + secure = this@InternalCookie.secure == true + version = this@InternalCookie.version ?: 0 + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + isHttpOnly = (this@InternalCookie.httpOnly == true) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/cookies/stores/InMemoryCookieStore.kt b/library/src/main/java/io/appwrite/cookies/stores/InMemoryCookieStore.kt new file mode 100644 index 0000000..7de9ec9 --- /dev/null +++ b/library/src/main/java/io/appwrite/cookies/stores/InMemoryCookieStore.kt @@ -0,0 +1,269 @@ +package io.appwrite.cookies.stores + +import android.os.Build +import android.util.Log +import java.net.CookieStore +import java.net.HttpCookie +import java.net.URI +import java.net.URISyntaxException +import java.util.Collections +import java.util.concurrent.locks.ReentrantLock + +open class InMemoryCookieStore(private val name: String) : CookieStore { + + internal val uriIndex = mutableMapOf>() + private val lock = ReentrantLock(false) + + override fun removeAll(): Boolean { + lock.lock() + + return try { + uriIndex.clear() + uriIndex.isEmpty() + } finally { + lock.unlock() + } + } + + override fun add(uri: URI?, cookie: HttpCookie?) { + if (cookie == null) { + Log.i( + javaClass.simpleName, + "tried to add null cookie in cookie store named $name. Doing nothing." + ) + return + } + + if (uri == null) { + Log.i( + javaClass.simpleName, + "tried to add null URI in cookie store named $name. Doing nothing." + ) + return + } + + lock.lock() + try { + addIndex(getEffectiveURI(uri), cookie) + } finally { + lock.unlock() + } + } + + override fun getCookies(): List { + val cookies = mutableListOf() + + lock.lock() + try { + for (list in uriIndex.values) { + val it = list.iterator() + while (it.hasNext()) { + val cookie = it.next() + if (cookie.hasExpired()) { + it.remove() + } else if (!cookies.contains(cookie)) { + cookies.add(cookie) + } + } + } + } finally { + lock.unlock() + } + + return cookies + } + + override fun getURIs(): List { + val uris = mutableListOf() + + lock.lock() + return try { + uriIndex.keys.toList() + } finally { + uris.addAll(uriIndex.keys) + lock.unlock() + } + } + + override fun remove(uri: URI?, cookie: HttpCookie?): Boolean { + if (cookie == null) { + Log.i( + javaClass.simpleName, + "tried to remove null cookie from cookie store named $name. Doing nothing." + ) + return true + } + + if (uri == null) { + Log.i( + javaClass.simpleName, + "tried to remove null URI from cookie store named $name. Doing nothing." + ) + return true + } + + lock.lock() + + return try { + val lintedURI = getEffectiveURI(uri) + + if (uriIndex[lintedURI] == null) { + false + } else { + val cookies = uriIndex[lintedURI] + cookies?.remove(cookie) ?: false + } + } finally { + lock.unlock() + } + } + + override fun get(uri: URI?): List { + if (uri == null) { + Log.i( + javaClass.simpleName, + "getting cookies from cookie store named $name for null URI results in empty list" + ) + return emptyList() + } + + val cookies = arrayListOf() + + lock.lock() + try { + uri.host?.let { cookies.addAll(getInternal1(it)) } + val internal2 = getInternal2(getEffectiveURI(uri)).filter { !cookies.contains(it) } + cookies.addAll(internal2) + } finally { + lock.unlock() + } + + return cookies + } + + internal fun getEffectiveURI(uri: URI): URI { + return try { + URI(uri.scheme ?: "http", uri.host, null, null, null) + } catch (ignored: URISyntaxException) { + uri + } + } + + private fun addIndex(index: URI, cookie: HttpCookie) { + val cookies = uriIndex[index] + + if (cookies != null) { + cookies.remove(cookie) + cookies.add(cookie) + } else { + val newCookies = mutableListOf() + newCookies.add(cookie) + uriIndex[index] = newCookies + } + } + + private fun netscapeDomainMatches(domain: String?, host: String?): Boolean { + if (domain == null || host == null) { + return false + } + + // If there's no embedded dot in domain and domain is not .local + val isLocalDomain = ".local".equals(domain, ignoreCase = true) + var embeddedDotInDomain = domain.indexOf('.') + if (embeddedDotInDomain == 0) { + embeddedDotInDomain = domain.indexOf('.', 1) + } + if (!isLocalDomain && (embeddedDotInDomain == -1 || embeddedDotInDomain == domain.length - 1)) { + return false + } + + // If the host name contains no dot and the domain name is .local + val firstDotInHost = host.indexOf('.') + if (firstDotInHost == -1 && isLocalDomain) { + return true + } + + val domainLength = domain.length + val lengthDiff = host.length - domainLength + if (lengthDiff == 0) { + // If the host name and the domain name are just string-compare euqal + return host.equals(domain, ignoreCase = true) + } else if (lengthDiff > 0) { + // need to check H & D component + val D = host.substring(lengthDiff) + + // Android-changed: b/26456024 targetSdkVersion based compatibility for domain matching + // Android M and earlier: Cookies with domain "foo.com" would not match "bar.foo.com". + // The RFC dictates that the user agent must treat those domains as if they had a + // leading period and must therefore match "bar.foo.com". + return if (Build.VERSION.SDK_INT <= 23 && !domain.startsWith(".")) { + false + } else D.equals(domain, ignoreCase = true) + } else if (lengthDiff == -1) { + // if domain is actually .host + return domain[0] == '.' && host.equals(domain.substring(1), ignoreCase = true) + } + + return false + } + + private fun getInternal1(host: String): List { + // BEGIN Android-changed: b/25897688 InMemoryCookieStore ignores scheme (http/https) + // Use a separate list to handle cookies that need to be removed so + // that there is no conflict with iterators. + val toRemove = mutableListOf() + val cookies = mutableListOf() + + for ((_, lst) in uriIndex) { + for (c in lst) { + val domain = c.domain + if (c.version == 0 && netscapeDomainMatches( + domain, + host + ) || c.version == 1 && HttpCookie.domainMatches(domain, host) + ) { + if (!c.hasExpired()) { + if (!cookies.contains(c)) { + cookies.add(c) + } + } else { + toRemove.add(c) + } + } + } + // Clean up the cookies that need to be removed + for (c in toRemove) { + lst.remove(c) + } + toRemove.clear() + } + return cookies + } + + private fun getInternal2(comparator: URI): List { + // BEGIN Android-changed: b/25897688 InMemoryCookieStore ignores scheme (http/https) + // Removed cookieJar + val cookies = mutableListOf() + + for (index in uriIndex.keys) { + if (index === comparator || comparator.compareTo(index) == 0) { + val indexedCookies = uriIndex[index] + // Check the list of cookies associated with this domain + if (indexedCookies != null) { + val it = indexedCookies.iterator() + while (it.hasNext()) { + val ck = it.next() + if (!ck.hasExpired()) { + if (!cookies.contains(ck)) + cookies.add(ck) + } else { + it.remove() + } + } + } + } + } + + return cookies + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/cookies/stores/SharedPreferencesCookieStore.kt b/library/src/main/java/io/appwrite/cookies/stores/SharedPreferencesCookieStore.kt new file mode 100644 index 0000000..83c677d --- /dev/null +++ b/library/src/main/java/io/appwrite/cookies/stores/SharedPreferencesCookieStore.kt @@ -0,0 +1,99 @@ +package io.appwrite.cookies.stores + +import io.appwrite.cookies.InternalCookie +import android.content.Context +import android.os.Build +import android.util.Log +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import java.net.HttpCookie +import java.net.URI + +open class SharedPreferencesCookieStore( + context: Context, + private val name: String +) : InMemoryCookieStore(name) { + + private val preferences = context.getSharedPreferences(name, Context.MODE_PRIVATE) + private val gson = Gson() + + init { + synchronized(SharedPreferencesCookieStore::class.java) { + preferences.all.forEach { (key, value) -> + try { + val index = URI.create(key) + val listType = object : TypeToken>() {}.type + val internalCookies = + gson.fromJson>(value.toString(), listType) + val cookies = internalCookies.map { it.toHttpCookie() }.toMutableList() + uriIndex[index] = cookies + } catch (exception: Throwable) { + Log.e( + javaClass.simpleName, + "Error while loading key = $key, value = $value from cookie store named $name", + exception + ) + } + } + } + } + + override fun removeAll(): Boolean = + synchronized(SharedPreferencesCookieStore::class.java) { + super.removeAll() + preferences.edit().clear().apply() + true + } + + override fun add(uri: URI?, cookie: HttpCookie?) = + synchronized(SharedPreferencesCookieStore::class.java) { + uri ?: return@synchronized + + super.add(uri, cookie) + val index = getEffectiveURI(uri) + val cookies = uriIndex[index] ?: return@synchronized + + val internalCookies = cookies.map { + InternalCookie(it).apply { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + httpOnly = it.isHttpOnly + } + } + } + + val listType = object : TypeToken>() {}.type + val json = gson.toJson(internalCookies, listType) + + preferences + .edit() + .putString(index.toString(), json) + .apply() + } + + override fun remove(uri: URI?, cookie: HttpCookie?): Boolean = + synchronized(SharedPreferencesCookieStore::class.java) { + uri ?: return false + + val result = super.remove(uri, cookie) + val index = getEffectiveURI(uri) + val cookies = uriIndex[index] + val internalCookies = cookies?.map { + InternalCookie(it).apply { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + httpOnly = it.isHttpOnly + } + } + } + val listType = object : TypeToken>() {}.type + val json = gson.toJson(internalCookies, listType) + + preferences.edit().apply { + when (cookies) { + null -> remove(index.toString()) + else -> putString(index.toString(), json) + } + }.apply() + + return result + } +} \ No newline at end of file From e752f5efdc91e669797702334b0726a5f9bf6885 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 13 Apr 2022 09:58:08 +0545 Subject: [PATCH 17/21] resumable upload support --- README.md | 4 +- library/src/main/java/io/appwrite/Client.kt | 72 ++++++++++------- .../main/java/io/appwrite/services/Account.kt | 80 +++++++++---------- .../java/io/appwrite/services/Database.kt | 16 ++-- .../java/io/appwrite/services/Functions.kt | 12 +-- .../main/java/io/appwrite/services/Locale.kt | 28 +++---- .../main/java/io/appwrite/services/Storage.kt | 19 +++-- .../main/java/io/appwrite/services/Teams.kt | 36 ++++----- 8 files changed, 141 insertions(+), 126 deletions(-) diff --git a/README.md b/README.md index 6051870..2b1d293 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:0.4.1") +implementation("io.appwrite:sdk-for-android:0.5.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 0.4.1 + 0.5.0 ``` diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index fefa174..be3fe85 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -23,6 +23,7 @@ import okhttp3.RequestBody.Companion.toRequestBody import java.io.BufferedInputStream import java.io.BufferedReader import java.io.File +import java.io.RandomAccessFile import java.io.IOException import java.net.CookieManager import java.net.CookiePolicy @@ -245,7 +246,7 @@ class Client @JvmOverloads constructor( headers: Map = mapOf(), params: Map = mapOf(), responseType: Class, - convert: ((Map) -> T)? = null + converter: ((Map) -> T)? = null ): T { val filteredParams = params.filterValues { it != null } @@ -281,7 +282,7 @@ class Client @JvmOverloads constructor( .get() .build() - return awaitResponse(request, responseType, convert) + return awaitResponse(request, responseType, converter) } val body = if (MultipartBody.FORM.toString() == headers["content-type"]) { @@ -318,7 +319,7 @@ class Client @JvmOverloads constructor( .method(method, body) .build() - return awaitResponse(request, responseType, convert) + return awaitResponse(request, responseType, converter) } /** @@ -336,8 +337,9 @@ class Client @JvmOverloads constructor( headers: MutableMap, params: MutableMap, responseType: Class, - convert: ((Map) -> T), + converter: ((Map) -> T), paramName: String, + idParamName: String? = null, onProgress: ((UploadProgress) -> Unit)? = null, ): T { val file = params[paramName] as File @@ -350,58 +352,68 @@ class Client @JvmOverloads constructor( file.asRequestBody() ) return call( - "POST", + method = "POST", path, headers, params, responseType, - convert + converter ) } - val input = file.inputStream().buffered() + val input = RandomAccessFile(file, "r") 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 { + if (idParamName?.isNotEmpty() == true && params[idParamName] != "unique()") { + // Make a request to check if a file already exists + val current = call( + method = "GET", + path = "$path/${params[idParamName]}", + headers = headers, + params = emptyMap(), + responseType = Map::class.java, + ) + val chunksUploaded = current["chunksUploaded"] as Long + offset = (chunksUploaded * CHUNK_SIZE).coerceAtMost(size) + } + + while (offset < size) { + input.seek(offset) + input.read(buffer) + params[paramName] = MultipartBody.Part.createFormData( paramName, file.name, - it.toRequestBody() + buffer.toRequestBody() ) headers["Content-Range"] = "bytes $offset-${((offset + CHUNK_SIZE) - 1).coerceAtMost(size)}/$size" result = call( - "POST", + method = "POST", path, headers, params, - Map::class.java + responseType = Map::class.java ) offset += CHUNK_SIZE headers["x-appwrite-id"] = result!!["\$id"].toString() - onProgress?.invoke(UploadProgress( - id = result!!["\$id"].toString(), - progress = offset.coerceAtMost(size).toDouble()/size * 100, - sizeUploaded = offset.coerceAtMost(size), - chunksTotal = result!!["chunksTotal"].toString().toInt(), - chunksUploaded = result!!["chunksUploaded"].toString().toInt(), - )) + onProgress?.invoke( + UploadProgress( + id = result!!["\$id"].toString(), + progress = offset.coerceAtMost(size).toDouble() / size * 100, + sizeUploaded = offset.coerceAtMost(size), + chunksTotal = result!!["chunksTotal"].toString().toInt(), + chunksUploaded = result!!["chunksUploaded"].toString().toInt(), + ) + ) } - return convert(result as Map) + return converter(result as Map) } /** @@ -409,7 +421,7 @@ class Client @JvmOverloads constructor( * * @param request * @param responseType - * @param convert + * @param converter * * @return [T] */ @@ -417,7 +429,7 @@ class Client @JvmOverloads constructor( private suspend fun awaitResponse( request: Request, responseType: Class, - convert: ((Map) -> T)? = null + converter: ((Map) -> T)? = null ) = suspendCancellableCoroutine { http.newCall(request).enqueue(object : Callback { override fun onFailure(call: Call, e: IOException) { @@ -483,7 +495,7 @@ class Client @JvmOverloads constructor( object : TypeToken>(){}.type ) it.resume( - convert?.invoke(map) ?: map as T + converter?.invoke(map) ?: map as T ) } }) diff --git a/library/src/main/java/io/appwrite/services/Account.kt b/library/src/main/java/io/appwrite/services/Account.kt index 997b7c7..d47a521 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -30,7 +30,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.User = { + val converter: (Map) -> io.appwrite.models.User = { io.appwrite.models.User.from(map = it) } return client.call( @@ -39,7 +39,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.User::class.java, - convert = convert, + converter, ) } @@ -77,7 +77,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.User = { + val converter: (Map) -> io.appwrite.models.User = { io.appwrite.models.User.from(map = it) } return client.call( @@ -86,7 +86,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.User::class.java, - convert = convert, + converter, ) } @@ -149,7 +149,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.User = { + val converter: (Map) -> io.appwrite.models.User = { io.appwrite.models.User.from(map = it) } return client.call( @@ -158,7 +158,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.User::class.java, - convert = convert, + converter, ) } @@ -182,7 +182,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Jwt = { + val converter: (Map) -> io.appwrite.models.Jwt = { io.appwrite.models.Jwt.from(map = it) } return client.call( @@ -191,7 +191,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Jwt::class.java, - convert = convert, + converter, ) } @@ -219,7 +219,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.LogList = { + val converter: (Map) -> io.appwrite.models.LogList = { io.appwrite.models.LogList.from(map = it) } return client.call( @@ -228,7 +228,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.LogList::class.java, - convert = convert, + converter, ) } @@ -252,7 +252,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.User = { + val converter: (Map) -> io.appwrite.models.User = { io.appwrite.models.User.from(map = it) } return client.call( @@ -261,7 +261,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.User::class.java, - convert = convert, + converter, ) } @@ -290,7 +290,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.User = { + val converter: (Map) -> io.appwrite.models.User = { io.appwrite.models.User.from(map = it) } return client.call( @@ -299,7 +299,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.User::class.java, - convert = convert, + converter, ) } @@ -319,7 +319,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Preferences = { + val converter: (Map) -> io.appwrite.models.Preferences = { io.appwrite.models.Preferences.from(map = it) } return client.call( @@ -328,7 +328,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Preferences::class.java, - convert = convert, + converter, ) } @@ -354,7 +354,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.User = { + val converter: (Map) -> io.appwrite.models.User = { io.appwrite.models.User.from(map = it) } return client.call( @@ -363,7 +363,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.User::class.java, - convert = convert, + converter, ) } @@ -397,7 +397,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Token = { + val converter: (Map) -> io.appwrite.models.Token = { io.appwrite.models.Token.from(map = it) } return client.call( @@ -406,7 +406,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Token::class.java, - convert = convert, + converter, ) } @@ -447,7 +447,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Token = { + val converter: (Map) -> io.appwrite.models.Token = { io.appwrite.models.Token.from(map = it) } return client.call( @@ -456,7 +456,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Token::class.java, - convert = convert, + converter, ) } @@ -477,7 +477,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.SessionList = { + val converter: (Map) -> io.appwrite.models.SessionList = { io.appwrite.models.SessionList.from(map = it) } return client.call( @@ -486,7 +486,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.SessionList::class.java, - convert = convert, + converter, ) } @@ -514,7 +514,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Session = { + val converter: (Map) -> io.appwrite.models.Session = { io.appwrite.models.Session.from(map = it) } return client.call( @@ -523,7 +523,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Session::class.java, - convert = convert, + converter, ) } @@ -574,7 +574,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Session = { + val converter: (Map) -> io.appwrite.models.Session = { io.appwrite.models.Session.from(map = it) } return client.call( @@ -583,7 +583,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Session::class.java, - convert = convert, + converter, ) } @@ -622,7 +622,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Token = { + val converter: (Map) -> io.appwrite.models.Token = { io.appwrite.models.Token.from(map = it) } return client.call( @@ -631,7 +631,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Token::class.java, - convert = convert, + converter, ) } @@ -668,7 +668,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Session = { + val converter: (Map) -> io.appwrite.models.Session = { io.appwrite.models.Session.from(map = it) } return client.call( @@ -677,7 +677,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Session::class.java, - convert = convert, + converter, ) } @@ -783,7 +783,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Session = { + val converter: (Map) -> io.appwrite.models.Session = { io.appwrite.models.Session.from(map = it) } return client.call( @@ -792,7 +792,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Session::class.java, - convert = convert, + converter, ) } @@ -813,7 +813,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Session = { + val converter: (Map) -> io.appwrite.models.Session = { io.appwrite.models.Session.from(map = it) } return client.call( @@ -822,7 +822,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Session::class.java, - convert = convert, + converter, ) } @@ -891,7 +891,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Token = { + val converter: (Map) -> io.appwrite.models.Token = { io.appwrite.models.Token.from(map = it) } return client.call( @@ -900,7 +900,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Token::class.java, - convert = convert, + converter, ) } @@ -930,7 +930,7 @@ class Account(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Token = { + val converter: (Map) -> io.appwrite.models.Token = { io.appwrite.models.Token.from(map = it) } return client.call( @@ -939,7 +939,7 @@ class Account(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Token::class.java, - convert = convert, + converter, ) } diff --git a/library/src/main/java/io/appwrite/services/Database.kt b/library/src/main/java/io/appwrite/services/Database.kt index 8db1ac2..85a04ca 100644 --- a/library/src/main/java/io/appwrite/services/Database.kt +++ b/library/src/main/java/io/appwrite/services/Database.kt @@ -53,7 +53,7 @@ class Database(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.DocumentList = { + val converter: (Map) -> io.appwrite.models.DocumentList = { io.appwrite.models.DocumentList.from(map = it) } return client.call( @@ -62,7 +62,7 @@ class Database(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.DocumentList::class.java, - convert = convert, + converter, ) } @@ -100,7 +100,7 @@ class Database(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Document = { + val converter: (Map) -> io.appwrite.models.Document = { io.appwrite.models.Document.from(map = it) } return client.call( @@ -109,7 +109,7 @@ class Database(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Document::class.java, - convert = convert, + converter, ) } @@ -135,7 +135,7 @@ class Database(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Document = { + val converter: (Map) -> io.appwrite.models.Document = { io.appwrite.models.Document.from(map = it) } return client.call( @@ -144,7 +144,7 @@ class Database(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Document::class.java, - convert = convert, + converter, ) } @@ -179,7 +179,7 @@ class Database(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Document = { + val converter: (Map) -> io.appwrite.models.Document = { io.appwrite.models.Document.from(map = it) } return client.call( @@ -188,7 +188,7 @@ class Database(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Document::class.java, - convert = convert, + converter, ) } diff --git a/library/src/main/java/io/appwrite/services/Functions.kt b/library/src/main/java/io/appwrite/services/Functions.kt index 36f6b33..85a1f2c 100644 --- a/library/src/main/java/io/appwrite/services/Functions.kt +++ b/library/src/main/java/io/appwrite/services/Functions.kt @@ -77,7 +77,7 @@ class Functions(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.ExecutionList = { + val converter: (Map) -> io.appwrite.models.ExecutionList = { io.appwrite.models.ExecutionList.from(map = it) } return client.call( @@ -86,7 +86,7 @@ class Functions(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.ExecutionList::class.java, - convert = convert, + converter, ) } @@ -118,7 +118,7 @@ class Functions(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Execution = { + val converter: (Map) -> io.appwrite.models.Execution = { io.appwrite.models.Execution.from(map = it) } return client.call( @@ -127,7 +127,7 @@ class Functions(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Execution::class.java, - convert = convert, + converter, ) } @@ -152,7 +152,7 @@ class Functions(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Execution = { + val converter: (Map) -> io.appwrite.models.Execution = { io.appwrite.models.Execution.from(map = it) } return client.call( @@ -161,7 +161,7 @@ class Functions(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Execution::class.java, - convert = convert, + converter, ) } diff --git a/library/src/main/java/io/appwrite/services/Locale.kt b/library/src/main/java/io/appwrite/services/Locale.kt index c8837b4..21b297c 100644 --- a/library/src/main/java/io/appwrite/services/Locale.kt +++ b/library/src/main/java/io/appwrite/services/Locale.kt @@ -31,7 +31,7 @@ class Locale(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Locale = { + val converter: (Map) -> io.appwrite.models.Locale = { io.appwrite.models.Locale.from(map = it) } return client.call( @@ -40,7 +40,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Locale::class.java, - convert = convert, + converter, ) } @@ -61,7 +61,7 @@ class Locale(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.ContinentList = { + val converter: (Map) -> io.appwrite.models.ContinentList = { io.appwrite.models.ContinentList.from(map = it) } return client.call( @@ -70,7 +70,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.ContinentList::class.java, - convert = convert, + converter, ) } @@ -91,7 +91,7 @@ class Locale(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.CountryList = { + val converter: (Map) -> io.appwrite.models.CountryList = { io.appwrite.models.CountryList.from(map = it) } return client.call( @@ -100,7 +100,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.CountryList::class.java, - convert = convert, + converter, ) } @@ -121,7 +121,7 @@ class Locale(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.CountryList = { + val converter: (Map) -> io.appwrite.models.CountryList = { io.appwrite.models.CountryList.from(map = it) } return client.call( @@ -130,7 +130,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.CountryList::class.java, - convert = convert, + converter, ) } @@ -151,7 +151,7 @@ class Locale(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.PhoneList = { + val converter: (Map) -> io.appwrite.models.PhoneList = { io.appwrite.models.PhoneList.from(map = it) } return client.call( @@ -160,7 +160,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.PhoneList::class.java, - convert = convert, + converter, ) } @@ -182,7 +182,7 @@ class Locale(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.CurrencyList = { + val converter: (Map) -> io.appwrite.models.CurrencyList = { io.appwrite.models.CurrencyList.from(map = it) } return client.call( @@ -191,7 +191,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.CurrencyList::class.java, - convert = convert, + converter, ) } @@ -212,7 +212,7 @@ class Locale(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.LanguageList = { + val converter: (Map) -> io.appwrite.models.LanguageList = { io.appwrite.models.LanguageList.from(map = it) } return client.call( @@ -221,7 +221,7 @@ class Locale(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.LanguageList::class.java, - convert = convert, + converter, ) } diff --git a/library/src/main/java/io/appwrite/services/Storage.kt b/library/src/main/java/io/appwrite/services/Storage.kt index 0117a62..927829b 100644 --- a/library/src/main/java/io/appwrite/services/Storage.kt +++ b/library/src/main/java/io/appwrite/services/Storage.kt @@ -51,7 +51,7 @@ class Storage(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.FileList = { + val converter: (Map) -> io.appwrite.models.FileList = { io.appwrite.models.FileList.from(map = it) } return client.call( @@ -60,7 +60,7 @@ class Storage(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.FileList::class.java, - convert = convert, + converter, ) } @@ -112,17 +112,20 @@ class Storage(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "multipart/form-data" ) - val convert: (Map) -> io.appwrite.models.File = { + val converter: (Map) -> io.appwrite.models.File = { io.appwrite.models.File.from(map = it) } + val idParamName: String? = "fileId" + idParamName = "fileId" val paramName = "file" return client.chunkedUpload( path, headers, params, responseType = io.appwrite.models.File::class.java, - convert = convert, + converter, paramName, + idParamName, onProgress, ) } @@ -149,7 +152,7 @@ class Storage(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.File = { + val converter: (Map) -> io.appwrite.models.File = { io.appwrite.models.File.from(map = it) } return client.call( @@ -158,7 +161,7 @@ class Storage(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.File::class.java, - convert = convert, + converter, ) } @@ -190,7 +193,7 @@ class Storage(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.File = { + val converter: (Map) -> io.appwrite.models.File = { io.appwrite.models.File.from(map = it) } return client.call( @@ -199,7 +202,7 @@ class Storage(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.File::class.java, - convert = convert, + converter, ) } diff --git a/library/src/main/java/io/appwrite/services/Teams.kt b/library/src/main/java/io/appwrite/services/Teams.kt index f58df7c..e8b232c 100644 --- a/library/src/main/java/io/appwrite/services/Teams.kt +++ b/library/src/main/java/io/appwrite/services/Teams.kt @@ -49,7 +49,7 @@ class Teams(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.TeamList = { + val converter: (Map) -> io.appwrite.models.TeamList = { io.appwrite.models.TeamList.from(map = it) } return client.call( @@ -58,7 +58,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.TeamList::class.java, - convert = convert, + converter, ) } @@ -90,7 +90,7 @@ class Teams(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Team = { + val converter: (Map) -> io.appwrite.models.Team = { io.appwrite.models.Team.from(map = it) } return client.call( @@ -99,7 +99,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Team::class.java, - convert = convert, + converter, ) } @@ -122,7 +122,7 @@ class Teams(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Team = { + val converter: (Map) -> io.appwrite.models.Team = { io.appwrite.models.Team.from(map = it) } return client.call( @@ -131,7 +131,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Team::class.java, - convert = convert, + converter, ) } @@ -158,7 +158,7 @@ class Teams(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Team = { + val converter: (Map) -> io.appwrite.models.Team = { io.appwrite.models.Team.from(map = it) } return client.call( @@ -167,7 +167,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Team::class.java, - convert = convert, + converter, ) } @@ -238,7 +238,7 @@ class Teams(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.MembershipList = { + val converter: (Map) -> io.appwrite.models.MembershipList = { io.appwrite.models.MembershipList.from(map = it) } return client.call( @@ -247,7 +247,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.MembershipList::class.java, - convert = convert, + converter, ) } @@ -296,7 +296,7 @@ class Teams(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Membership = { + val converter: (Map) -> io.appwrite.models.Membership = { io.appwrite.models.Membership.from(map = it) } return client.call( @@ -305,7 +305,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Membership::class.java, - convert = convert, + converter, ) } @@ -331,7 +331,7 @@ class Teams(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.MembershipList = { + val converter: (Map) -> io.appwrite.models.MembershipList = { io.appwrite.models.MembershipList.from(map = it) } return client.call( @@ -340,7 +340,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.MembershipList::class.java, - convert = convert, + converter, ) } @@ -370,7 +370,7 @@ class Teams(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Membership = { + val converter: (Map) -> io.appwrite.models.Membership = { io.appwrite.models.Membership.from(map = it) } return client.call( @@ -379,7 +379,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Membership::class.java, - convert = convert, + converter, ) } @@ -448,7 +448,7 @@ class Teams(client: Client) : Service(client) { val headers = mutableMapOf( "content-type" to "application/json" ) - val convert: (Map) -> io.appwrite.models.Membership = { + val converter: (Map) -> io.appwrite.models.Membership = { io.appwrite.models.Membership.from(map = it) } return client.call( @@ -457,7 +457,7 @@ class Teams(client: Client) : Service(client) { headers, params, responseType = io.appwrite.models.Membership::class.java, - convert = convert, + converter, ) } From d739daa65a1ed22d4e0c48796e5f9b35f7f7b440 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 13 Apr 2022 18:27:30 +1200 Subject: [PATCH 18/21] Merge conflict fix --- library/src/main/java/io/appwrite/services/Storage.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/src/main/java/io/appwrite/services/Storage.kt b/library/src/main/java/io/appwrite/services/Storage.kt index 927829b..a632fd2 100644 --- a/library/src/main/java/io/appwrite/services/Storage.kt +++ b/library/src/main/java/io/appwrite/services/Storage.kt @@ -115,8 +115,7 @@ class Storage(client: Client) : Service(client) { val converter: (Map) -> io.appwrite.models.File = { io.appwrite.models.File.from(map = it) } - val idParamName: String? = "fileId" - idParamName = "fileId" + val idParamName: String? = "fileId" val paramName = "file" return client.chunkedUpload( path, From 12da1a341d461ba051fe618fcfe700c841a06a1a Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 16 May 2022 18:36:09 +0200 Subject: [PATCH 19/21] feat: support for 0.14.x --- README.md | 8 +-- .../account/{delete.md => update-status.md} | 2 +- .../account/{delete.md => update-status.md} | 2 +- .../main/java/io/appwrite/models/Execution.kt | 10 +-- .../java/io/appwrite/models/Membership.kt | 37 ++++++---- .../main/java/io/appwrite/services/Account.kt | 70 ++++++++++--------- .../main/java/io/appwrite/services/Avatars.kt | 42 +++++++++-- .../java/io/appwrite/services/Database.kt | 12 ++-- .../main/java/io/appwrite/services/Storage.kt | 3 +- .../main/java/io/appwrite/services/Teams.kt | 6 +- 10 files changed, 118 insertions(+), 74 deletions(-) rename docs/examples/java/account/{delete.md => update-status.md} (96%) rename docs/examples/kotlin/account/{delete.md => update-status.md} (93%) diff --git a/README.md b/README.md index 2b1d293..1f076d6 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.13.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-0.14.0-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.13.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.14.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) @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:0.5.0") +implementation("io.appwrite:sdk-for-android:0.6.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 0.5.0 + 0.6.0 ``` diff --git a/docs/examples/java/account/delete.md b/docs/examples/java/account/update-status.md similarity index 96% rename from docs/examples/java/account/delete.md rename to docs/examples/java/account/update-status.md index aec96f1..0ef6a6e 100644 --- a/docs/examples/java/account/delete.md +++ b/docs/examples/java/account/update-status.md @@ -18,7 +18,7 @@ public class MainActivity extends AppCompatActivity { Account account = new Account(client); - account.delete(new Continuation() { + account.updateStatus(new Continuation() { @NotNull @Override public CoroutineContext getContext() { diff --git a/docs/examples/kotlin/account/delete.md b/docs/examples/kotlin/account/update-status.md similarity index 93% rename from docs/examples/kotlin/account/delete.md rename to docs/examples/kotlin/account/update-status.md index 7bfe95e..e138751 100644 --- a/docs/examples/kotlin/account/delete.md +++ b/docs/examples/kotlin/account/update-status.md @@ -17,7 +17,7 @@ class MainActivity : AppCompatActivity() { val account = Account(client) GlobalScope.launch { - val response = account.delete() + val response = account.updateStatus() val json = response.body?.string() } } diff --git a/library/src/main/java/io/appwrite/models/Execution.kt b/library/src/main/java/io/appwrite/models/Execution.kt index c8f2ae2..06c2811 100644 --- a/library/src/main/java/io/appwrite/models/Execution.kt +++ b/library/src/main/java/io/appwrite/models/Execution.kt @@ -56,11 +56,11 @@ data class Execution( val statusCode: Long, /** - * The script stdout output string. Logs the last 4,000 characters of the execution stdout output. + * The script response output string. Logs the last 4,000 characters of the execution response output. * */ - @SerializedName("stdout") - val stdout: String, + @SerializedName("response") + val response: String, /** * The script stderr output string. Logs the last 4,000 characters of the execution stderr output @@ -86,7 +86,7 @@ data class Execution( trigger = map["trigger"] as String, status = map["status"] as String, statusCode = (map["statusCode"] as Number).toLong(), - stdout = map["stdout"] as String, + response = map["response"] as String, stderr = map["stderr"] as String, time = (map["time"] as Number).toDouble() ) @@ -100,7 +100,7 @@ data class Execution( "trigger" to trigger as Any, "status" to status as Any, "statusCode" to statusCode as Any, - "stdout" to stdout as Any, + "response" to response as Any, "stderr" to stderr as Any, "time" to time as Any ) diff --git a/library/src/main/java/io/appwrite/models/Membership.kt b/library/src/main/java/io/appwrite/models/Membership.kt index 45b42c8..3df7b69 100644 --- a/library/src/main/java/io/appwrite/models/Membership.kt +++ b/library/src/main/java/io/appwrite/models/Membership.kt @@ -20,6 +20,20 @@ data class Membership( @SerializedName("userId") val userId: String, + /** + * User name. + * + */ + @SerializedName("userName") + val userName: String, + + /** + * User email address. + * + */ + @SerializedName("userEmail") + val userEmail: String, + /** * Team ID. * @@ -28,18 +42,11 @@ data class Membership( val teamId: String, /** - * User name. + * Team name. * */ - @SerializedName("name") - val name: String, - - /** - * User email address. - * - */ - @SerializedName("email") - val email: String, + @SerializedName("teamName") + val teamName: String, /** * Date, the user has been invited to join the team in Unix timestamp. @@ -74,9 +81,10 @@ data class Membership( fun from(map: Map) = Membership( id = map["\$id"] as String, userId = map["userId"] as String, + userName = map["userName"] as String, + userEmail = map["userEmail"] as String, teamId = map["teamId"] as String, - name = map["name"] as String, - email = map["email"] as String, + teamName = map["teamName"] as String, invited = (map["invited"] as Number).toLong(), joined = (map["joined"] as Number).toLong(), confirm = map["confirm"] as Boolean, @@ -87,9 +95,10 @@ data class Membership( fun toMap(): Map = mapOf( "\$id" to id as Any, "userId" to userId as Any, + "userName" to userName as Any, + "userEmail" to userEmail as Any, "teamId" to teamId as Any, - "name" to name as Any, - "email" to email as Any, + "teamName" to teamName as Any, "invited" to invited as Any, "joined" to joined as Any, "confirm" to confirm 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 d47a521..8f144de 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -90,35 +90,6 @@ class Account(client: Client) : Service(client) { ) } - /** - * Delete Account - * - * Delete a currently logged in user account. Behind the scene, the user - * record is not deleted but permanently blocked from any access. This is done - * to avoid deleted accounts being overtaken by new users with the same email - * address. Any user-related resources like documents or storage files should - * be deleted separately. - * - * @return [Any] - */ - @JvmOverloads - @Throws(AppwriteException::class) - suspend fun delete(): Any { - val path = "/account" - val params = mutableMapOf( - ) - val headers = mutableMapOf( - "content-type" to "application/json" - ) - return client.call( - "DELETE", - path, - headers, - params, - responseType = Any::class.java, - ) - } - /** * Update Account Email * @@ -270,7 +241,7 @@ class Account(client: Client) : Service(client) { * * Update currently logged in user password. For validation, user is required * to pass in the new password, and the old password. For users created with - * OAuth and Team Invites, oldPassword is optional. + * OAuth, Team Invites and Magic URL, oldPassword is optional. * * @param password New user password. Must be at least 8 chars. * @param oldPassword Current user password. Must be at least 8 chars. @@ -697,10 +668,10 @@ 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, notion, paypal, paypalSandbox, salesforce, slack, spotify, tradeshift, tradeshiftBox, twitch, vk, yahoo, yammer, yandex, wordpress, stripe. + * @param provider OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, bitbucket, bitly, box, discord, dropbox, facebook, github, gitlab, google, linkedin, microsoft, notion, okta, paypal, paypalSandbox, salesforce, slack, spotify, tradeshift, tradeshiftBox, twitch, zoom, 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. + * @param scopes A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 128 characters long. * */ @JvmOverloads @@ -799,6 +770,10 @@ class Account(client: Client) : Service(client) { /** * Update Session (Refresh Tokens) * + * Access tokens have limited lifespan and expire to mitigate security risks. + * If session was created using an OAuth provider, this route can be used to + * "refresh" the access token. + * * @param sessionId Session ID. Use the string 'current' to update the current device session. * @return [io.appwrite.models.Session] */ @@ -857,6 +832,37 @@ class Account(client: Client) : Service(client) { ) } + /** + * Update Account Status + * + * Block the currently logged in user account. Behind the scene, the user + * record is not deleted but permanently blocked from any access. To + * completely delete a user, use the Users API instead. + * + * @return [io.appwrite.models.User] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun updateStatus(): io.appwrite.models.User { + val path = "/account/status" + val params = mutableMapOf( + ) + val headers = mutableMapOf( + "content-type" to "application/json" + ) + val converter: (Map) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it) + } + return client.call( + "PATCH", + path, + headers, + params, + responseType = io.appwrite.models.User::class.java, + converter, + ) + } + /** * Create Email Verification * diff --git a/library/src/main/java/io/appwrite/services/Avatars.kt b/library/src/main/java/io/appwrite/services/Avatars.kt index 09afbc6..20e1f54 100644 --- a/library/src/main/java/io/appwrite/services/Avatars.kt +++ b/library/src/main/java/io/appwrite/services/Avatars.kt @@ -16,9 +16,14 @@ class Avatars(client: Client) : Service(client) { * Get Browser Icon * * You can use this endpoint to show different browser icons to your users. - * The code argument receives the browser code as it appears in your user - * /account/sessions endpoint. Use width, height and quality arguments to - * change the output settings. + * The code argument receives the browser code as it appears in your user [GET + * /account/sessions](/docs/client/account#accountGetSessions) endpoint. Use + * width, height and quality arguments to change the output settings. + * + * When one dimension is specified and the other is 0, the image is scaled + * with preserved aspect ratio. If both dimensions are 0, the API provides an + * image at source quality. If dimensions are not specified, the default size + * of image returned is 100x100px. * * @param code Browser Code. * @param width Image width. Pass an integer between 0 to 2000. Defaults to 100. @@ -55,6 +60,12 @@ class Avatars(client: Client) : Service(client) { * The credit card endpoint will return you the icon of the credit card * provider you need. Use width, height and quality arguments to change the * output settings. + * + * When one dimension is specified and the other is 0, the image is scaled + * with preserved aspect ratio. If both dimensions are 0, the API provides an + * image at source quality. If dimensions are not specified, the default size + * of image returned is 100x100px. + * * * @param code Credit Card Code. Possible values: amex, argencard, cabal, censosud, diners, discover, elo, hipercard, jcb, mastercard, naranja, targeta-shopping, union-china-pay, visa, mir, maestro. * @param width Image width. Pass an integer between 0 to 2000. Defaults to 100. @@ -119,6 +130,12 @@ class Avatars(client: Client) : Service(client) { * You can use this endpoint to show different country flags icons to your * users. The code argument receives the 2 letter country code. Use width, * height and quality arguments to change the output settings. + * + * When one dimension is specified and the other is 0, the image is scaled + * with preserved aspect ratio. If both dimensions are 0, the API provides an + * image at source quality. If dimensions are not specified, the default size + * of image returned is 100x100px. + * * * @param code Country Code. ISO Alpha-2 country code format. * @param width Image width. Pass an integer between 0 to 2000. Defaults to 100. @@ -156,10 +173,16 @@ class Avatars(client: Client) : Service(client) { * you want. This endpoint is very useful if you need to crop and display * remote images in your app or in case you want to make sure a 3rd party * image is properly served using a TLS protocol. + * + * When one dimension is specified and the other is 0, the image is scaled + * with preserved aspect ratio. If both dimensions are 0, the API provides an + * image at source quality. If dimensions are not specified, the default size + * of image returned is 400x400px. + * * * @param url Image URL which you want to crop. - * @param width Resize preview image width, Pass an integer between 0 to 2000. - * @param height Resize preview image height, Pass an integer between 0 to 2000. + * @param width Resize preview image width, Pass an integer between 0 to 2000. Defaults to 400. + * @param height Resize preview image height, Pass an integer between 0 to 2000. Defaults to 400. * @return [ByteArray] */ @JvmOverloads @@ -197,6 +220,12 @@ class Avatars(client: Client) : Service(client) { * default, a random theme will be selected. The random theme will persist for * the user's initials when reloading the same theme will always return for * the same initials. + * + * When one dimension is specified and the other is 0, the image is scaled + * with preserved aspect ratio. If both dimensions are 0, the API provides an + * image at source quality. If dimensions are not specified, the default size + * of image returned is 100x100px. + * * * @param name Full Name. When empty, current user name or email will be used. Max length: 128 chars. * @param width Image width. Pass an integer between 0 to 2000. Defaults to 100. @@ -236,9 +265,10 @@ class Avatars(client: Client) : Service(client) { * * Converts a given plain text to a QR code image. You can use the query * parameters to change the size and style of the resulting image. + * * * @param text Plain text to be converted to QR code image. - * @param size QR code size. Pass an integer between 0 to 1000. Defaults to 400. + * @param size QR code size. Pass an integer between 1 to 1000. Defaults to 400. * @param margin Margin from edge. Pass an integer between 0 to 10. Defaults to 1. * @param download Return resulting image with 'Content-Disposition: attachment ' headers for the browser to start downloading it. Pass 0 for no header, or 1 for otherwise. Default value is set to 0. * @return [ByteArray] diff --git a/library/src/main/java/io/appwrite/services/Database.kt b/library/src/main/java/io/appwrite/services/Database.kt index 85a04ca..74bced3 100644 --- a/library/src/main/java/io/appwrite/services/Database.kt +++ b/library/src/main/java/io/appwrite/services/Database.kt @@ -19,13 +19,13 @@ class Database(client: Client) : Service(client) { * modes](/docs/admin). * * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection). - * @param queries Array of query strings. + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/database#querying-documents). Maximum of 100 queries are allowed, each 128 characters long. * @param limit Maximum number of documents 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 value to manage pagination. [learn more about pagination](https://appwrite.io/docs/pagination) * @param cursor ID of the document used as the starting point for the query, excluding the document itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](https://appwrite.io/docs/pagination) * @param cursorDirection Direction of the cursor. - * @param orderAttributes Array of attributes used to sort results. - * @param orderTypes Array of order directions for sorting attribtues. Possible values are DESC for descending order, or ASC for ascending order. + * @param orderAttributes Array of attributes used to sort results. Maximum of 100 order attributes are allowed, each 128 characters long. + * @param orderTypes Array of order directions for sorting attribtues. Possible values are DESC for descending order, or ASC for ascending order. Maximum of 100 order types are allowed. * @return [io.appwrite.models.DocumentList] */ @JvmOverloads @@ -156,7 +156,7 @@ class Database(client: Client) : Service(client) { * * @param collectionId Collection ID. * @param documentId Document ID. - * @param data Document data as JSON object. + * @param data Document data as JSON object. Include only attribute and value pairs to be updated. * @param read An array of strings with read permissions. By default inherits the existing 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 inherits the existing write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. * @return [io.appwrite.models.Document] @@ -195,9 +195,7 @@ class Database(client: Client) : Service(client) { /** * Delete Document * - * Delete a document by its unique ID. This endpoint deletes only the parent - * documents, its attributes and relations to other documents. Child documents - * **will not** be deleted. + * Delete a document by its unique ID. * * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection). * @param documentId Document ID. diff --git a/library/src/main/java/io/appwrite/services/Storage.kt b/library/src/main/java/io/appwrite/services/Storage.kt index a632fd2..927829b 100644 --- a/library/src/main/java/io/appwrite/services/Storage.kt +++ b/library/src/main/java/io/appwrite/services/Storage.kt @@ -115,7 +115,8 @@ class Storage(client: Client) : Service(client) { val converter: (Map) -> io.appwrite.models.File = { io.appwrite.models.File.from(map = it) } - val idParamName: String? = "fileId" + val idParamName: String? = "fileId" + idParamName = "fileId" val paramName = "file" return client.chunkedUpload( path, diff --git a/library/src/main/java/io/appwrite/services/Teams.kt b/library/src/main/java/io/appwrite/services/Teams.kt index e8b232c..5b74d1d 100644 --- a/library/src/main/java/io/appwrite/services/Teams.kt +++ b/library/src/main/java/io/appwrite/services/Teams.kt @@ -71,7 +71,7 @@ class Teams(client: Client) : Service(client) { * * @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. + * @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). Maximum of 100 roles are allowed, each 32 characters long. * @return [io.appwrite.models.Team] */ @JvmOverloads @@ -272,7 +272,7 @@ class Teams(client: Client) : Service(client) { * * @param teamId Team ID. * @param email Email of the new team member. - * @param roles Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Max length for each role is 32 chars. + * @param roles Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. * @param url URL to redirect the user back to your app from the invitation email. 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 name Name of the new team member. Max length: 128 chars. * @return [io.appwrite.models.Membership] @@ -353,7 +353,7 @@ class Teams(client: Client) : Service(client) { * * @param teamId Team ID. * @param membershipId Membership ID. - * @param roles An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Max length for each role is 32 chars. + * @param roles An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. * @return [io.appwrite.models.Membership] */ @JvmOverloads From bbed3c1d79e7f89a426a8a43946112daf19686ef Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 17 May 2022 10:45:35 +0200 Subject: [PATCH 20/21] feat: add response format for 0.14.0 --- library/src/main/java/io/appwrite/Client.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index be3fe85..4e5e78f 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -85,7 +85,7 @@ class Client @JvmOverloads constructor( "origin" to "appwrite-android://${context.packageName}", "user-agent" to "${context.packageName}/${appVersion}, ${System.getProperty("http.agent")}", "x-sdk-version" to "appwrite:android:${BuildConfig.SDK_VERSION}", - "x-appwrite-response-format" to "0.13.0" + "x-appwrite-response-format" to "0.14.0" ) config = mutableMapOf() From 0fdccea7ddb57184eed26e8bcc8e494023ba4537 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 17 May 2022 14:15:18 +0200 Subject: [PATCH 21/21] fix: realtime event payload --- docs/examples/java/storage/create-file.md | 2 +- docs/examples/kotlin/storage/create-file.md | 2 +- library/src/main/java/io/appwrite/models/RealtimeModels.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/examples/java/storage/create-file.md b/docs/examples/java/storage/create-file.md index bc1df1a..3b7099e 100644 --- a/docs/examples/java/storage/create-file.md +++ b/docs/examples/java/storage/create-file.md @@ -21,7 +21,7 @@ public class MainActivity extends AppCompatActivity { storage.createFile( "[BUCKET_ID]", "[FILE_ID]", - File("./path-to-files/image.jpg"), + File("file.png"), new Continuation() { @NotNull @Override diff --git a/docs/examples/kotlin/storage/create-file.md b/docs/examples/kotlin/storage/create-file.md index 437bdeb..c5cc6a3 100644 --- a/docs/examples/kotlin/storage/create-file.md +++ b/docs/examples/kotlin/storage/create-file.md @@ -20,7 +20,7 @@ class MainActivity : AppCompatActivity() { val response = storage.createFile( bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]", - file = File("./path-to-files/image.jpg"), + file = File("file.png"), ) val json = response.body?.string() } diff --git a/library/src/main/java/io/appwrite/models/RealtimeModels.kt b/library/src/main/java/io/appwrite/models/RealtimeModels.kt index 4237638..9041554 100644 --- a/library/src/main/java/io/appwrite/models/RealtimeModels.kt +++ b/library/src/main/java/io/appwrite/models/RealtimeModels.kt @@ -21,7 +21,7 @@ open class RealtimeResponse( ) data class RealtimeResponseEvent( - val event: String, + val events: Collection, val channels: Collection, val timestamp: Long, var payload: T