diff --git a/LICENSE.md b/LICENSE.md index 47cfdfb..5479bb8 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2023 Appwrite (https://appwrite.io) and individual contributors. +Copyright (c) 2024 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 e5d5922..054a54c 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-1.4.12-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.4.13-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 1.4.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).** +**This SDK is compatible with Appwrite server version 1.5.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:4.0.1") +implementation("io.appwrite:sdk-for-android:5.0.0-rc.1") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 4.0.1 + 5.0.0-rc.1 ``` diff --git a/build.gradle b/build.gradle index f2080e6..0b0c86c 100644 --- a/build.gradle +++ b/build.gradle @@ -2,20 +2,19 @@ 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.8.0" + ext.kotlin_version = "1.9.10" + version System.getenv("SDK_VERSION") + repositories { maven { url "https://plugins.gradle.org/m2/" } google() mavenCentral() } dependencies { - classpath "com.android.tools.build:gradle:4.2.2" + classpath "com.android.tools.build:gradle:8.2.2" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath 'io.github.gradle-nexus:publish-plugin:1.1.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath "io.github.gradle-nexus:publish-plugin:1.3.0" } } diff --git a/docs/examples/java/account/add-authenticator.md b/docs/examples/java/account/add-authenticator.md new file mode 100644 index 0000000..35935a4 --- /dev/null +++ b/docs/examples/java/account/add-authenticator.md @@ -0,0 +1,22 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; +import io.appwrite.enums.AuthenticatorFactor; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Account account = new Account(client); + +account.addAuthenticator( + AuthenticatorFactor.TOTP, + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); \ No newline at end of file diff --git a/docs/examples/java/account/create-anonymous-session.md b/docs/examples/java/account/create-anonymous-session.md index 59c7630..46ae275 100644 --- a/docs/examples/java/account/create-anonymous-session.md +++ b/docs/examples/java/account/create-anonymous-session.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.createAnonymousSession(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/account/create-challenge.md b/docs/examples/java/account/create-challenge.md new file mode 100644 index 0000000..5080f10 --- /dev/null +++ b/docs/examples/java/account/create-challenge.md @@ -0,0 +1,22 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; +import io.appwrite.enums.AuthenticatorProvider; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Account account = new Account(client); + +account.createChallenge( + AuthenticatorProvider.TOTP, + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); \ No newline at end of file diff --git a/docs/examples/java/account/create-email-password-session.md b/docs/examples/java/account/create-email-password-session.md new file mode 100644 index 0000000..e3cd353 --- /dev/null +++ b/docs/examples/java/account/create-email-password-session.md @@ -0,0 +1,22 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Account account = new Account(client); + +account.createEmailPasswordSession( + "email@example.com", + "password", + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); \ No newline at end of file diff --git a/docs/examples/java/account/create-magic-u-r-l-session.md b/docs/examples/java/account/create-email-token.md similarity index 94% rename from docs/examples/java/account/create-magic-u-r-l-session.md rename to docs/examples/java/account/create-email-token.md index 0ed43dc..f032eb6 100644 --- a/docs/examples/java/account/create-magic-u-r-l-session.md +++ b/docs/examples/java/account/create-email-token.md @@ -8,7 +8,7 @@ Client client = new Client(context) Account account = new Account(client); -account.createMagicURLSession( +account.createEmailToken( "[USER_ID]", "email@example.com", new CoroutineCallback<>((result, error) -> { @@ -19,4 +19,4 @@ account.createMagicURLSession( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/create-j-w-t.md b/docs/examples/java/account/create-j-w-t.md index c312386..13e6e49 100644 --- a/docs/examples/java/account/create-j-w-t.md +++ b/docs/examples/java/account/create-j-w-t.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.createJWT(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/account/create-email-session.md b/docs/examples/java/account/create-magic-u-r-l-token.md similarity index 91% rename from docs/examples/java/account/create-email-session.md rename to docs/examples/java/account/create-magic-u-r-l-token.md index e3e6fdd..48a8b9b 100644 --- a/docs/examples/java/account/create-email-session.md +++ b/docs/examples/java/account/create-magic-u-r-l-token.md @@ -8,9 +8,9 @@ Client client = new Client(context) Account account = new Account(client); -account.createEmailSession( +account.createMagicURLToken( + "[USER_ID]", "email@example.com", - "password" new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ account.createEmailSession( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/create-o-auth2session.md b/docs/examples/java/account/create-o-auth2session.md index cb9386a..1389673 100644 --- a/docs/examples/java/account/create-o-auth2session.md +++ b/docs/examples/java/account/create-o-auth2session.md @@ -1,6 +1,7 @@ import io.appwrite.Client; import io.appwrite.coroutines.CoroutineCallback; import io.appwrite.services.Account; +import io.appwrite.enums.OAuthProvider; Client client = new Client(context) .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint @@ -9,7 +10,7 @@ Client client = new Client(context) Account account = new Account(client); account.createOAuth2Session( - "amazon", + OAuthProvider.AMAZON, new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +19,4 @@ account.createOAuth2Session( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/create-phone-session.md b/docs/examples/java/account/create-phone-token.md similarity index 91% rename from docs/examples/java/account/create-phone-session.md rename to docs/examples/java/account/create-phone-token.md index df5bc86..a839e81 100644 --- a/docs/examples/java/account/create-phone-session.md +++ b/docs/examples/java/account/create-phone-token.md @@ -8,9 +8,9 @@ Client client = new Client(context) Account account = new Account(client); -account.createPhoneSession( +account.createPhoneToken( "[USER_ID]", - "+12065550100" + "+12065550100", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ account.createPhoneSession( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/create-phone-verification.md b/docs/examples/java/account/create-phone-verification.md index 1545d0f..ef14ce8 100644 --- a/docs/examples/java/account/create-phone-verification.md +++ b/docs/examples/java/account/create-phone-verification.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.createPhoneVerification(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/account/create-push-target.md b/docs/examples/java/account/create-push-target.md new file mode 100644 index 0000000..18a5e76 --- /dev/null +++ b/docs/examples/java/account/create-push-target.md @@ -0,0 +1,22 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Account account = new Account(client); + +account.createPushTarget( + "[TARGET_ID]", + "[IDENTIFIER]", + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); \ No newline at end of file diff --git a/docs/examples/java/account/create-recovery.md b/docs/examples/java/account/create-recovery.md index 5e8584f..f167af2 100644 --- a/docs/examples/java/account/create-recovery.md +++ b/docs/examples/java/account/create-recovery.md @@ -10,7 +10,7 @@ Account account = new Account(client); account.createRecovery( "email@example.com", - "https://example.com" + "https://example.com", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ account.createRecovery( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/update-phone-session.md b/docs/examples/java/account/create-session.md similarity index 92% rename from docs/examples/java/account/update-phone-session.md rename to docs/examples/java/account/create-session.md index 589e4ff..d853209 100644 --- a/docs/examples/java/account/update-phone-session.md +++ b/docs/examples/java/account/create-session.md @@ -8,9 +8,9 @@ Client client = new Client(context) Account account = new Account(client); -account.updatePhoneSession( +account.createSession( "[USER_ID]", - "[SECRET]" + "[SECRET]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ account.updatePhoneSession( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/create-verification.md b/docs/examples/java/account/create-verification.md index fcea98f..eb7a537 100644 --- a/docs/examples/java/account/create-verification.md +++ b/docs/examples/java/account/create-verification.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.createVerification( - "https://example.com" + "https://example.com", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ account.createVerification( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/create.md b/docs/examples/java/account/create.md index e08731f..a16d2c7 100644 --- a/docs/examples/java/account/create.md +++ b/docs/examples/java/account/create.md @@ -20,4 +20,4 @@ account.create( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/delete-authenticator.md b/docs/examples/java/account/delete-authenticator.md new file mode 100644 index 0000000..d7e4196 --- /dev/null +++ b/docs/examples/java/account/delete-authenticator.md @@ -0,0 +1,23 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; +import io.appwrite.enums.AuthenticatorProvider; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Account account = new Account(client); + +account.deleteAuthenticator( + AuthenticatorProvider.TOTP, + "[OTP]", + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); \ No newline at end of file diff --git a/docs/examples/java/account/delete-identity.md b/docs/examples/java/account/delete-identity.md index 0d92d04..f33c29a 100644 --- a/docs/examples/java/account/delete-identity.md +++ b/docs/examples/java/account/delete-identity.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.deleteIdentity( - "[IDENTITY_ID]" + "[IDENTITY_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ account.deleteIdentity( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/delete-push-target.md b/docs/examples/java/account/delete-push-target.md new file mode 100644 index 0000000..77b21d6 --- /dev/null +++ b/docs/examples/java/account/delete-push-target.md @@ -0,0 +1,21 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Account account = new Account(client); + +account.deletePushTarget( + "[TARGET_ID]", + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); \ No newline at end of file diff --git a/docs/examples/java/account/delete-session.md b/docs/examples/java/account/delete-session.md index 28009d0..2b8d228 100644 --- a/docs/examples/java/account/delete-session.md +++ b/docs/examples/java/account/delete-session.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.deleteSession( - "[SESSION_ID]" + "[SESSION_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ account.deleteSession( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/delete-sessions.md b/docs/examples/java/account/delete-sessions.md index 6bdc840..147523e 100644 --- a/docs/examples/java/account/delete-sessions.md +++ b/docs/examples/java/account/delete-sessions.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.deleteSessions(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/account/get-prefs.md b/docs/examples/java/account/get-prefs.md index 9911ad3..bfa3c1a 100644 --- a/docs/examples/java/account/get-prefs.md +++ b/docs/examples/java/account/get-prefs.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.getPrefs(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/account/get-session.md b/docs/examples/java/account/get-session.md index fecb543..dd9c89c 100644 --- a/docs/examples/java/account/get-session.md +++ b/docs/examples/java/account/get-session.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.getSession( - "[SESSION_ID]" + "[SESSION_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ account.getSession( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/get.md b/docs/examples/java/account/get.md index 2e5f40a..9006cb8 100644 --- a/docs/examples/java/account/get.md +++ b/docs/examples/java/account/get.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.get(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/account/list-factors.md b/docs/examples/java/account/list-factors.md new file mode 100644 index 0000000..e2d92b5 --- /dev/null +++ b/docs/examples/java/account/list-factors.md @@ -0,0 +1,18 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Account account = new Account(client); + +account.listFactors(new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); +})); diff --git a/docs/examples/java/account/list-identities.md b/docs/examples/java/account/list-identities.md index d1f6a48..08d4c19 100644 --- a/docs/examples/java/account/list-identities.md +++ b/docs/examples/java/account/list-identities.md @@ -17,4 +17,4 @@ account.listIdentities( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/list-logs.md b/docs/examples/java/account/list-logs.md index d2ce790..f4c39fb 100644 --- a/docs/examples/java/account/list-logs.md +++ b/docs/examples/java/account/list-logs.md @@ -17,4 +17,4 @@ account.listLogs( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/list-sessions.md b/docs/examples/java/account/list-sessions.md index 7fd587e..9e70f0d 100644 --- a/docs/examples/java/account/list-sessions.md +++ b/docs/examples/java/account/list-sessions.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.listSessions(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/account/update-challenge.md b/docs/examples/java/account/update-challenge.md new file mode 100644 index 0000000..d972a14 --- /dev/null +++ b/docs/examples/java/account/update-challenge.md @@ -0,0 +1,22 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Account account = new Account(client); + +account.updateChallenge( + "[CHALLENGE_ID]", + "[OTP]", + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); \ No newline at end of file diff --git a/docs/examples/java/account/update-email.md b/docs/examples/java/account/update-email.md index 8034ada..a7cb414 100644 --- a/docs/examples/java/account/update-email.md +++ b/docs/examples/java/account/update-email.md @@ -10,7 +10,7 @@ Account account = new Account(client); account.updateEmail( "email@example.com", - "password" + "password", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ account.updateEmail( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/update-m-f-a.md b/docs/examples/java/account/update-m-f-a.md new file mode 100644 index 0000000..16f6973 --- /dev/null +++ b/docs/examples/java/account/update-m-f-a.md @@ -0,0 +1,21 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Account account = new Account(client); + +account.updateMFA( + false, + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.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 0f8f2b3..f46422b 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 @@ -10,7 +10,7 @@ Account account = new Account(client); account.updateMagicURLSession( "[USER_ID]", - "[SECRET]" + "[SECRET]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ account.updateMagicURLSession( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/update-name.md b/docs/examples/java/account/update-name.md index 5940f93..8b27389 100644 --- a/docs/examples/java/account/update-name.md +++ b/docs/examples/java/account/update-name.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.updateName( - "[NAME]" + "[NAME]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ account.updateName( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/update-password.md b/docs/examples/java/account/update-password.md index d942632..430ab7e 100644 --- a/docs/examples/java/account/update-password.md +++ b/docs/examples/java/account/update-password.md @@ -18,4 +18,4 @@ account.updatePassword( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/update-phone-verification.md b/docs/examples/java/account/update-phone-verification.md index 81785f9..7d66fd9 100644 --- a/docs/examples/java/account/update-phone-verification.md +++ b/docs/examples/java/account/update-phone-verification.md @@ -10,7 +10,7 @@ Account account = new Account(client); account.updatePhoneVerification( "[USER_ID]", - "[SECRET]" + "[SECRET]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ account.updatePhoneVerification( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/update-phone.md b/docs/examples/java/account/update-phone.md index a8572f9..c958911 100644 --- a/docs/examples/java/account/update-phone.md +++ b/docs/examples/java/account/update-phone.md @@ -10,7 +10,7 @@ Account account = new Account(client); account.updatePhone( "+12065550100", - "password" + "password", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ account.updatePhone( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/update-prefs.md b/docs/examples/java/account/update-prefs.md index ffd5ef0..5d2e75d 100644 --- a/docs/examples/java/account/update-prefs.md +++ b/docs/examples/java/account/update-prefs.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.updatePrefs( - mapOf( "a" to "b" ) + mapOf( "a" to "b" ), new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ account.updatePrefs( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/update-push-target.md b/docs/examples/java/account/update-push-target.md new file mode 100644 index 0000000..10efbad --- /dev/null +++ b/docs/examples/java/account/update-push-target.md @@ -0,0 +1,22 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Account account = new Account(client); + +account.updatePushTarget( + "[TARGET_ID]", + "[IDENTIFIER]", + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); \ No newline at end of file diff --git a/docs/examples/java/account/update-recovery.md b/docs/examples/java/account/update-recovery.md index 7b0f392..313eaa5 100644 --- a/docs/examples/java/account/update-recovery.md +++ b/docs/examples/java/account/update-recovery.md @@ -11,8 +11,7 @@ Account account = new Account(client); account.updateRecovery( "[USER_ID]", "[SECRET]", - "password", - "password" + "", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -21,4 +20,4 @@ account.updateRecovery( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/update-session.md b/docs/examples/java/account/update-session.md index 27b8f00..66eda54 100644 --- a/docs/examples/java/account/update-session.md +++ b/docs/examples/java/account/update-session.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.updateSession( - "[SESSION_ID]" + "[SESSION_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ account.updateSession( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/update-status.md b/docs/examples/java/account/update-status.md index 1e18ded..61cb944 100644 --- a/docs/examples/java/account/update-status.md +++ b/docs/examples/java/account/update-status.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.updateStatus(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/account/update-verification.md b/docs/examples/java/account/update-verification.md index d852dbf..9beb1bd 100644 --- a/docs/examples/java/account/update-verification.md +++ b/docs/examples/java/account/update-verification.md @@ -10,7 +10,7 @@ Account account = new Account(client); account.updateVerification( "[USER_ID]", - "[SECRET]" + "[SECRET]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ account.updateVerification( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/account/verify-authenticator.md b/docs/examples/java/account/verify-authenticator.md new file mode 100644 index 0000000..7a99ffc --- /dev/null +++ b/docs/examples/java/account/verify-authenticator.md @@ -0,0 +1,23 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; +import io.appwrite.enums.AuthenticatorFactor; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Account account = new Account(client); + +account.verifyAuthenticator( + AuthenticatorFactor.TOTP, + "[OTP]", + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); \ No newline at end of file diff --git a/docs/examples/java/avatars/get-browser.md b/docs/examples/java/avatars/get-browser.md index f072110..0652a47 100644 --- a/docs/examples/java/avatars/get-browser.md +++ b/docs/examples/java/avatars/get-browser.md @@ -1,6 +1,7 @@ import io.appwrite.Client; import io.appwrite.coroutines.CoroutineCallback; import io.appwrite.services.Avatars; +import io.appwrite.enums.Browser; Client client = new Client(context) .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint @@ -9,7 +10,7 @@ Client client = new Client(context) Avatars avatars = new Avatars(client); avatars.getBrowser( - "aa", + Browser.AVANT_BROWSER, new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +19,4 @@ avatars.getBrowser( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/avatars/get-credit-card.md b/docs/examples/java/avatars/get-credit-card.md index 0a73312..0f0541a 100644 --- a/docs/examples/java/avatars/get-credit-card.md +++ b/docs/examples/java/avatars/get-credit-card.md @@ -1,6 +1,7 @@ import io.appwrite.Client; import io.appwrite.coroutines.CoroutineCallback; import io.appwrite.services.Avatars; +import io.appwrite.enums.CreditCard; Client client = new Client(context) .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint @@ -9,7 +10,7 @@ Client client = new Client(context) Avatars avatars = new Avatars(client); avatars.getCreditCard( - "amex", + CreditCard.AMERICAN_EXPRESS, new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +19,4 @@ avatars.getCreditCard( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/avatars/get-favicon.md b/docs/examples/java/avatars/get-favicon.md index e0c1cb6..cef5b08 100644 --- a/docs/examples/java/avatars/get-favicon.md +++ b/docs/examples/java/avatars/get-favicon.md @@ -9,7 +9,7 @@ Client client = new Client(context) Avatars avatars = new Avatars(client); avatars.getFavicon( - "https://example.com" + "https://example.com", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ avatars.getFavicon( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/avatars/get-flag.md b/docs/examples/java/avatars/get-flag.md index a5f4790..c931336 100644 --- a/docs/examples/java/avatars/get-flag.md +++ b/docs/examples/java/avatars/get-flag.md @@ -1,6 +1,7 @@ import io.appwrite.Client; import io.appwrite.coroutines.CoroutineCallback; import io.appwrite.services.Avatars; +import io.appwrite.enums.Flag; Client client = new Client(context) .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint @@ -9,7 +10,7 @@ Client client = new Client(context) Avatars avatars = new Avatars(client); avatars.getFlag( - "af", + Flag.AFGHANISTAN, new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +19,4 @@ avatars.getFlag( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/avatars/get-image.md b/docs/examples/java/avatars/get-image.md index cdc8ac7..8ae4df1 100644 --- a/docs/examples/java/avatars/get-image.md +++ b/docs/examples/java/avatars/get-image.md @@ -18,4 +18,4 @@ avatars.getImage( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/avatars/get-initials.md b/docs/examples/java/avatars/get-initials.md index c02490c..36757c4 100644 --- a/docs/examples/java/avatars/get-initials.md +++ b/docs/examples/java/avatars/get-initials.md @@ -17,4 +17,4 @@ avatars.getInitials( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/avatars/get-q-r.md b/docs/examples/java/avatars/get-q-r.md index 2532f20..4894433 100644 --- a/docs/examples/java/avatars/get-q-r.md +++ b/docs/examples/java/avatars/get-q-r.md @@ -18,4 +18,4 @@ avatars.getQR( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/databases/create-document.md b/docs/examples/java/databases/create-document.md index 715e4cd..c26a142 100644 --- a/docs/examples/java/databases/create-document.md +++ b/docs/examples/java/databases/create-document.md @@ -21,4 +21,4 @@ databases.createDocument( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/databases/delete-document.md b/docs/examples/java/databases/delete-document.md index 1387f48..d59266b 100644 --- a/docs/examples/java/databases/delete-document.md +++ b/docs/examples/java/databases/delete-document.md @@ -11,7 +11,7 @@ Databases databases = new Databases(client); databases.deleteDocument( "[DATABASE_ID]", "[COLLECTION_ID]", - "[DOCUMENT_ID]" + "[DOCUMENT_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -20,4 +20,4 @@ databases.deleteDocument( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/databases/get-document.md b/docs/examples/java/databases/get-document.md index b1a7161..a63836e 100644 --- a/docs/examples/java/databases/get-document.md +++ b/docs/examples/java/databases/get-document.md @@ -20,4 +20,4 @@ databases.getDocument( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/databases/list-documents.md b/docs/examples/java/databases/list-documents.md index 62dc2c7..6f577ef 100644 --- a/docs/examples/java/databases/list-documents.md +++ b/docs/examples/java/databases/list-documents.md @@ -19,4 +19,4 @@ databases.listDocuments( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/databases/update-document.md b/docs/examples/java/databases/update-document.md index d1ed59d..ae4d539 100644 --- a/docs/examples/java/databases/update-document.md +++ b/docs/examples/java/databases/update-document.md @@ -20,4 +20,4 @@ databases.updateDocument( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/functions/create-execution.md b/docs/examples/java/functions/create-execution.md index 3cce1c3..985d502 100644 --- a/docs/examples/java/functions/create-execution.md +++ b/docs/examples/java/functions/create-execution.md @@ -18,4 +18,4 @@ functions.createExecution( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/functions/get-execution.md b/docs/examples/java/functions/get-execution.md index 459d743..c066540 100644 --- a/docs/examples/java/functions/get-execution.md +++ b/docs/examples/java/functions/get-execution.md @@ -10,7 +10,7 @@ Functions functions = new Functions(client); functions.getExecution( "[FUNCTION_ID]", - "[EXECUTION_ID]" + "[EXECUTION_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ functions.getExecution( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/functions/list-executions.md b/docs/examples/java/functions/list-executions.md index c1f982b..53f45ca 100644 --- a/docs/examples/java/functions/list-executions.md +++ b/docs/examples/java/functions/list-executions.md @@ -18,4 +18,4 @@ functions.listExecutions( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/graphql/mutation.md b/docs/examples/java/graphql/mutation.md index 262e513..5d140d6 100644 --- a/docs/examples/java/graphql/mutation.md +++ b/docs/examples/java/graphql/mutation.md @@ -9,7 +9,7 @@ Client client = new Client(context) Graphql graphql = new Graphql(client); graphql.mutation( - mapOf( "a" to "b" ) + mapOf( "a" to "b" ), new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ graphql.mutation( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/graphql/query.md b/docs/examples/java/graphql/query.md index 4291b47..de693fa 100644 --- a/docs/examples/java/graphql/query.md +++ b/docs/examples/java/graphql/query.md @@ -9,7 +9,7 @@ Client client = new Client(context) Graphql graphql = new Graphql(client); graphql.query( - mapOf( "a" to "b" ) + mapOf( "a" to "b" ), new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ graphql.query( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/locale/get.md b/docs/examples/java/locale/get.md index 4d14be6..cc37896 100644 --- a/docs/examples/java/locale/get.md +++ b/docs/examples/java/locale/get.md @@ -9,7 +9,7 @@ Client client = new Client(context) Locale locale = new Locale(client); locale.get(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/locale/list-codes.md b/docs/examples/java/locale/list-codes.md index 599070e..3fbdf85 100644 --- a/docs/examples/java/locale/list-codes.md +++ b/docs/examples/java/locale/list-codes.md @@ -9,7 +9,7 @@ Client client = new Client(context) Locale locale = new Locale(client); locale.listCodes(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/locale/list-continents.md b/docs/examples/java/locale/list-continents.md index 6abe97a..296eade 100644 --- a/docs/examples/java/locale/list-continents.md +++ b/docs/examples/java/locale/list-continents.md @@ -9,7 +9,7 @@ Client client = new Client(context) Locale locale = new Locale(client); locale.listContinents(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/locale/list-countries-e-u.md b/docs/examples/java/locale/list-countries-e-u.md index 3c5ca3a..f674ac5 100644 --- a/docs/examples/java/locale/list-countries-e-u.md +++ b/docs/examples/java/locale/list-countries-e-u.md @@ -9,7 +9,7 @@ Client client = new Client(context) Locale locale = new Locale(client); locale.listCountriesEU(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/locale/list-countries-phones.md b/docs/examples/java/locale/list-countries-phones.md index 81ef94d..6280cbb 100644 --- a/docs/examples/java/locale/list-countries-phones.md +++ b/docs/examples/java/locale/list-countries-phones.md @@ -9,7 +9,7 @@ Client client = new Client(context) Locale locale = new Locale(client); locale.listCountriesPhones(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/locale/list-countries.md b/docs/examples/java/locale/list-countries.md index dc0d5f5..eab9ae2 100644 --- a/docs/examples/java/locale/list-countries.md +++ b/docs/examples/java/locale/list-countries.md @@ -9,7 +9,7 @@ Client client = new Client(context) Locale locale = new Locale(client); locale.listCountries(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/locale/list-currencies.md b/docs/examples/java/locale/list-currencies.md index 7a327b3..662e025 100644 --- a/docs/examples/java/locale/list-currencies.md +++ b/docs/examples/java/locale/list-currencies.md @@ -9,7 +9,7 @@ Client client = new Client(context) Locale locale = new Locale(client); locale.listCurrencies(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/locale/list-languages.md b/docs/examples/java/locale/list-languages.md index 0688614..dd68bf2 100644 --- a/docs/examples/java/locale/list-languages.md +++ b/docs/examples/java/locale/list-languages.md @@ -9,7 +9,7 @@ Client client = new Client(context) Locale locale = new Locale(client); locale.listLanguages(new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } diff --git a/docs/examples/java/messaging/create-subscriber.md b/docs/examples/java/messaging/create-subscriber.md new file mode 100644 index 0000000..d071008 --- /dev/null +++ b/docs/examples/java/messaging/create-subscriber.md @@ -0,0 +1,23 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Messaging; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Messaging messaging = new Messaging(client); + +messaging.createSubscriber( + "[TOPIC_ID]", + "[SUBSCRIBER_ID]", + "[TARGET_ID]", + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); \ No newline at end of file diff --git a/docs/examples/java/messaging/delete-subscriber.md b/docs/examples/java/messaging/delete-subscriber.md new file mode 100644 index 0000000..a1d5686 --- /dev/null +++ b/docs/examples/java/messaging/delete-subscriber.md @@ -0,0 +1,22 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Messaging; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Messaging messaging = new Messaging(client); + +messaging.deleteSubscriber( + "[TOPIC_ID]", + "[SUBSCRIBER_ID]", + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.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 732b302..b99312b 100644 --- a/docs/examples/java/storage/create-file.md +++ b/docs/examples/java/storage/create-file.md @@ -21,4 +21,4 @@ storage.createFile( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/storage/delete-file.md b/docs/examples/java/storage/delete-file.md index 69a0f0f..9ac7f2e 100644 --- a/docs/examples/java/storage/delete-file.md +++ b/docs/examples/java/storage/delete-file.md @@ -10,7 +10,7 @@ Storage storage = new Storage(client); storage.deleteFile( "[BUCKET_ID]", - "[FILE_ID]" + "[FILE_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ storage.deleteFile( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/storage/get-file-download.md b/docs/examples/java/storage/get-file-download.md index 2ab30dc..7428cc0 100644 --- a/docs/examples/java/storage/get-file-download.md +++ b/docs/examples/java/storage/get-file-download.md @@ -10,7 +10,7 @@ Storage storage = new Storage(client); storage.getFileDownload( "[BUCKET_ID]", - "[FILE_ID]" + "[FILE_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ storage.getFileDownload( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/storage/get-file-preview.md b/docs/examples/java/storage/get-file-preview.md index 483f2fc..6de0abf 100644 --- a/docs/examples/java/storage/get-file-preview.md +++ b/docs/examples/java/storage/get-file-preview.md @@ -19,4 +19,4 @@ storage.getFilePreview( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/storage/get-file-view.md b/docs/examples/java/storage/get-file-view.md index 5614b69..3c0392d 100644 --- a/docs/examples/java/storage/get-file-view.md +++ b/docs/examples/java/storage/get-file-view.md @@ -10,7 +10,7 @@ Storage storage = new Storage(client); storage.getFileView( "[BUCKET_ID]", - "[FILE_ID]" + "[FILE_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ storage.getFileView( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/storage/get-file.md b/docs/examples/java/storage/get-file.md index 4ae0de0..c425758 100644 --- a/docs/examples/java/storage/get-file.md +++ b/docs/examples/java/storage/get-file.md @@ -10,7 +10,7 @@ Storage storage = new Storage(client); storage.getFile( "[BUCKET_ID]", - "[FILE_ID]" + "[FILE_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ storage.getFile( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/storage/list-files.md b/docs/examples/java/storage/list-files.md index dedfb6c..b6d38aa 100644 --- a/docs/examples/java/storage/list-files.md +++ b/docs/examples/java/storage/list-files.md @@ -18,4 +18,4 @@ storage.listFiles( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/storage/update-file.md b/docs/examples/java/storage/update-file.md index 9b4dd92..6aae427 100644 --- a/docs/examples/java/storage/update-file.md +++ b/docs/examples/java/storage/update-file.md @@ -19,4 +19,4 @@ storage.updateFile( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/create-membership.md b/docs/examples/java/teams/create-membership.md index 6073f5b..3091164 100644 --- a/docs/examples/java/teams/create-membership.md +++ b/docs/examples/java/teams/create-membership.md @@ -19,4 +19,4 @@ teams.createMembership( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/create.md b/docs/examples/java/teams/create.md index 263fa57..aa7f567 100644 --- a/docs/examples/java/teams/create.md +++ b/docs/examples/java/teams/create.md @@ -19,4 +19,4 @@ teams.create( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/delete-membership.md b/docs/examples/java/teams/delete-membership.md index 40f28f0..3837fad 100644 --- a/docs/examples/java/teams/delete-membership.md +++ b/docs/examples/java/teams/delete-membership.md @@ -10,7 +10,7 @@ Teams teams = new Teams(client); teams.deleteMembership( "[TEAM_ID]", - "[MEMBERSHIP_ID]" + "[MEMBERSHIP_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ teams.deleteMembership( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/delete.md b/docs/examples/java/teams/delete.md index 5b4c378..75355ae 100644 --- a/docs/examples/java/teams/delete.md +++ b/docs/examples/java/teams/delete.md @@ -9,7 +9,7 @@ Client client = new Client(context) Teams teams = new Teams(client); teams.delete( - "[TEAM_ID]" + "[TEAM_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ teams.delete( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/get-membership.md b/docs/examples/java/teams/get-membership.md index f2f1d99..0ba9c87 100644 --- a/docs/examples/java/teams/get-membership.md +++ b/docs/examples/java/teams/get-membership.md @@ -10,7 +10,7 @@ Teams teams = new Teams(client); teams.getMembership( "[TEAM_ID]", - "[MEMBERSHIP_ID]" + "[MEMBERSHIP_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ teams.getMembership( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/get-prefs.md b/docs/examples/java/teams/get-prefs.md index 6963cb4..e93b482 100644 --- a/docs/examples/java/teams/get-prefs.md +++ b/docs/examples/java/teams/get-prefs.md @@ -9,7 +9,7 @@ Client client = new Client(context) Teams teams = new Teams(client); teams.getPrefs( - "[TEAM_ID]" + "[TEAM_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ teams.getPrefs( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/get.md b/docs/examples/java/teams/get.md index 549af20..f5406a2 100644 --- a/docs/examples/java/teams/get.md +++ b/docs/examples/java/teams/get.md @@ -9,7 +9,7 @@ Client client = new Client(context) Teams teams = new Teams(client); teams.get( - "[TEAM_ID]" + "[TEAM_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -18,4 +18,4 @@ teams.get( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/list-memberships.md b/docs/examples/java/teams/list-memberships.md index 3da4e33..b61b0d0 100644 --- a/docs/examples/java/teams/list-memberships.md +++ b/docs/examples/java/teams/list-memberships.md @@ -18,4 +18,4 @@ teams.listMemberships( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/list.md b/docs/examples/java/teams/list.md index b20ad4a..2f21813 100644 --- a/docs/examples/java/teams/list.md +++ b/docs/examples/java/teams/list.md @@ -17,4 +17,4 @@ teams.list( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/update-membership-status.md b/docs/examples/java/teams/update-membership-status.md index 499251f..33bd869 100644 --- a/docs/examples/java/teams/update-membership-status.md +++ b/docs/examples/java/teams/update-membership-status.md @@ -12,7 +12,7 @@ teams.updateMembershipStatus( "[TEAM_ID]", "[MEMBERSHIP_ID]", "[USER_ID]", - "[SECRET]" + "[SECRET]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -21,4 +21,4 @@ teams.updateMembershipStatus( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/update-membership.md b/docs/examples/java/teams/update-membership.md index 6cb3346..48efbe3 100644 --- a/docs/examples/java/teams/update-membership.md +++ b/docs/examples/java/teams/update-membership.md @@ -11,7 +11,7 @@ Teams teams = new Teams(client); teams.updateMembership( "[TEAM_ID]", "[MEMBERSHIP_ID]", - listOf() + listOf(), new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -20,4 +20,4 @@ teams.updateMembership( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/update-name.md b/docs/examples/java/teams/update-name.md index 170ee59..a84ba84 100644 --- a/docs/examples/java/teams/update-name.md +++ b/docs/examples/java/teams/update-name.md @@ -10,7 +10,7 @@ Teams teams = new Teams(client); teams.updateName( "[TEAM_ID]", - "[NAME]" + "[NAME]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ teams.updateName( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/teams/update-prefs.md b/docs/examples/java/teams/update-prefs.md index a19ad82..874f976 100644 --- a/docs/examples/java/teams/update-prefs.md +++ b/docs/examples/java/teams/update-prefs.md @@ -10,7 +10,7 @@ Teams teams = new Teams(client); teams.updatePrefs( "[TEAM_ID]", - mapOf( "a" to "b" ) + mapOf( "a" to "b" ), new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -19,4 +19,4 @@ teams.updatePrefs( Log.d("Appwrite", result.toString()); }) -); +); \ No newline at end of file diff --git a/docs/examples/java/users/delete-authenticator.md b/docs/examples/java/users/delete-authenticator.md new file mode 100644 index 0000000..2de3df7 --- /dev/null +++ b/docs/examples/java/users/delete-authenticator.md @@ -0,0 +1,24 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Users; +import io.appwrite.enums.AuthenticatorProvider; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Users users = new Users(client); + +users.deleteAuthenticator( + "[USER_ID]", + AuthenticatorProvider.TOTP, + "[OTP]", + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); \ No newline at end of file diff --git a/docs/examples/java/users/list-providers.md b/docs/examples/java/users/list-providers.md new file mode 100644 index 0000000..ca2f27d --- /dev/null +++ b/docs/examples/java/users/list-providers.md @@ -0,0 +1,21 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Users; + +Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Users users = new Users(client); + +users.listProviders( + "[USER_ID]", + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); \ No newline at end of file diff --git a/docs/examples/kotlin/account/add-authenticator.md b/docs/examples/kotlin/account/add-authenticator.md new file mode 100644 index 0000000..adb0cf9 --- /dev/null +++ b/docs/examples/kotlin/account/add-authenticator.md @@ -0,0 +1,14 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account +import io.appwrite.enums.AuthenticatorFactor + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val account = Account(client) + +val response = account.addAuthenticator( + factor = AuthenticatorFactor.TOTP, +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/create-anonymous-session.md b/docs/examples/kotlin/account/create-anonymous-session.md index cdcf401..6d1e632 100644 --- a/docs/examples/kotlin/account/create-anonymous-session.md +++ b/docs/examples/kotlin/account/create-anonymous-session.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) diff --git a/docs/examples/kotlin/account/create-challenge.md b/docs/examples/kotlin/account/create-challenge.md new file mode 100644 index 0000000..d1b0df9 --- /dev/null +++ b/docs/examples/kotlin/account/create-challenge.md @@ -0,0 +1,14 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account +import io.appwrite.enums.AuthenticatorProvider + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val account = Account(client) + +val response = account.createChallenge( + provider = AuthenticatorProvider.TOTP, +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/create-email-password-session.md b/docs/examples/kotlin/account/create-email-password-session.md new file mode 100644 index 0000000..016e73b --- /dev/null +++ b/docs/examples/kotlin/account/create-email-password-session.md @@ -0,0 +1,14 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val account = Account(client) + +val response = account.createEmailPasswordSession( + email = "email@example.com", + password = "password", +) \ 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-email-token.md similarity index 77% rename from docs/examples/kotlin/account/create-magic-u-r-l-session.md rename to docs/examples/kotlin/account/create-email-token.md index 51368b5..6165707 100644 --- a/docs/examples/kotlin/account/create-magic-u-r-l-session.md +++ b/docs/examples/kotlin/account/create-email-token.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -7,7 +8,7 @@ val client = Client(context) val account = Account(client) -val response = account.createMagicURLSession( +val response = account.createEmailToken( userId = "[USER_ID]", email = "email@example.com", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/create-j-w-t.md b/docs/examples/kotlin/account/create-j-w-t.md index 35e7a6f..c3131e6 100644 --- a/docs/examples/kotlin/account/create-j-w-t.md +++ b/docs/examples/kotlin/account/create-j-w-t.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) diff --git a/docs/examples/kotlin/account/create-email-session.md b/docs/examples/kotlin/account/create-magic-u-r-l-token.md similarity index 70% rename from docs/examples/kotlin/account/create-email-session.md rename to docs/examples/kotlin/account/create-magic-u-r-l-token.md index ab8d581..9d02c96 100644 --- a/docs/examples/kotlin/account/create-email-session.md +++ b/docs/examples/kotlin/account/create-magic-u-r-l-token.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -7,7 +8,7 @@ val client = Client(context) val account = Account(client) -val response = account.createEmailSession( +val response = account.createMagicURLToken( + userId = "[USER_ID]", email = "email@example.com", - password = "password" -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/create-o-auth2session.md b/docs/examples/kotlin/account/create-o-auth2session.md index 395bfad..ac01fe5 100644 --- a/docs/examples/kotlin/account/create-o-auth2session.md +++ b/docs/examples/kotlin/account/create-o-auth2session.md @@ -1,5 +1,7 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account +import io.appwrite.enums.OAuthProvider val client = Client(context) .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint @@ -8,5 +10,5 @@ val client = Client(context) val account = Account(client) account.createOAuth2Session( - provider = "amazon", -) + provider = OAuthProvider.AMAZON, +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/create-phone-token.md b/docs/examples/kotlin/account/create-phone-token.md new file mode 100644 index 0000000..abb46c5 --- /dev/null +++ b/docs/examples/kotlin/account/create-phone-token.md @@ -0,0 +1,14 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val account = Account(client) + +val response = account.createPhoneToken( + userId = "[USER_ID]", + phone = "+12065550100", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/create-phone-verification.md b/docs/examples/kotlin/account/create-phone-verification.md index 12fb9f7..3fb5064 100644 --- a/docs/examples/kotlin/account/create-phone-verification.md +++ b/docs/examples/kotlin/account/create-phone-verification.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) diff --git a/docs/examples/kotlin/account/create-push-target.md b/docs/examples/kotlin/account/create-push-target.md new file mode 100644 index 0000000..30c4d39 --- /dev/null +++ b/docs/examples/kotlin/account/create-push-target.md @@ -0,0 +1,14 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val account = Account(client) + +val response = account.createPushTarget( + targetId = "[TARGET_ID]", + identifier = "[IDENTIFIER]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/create-recovery.md b/docs/examples/kotlin/account/create-recovery.md index 7d73a67..f678fcf 100644 --- a/docs/examples/kotlin/account/create-recovery.md +++ b/docs/examples/kotlin/account/create-recovery.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -9,5 +10,5 @@ val account = Account(client) val response = account.createRecovery( email = "email@example.com", - url = "https://example.com" -) + url = "https://example.com", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/create-session.md b/docs/examples/kotlin/account/create-session.md new file mode 100644 index 0000000..ceb7726 --- /dev/null +++ b/docs/examples/kotlin/account/create-session.md @@ -0,0 +1,14 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val account = Account(client) + +val response = account.createSession( + userId = "[USER_ID]", + secret = "[SECRET]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/create-verification.md b/docs/examples/kotlin/account/create-verification.md index b3dc43a..1832348 100644 --- a/docs/examples/kotlin/account/create-verification.md +++ b/docs/examples/kotlin/account/create-verification.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -8,5 +9,5 @@ val client = Client(context) val account = Account(client) val response = account.createVerification( - url = "https://example.com" -) + url = "https://example.com", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/create.md b/docs/examples/kotlin/account/create.md index c72ae90..8022955 100644 --- a/docs/examples/kotlin/account/create.md +++ b/docs/examples/kotlin/account/create.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -11,4 +12,4 @@ val response = account.create( userId = "[USER_ID]", email = "email@example.com", password = "", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/delete-authenticator.md b/docs/examples/kotlin/account/delete-authenticator.md new file mode 100644 index 0000000..beb63f1 --- /dev/null +++ b/docs/examples/kotlin/account/delete-authenticator.md @@ -0,0 +1,15 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account +import io.appwrite.enums.AuthenticatorProvider + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val account = Account(client) + +val response = account.deleteAuthenticator( + provider = AuthenticatorProvider.TOTP, + otp = "[OTP]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/delete-identity.md b/docs/examples/kotlin/account/delete-identity.md index 440333e..cbf6913 100644 --- a/docs/examples/kotlin/account/delete-identity.md +++ b/docs/examples/kotlin/account/delete-identity.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -8,5 +9,5 @@ val client = Client(context) val account = Account(client) val response = account.deleteIdentity( - identityId = "[IDENTITY_ID]" -) + identityId = "[IDENTITY_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/delete-push-target.md b/docs/examples/kotlin/account/delete-push-target.md new file mode 100644 index 0000000..ea79749 --- /dev/null +++ b/docs/examples/kotlin/account/delete-push-target.md @@ -0,0 +1,13 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val account = Account(client) + +val response = account.deletePushTarget( + targetId = "[TARGET_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/delete-session.md b/docs/examples/kotlin/account/delete-session.md index a98a286..615f218 100644 --- a/docs/examples/kotlin/account/delete-session.md +++ b/docs/examples/kotlin/account/delete-session.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -8,5 +9,5 @@ val client = Client(context) val account = Account(client) val response = account.deleteSession( - sessionId = "[SESSION_ID]" -) + sessionId = "[SESSION_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/delete-sessions.md b/docs/examples/kotlin/account/delete-sessions.md index c9afbf1..db8e00d 100644 --- a/docs/examples/kotlin/account/delete-sessions.md +++ b/docs/examples/kotlin/account/delete-sessions.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) diff --git a/docs/examples/kotlin/account/get-prefs.md b/docs/examples/kotlin/account/get-prefs.md index bd3f81a..0112f8b 100644 --- a/docs/examples/kotlin/account/get-prefs.md +++ b/docs/examples/kotlin/account/get-prefs.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) diff --git a/docs/examples/kotlin/account/get-session.md b/docs/examples/kotlin/account/get-session.md index d6d6c72..1b15d5b 100644 --- a/docs/examples/kotlin/account/get-session.md +++ b/docs/examples/kotlin/account/get-session.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -8,5 +9,5 @@ val client = Client(context) val account = Account(client) val response = account.getSession( - sessionId = "[SESSION_ID]" -) + sessionId = "[SESSION_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/get.md b/docs/examples/kotlin/account/get.md index 4c8f0be..6c08a1c 100644 --- a/docs/examples/kotlin/account/get.md +++ b/docs/examples/kotlin/account/get.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) diff --git a/docs/examples/kotlin/account/update-phone-session.md b/docs/examples/kotlin/account/list-factors.md similarity index 72% rename from docs/examples/kotlin/account/update-phone-session.md rename to docs/examples/kotlin/account/list-factors.md index d3b02e0..e30f652 100644 --- a/docs/examples/kotlin/account/update-phone-session.md +++ b/docs/examples/kotlin/account/list-factors.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -7,7 +8,4 @@ val client = Client(context) val account = Account(client) -val response = account.updatePhoneSession( - userId = "[USER_ID]", - secret = "[SECRET]" -) +val response = account.listFactors() diff --git a/docs/examples/kotlin/account/list-identities.md b/docs/examples/kotlin/account/list-identities.md index 3292b35..d87409c 100644 --- a/docs/examples/kotlin/account/list-identities.md +++ b/docs/examples/kotlin/account/list-identities.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -8,4 +9,4 @@ val client = Client(context) val account = Account(client) val response = account.listIdentities( -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/list-logs.md b/docs/examples/kotlin/account/list-logs.md index eb337ca..f4ce74f 100644 --- a/docs/examples/kotlin/account/list-logs.md +++ b/docs/examples/kotlin/account/list-logs.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -8,4 +9,4 @@ val client = Client(context) val account = Account(client) val response = account.listLogs( -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/list-sessions.md b/docs/examples/kotlin/account/list-sessions.md index cd9f63b..2c692b8 100644 --- a/docs/examples/kotlin/account/list-sessions.md +++ b/docs/examples/kotlin/account/list-sessions.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) diff --git a/docs/examples/kotlin/account/update-challenge.md b/docs/examples/kotlin/account/update-challenge.md new file mode 100644 index 0000000..23718d2 --- /dev/null +++ b/docs/examples/kotlin/account/update-challenge.md @@ -0,0 +1,14 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val account = Account(client) + +val response = account.updateChallenge( + challengeId = "[CHALLENGE_ID]", + otp = "[OTP]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/update-email.md b/docs/examples/kotlin/account/update-email.md index 85a0242..6b3655a 100644 --- a/docs/examples/kotlin/account/update-email.md +++ b/docs/examples/kotlin/account/update-email.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -9,5 +10,5 @@ val account = Account(client) val response = account.updateEmail( email = "email@example.com", - password = "password" -) + password = "password", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/create-phone-session.md b/docs/examples/kotlin/account/update-m-f-a.md similarity index 71% rename from docs/examples/kotlin/account/create-phone-session.md rename to docs/examples/kotlin/account/update-m-f-a.md index eed6f7a..1bd3fd2 100644 --- a/docs/examples/kotlin/account/create-phone-session.md +++ b/docs/examples/kotlin/account/update-m-f-a.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -7,7 +8,6 @@ val client = Client(context) val account = Account(client) -val response = account.createPhoneSession( - userId = "[USER_ID]", - phone = "+12065550100" -) +val response = account.updateMFA( + mfa = false, +) \ No newline at end of file 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 c7286ba..1f77281 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 @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -9,5 +10,5 @@ val account = Account(client) val response = account.updateMagicURLSession( userId = "[USER_ID]", - secret = "[SECRET]" -) + secret = "[SECRET]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/update-name.md b/docs/examples/kotlin/account/update-name.md index 574f493..5d18e1f 100644 --- a/docs/examples/kotlin/account/update-name.md +++ b/docs/examples/kotlin/account/update-name.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -8,5 +9,5 @@ val client = Client(context) val account = Account(client) val response = account.updateName( - name = "[NAME]" -) + name = "[NAME]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/update-password.md b/docs/examples/kotlin/account/update-password.md index c5338b8..45e9556 100644 --- a/docs/examples/kotlin/account/update-password.md +++ b/docs/examples/kotlin/account/update-password.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -9,4 +10,4 @@ val account = Account(client) val response = account.updatePassword( password = "", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/update-phone-verification.md b/docs/examples/kotlin/account/update-phone-verification.md index 0314f74..c4c0e84 100644 --- a/docs/examples/kotlin/account/update-phone-verification.md +++ b/docs/examples/kotlin/account/update-phone-verification.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -9,5 +10,5 @@ val account = Account(client) val response = account.updatePhoneVerification( userId = "[USER_ID]", - secret = "[SECRET]" -) + secret = "[SECRET]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/update-phone.md b/docs/examples/kotlin/account/update-phone.md index 76eb8aa..d86e628 100644 --- a/docs/examples/kotlin/account/update-phone.md +++ b/docs/examples/kotlin/account/update-phone.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -9,5 +10,5 @@ val account = Account(client) val response = account.updatePhone( phone = "+12065550100", - password = "password" -) + password = "password", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/update-prefs.md b/docs/examples/kotlin/account/update-prefs.md index f16e40b..58d5cd0 100644 --- a/docs/examples/kotlin/account/update-prefs.md +++ b/docs/examples/kotlin/account/update-prefs.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -8,5 +9,5 @@ val client = Client(context) val account = Account(client) val response = account.updatePrefs( - prefs = mapOf( "a" to "b" ) -) + prefs = mapOf( "a" to "b" ), +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/update-push-target.md b/docs/examples/kotlin/account/update-push-target.md new file mode 100644 index 0000000..ff1e3a1 --- /dev/null +++ b/docs/examples/kotlin/account/update-push-target.md @@ -0,0 +1,14 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val account = Account(client) + +val response = account.updatePushTarget( + targetId = "[TARGET_ID]", + identifier = "[IDENTIFIER]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/update-recovery.md b/docs/examples/kotlin/account/update-recovery.md index 9682899..6b7a6d0 100644 --- a/docs/examples/kotlin/account/update-recovery.md +++ b/docs/examples/kotlin/account/update-recovery.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -10,6 +11,5 @@ val account = Account(client) val response = account.updateRecovery( userId = "[USER_ID]", secret = "[SECRET]", - password = "password", - passwordAgain = "password" -) + password = "", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/update-session.md b/docs/examples/kotlin/account/update-session.md index e9e83d0..1257334 100644 --- a/docs/examples/kotlin/account/update-session.md +++ b/docs/examples/kotlin/account/update-session.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -8,5 +9,5 @@ val client = Client(context) val account = Account(client) val response = account.updateSession( - sessionId = "[SESSION_ID]" -) + sessionId = "[SESSION_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/update-status.md b/docs/examples/kotlin/account/update-status.md index f7789ea..e822de9 100644 --- a/docs/examples/kotlin/account/update-status.md +++ b/docs/examples/kotlin/account/update-status.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) diff --git a/docs/examples/kotlin/account/update-verification.md b/docs/examples/kotlin/account/update-verification.md index af800c1..0dcd75b 100644 --- a/docs/examples/kotlin/account/update-verification.md +++ b/docs/examples/kotlin/account/update-verification.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Account val client = Client(context) @@ -9,5 +10,5 @@ val account = Account(client) val response = account.updateVerification( userId = "[USER_ID]", - secret = "[SECRET]" -) + secret = "[SECRET]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/verify-authenticator.md b/docs/examples/kotlin/account/verify-authenticator.md new file mode 100644 index 0000000..65144f7 --- /dev/null +++ b/docs/examples/kotlin/account/verify-authenticator.md @@ -0,0 +1,15 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account +import io.appwrite.enums.AuthenticatorFactor + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val account = Account(client) + +val response = account.verifyAuthenticator( + factor = AuthenticatorFactor.TOTP, + otp = "[OTP]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/avatars/get-browser.md b/docs/examples/kotlin/avatars/get-browser.md index b1b2d08..ab7c749 100644 --- a/docs/examples/kotlin/avatars/get-browser.md +++ b/docs/examples/kotlin/avatars/get-browser.md @@ -1,5 +1,7 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Avatars +import io.appwrite.enums.Browser val client = Client(context) .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint @@ -7,6 +9,6 @@ val client = Client(context) val avatars = Avatars(client) -val result = avatars.getBrowser( - code = "aa", -) +val result =avatars.getBrowser( + code = Browser.AVANT_BROWSER, +) \ No newline at end of file diff --git a/docs/examples/kotlin/avatars/get-credit-card.md b/docs/examples/kotlin/avatars/get-credit-card.md index 411e05a..758f70d 100644 --- a/docs/examples/kotlin/avatars/get-credit-card.md +++ b/docs/examples/kotlin/avatars/get-credit-card.md @@ -1,5 +1,7 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Avatars +import io.appwrite.enums.CreditCard val client = Client(context) .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint @@ -7,6 +9,6 @@ val client = Client(context) val avatars = Avatars(client) -val result = avatars.getCreditCard( - code = "amex", -) +val result =avatars.getCreditCard( + code = CreditCard.AMERICAN_EXPRESS, +) \ No newline at end of file diff --git a/docs/examples/kotlin/avatars/get-favicon.md b/docs/examples/kotlin/avatars/get-favicon.md index 1a4b217..1bb1372 100644 --- a/docs/examples/kotlin/avatars/get-favicon.md +++ b/docs/examples/kotlin/avatars/get-favicon.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Avatars val client = Client(context) @@ -7,6 +8,6 @@ val client = Client(context) val avatars = Avatars(client) -val result = avatars.getFavicon( - url = "https://example.com" -) +val result =avatars.getFavicon( + url = "https://example.com", +) \ No newline at end of file diff --git a/docs/examples/kotlin/avatars/get-flag.md b/docs/examples/kotlin/avatars/get-flag.md index 5c882d6..142f626 100644 --- a/docs/examples/kotlin/avatars/get-flag.md +++ b/docs/examples/kotlin/avatars/get-flag.md @@ -1,5 +1,7 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Avatars +import io.appwrite.enums.Flag val client = Client(context) .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint @@ -7,6 +9,6 @@ val client = Client(context) val avatars = Avatars(client) -val result = avatars.getFlag( - code = "af", -) +val result =avatars.getFlag( + code = Flag.AFGHANISTAN, +) \ No newline at end of file diff --git a/docs/examples/kotlin/avatars/get-image.md b/docs/examples/kotlin/avatars/get-image.md index 20d8dff..c1ccd96 100644 --- a/docs/examples/kotlin/avatars/get-image.md +++ b/docs/examples/kotlin/avatars/get-image.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Avatars val client = Client(context) @@ -7,6 +8,6 @@ val client = Client(context) val avatars = Avatars(client) -val result = avatars.getImage( +val result =avatars.getImage( url = "https://example.com", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/avatars/get-initials.md b/docs/examples/kotlin/avatars/get-initials.md index 70ef9b2..62c69c8 100644 --- a/docs/examples/kotlin/avatars/get-initials.md +++ b/docs/examples/kotlin/avatars/get-initials.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Avatars val client = Client(context) @@ -7,5 +8,5 @@ val client = Client(context) val avatars = Avatars(client) -val result = avatars.getInitials( -) +val result =avatars.getInitials( +) \ No newline at end of file diff --git a/docs/examples/kotlin/avatars/get-q-r.md b/docs/examples/kotlin/avatars/get-q-r.md index 92b17e1..85de6d3 100644 --- a/docs/examples/kotlin/avatars/get-q-r.md +++ b/docs/examples/kotlin/avatars/get-q-r.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Avatars val client = Client(context) @@ -7,6 +8,6 @@ val client = Client(context) val avatars = Avatars(client) -val result = avatars.getQR( +val result =avatars.getQR( text = "[TEXT]", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/databases/create-document.md b/docs/examples/kotlin/databases/create-document.md index d7f1991..bc5445a 100644 --- a/docs/examples/kotlin/databases/create-document.md +++ b/docs/examples/kotlin/databases/create-document.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Databases val client = Client(context) @@ -12,4 +13,4 @@ val response = databases.createDocument( collectionId = "[COLLECTION_ID]", documentId = "[DOCUMENT_ID]", data = mapOf( "a" to "b" ), -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/databases/delete-document.md b/docs/examples/kotlin/databases/delete-document.md index c5bf2a2..d24db61 100644 --- a/docs/examples/kotlin/databases/delete-document.md +++ b/docs/examples/kotlin/databases/delete-document.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Databases val client = Client(context) @@ -10,5 +11,5 @@ val databases = Databases(client) val response = databases.deleteDocument( databaseId = "[DATABASE_ID]", collectionId = "[COLLECTION_ID]", - documentId = "[DOCUMENT_ID]" -) + documentId = "[DOCUMENT_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/databases/get-document.md b/docs/examples/kotlin/databases/get-document.md index abdee36..328b801 100644 --- a/docs/examples/kotlin/databases/get-document.md +++ b/docs/examples/kotlin/databases/get-document.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Databases val client = Client(context) @@ -11,4 +12,4 @@ val response = databases.getDocument( databaseId = "[DATABASE_ID]", collectionId = "[COLLECTION_ID]", documentId = "[DOCUMENT_ID]", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/databases/list-documents.md b/docs/examples/kotlin/databases/list-documents.md index f97d878..b5511d6 100644 --- a/docs/examples/kotlin/databases/list-documents.md +++ b/docs/examples/kotlin/databases/list-documents.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Databases val client = Client(context) @@ -10,4 +11,4 @@ val databases = Databases(client) val response = databases.listDocuments( databaseId = "[DATABASE_ID]", collectionId = "[COLLECTION_ID]", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/databases/update-document.md b/docs/examples/kotlin/databases/update-document.md index 3820b89..e2d989e 100644 --- a/docs/examples/kotlin/databases/update-document.md +++ b/docs/examples/kotlin/databases/update-document.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Databases val client = Client(context) @@ -11,4 +12,4 @@ val response = databases.updateDocument( databaseId = "[DATABASE_ID]", collectionId = "[COLLECTION_ID]", documentId = "[DOCUMENT_ID]", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/functions/create-execution.md b/docs/examples/kotlin/functions/create-execution.md index 77d4587..96dad59 100644 --- a/docs/examples/kotlin/functions/create-execution.md +++ b/docs/examples/kotlin/functions/create-execution.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Functions val client = Client(context) @@ -9,4 +10,4 @@ val functions = Functions(client) val response = functions.createExecution( functionId = "[FUNCTION_ID]", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/functions/get-execution.md b/docs/examples/kotlin/functions/get-execution.md index b576686..e366f4b 100644 --- a/docs/examples/kotlin/functions/get-execution.md +++ b/docs/examples/kotlin/functions/get-execution.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Functions val client = Client(context) @@ -9,5 +10,5 @@ val functions = Functions(client) val response = functions.getExecution( functionId = "[FUNCTION_ID]", - executionId = "[EXECUTION_ID]" -) + executionId = "[EXECUTION_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/functions/list-executions.md b/docs/examples/kotlin/functions/list-executions.md index 14b613f..ba2ff2d 100644 --- a/docs/examples/kotlin/functions/list-executions.md +++ b/docs/examples/kotlin/functions/list-executions.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Functions val client = Client(context) @@ -9,4 +10,4 @@ val functions = Functions(client) val response = functions.listExecutions( functionId = "[FUNCTION_ID]", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/graphql/mutation.md b/docs/examples/kotlin/graphql/mutation.md index dc37a3e..eee3f82 100644 --- a/docs/examples/kotlin/graphql/mutation.md +++ b/docs/examples/kotlin/graphql/mutation.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Graphql val client = Client(context) @@ -8,5 +9,5 @@ val client = Client(context) val graphql = Graphql(client) val response = graphql.mutation( - query = mapOf( "a" to "b" ) -) + query = mapOf( "a" to "b" ), +) \ No newline at end of file diff --git a/docs/examples/kotlin/graphql/query.md b/docs/examples/kotlin/graphql/query.md index d821070..1337d36 100644 --- a/docs/examples/kotlin/graphql/query.md +++ b/docs/examples/kotlin/graphql/query.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Graphql val client = Client(context) @@ -8,5 +9,5 @@ val client = Client(context) val graphql = Graphql(client) val response = graphql.query( - query = mapOf( "a" to "b" ) -) + query = mapOf( "a" to "b" ), +) \ No newline at end of file diff --git a/docs/examples/kotlin/locale/get.md b/docs/examples/kotlin/locale/get.md index a2044c7..ec7f625 100644 --- a/docs/examples/kotlin/locale/get.md +++ b/docs/examples/kotlin/locale/get.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Locale val client = Client(context) diff --git a/docs/examples/kotlin/locale/list-codes.md b/docs/examples/kotlin/locale/list-codes.md index b4e949b..e81e106 100644 --- a/docs/examples/kotlin/locale/list-codes.md +++ b/docs/examples/kotlin/locale/list-codes.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Locale val client = Client(context) diff --git a/docs/examples/kotlin/locale/list-continents.md b/docs/examples/kotlin/locale/list-continents.md index 610747e..0255e65 100644 --- a/docs/examples/kotlin/locale/list-continents.md +++ b/docs/examples/kotlin/locale/list-continents.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Locale val client = Client(context) diff --git a/docs/examples/kotlin/locale/list-countries-e-u.md b/docs/examples/kotlin/locale/list-countries-e-u.md index fa5483f..4cf60d9 100644 --- a/docs/examples/kotlin/locale/list-countries-e-u.md +++ b/docs/examples/kotlin/locale/list-countries-e-u.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Locale val client = Client(context) diff --git a/docs/examples/kotlin/locale/list-countries-phones.md b/docs/examples/kotlin/locale/list-countries-phones.md index 6aba463..1f8f75b 100644 --- a/docs/examples/kotlin/locale/list-countries-phones.md +++ b/docs/examples/kotlin/locale/list-countries-phones.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Locale val client = Client(context) diff --git a/docs/examples/kotlin/locale/list-countries.md b/docs/examples/kotlin/locale/list-countries.md index c58456b..f221fc6 100644 --- a/docs/examples/kotlin/locale/list-countries.md +++ b/docs/examples/kotlin/locale/list-countries.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Locale val client = Client(context) diff --git a/docs/examples/kotlin/locale/list-currencies.md b/docs/examples/kotlin/locale/list-currencies.md index 2cf0644..6e5ab0d 100644 --- a/docs/examples/kotlin/locale/list-currencies.md +++ b/docs/examples/kotlin/locale/list-currencies.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Locale val client = Client(context) diff --git a/docs/examples/kotlin/locale/list-languages.md b/docs/examples/kotlin/locale/list-languages.md index afc00b1..97a9eb7 100644 --- a/docs/examples/kotlin/locale/list-languages.md +++ b/docs/examples/kotlin/locale/list-languages.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Locale val client = Client(context) diff --git a/docs/examples/kotlin/messaging/create-subscriber.md b/docs/examples/kotlin/messaging/create-subscriber.md new file mode 100644 index 0000000..1da3ed3 --- /dev/null +++ b/docs/examples/kotlin/messaging/create-subscriber.md @@ -0,0 +1,15 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Messaging + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val messaging = Messaging(client) + +val response = messaging.createSubscriber( + topicId = "[TOPIC_ID]", + subscriberId = "[SUBSCRIBER_ID]", + targetId = "[TARGET_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/messaging/delete-subscriber.md b/docs/examples/kotlin/messaging/delete-subscriber.md new file mode 100644 index 0000000..0096de3 --- /dev/null +++ b/docs/examples/kotlin/messaging/delete-subscriber.md @@ -0,0 +1,14 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Messaging + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val messaging = Messaging(client) + +val response = messaging.deleteSubscriber( + topicId = "[TOPIC_ID]", + subscriberId = "[SUBSCRIBER_ID]", +) \ 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 7bb79ac..19eae0f 100644 --- a/docs/examples/kotlin/storage/create-file.md +++ b/docs/examples/kotlin/storage/create-file.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.models.InputFile import io.appwrite.services.Storage @@ -12,4 +13,4 @@ val response = storage.createFile( bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]", file = InputFile.fromPath("file.png"), -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/storage/delete-file.md b/docs/examples/kotlin/storage/delete-file.md index 9430d7e..c64e8dc 100644 --- a/docs/examples/kotlin/storage/delete-file.md +++ b/docs/examples/kotlin/storage/delete-file.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Storage val client = Client(context) @@ -9,5 +10,5 @@ val storage = Storage(client) val response = storage.deleteFile( bucketId = "[BUCKET_ID]", - fileId = "[FILE_ID]" -) + fileId = "[FILE_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/storage/get-file-download.md b/docs/examples/kotlin/storage/get-file-download.md index 85bd22c..07ebcc0 100644 --- a/docs/examples/kotlin/storage/get-file-download.md +++ b/docs/examples/kotlin/storage/get-file-download.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Storage val client = Client(context) @@ -7,7 +8,7 @@ val client = Client(context) val storage = Storage(client) -val result = storage.getFileDownload( +val result =storage.getFileDownload( bucketId = "[BUCKET_ID]", - fileId = "[FILE_ID]" -) + fileId = "[FILE_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/storage/get-file-preview.md b/docs/examples/kotlin/storage/get-file-preview.md index c5bbdef..b5995ae 100644 --- a/docs/examples/kotlin/storage/get-file-preview.md +++ b/docs/examples/kotlin/storage/get-file-preview.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Storage val client = Client(context) @@ -7,7 +8,7 @@ val client = Client(context) val storage = Storage(client) -val result = storage.getFilePreview( +val result =storage.getFilePreview( bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/storage/get-file-view.md b/docs/examples/kotlin/storage/get-file-view.md index 7e7589c..82b55c2 100644 --- a/docs/examples/kotlin/storage/get-file-view.md +++ b/docs/examples/kotlin/storage/get-file-view.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Storage val client = Client(context) @@ -7,7 +8,7 @@ val client = Client(context) val storage = Storage(client) -val result = storage.getFileView( +val result =storage.getFileView( bucketId = "[BUCKET_ID]", - fileId = "[FILE_ID]" -) + fileId = "[FILE_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/storage/get-file.md b/docs/examples/kotlin/storage/get-file.md index 8fb6e24..9c1abd4 100644 --- a/docs/examples/kotlin/storage/get-file.md +++ b/docs/examples/kotlin/storage/get-file.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Storage val client = Client(context) @@ -9,5 +10,5 @@ val storage = Storage(client) val response = storage.getFile( bucketId = "[BUCKET_ID]", - fileId = "[FILE_ID]" -) + fileId = "[FILE_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/storage/list-files.md b/docs/examples/kotlin/storage/list-files.md index 191a3cc..575a8b9 100644 --- a/docs/examples/kotlin/storage/list-files.md +++ b/docs/examples/kotlin/storage/list-files.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Storage val client = Client(context) @@ -9,4 +10,4 @@ val storage = Storage(client) val response = storage.listFiles( bucketId = "[BUCKET_ID]", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/storage/update-file.md b/docs/examples/kotlin/storage/update-file.md index 005270f..75585fa 100644 --- a/docs/examples/kotlin/storage/update-file.md +++ b/docs/examples/kotlin/storage/update-file.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Storage val client = Client(context) @@ -10,4 +11,4 @@ val storage = Storage(client) val response = storage.updateFile( bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/create-membership.md b/docs/examples/kotlin/teams/create-membership.md index 4d1de49..231a991 100644 --- a/docs/examples/kotlin/teams/create-membership.md +++ b/docs/examples/kotlin/teams/create-membership.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -10,4 +11,4 @@ val teams = Teams(client) val response = teams.createMembership( teamId = "[TEAM_ID]", roles = listOf(), -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/create.md b/docs/examples/kotlin/teams/create.md index 5e70bd8..dd1125c 100644 --- a/docs/examples/kotlin/teams/create.md +++ b/docs/examples/kotlin/teams/create.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -10,4 +11,4 @@ val teams = Teams(client) val response = teams.create( teamId = "[TEAM_ID]", name = "[NAME]", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/delete-membership.md b/docs/examples/kotlin/teams/delete-membership.md index 04ef5d3..3f165a7 100644 --- a/docs/examples/kotlin/teams/delete-membership.md +++ b/docs/examples/kotlin/teams/delete-membership.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -9,5 +10,5 @@ val teams = Teams(client) val response = teams.deleteMembership( teamId = "[TEAM_ID]", - membershipId = "[MEMBERSHIP_ID]" -) + membershipId = "[MEMBERSHIP_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/delete.md b/docs/examples/kotlin/teams/delete.md index 7d58960..756e91f 100644 --- a/docs/examples/kotlin/teams/delete.md +++ b/docs/examples/kotlin/teams/delete.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -8,5 +9,5 @@ val client = Client(context) val teams = Teams(client) val response = teams.delete( - teamId = "[TEAM_ID]" -) + teamId = "[TEAM_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/get-membership.md b/docs/examples/kotlin/teams/get-membership.md index 653bd52..7c5d286 100644 --- a/docs/examples/kotlin/teams/get-membership.md +++ b/docs/examples/kotlin/teams/get-membership.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -9,5 +10,5 @@ val teams = Teams(client) val response = teams.getMembership( teamId = "[TEAM_ID]", - membershipId = "[MEMBERSHIP_ID]" -) + membershipId = "[MEMBERSHIP_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/get-prefs.md b/docs/examples/kotlin/teams/get-prefs.md index bfd8f75..2953dcf 100644 --- a/docs/examples/kotlin/teams/get-prefs.md +++ b/docs/examples/kotlin/teams/get-prefs.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -8,5 +9,5 @@ val client = Client(context) val teams = Teams(client) val response = teams.getPrefs( - teamId = "[TEAM_ID]" -) + teamId = "[TEAM_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/get.md b/docs/examples/kotlin/teams/get.md index 72aea07..63cdd05 100644 --- a/docs/examples/kotlin/teams/get.md +++ b/docs/examples/kotlin/teams/get.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -8,5 +9,5 @@ val client = Client(context) val teams = Teams(client) val response = teams.get( - teamId = "[TEAM_ID]" -) + teamId = "[TEAM_ID]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/list-memberships.md b/docs/examples/kotlin/teams/list-memberships.md index 53bd6f3..c82fa52 100644 --- a/docs/examples/kotlin/teams/list-memberships.md +++ b/docs/examples/kotlin/teams/list-memberships.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -9,4 +10,4 @@ val teams = Teams(client) val response = teams.listMemberships( teamId = "[TEAM_ID]", -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/list.md b/docs/examples/kotlin/teams/list.md index 57c5fe8..f0f4af2 100644 --- a/docs/examples/kotlin/teams/list.md +++ b/docs/examples/kotlin/teams/list.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -8,4 +9,4 @@ val client = Client(context) val teams = Teams(client) val response = teams.list( -) +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/update-membership-status.md b/docs/examples/kotlin/teams/update-membership-status.md index 33de006..50f04a2 100644 --- a/docs/examples/kotlin/teams/update-membership-status.md +++ b/docs/examples/kotlin/teams/update-membership-status.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -11,5 +12,5 @@ val response = teams.updateMembershipStatus( teamId = "[TEAM_ID]", membershipId = "[MEMBERSHIP_ID]", userId = "[USER_ID]", - secret = "[SECRET]" -) + secret = "[SECRET]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/update-membership.md b/docs/examples/kotlin/teams/update-membership.md index 40005ed..9990cc4 100644 --- a/docs/examples/kotlin/teams/update-membership.md +++ b/docs/examples/kotlin/teams/update-membership.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -10,5 +11,5 @@ val teams = Teams(client) val response = teams.updateMembership( teamId = "[TEAM_ID]", membershipId = "[MEMBERSHIP_ID]", - roles = listOf() -) + roles = listOf(), +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/update-name.md b/docs/examples/kotlin/teams/update-name.md index 59c6812..1332fe1 100644 --- a/docs/examples/kotlin/teams/update-name.md +++ b/docs/examples/kotlin/teams/update-name.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -9,5 +10,5 @@ val teams = Teams(client) val response = teams.updateName( teamId = "[TEAM_ID]", - name = "[NAME]" -) + name = "[NAME]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/teams/update-prefs.md b/docs/examples/kotlin/teams/update-prefs.md index 6a89ac7..5f77c6c 100644 --- a/docs/examples/kotlin/teams/update-prefs.md +++ b/docs/examples/kotlin/teams/update-prefs.md @@ -1,4 +1,5 @@ import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback import io.appwrite.services.Teams val client = Client(context) @@ -9,5 +10,5 @@ val teams = Teams(client) val response = teams.updatePrefs( teamId = "[TEAM_ID]", - prefs = mapOf( "a" to "b" ) -) + prefs = mapOf( "a" to "b" ), +) \ No newline at end of file diff --git a/docs/examples/kotlin/users/delete-authenticator.md b/docs/examples/kotlin/users/delete-authenticator.md new file mode 100644 index 0000000..9c36173 --- /dev/null +++ b/docs/examples/kotlin/users/delete-authenticator.md @@ -0,0 +1,16 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Users +import io.appwrite.enums.AuthenticatorProvider + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val users = Users(client) + +val response = users.deleteAuthenticator( + userId = "[USER_ID]", + provider = AuthenticatorProvider.TOTP, + otp = "[OTP]", +) \ No newline at end of file diff --git a/docs/examples/kotlin/users/list-providers.md b/docs/examples/kotlin/users/list-providers.md new file mode 100644 index 0000000..008cf93 --- /dev/null +++ b/docs/examples/kotlin/users/list-providers.md @@ -0,0 +1,13 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Users + +val client = Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val users = Users(client) + +val response = users.listProviders( + userId = "[USER_ID]", +) \ No newline at end of file diff --git a/example-java/.gitignore b/example-java/.gitignore deleted file mode 100644 index 42afabf..0000000 --- a/example-java/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/example-java/build.gradle b/example-java/build.gradle deleted file mode 100644 index 774d3ba..0000000 --- a/example-java/build.gradle +++ /dev/null @@ -1,39 +0,0 @@ -plugins { - id 'com.android.application' -} - -android { - compileSdkVersion 33 - - defaultConfig { - applicationId "io.appwrite.example_java" - minSdkVersion 23 - targetSdkVersion 33 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - implementation project(path: ':library') - - implementation 'androidx.appcompat:appcompat:1.6.0' - implementation 'com.google.android.material:material:1.8.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.5' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' -} \ No newline at end of file diff --git a/example-java/src/main/AndroidManifest.xml b/example-java/src/main/AndroidManifest.xml deleted file mode 100644 index 0276c9c..0000000 --- a/example-java/src/main/AndroidManifest.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file 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 deleted file mode 100644 index 04f46b3..0000000 --- a/example-java/src/main/java/io/appwrite/example_java/MainActivity.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.appwrite.example_java; - -import android.os.Bundle; -import android.util.Log; - -import androidx.appcompat.app.AppCompatActivity; - -import io.appwrite.Client; -import io.appwrite.coroutines.CoroutineCallback; -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://demo.appwrite.io/v1") - .setProject("6070749e6acd4"); - - Account account = new Account(client); - - account.createEmailSession("test7@test.com", "password", new CoroutineCallback<>((session, error) -> { - if (error != null) { - Log.e("Appwrite", error.getMessage()); - return; - } - - Log.d("Appwrite", session.toMap().toString()); - })); - } -} \ No newline at end of file diff --git a/example-java/src/main/res/drawable/ic_launcher_background.xml b/example-java/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index 07d5da9..0000000 --- a/example-java/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/example-java/src/main/res/drawable/ic_launcher_foreground.xml b/example-java/src/main/res/drawable/ic_launcher_foreground.xml deleted file mode 100644 index 2b068d1..0000000 --- a/example-java/src/main/res/drawable/ic_launcher_foreground.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/example-java/src/main/res/layout/activity_main.xml b/example-java/src/main/res/layout/activity_main.xml deleted file mode 100644 index 4fc2444..0000000 --- a/example-java/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/example-java/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/example-java/src/main/res/mipmap-anydpi-v26/ic_launcher.xml deleted file mode 100644 index eca70cf..0000000 --- a/example-java/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/example-java/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/example-java/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml deleted file mode 100644 index eca70cf..0000000 --- a/example-java/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/example-java/src/main/res/values/colors.xml b/example-java/src/main/res/values/colors.xml deleted file mode 100644 index f8c6127..0000000 --- a/example-java/src/main/res/values/colors.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - #FFBB86FC - #FF6200EE - #FF3700B3 - #FF03DAC5 - #FF018786 - #FF000000 - #FFFFFFFF - \ No newline at end of file diff --git a/example-java/src/main/res/values/strings.xml b/example-java/src/main/res/values/strings.xml deleted file mode 100644 index 71e50b3..0000000 --- a/example-java/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - Example Java - \ No newline at end of file diff --git a/example-java/src/main/res/values/themes.xml b/example-java/src/main/res/values/themes.xml deleted file mode 100644 index dde245d..0000000 --- a/example-java/src/main/res/values/themes.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - \ No newline at end of file diff --git a/example/build.gradle b/example/build.gradle index 62a34ed..e57d59b 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -1,15 +1,18 @@ plugins { id 'com.android.application' id 'kotlin-android' + id 'kotlin-kapt' } android { - compileSdkVersion 33 + namespace "io.appwrite.android" + + compileSdkVersion 34 defaultConfig { applicationId "io.appwrite.android" minSdkVersion 21 - targetSdkVersion 33 + targetSdkVersion 34 versionCode 1 versionName "1.0" @@ -39,19 +42,19 @@ dependencies { implementation project(path: ':library') implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.core:core-ktx:1.9.0' - implementation 'androidx.appcompat:appcompat:1.6.0' - implementation 'com.google.android.material:material:1.8.0' + implementation 'androidx.core:core-ktx:1.12.0' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.11.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3' - implementation "androidx.fragment:fragment-ktx:1.5.5" - implementation 'androidx.navigation:navigation-ui-ktx:2.5.3' - implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1' - implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1' - implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3' - implementation 'androidx.navigation:navigation-ui-ktx:2.5.3' - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1" + implementation 'androidx.navigation:navigation-fragment-ktx:2.7.6' + implementation "androidx.fragment:fragment-ktx:1.6.2" + implementation 'androidx.navigation:navigation-ui-ktx:2.7.6' + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.7.0' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0' + implementation 'androidx.navigation:navigation-fragment-ktx:2.7.6' + implementation 'androidx.navigation:navigation-ui-ktx:2.7.6' + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1" testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml index e3c2421..5c2e7b0 100644 --- a/example/src/main/AndroidManifest.xml +++ b/example/src/main/AndroidManifest.xml @@ -3,12 +3,14 @@ package="io.appwrite.android"> + android:theme="@style/Theme.AppwriteAndroidSDK" + android:usesCleartextTraffic="true"> + @@ -24,6 +26,13 @@ + + + + + + + \ No newline at end of file diff --git a/example/src/main/java/io/appwrite/android/ui/accounts/AccountsFragment.kt b/example/src/main/java/io/appwrite/android/ui/accounts/AccountsFragment.kt index a31cced..7e590d5 100644 --- a/example/src/main/java/io/appwrite/android/ui/accounts/AccountsFragment.kt +++ b/example/src/main/java/io/appwrite/android/ui/accounts/AccountsFragment.kt @@ -34,34 +34,30 @@ class AccountsFragment : Fragment() { binding.login.setOnClickListener{ viewModel.onLogin(binding.email.text, binding.password.text) } - binding.signup.setOnClickListener{ viewModel.onSignup(binding.email.text, binding.password.text, binding.name.text) } - binding.getUser.setOnClickListener{ viewModel.getUser() } - binding.oAuth.setOnClickListener{ viewModel.oAuthLogin(activity as ComponentActivity) } - binding.logout.setOnClickListener{ viewModel.logout() } - viewModel.error.observe(viewLifecycleOwner, Observer { event -> - event?.getContentIfNotHandled()?.let { // Only proceed if the event has never been handled - Toast.makeText(requireContext(), it.message , Toast.LENGTH_SHORT).show() + viewModel.error.observe(viewLifecycleOwner) { event -> + event?.getContentIfNotHandled()?.let { + Toast.makeText(requireContext(), it.message, Toast.LENGTH_SHORT).show() } - }) + } - viewModel.response.observe(viewLifecycleOwner, Observer { event -> + viewModel.response.observe(viewLifecycleOwner) { event -> event?.getContentIfNotHandled()?.let { binding.responseTV.setText(it) } - }) + } return binding.root } 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 ede86d3..0e558f1 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 @@ -3,8 +3,10 @@ package io.appwrite.android.ui.accounts import android.text.Editable import androidx.activity.ComponentActivity import androidx.lifecycle.* +import io.appwrite.ID import io.appwrite.android.utils.Client.client import io.appwrite.android.utils.Event +import io.appwrite.enums.OAuthProvider import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.toJson import io.appwrite.services.Account @@ -29,7 +31,10 @@ class AccountsViewModel : ViewModel() { fun onLogin(email: Editable, password: Editable) { viewModelScope.launch { try { - val session = accountService.createEmailSession(email.toString(), password.toString()) + val session = accountService.createEmailPasswordSession( + email.toString(), + password.toString() + ) _response.postValue(Event(session.toJson())) } catch (e: AppwriteException) { _error.postValue(Event(e)) @@ -41,8 +46,12 @@ class AccountsViewModel : ViewModel() { fun onSignup(email: Editable, password: Editable, name: Editable) { viewModelScope.launch { try { - val user = - accountService.create(email.toString(), password.toString(), name.toString()) + val user = accountService.create( + ID.unique(), + email.toString(), + password.toString(), + name.toString() + ) _response.postValue(Event(user.toJson())) } catch (e: AppwriteException) { _error.postValue(Event(e)) @@ -56,7 +65,7 @@ class AccountsViewModel : ViewModel() { try { accountService.createOAuth2Session( activity, - "facebook", + OAuthProvider.FACEBOOK, "appwrite-callback-6070749e6acd4://demo.appwrite.io/auth/oauth2/success", "appwrite-callback-6070749e6acd4://demo.appwrite.io/auth/oauth2/failure" ) diff --git a/example/src/main/java/io/appwrite/android/utils/Client.kt b/example/src/main/java/io/appwrite/android/utils/Client.kt index 66ce681..027b718 100644 --- a/example/src/main/java/io/appwrite/android/utils/Client.kt +++ b/example/src/main/java/io/appwrite/android/utils/Client.kt @@ -8,13 +8,8 @@ object Client { fun create(context: Context) { client = Client(context) - .setEndpoint("https://demo.appwrite.io/v1") - .setProject("6070749e6acd4") - - /* Useful when testing locally */ -// client = Client(context) -// .setEndpoint("https://192.168.1.35/v1") -// .setProject("60bdbc911784e") -// .setSelfSigned(true) + .setEndpoint("http://192.168.4.24/v1") + .setProject("65a8e2b4632c04b1f5da") + .setSelfSigned(true) } } \ No newline at end of file diff --git a/example/src/main/res/layout/fragment_account.xml b/example/src/main/res/layout/fragment_account.xml index 2fb34c9..4173be1 100644 --- a/example/src/main/res/layout/fragment_account.xml +++ b/example/src/main/res/layout/fragment_account.xml @@ -57,6 +57,7 @@ android:layout_height="wrap_content" android:layout_marginTop="16dp" android:hint="name" + android:text="Tester" android:inputType="text" app:layout_constraintStart_toStartOf="@id/password" app:layout_constraintTop_toBottomOf="@id/password" /> diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 85e684f..ebd754f 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.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/library/build.gradle b/library/build.gradle index baa5b1e..b361708 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -22,11 +22,17 @@ ext { version PUBLISH_VERSION android { - compileSdkVersion(33) + namespace PUBLISH_GROUP_ID + + compileSdkVersion(34) + + buildFeatures { + buildConfig true + } defaultConfig { minSdkVersion(21) - targetSdkVersion(33) + targetSdkVersion(34) versionCode = 1 versionName = "1.0" buildConfigField "String", "SDK_VERSION", "\"${PUBLISH_VERSION}\"" @@ -43,10 +49,6 @@ android { ) } } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } kotlinOptions { jvmTarget = "1.8" } @@ -54,27 +56,31 @@ android { dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version") - api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1") - api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1") + api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1") + api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1") - api(platform("com.squareup.okhttp3:okhttp-bom:4.10.0")) + api(platform("com.squareup.okhttp3:okhttp-bom:4.12.0")) api("com.squareup.okhttp3:okhttp") implementation("com.squareup.okhttp3:okhttp-urlconnection") implementation("com.squareup.okhttp3:logging-interceptor") - implementation("com.google.code.gson:gson:2.9.0") + implementation("com.google.code.gson:gson:2.10.1") - implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.5.1") - implementation("androidx.lifecycle:lifecycle-common-java8:2.5.1") - implementation("androidx.appcompat:appcompat:1.6.0") - implementation("androidx.fragment:fragment-ktx:1.5.5") - implementation("androidx.activity:activity-ktx:1.6.1") - implementation("androidx.browser:browser:1.4.0") + api(platform("com.google.firebase:firebase-bom:32.7.0")) + api("com.google.firebase:firebase-messaging") - testImplementation 'junit:junit:4.13.2' - testImplementation "androidx.test.ext:junit-ktx:1.1.5" - testImplementation "androidx.test:core-ktx:1.5.0" - testImplementation "org.robolectric:robolectric:4.5.1" - testApi("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.1") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0") + implementation("androidx.lifecycle:lifecycle-common-java8:2.7.0") + implementation("androidx.appcompat:appcompat:1.6.1") + implementation("androidx.fragment:fragment-ktx:1.6.2") + implementation("androidx.activity:activity-ktx:1.8.2") + implementation("androidx.browser:browser:1.7.0") + implementation("androidx.core:core-ktx:1.12.0") + + testImplementation("junit:junit:4.13.2") + testImplementation("androidx.test.ext:junit-ktx:1.1.5") + testImplementation("androidx.test:core-ktx:1.5.0") + testImplementation("org.robolectric:robolectric:4.5.1") + testApi("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1") } apply from: "${rootProject.projectDir}/scripts/publish-module.gradle" \ No newline at end of file diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index b0ab63a..899321d 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,8 +1,7 @@ - + - + + \ 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 94f82b6..eeda5ce 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -1,13 +1,13 @@ package io.appwrite import android.content.Context +import android.content.Intent 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.ListenableCookieJar import io.appwrite.cookies.stores.SharedPreferencesCookieStore import io.appwrite.exceptions.AppwriteException -import io.appwrite.extensions.fromJson import io.appwrite.json.PreciseNumberAdapter import io.appwrite.models.InputFile import io.appwrite.models.UploadProgress @@ -30,7 +30,6 @@ import java.net.CookieManager import java.net.CookiePolicy import java.security.SecureRandom import java.security.cert.X509Certificate -import javax.net.ssl.HostnameVerifier import javax.net.ssl.SSLContext import javax.net.ssl.SSLSocketFactory import javax.net.ssl.TrustManager @@ -40,13 +39,15 @@ import kotlin.coroutines.resume class Client @JvmOverloads constructor( context: Context, - var endPoint: String = "https://HOSTNAME/v1", - var endPointRealtime: String? = null, + var endpoint: String = "https://HOSTNAME/v1", + var endpointRealtime: String? = null, private var selfSigned: Boolean = false ) : CoroutineScope { companion object { - const val CHUNK_SIZE = 5*1024*1024; // 5MB + internal const val CHUNK_SIZE = 5*1024*1024; // 5MB + internal const val GLOBAL_PREFS = "io.appwrite" + internal const val COOKIE_PREFS = "myCookie" } override val coroutineContext: CoroutineContext @@ -59,16 +60,16 @@ class Client @JvmOverloads constructor( PreciseNumberAdapter() ).create() - lateinit var http: OkHttpClient + internal lateinit var http: OkHttpClient - private val headers: MutableMap + internal val headers: MutableMap val config: MutableMap - private val cookieJar = CookieManager( - SharedPreferencesCookieStore(context, "myCookie"), + internal val cookieJar = ListenableCookieJar(CookieManager( + SharedPreferencesCookieStore(context.getSharedPreferences(COOKIE_PREFS, Context.MODE_PRIVATE)), CookiePolicy.ACCEPT_ALL - ) + )) private val appVersion by lazy { try { @@ -88,12 +89,18 @@ class Client @JvmOverloads constructor( "x-sdk-name" to "Android", "x-sdk-platform" to "client", "x-sdk-language" to "android", - "x-sdk-version" to "4.0.1", + "x-sdk-version" to "5.0.0-rc.1", "x-appwrite-response-format" to "1.4.0" ) config = mutableMapOf() setSelfSigned(selfSigned) + + NotificationHandler.client = this + + context.startService(Intent(context, NotificationHandler::class.java).apply { + action = NotificationHandler.ACTION_CLIENT_INIT + }) } /** @@ -139,6 +146,21 @@ class Client @JvmOverloads constructor( return this } + /** + * Set Session + * + * The user session to authenticate with + * + * @param {string} session + * + * @return this + */ + fun setSession(value: String): Client { + config["session"] = value + addHeader("x-appwrite-session", value) + return this + } + /** * Set self Signed * @@ -151,7 +173,7 @@ class Client @JvmOverloads constructor( val builder = OkHttpClient() .newBuilder() - .cookieJar(JavaNetCookieJar(cookieJar)) + .cookieJar(cookieJar) if (!selfSigned) { http = builder.build() @@ -181,7 +203,7 @@ class Client @JvmOverloads constructor( // Create an ssl socket factory with our all-trusting manager val sslSocketFactory: SSLSocketFactory = sslContext.socketFactory builder.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager) - builder.hostnameVerifier(HostnameVerifier { _, _ -> true }) + builder.hostnameVerifier { _, _ -> true } http = builder.build() } catch (e: Exception) { @@ -198,11 +220,11 @@ class Client @JvmOverloads constructor( * * @return this */ - fun setEndpoint(endPoint: String): Client { - this.endPoint = endPoint + fun setEndpoint(endpoint: String): Client { + this.endpoint = endpoint - if (this.endPointRealtime == null && endPoint.startsWith("http")) { - this.endPointRealtime = endPoint.replaceFirst("http", "ws") + if (this.endpointRealtime == null && endpoint.startsWith("http")) { + this.endpointRealtime = endpoint.replaceFirst("http", "ws") } return this @@ -215,8 +237,20 @@ class Client @JvmOverloads constructor( * * @return this */ - fun setEndpointRealtime(endPoint: String): Client { - this.endPointRealtime = endPoint + fun setEndpointRealtime(endpoint: String): Client { + this.endpointRealtime = endpoint + return this + } + + /** + * Set push provider ID + * + * @param endpoint + * + * @return this + */ + fun setPushProviderId(providerId: String): Client { + NotificationHandler.providerId = providerId return this } @@ -258,7 +292,7 @@ class Client @JvmOverloads constructor( .addAll(headers.toHeaders()) .build() - val httpBuilder = (endPoint + path).toHttpUrl().newBuilder() + val httpBuilder = (endpoint + path).toHttpUrl().newBuilder() if ("GET" == method) { filteredParams.forEach { @@ -436,14 +470,14 @@ class Client @JvmOverloads constructor( ) offset += CHUNK_SIZE - headers["x-appwrite-id"] = result!!["\$id"].toString() + headers["x-appwrite-id"] = result["\$id"].toString() onProgress?.invoke( UploadProgress( - id = result!!["\$id"].toString(), + 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(), + chunksTotal = result["chunksTotal"].toString().toInt(), + chunksUploaded = result["chunksUploaded"].toString().toInt(), ) ) } diff --git a/library/src/main/java/io/appwrite/NotificationHandler.kt b/library/src/main/java/io/appwrite/NotificationHandler.kt new file mode 100644 index 0000000..db007b8 --- /dev/null +++ b/library/src/main/java/io/appwrite/NotificationHandler.kt @@ -0,0 +1,410 @@ +package io.appwrite + +import android.Manifest +import android.app.NotificationChannel +import android.app.NotificationManager +import android.app.PendingIntent +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import android.content.pm.PackageManager +import android.os.Build +import android.util.Log +import androidx.annotation.RequiresApi +import androidx.core.app.NotificationCompat +import com.google.android.gms.tasks.OnCompleteListener +import com.google.firebase.messaging.FirebaseMessaging +import com.google.firebase.messaging.FirebaseMessagingService +import com.google.firebase.messaging.RemoteMessage +import io.appwrite.cookies.CookieListener +import io.appwrite.exceptions.AppwriteException +import io.appwrite.extensions.fromJson +import io.appwrite.extensions.onNotificationReceived +import io.appwrite.extensions.toJson +import io.appwrite.models.Notification +import io.appwrite.models.Target +import io.appwrite.models.User +import io.appwrite.services.Account +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.suspendCancellableCoroutine +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock +import okhttp3.Cookie +import okhttp3.Headers +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody +import okhttp3.internal.cookieToString +import java.io.IOException +import kotlin.properties.Delegates + +class NotificationHandler : FirebaseMessagingService() { + + companion object { + internal const val ACTION_CLIENT_INIT = "io.appwrite.ACTION_CLIENT_INIT" + internal const val LISTENER_KEY = "io.appwrite.NotificationHandler" + + internal val httpClient = OkHttpClient() + + internal var client: Client? = null + internal var account: Account? = null + internal var providerId: String? = null + + internal var cookieListener: CookieListener? = null + + /** + * Should notifications be automatically displayed if the app is in the foreground + */ + var displayForeground = true + + /** + * The icon to display in the notification + */ + var displayIcon by Delegates.notNull() + + /** + * Should the notification be automatically canceled when the user clicks on it + */ + var autoCancel = false + + /** + * The intent to fire when the user clicks on the notification + */ + var contentIntent: PendingIntent? = null + + /** + * The channel id to use for the notification + */ + @RequiresApi(Build.VERSION_CODES.N) + var channelId = "io.appwrite.notifications" + + /** + * The channel name to use for the notification + */ + @RequiresApi(Build.VERSION_CODES.N) + var channelName = "All Notifications" + + /** + * The channel description to use for the notification + */ + @RequiresApi(Build.VERSION_CODES.N) + var channelDescription = "All notifications" + + /** + * The channel importance to use for the notification + */ + @RequiresApi(Build.VERSION_CODES.N) + var channelImportance = NotificationManager.IMPORTANCE_DEFAULT + } + + private lateinit var mutex: Mutex + + private lateinit var globalPrefs: SharedPreferences + + private var existingCookies: List = listOf() + private var newCookies: List = listOf() + + override fun getStartCommandIntent(originalIntent: Intent?): Intent { + if (originalIntent?.action == ACTION_CLIENT_INIT) { + return originalIntent + } + + return super.getStartCommandIntent(originalIntent) + } + + override fun handleIntent(intent: Intent?) { + if (intent?.action == ACTION_CLIENT_INIT) { + onClientInit() + return + } + + super.handleIntent(intent) + } + + override fun onCreate() { + super.onCreate() + + globalPrefs = applicationContext.getSharedPreferences( + Client.GLOBAL_PREFS, Context.MODE_PRIVATE + ) + + displayIcon = resources.getIdentifier( + "ic_launcher_foreground", "drawable", packageName + ) + + mutex = Mutex() + + if (cookieListener == null) { + cookieListener = { existing, new -> + FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task -> + if (!task.isSuccessful) { + Log.w(javaClass.name, "Fetching FCM registration token failed", task.exception) + return@OnCompleteListener + } + + val token = task.result + if (token.isNullOrEmpty()) { + return@OnCompleteListener + } + + existingCookies = existing + newCookies = new + + onNewToken(token) + }) + } + } + + if (client != null) { + client?.cookieJar?.onSave(LISTENER_KEY, cookieListener!!) + } + } + + override fun onNewToken(token: String) { + runBlocking { + mutex.withLock { + pushToken(token) + } + } + } + + override fun onMessageReceived(message: RemoteMessage) { + super.onMessageReceived(message) + + // Fire callbacks before display so handler can be configured if needed + onNotificationReceived( + Notification( + title = message.notification?.title ?: "", + body = message.notification?.body ?: "", + clickAction = message.notification?.clickAction ?: "", + color = message.notification?.color ?: "", + icon = message.notification?.icon ?: "", + imageURL = message.notification?.imageUrl?.toString() ?: "", + sound = message.notification?.sound ?: "", + data = message.data + ) + ) + + val notificationManager = + getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val channel = NotificationChannel( + channelId, channelName, channelImportance + ).apply { + description = channelDescription + } + + // Recreate is a no-op if the channel already exists + notificationManager.createNotificationChannel(channel) + } + + if (message.notification != null && displayForeground) { + val builder = NotificationCompat.Builder(this, "io.appwrite.notifications") + .setContentTitle(message.notification?.title) + .setContentText(message.notification?.body) + .setPriority(NotificationCompat.PRIORITY_DEFAULT).setAutoCancel(autoCancel) + .setContentIntent(contentIntent) + + if (displayIcon != 0) { + builder.setSmallIcon(displayIcon) + } + + val notification = builder.build() + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + val hasPermission = packageManager.checkPermission( + Manifest.permission.POST_NOTIFICATIONS, + packageName + ) == PackageManager.PERMISSION_GRANTED + + if (!hasPermission) { + Log.w(javaClass.name, "Permission denied, make sure you have requested the POST_NOTIFICATIONS permission") + } + } + + notificationManager.notify(message.hashCode(), notification) + } + } + + private fun onClientInit() { + if (client == null) { + return + } + + if (account == null) { + account = Account(client!!) + } + + client?.cookieJar?.onSave(LISTENER_KEY, cookieListener!!) + } + + private suspend fun pushToken(token: String) { + if (client == null) { + return + } + + val currentToken = globalPrefs.getString("fcmToken", "") ?: "" + var currentTargetId = globalPrefs.getString("targetId", "") ?: "" + val existingUser: User>? + try { + existingUser = if (existingCookies.isEmpty() && newCookies.isNotEmpty()) { + request( + "GET", + "/account", + mapOf("cookie" to newCookies.joinToString("; ") { + cookieToString(it, true) + }) + ) + } else if (existingCookies.isNotEmpty()) { + request( + "GET", + "/account", + mapOf("cookie" to existingCookies.joinToString("; ") { + cookieToString(it, true) + }) + ) + } else { + account?.get() + } + } catch (ex: AppwriteException) { + Log.d(javaClass.name, "No existing user") + return + } + + if (existingUser == null) { + Log.d(javaClass.name, "No existing user") + return + } + + var newUser: User>? = null + if (newCookies.isNotEmpty()) { + newUser = request( + "GET", + "/account", + mapOf("cookie" to newCookies.joinToString("; ") { + cookieToString(it, true) + }) + ) + Log.d(javaClass.name, "New user: ${newUser!!.id}") + } + + if ( + token == currentToken + && (existingCookies.isNotEmpty() && existingUser.id == newUser?.id) + ) { + Log.d(javaClass.name, "Token and user are the same") + return + } + + globalPrefs.edit().putString("fcmToken", token).apply() + + try { + if (existingCookies.isNotEmpty() && existingUser.id != newUser?.id) { + Log.d(javaClass.name, "User has changed") + if (currentTargetId.isNotEmpty()) { + Log.d(javaClass.name, "Deleting existing target") + request( + "DELETE", + "/account/targets/$currentTargetId/push", + mapOf("cookie" to existingCookies.joinToString("; ") { + cookieToString(it, true) + }) + ) + globalPrefs.edit().remove("targetId").apply() + currentTargetId = "" + } + } + } catch (ex: AppwriteException) { + Log.e(javaClass.name, "Failed to delete existing target", ex) + } + + try { + val target: Target? + + if ((currentTargetId.isEmpty() && existingCookies.isEmpty()) || existingUser.id != newUser?.id) { + Log.d(javaClass.name, "Creating new target") + val params = mutableMapOf( + "targetId" to ID.unique(), + "identifier" to token + ) + if (providerId != null) { + params["providerId"] = providerId!! + } + target = request( + "POST", + "/account/targets/push", + mapOf("cookie" to newCookies.joinToString("; ") { + cookieToString(it, true) + }), + params.toJson().toRequestBody("application/json".toMediaType()) + ) + Log.d(javaClass.name, "New target: ${target?.id}") + } else { + Log.d(javaClass.name, "Updating existing target") + target = account?.updatePushTarget(currentTargetId, token) + Log.d(javaClass.name, "Updated target: ${target?.id}") + } + + globalPrefs.edit().putString("targetId", target?.id).apply() + } catch (ex: AppwriteException) { + Log.e(javaClass.name, "Failed to push token", ex) + } + + existingCookies = emptyList() + newCookies = emptyList() + Log.d(javaClass.name, "Token pushed") + } + + private suspend inline fun request( + method: String, + path: String, + headers: Map, + body: RequestBody? = null + ): T? { + val headerBuilder = Headers.Builder() + + for ((key, value) in client?.headers ?: mapOf()) { + headerBuilder.add(key, value) + } + + for ((key, value) in headers) { + headerBuilder.add(key, value) + } + + val request = Request.Builder() + .method(method, body) + .url(client?.endpoint + path) + .headers(headerBuilder.build()) + .build() + + try { + return suspendCancellableCoroutine { + httpClient + .newCall(request) + .enqueue(object : okhttp3.Callback { + override fun onFailure(call: okhttp3.Call, e: IOException) { + Log.e(javaClass.name, "Request failed", e) + it.resumeWith(Result.failure(e)) + } + override fun onResponse( + call: okhttp3.Call, + response: okhttp3.Response + ) { + if (response.isSuccessful) { + val bodyString = response.body?.string() + + it.resumeWith(Result.success(bodyString?.fromJson())) + } else { + it.resumeWith(Result.failure(IOException("Request failed with code ${response.code}"))) + } + } + }) + } + } catch (ex: IOException) { + return null + } + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/Query.kt b/library/src/main/java/io/appwrite/Query.kt index 7957865..6efbb11 100644 --- a/library/src/main/java/io/appwrite/Query.kt +++ b/library/src/main/java/io/appwrite/Query.kt @@ -1,60 +1,65 @@ package io.appwrite -class Query { - companion object { - fun equal(attribute: String, value: Any) = addQuery(attribute, "equal", value) +import io.appwrite.extensions.toJson +import io.appwrite.extensions.fromJson - fun notEqual(attribute: String, value: Any) = Query.addQuery(attribute, "notEqual", value) +class Query( + val method: String, + val attribute: String? = null, + val values: List? = null, +) { + override fun toString() = this.toJson() - fun lessThan(attribute: String, value: Any) = Query.addQuery(attribute, "lessThan", value) + companion object { + fun equal(attribute: String, value: Any) = Query("equal", attribute, parseValue(value)).toJson() - fun lessThanEqual(attribute: String, value: Any) = Query.addQuery(attribute, "lessThanEqual", value) + fun notEqual(attribute: String, value: Any) = Query("notEqual", attribute, parseValue(value)).toJson() - fun greaterThan(attribute: String, value: Any) = Query.addQuery(attribute, "greaterThan", value) + fun lessThan(attribute: String, value: Any) = Query("lessThan", attribute, parseValue(value)).toJson() - fun greaterThanEqual(attribute: String, value: Any) = Query.addQuery(attribute, "greaterThanEqual", value) - - fun search(attribute: String, value: String) = Query.addQuery(attribute, "search", value) + fun lessThanEqual(attribute: String, value: Any) = Query("lessThanEqual", attribute, parseValue(value)).toJson() - fun isNull(attribute: String) = "isNull(\"${attribute}\")" + fun greaterThan(attribute: String, value: Any) = Query("greaterThan", attribute, parseValue(value)).toJson() - fun isNotNull(attribute: String) = "isNotNull(\"${attribute}\")" + fun greaterThanEqual(attribute: String, value: Any) = Query("greaterThanEqual", attribute, parseValue(value)).toJson() - fun between(attribute: String, start: Int, end: Int) = "between(\"${attribute}\", ${start}, ${end})" + fun search(attribute: String, value: String) = Query("search", attribute, listOf(value)).toJson() - fun between(attribute: String, start: Double, end: Double) = "between(\"${attribute}\", ${start}, ${end})" + fun isNull(attribute: String) = Query("isNull", attribute).toJson() - fun between(attribute: String, start: String, end: String) = "between(\"${attribute}\", \"${start}\", \"${end}\")" + fun isNotNull(attribute: String) = Query("isNotNull", attribute).toJson() - fun startsWith(attribute: String, value: String) = Query.addQuery(attribute, "startsWith", value) + fun between(attribute: String, start: Any, end: Any) = Query("between", attribute, listOf(start, end)).toJson() - fun endsWith(attribute: String, value: String) = Query.addQuery(attribute, "endsWith", value) + fun startsWith(attribute: String, value: String) = Query("startsWith", attribute, listOf(value)).toJson() - fun select(attributes: List) = "select([${attributes.joinToString(",") { "\"$it\"" }}])" + fun endsWith(attribute: String, value: String) = Query("endsWith", attribute, listOf(value)).toJson() - fun orderAsc(attribute: String) = "orderAsc(\"${attribute}\")" + fun select(attributes: List) = Query("select", null, attributes).toJson() - fun orderDesc(attribute: String) = "orderDesc(\"${attribute}\")" + fun orderAsc(attribute: String) = Query("orderAsc", attribute).toJson() - fun cursorBefore(documentId: String) = "cursorBefore(\"${documentId}\")" + fun orderDesc(attribute: String) = Query("orderDesc", attribute).toJson() - fun cursorAfter(documentId: String) = "cursorAfter(\"${documentId}\")" + fun cursorBefore(documentId: String) = Query("cursorBefore", null, listOf(documentId)).toJson() - fun limit(limit: Int) = "limit(${limit})" + fun cursorAfter(documentId: String) = Query("cursorAfter", null, listOf(documentId)).toJson() - fun offset(offset: Int) = "offset(${offset})" + fun limit(limit: Int) = Query("limit", null, listOf(limit)).toJson() - private fun addQuery(attribute: String, method: String, value: Any): String { - return when (value) { - is List<*> -> "${method}(\"${attribute}\", [${value.map{it -> parseValues(it!!)}.joinToString(",")}])" - else -> "${method}(\"${attribute}\", [${Query.parseValues(value)}])" - } + fun offset(offset: Int) = Query("offset", null, listOf(offset)).toJson() + + fun contains(attribute: String, value: Any) = Query("contains", attribute, parseValue(value)).toJson() + + fun or(queries: List) = Query("or", null, queries.map { it.fromJson() }).toJson() + + fun and(queries: List) = Query("and", null, queries.map { it.fromJson() }).toJson() + + private fun parseValue(value: Any): List { + return when (value) { + is List<*> -> value as List + else -> listOf(value) + } + } } - private fun parseValues(value: Any): String { - return when (value) { - is String -> "\"${value}\"" - else -> "${value}" - } - } - } -} +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/cookies/ListenableCookieJar.kt b/library/src/main/java/io/appwrite/cookies/ListenableCookieJar.kt new file mode 100644 index 0000000..863eb42 --- /dev/null +++ b/library/src/main/java/io/appwrite/cookies/ListenableCookieJar.kt @@ -0,0 +1,119 @@ +package io.appwrite.cookies + +import okhttp3.Cookie +import okhttp3.CookieJar +import okhttp3.HttpUrl +import okhttp3.internal.cookieToString +import okhttp3.internal.delimiterOffset +import okhttp3.internal.platform.Platform +import okhttp3.internal.trimSubstring +import java.io.IOException +import java.net.CookieHandler +import java.net.HttpCookie +import java.util.Collections + +typealias CookieListener = (existing: List, new: List) -> Unit + +class ListenableCookieJar(private val cookieHandler: CookieHandler) : CookieJar { + + private val listeners: MutableMap = mutableMapOf() + + fun onSave(key: String, listener: CookieListener) { + listeners[key.hashCode()] = listener + } + + override fun saveFromResponse(url: HttpUrl, cookies: List) { + val existingCookies = loadForRequest(url) + + listeners.values.forEach { it(existingCookies, cookies) } + + val cookieStrings = mutableListOf() + for (cookie in cookies) { + cookieStrings.add(cookieToString(cookie, true)) + } + val multimap = mapOf("Set-Cookie" to cookieStrings) + try { + cookieHandler.put(url.toUri(), multimap) + } catch (e: IOException) { + Platform.get().log( + "Saving cookies failed for " + url.resolve("/...")!!, + Platform.WARN, e + ) + } + } + + override fun loadForRequest(url: HttpUrl): List { + val cookieHeaders = try { + cookieHandler.get(url.toUri(), emptyMap>()) + } catch (e: IOException) { + Platform.get().log( + "Loading cookies failed for " + url.resolve("/...")!!, + Platform.WARN, e + ) + return emptyList() + } + + var cookies: MutableList? = null + for ((key, value) in cookieHeaders) { + if (("Cookie".equals(key, ignoreCase = true) || "Cookie2".equals( + key, + ignoreCase = true + )) && + value.isNotEmpty() + ) { + for (header in value) { + if (cookies == null) cookies = mutableListOf() + cookies.addAll(decodeHeaderAsJavaNetCookies(url, header)) + } + } + } + + return if (cookies != null) { + Collections.unmodifiableList(cookies) + } else { + emptyList() + } + } + + /** + * Convert a request header to OkHttp's cookies via [HttpCookie]. That extra step handles + * multiple cookies in a single request header, which [Cookie.parse] doesn't support. + */ + private fun decodeHeaderAsJavaNetCookies(url: HttpUrl, header: String): List { + val result = mutableListOf() + var pos = 0 + val limit = header.length + var pairEnd: Int + while (pos < limit) { + pairEnd = header.delimiterOffset(";,", pos, limit) + val equalsSign = header.delimiterOffset('=', pos, pairEnd) + val name = header.trimSubstring(pos, equalsSign) + if (name.startsWith("$")) { + pos = pairEnd + 1 + continue + } + + // We have either name=value or just a name. + var value = if (equalsSign < pairEnd) { + header.trimSubstring(equalsSign + 1, pairEnd) + } else { + "" + } + + // If the value is "quoted", drop the quotes. + if (value.startsWith("\"") && value.endsWith("\"")) { + value = value.substring(1, value.length - 1) + } + + result.add( + Cookie.Builder() + .name(name) + .value(value) + .domain(url.host) + .build() + ) + pos = pairEnd + 1 + } + return result + } +} \ 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 index 7de9ec9..1f2b536 100644 --- a/library/src/main/java/io/appwrite/cookies/stores/InMemoryCookieStore.kt +++ b/library/src/main/java/io/appwrite/cookies/stores/InMemoryCookieStore.kt @@ -6,10 +6,9 @@ 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 { +open class InMemoryCookieStore : CookieStore { internal val uriIndex = mutableMapOf>() private val lock = ReentrantLock(false) @@ -29,7 +28,7 @@ open class InMemoryCookieStore(private val name: String) : CookieStore { if (cookie == null) { Log.i( javaClass.simpleName, - "tried to add null cookie in cookie store named $name. Doing nothing." + "Tried to add null cookie in cookie store. Doing nothing." ) return } @@ -37,7 +36,7 @@ open class InMemoryCookieStore(private val name: String) : CookieStore { if (uri == null) { Log.i( javaClass.simpleName, - "tried to add null URI in cookie store named $name. Doing nothing." + "Tried to add null URI in cookie store. Doing nothing." ) return } @@ -89,7 +88,7 @@ open class InMemoryCookieStore(private val name: String) : CookieStore { if (cookie == null) { Log.i( javaClass.simpleName, - "tried to remove null cookie from cookie store named $name. Doing nothing." + "Tried to remove null cookie from cookie store. Doing nothing." ) return true } @@ -97,7 +96,7 @@ open class InMemoryCookieStore(private val name: String) : CookieStore { if (uri == null) { Log.i( javaClass.simpleName, - "tried to remove null URI from cookie store named $name. Doing nothing." + "Tried to remove null URI from cookie store. Doing nothing." ) return true } @@ -122,7 +121,7 @@ open class InMemoryCookieStore(private val name: String) : CookieStore { if (uri == null) { Log.i( javaClass.simpleName, - "getting cookies from cookie store named $name for null URI results in empty list" + "Getting cookies from cookie store for null URI results in empty list" ) return emptyList() } diff --git a/library/src/main/java/io/appwrite/cookies/stores/SharedPreferencesCookieStore.kt b/library/src/main/java/io/appwrite/cookies/stores/SharedPreferencesCookieStore.kt index 83c677d..0c0b760 100644 --- a/library/src/main/java/io/appwrite/cookies/stores/SharedPreferencesCookieStore.kt +++ b/library/src/main/java/io/appwrite/cookies/stores/SharedPreferencesCookieStore.kt @@ -1,7 +1,7 @@ package io.appwrite.cookies.stores import io.appwrite.cookies.InternalCookie -import android.content.Context +import android.content.SharedPreferences import android.os.Build import android.util.Log import com.google.gson.Gson @@ -10,11 +10,9 @@ import java.net.HttpCookie import java.net.URI open class SharedPreferencesCookieStore( - context: Context, - private val name: String -) : InMemoryCookieStore(name) { + private val preferences: SharedPreferences, +) : InMemoryCookieStore() { - private val preferences = context.getSharedPreferences(name, Context.MODE_PRIVATE) private val gson = Gson() init { @@ -30,7 +28,7 @@ open class SharedPreferencesCookieStore( } catch (exception: Throwable) { Log.e( javaClass.simpleName, - "Error while loading key = $key, value = $value from cookie store named $name", + "Error while loading key = $key, value = $value from cookie store", exception ) } diff --git a/library/src/main/java/io/appwrite/enums/AuthenticatorFactor.kt b/library/src/main/java/io/appwrite/enums/AuthenticatorFactor.kt new file mode 100644 index 0000000..1e0a0c4 --- /dev/null +++ b/library/src/main/java/io/appwrite/enums/AuthenticatorFactor.kt @@ -0,0 +1,7 @@ +package io.appwrite.enums + +enum class AuthenticatorFactor(val value: String) { + TOTP("totp"); + + override fun toString() = value +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/enums/AuthenticatorProvider.kt b/library/src/main/java/io/appwrite/enums/AuthenticatorProvider.kt new file mode 100644 index 0000000..7757f8e --- /dev/null +++ b/library/src/main/java/io/appwrite/enums/AuthenticatorProvider.kt @@ -0,0 +1,7 @@ +package io.appwrite.enums + +enum class AuthenticatorProvider(val value: String) { + TOTP("totp"); + + override fun toString() = value +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/enums/Browser.kt b/library/src/main/java/io/appwrite/enums/Browser.kt new file mode 100644 index 0000000..99f598e --- /dev/null +++ b/library/src/main/java/io/appwrite/enums/Browser.kt @@ -0,0 +1,20 @@ +package io.appwrite.enums + +enum class Browser(val value: String) { + AVANT_BROWSER("aa"), + ANDROID_WEB_VIEW_BETA("an"), + GOOGLE_CHROME("ch"), + GOOGLE_CHROMEI_OS("ci"), + GOOGLE_CHROME_MOBILE("cm"), + CHROMIUM("cr"), + MOZILLA_FIREFOX("ff"), + SAFARI("sf"), + MOBILE_SAFARI("mf"), + MICROSOFT_EDGE("ps"), + MICROSOFT_EDGEI_OS("oi"), + OPERA_MINI("om"), + OPERA("op"), + OPERA_NEXT("on"); + + override fun toString() = value +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/enums/CreditCard.kt b/library/src/main/java/io/appwrite/enums/CreditCard.kt new file mode 100644 index 0000000..e99519b --- /dev/null +++ b/library/src/main/java/io/appwrite/enums/CreditCard.kt @@ -0,0 +1,22 @@ +package io.appwrite.enums + +enum class CreditCard(val value: String) { + AMERICAN_EXPRESS("amex"), + ARGENCARD("argencard"), + CABAL("cabal"), + CONSOSUD("censosud"), + DINERS_CLUB("diners"), + DISCOVER("discover"), + ELO("elo"), + HIPERCARD("hipercard"), + JCB("jcb"), + MASTERCARD("mastercard"), + NARANJA("naranja"), + TARJETA_SHOPPING("targeta-shopping"), + UNION_CHINA_PAY("union-china-pay"), + VISA("visa"), + MIR("mir"), + MAESTRO("maestro"); + + override fun toString() = value +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/enums/ExecutionMethod.kt b/library/src/main/java/io/appwrite/enums/ExecutionMethod.kt new file mode 100644 index 0000000..edeb66b --- /dev/null +++ b/library/src/main/java/io/appwrite/enums/ExecutionMethod.kt @@ -0,0 +1,12 @@ +package io.appwrite.enums + +enum class ExecutionMethod(val value: String) { + GET("GET"), + POST("POST"), + PUT("PUT"), + PATCH("PATCH"), + DELETE("DELETE"), + OPTIONS("OPTIONS"); + + override fun toString() = value +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/enums/Flag.kt b/library/src/main/java/io/appwrite/enums/Flag.kt new file mode 100644 index 0000000..4fcdd88 --- /dev/null +++ b/library/src/main/java/io/appwrite/enums/Flag.kt @@ -0,0 +1,200 @@ +package io.appwrite.enums + +enum class Flag(val value: String) { + AFGHANISTAN("af"), + ANGOLA("ao"), + ALBANIA("al"), + ANDORRA("ad"), + UNITED_ARAB_EMIRATES("ae"), + ARGENTINA("ar"), + ARMENIA("am"), + ANTIGUAAND_BARBUDA("ag"), + AUSTRALIA("au"), + AUSTRIA("at"), + AZERBAIJAN("az"), + BURUNDI("bi"), + BELGIUM("be"), + BENIN("bj"), + BURKINA_FASO("bf"), + BANGLADESH("bd"), + BULGARIA("bg"), + BAHRAIN("bh"), + BAHAMAS("bs"), + BOSNIAAND_HERZEGOVINA("ba"), + BELARUS("by"), + BELIZE("bz"), + BOLIVIA("bo"), + BRAZIL("br"), + BARBADOS("bb"), + BRUNEI_DARUSSALAM("bn"), + BHUTAN("bt"), + BOTSWANA("bw"), + CENTRAL_AFRICAN_REPUBLIC("cf"), + CANADA("ca"), + SWITZERLAND("ch"), + CHILE("cl"), + CHINA("cn"), + CTED_IVOIRE("ci"), + CAMEROON("cm"), + DEMOCRATIC_REPUBLICOFTHE_CONGO("cd"), + REPUBLICOFTHE_CONGO("cg"), + COLOMBIA("co"), + COMOROS("km"), + CAPE_VERDE("cv"), + COSTA_RICA("cr"), + CUBA("cu"), + CYPRUS("cy"), + CZECH_REPUBLIC("cz"), + GERMANY("de"), + DJIBOUTI("dj"), + DOMINICA("dm"), + DENMARK("dk"), + DOMINICAN_REPUBLIC("do"), + ALGERIA("dz"), + ECUADOR("ec"), + EGYPT("eg"), + ERITREA("er"), + SPAIN("es"), + ESTONIA("ee"), + ETHIOPIA("et"), + FINLAND("fi"), + FIJI("fj"), + FRANCE("fr"), + MICRONESIA_FEDERATED_STATESOF("fm"), + GABON("ga"), + UNITED_KINGDOM("gb"), + GEORGIA("ge"), + GHANA("gh"), + GUINEA("gn"), + GAMBIA("gm"), + GUINEA_BISSAU("gw"), + EQUATORIAL_GUINEA("gq"), + GREECE("gr"), + GRENADA("gd"), + GUATEMALA("gt"), + GUYANA("gy"), + HONDURAS("hn"), + CROATIA("hr"), + HAITI("ht"), + HUNGARY("hu"), + INDONESIA("id"), + INDIA("in"), + IRELAND("ie"), + IRAN_ISLAMIC_REPUBLICOF("ir"), + IRAQ("iq"), + ICELAND("is"), + ISRAEL("il"), + ITALY("it"), + JAMAICA("jm"), + JORDAN("jo"), + JAPAN("jp"), + KAZAKHSTAN("kz"), + KENYA("ke"), + KYRGYZSTAN("kg"), + CAMBODIA("kh"), + KIRIBATI("ki"), + SAINT_KITTSAND_NEVIS("kn"), + SOUTH_KOREA("kr"), + KUWAIT("kw"), + LAO_PEOPLES_DEMOCRATIC_REPUBLIC("la"), + LEBANON("lb"), + LIBERIA("lr"), + LIBYA("ly"), + SAINT_LUCIA("lc"), + LIECHTENSTEIN("li"), + SRI_LANKA("lk"), + LESOTHO("ls"), + LITHUANIA("lt"), + LUXEMBOURG("lu"), + LATVIA("lv"), + MOROCCO("ma"), + MONACO("mc"), + MOLDOVA("md"), + MADAGASCAR("mg"), + MALDIVES("mv"), + MEXICO("mx"), + MARSHALL_ISLANDS("mh"), + NORTH_MACEDONIA("mk"), + MALI("ml"), + MALTA("mt"), + MYANMAR("mm"), + MONTENEGRO("me"), + MONGOLIA("mn"), + MOZAMBIQUE("mz"), + MAURITANIA("mr"), + MAURITIUS("mu"), + MALAWI("mw"), + MALAYSIA("my"), + NAMIBIA("na"), + NIGER("ne"), + NIGERIA("ng"), + NICARAGUA("ni"), + NETHERLANDS("nl"), + NORWAY("no"), + NEPAL("np"), + NAURU("nr"), + NEW_ZEALAND("nz"), + OMAN("om"), + PAKISTAN("pk"), + PANAMA("pa"), + PERU("pe"), + PHILIPPINES("ph"), + PALAU("pw"), + PAPUA_NEW_GUINEA("pg"), + POLAND("pl"), + NORTH_KOREA("kp"), + PORTUGAL("pt"), + PARAGUAY("py"), + QATAR("qa"), + ROMANIA("ro"), + RUSSIA("ru"), + RWANDA("rw"), + SAUDI_ARABIA("sa"), + SUDAN("sd"), + SENEGAL("sn"), + SINGAPORE("sg"), + SOLOMON_ISLANDS("sb"), + SIERRA_LEONE("sl"), + EL_SALVADOR("sv"), + SAN_MARINO("sm"), + SOMALIA("so"), + SERBIA("rs"), + SOUTH_SUDAN("ss"), + SAO_TOMEAND_PRINCIPE("st"), + SURINAME("sr"), + SLOVAKIA("sk"), + SLOVENIA("si"), + SWEDEN("se"), + ESWATINI("sz"), + SEYCHELLES("sc"), + SYRIA("sy"), + CHAD("td"), + TOGO("tg"), + THAILAND("th"), + TAJIKISTAN("tj"), + TURKMENISTAN("tm"), + TIMOR_LESTE("tl"), + TONGA("to"), + TRINIDADAND_TOBAGO("tt"), + TUNISIA("tn"), + TURKEY("tr"), + TUVALU("tv"), + TANZANIA("tz"), + UGANDA("ug"), + UKRAINE("ua"), + URUGUAY("uy"), + UNITED_STATES("us"), + UZBEKISTAN("uz"), + VATICAN_CITY("va"), + SAINT_VINCENTANDTHE_GRENADINES("vc"), + VENEZUELA("ve"), + VIETNAM("vn"), + VANUATU("vu"), + SAMOA("ws"), + YEMEN("ye"), + SOUTH_AFRICA("za"), + ZAMBIA("zm"), + ZIMBABWE("zw"); + + override fun toString() = value +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/enums/ImageFormat.kt b/library/src/main/java/io/appwrite/enums/ImageFormat.kt new file mode 100644 index 0000000..6a4c422 --- /dev/null +++ b/library/src/main/java/io/appwrite/enums/ImageFormat.kt @@ -0,0 +1,11 @@ +package io.appwrite.enums + +enum class ImageFormat(val value: String) { + JPG("jpg"), + JPEG("jpeg"), + GIF("gif"), + PNG("png"), + WEBP("webp"); + + override fun toString() = value +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/enums/ImageGravity.kt b/library/src/main/java/io/appwrite/enums/ImageGravity.kt new file mode 100644 index 0000000..a8fa441 --- /dev/null +++ b/library/src/main/java/io/appwrite/enums/ImageGravity.kt @@ -0,0 +1,15 @@ +package io.appwrite.enums + +enum class ImageGravity(val value: String) { + CENTER("center"), + TOPLEFT("top-left"), + TOP("top"), + TOPRIGHT("top-right"), + LEFT("left"), + RIGHT("right"), + BOTTOMLEFT("bottom-left"), + BOTTOM("bottom"), + BOTTOMRIGHT("bottom-right"); + + override fun toString() = value +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/enums/OAuthProvider.kt b/library/src/main/java/io/appwrite/enums/OAuthProvider.kt new file mode 100644 index 0000000..4a38a2e --- /dev/null +++ b/library/src/main/java/io/appwrite/enums/OAuthProvider.kt @@ -0,0 +1,45 @@ +package io.appwrite.enums + +enum class OAuthProvider(val value: String) { + AMAZON("amazon"), + APPLE("apple"), + AUTH0("auth0"), + AUTHENTIK("authentik"), + AUTODESK("autodesk"), + BITBUCKET("bitbucket"), + BITLY("bitly"), + BOX("box"), + DAILYMOTION("dailymotion"), + DISCORD("discord"), + DISQUS("disqus"), + DROPBOX("dropbox"), + ETSY("etsy"), + FACEBOOK("facebook"), + GITHUB("github"), + GITLAB("gitlab"), + GOOGLE("google"), + LINKEDIN("linkedin"), + MICROSOFT("microsoft"), + NOTION("notion"), + OIDC("oidc"), + OKTA("okta"), + PAYPAL("paypal"), + PAYPAL_SANDBOX("paypalSandbox"), + PODIO("podio"), + SALESFORCE("salesforce"), + SLACK("slack"), + SPOTIFY("spotify"), + STRIPE("stripe"), + TRADESHIFT("tradeshift"), + TRADESHIFT_BOX("tradeshiftBox"), + TWITCH("twitch"), + WORDPRESS("wordpress"), + YAHOO("yahoo"), + YAMMER("yammer"), + YANDEX("yandex"), + ZOHO("zoho"), + ZOOM("zoom"), + MOCK("mock"); + + override fun toString() = value +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/extensions/ActivityExtensions.kt b/library/src/main/java/io/appwrite/extensions/ActivityExtensions.kt new file mode 100644 index 0000000..b5164b8 --- /dev/null +++ b/library/src/main/java/io/appwrite/extensions/ActivityExtensions.kt @@ -0,0 +1,46 @@ +package io.appwrite.extensions + +import android.Manifest +import android.content.pm.PackageManager +import android.os.Build +import androidx.activity.result.contract.ActivityResultContracts +import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat + +fun AppCompatActivity.requestNotificationPermission( + onGranted: () -> Unit, + onDenied: () -> Unit, + onShowRationale: () -> Unit, +) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { + onGranted() + return + } + + if (ContextCompat.checkSelfPermission( + this, + Manifest.permission.POST_NOTIFICATIONS + ) == PackageManager.PERMISSION_GRANTED) { + onGranted() + } else if (shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) { + onShowRationale() + } else { + requestPermissionLauncher( + onGranted, + onDenied + ).launch(Manifest.permission.POST_NOTIFICATIONS) + } +} + +private fun AppCompatActivity.requestPermissionLauncher( + onGranted: () -> Unit, + onDenied: () -> Unit, +) = registerForActivityResult( + ActivityResultContracts.RequestPermission(), +) { isGranted: Boolean -> + if (isGranted) { + onGranted() + } else { + onDenied() + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/extensions/MessagingExtensions.kt b/library/src/main/java/io/appwrite/extensions/MessagingExtensions.kt new file mode 100644 index 0000000..515ef51 --- /dev/null +++ b/library/src/main/java/io/appwrite/extensions/MessagingExtensions.kt @@ -0,0 +1,14 @@ +package io.appwrite.extensions + +import io.appwrite.models.Notification +import io.appwrite.services.Messaging + +private val callbacks: MutableList<(Notification) -> Unit> = mutableListOf() + +internal fun onNotificationReceived(notification: Notification) { + callbacks.forEach { it(notification) } +} + +fun Messaging.onNotificationReceived(callback: (Notification) -> Unit) { + callbacks.add(callback) +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/extensions/TypeExtensions.kt b/library/src/main/java/io/appwrite/extensions/TypeExtensions.kt index 2674b99..e699a54 100644 --- a/library/src/main/java/io/appwrite/extensions/TypeExtensions.kt +++ b/library/src/main/java/io/appwrite/extensions/TypeExtensions.kt @@ -4,5 +4,6 @@ import kotlin.reflect.KClass import kotlin.reflect.typeOf inline fun classOf(): Class { + @Suppress("UNCHECKED_CAST") return (typeOf().classifier!! as KClass).java } \ 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 index 96a364f..17ab303 100644 --- a/library/src/main/java/io/appwrite/models/Membership.kt +++ b/library/src/main/java/io/appwrite/models/Membership.kt @@ -73,6 +73,12 @@ data class Membership( @SerializedName("confirm") val confirm: Boolean, + /** + * Multi factor authentication status, true if the user has MFA enabled or false otherwise. + */ + @SerializedName("mfa") + val mfa: Boolean, + /** * User list of roles */ @@ -92,6 +98,7 @@ data class Membership( "invited" to invited as Any, "joined" to joined as Any, "confirm" to confirm as Any, + "mfa" to mfa as Any, "roles" to roles as Any, ) @@ -112,6 +119,7 @@ data class Membership( invited = map["invited"] as String, joined = map["joined"] as String, confirm = map["confirm"] as Boolean, + mfa = map["mfa"] as Boolean, roles = map["roles"] as List, ) } diff --git a/library/src/main/java/io/appwrite/models/MfaChallenge.kt b/library/src/main/java/io/appwrite/models/MfaChallenge.kt new file mode 100644 index 0000000..82b1d18 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/MfaChallenge.kt @@ -0,0 +1,54 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * MFA Challenge + */ +data class MfaChallenge( + /** + * Token ID. + */ + @SerializedName("\$id") + val id: String, + + /** + * Token creation date in ISO 8601 format. + */ + @SerializedName("\$createdAt") + val createdAt: String, + + /** + * User ID. + */ + @SerializedName("userId") + val userId: String, + + /** + * Token expiration date in ISO 8601 format. + */ + @SerializedName("expire") + val expire: String, + +) { + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "\$createdAt" to createdAt as Any, + "userId" to userId as Any, + "expire" to expire as Any, + ) + + companion object { + + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = MfaChallenge( + id = map["\$id"] as String, + createdAt = map["\$createdAt"] as String, + userId = map["userId"] as String, + expire = map["expire"] as String, + ) + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/MfaProvider.kt b/library/src/main/java/io/appwrite/models/MfaProvider.kt new file mode 100644 index 0000000..330f98a --- /dev/null +++ b/library/src/main/java/io/appwrite/models/MfaProvider.kt @@ -0,0 +1,46 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * MFAProvider + */ +data class MfaProvider( + /** + * Backup codes. + */ + @SerializedName("backups") + val backups: List, + + /** + * Secret token used for TOTP factor. + */ + @SerializedName("secret") + val secret: String, + + /** + * URI for authenticator apps. + */ + @SerializedName("uri") + val uri: String, + +) { + fun toMap(): Map = mapOf( + "backups" to backups as Any, + "secret" to secret as Any, + "uri" to uri as Any, + ) + + companion object { + + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = MfaProvider( + backups = map["backups"] as List, + secret = map["secret"] as String, + uri = map["uri"] as String, + ) + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/MfaProviders.kt b/library/src/main/java/io/appwrite/models/MfaProviders.kt new file mode 100644 index 0000000..cb16f91 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/MfaProviders.kt @@ -0,0 +1,46 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * MFAProviders + */ +data class MfaProviders( + /** + * TOTP + */ + @SerializedName("totp") + val totp: Boolean, + + /** + * Phone + */ + @SerializedName("phone") + val phone: Boolean, + + /** + * Email + */ + @SerializedName("email") + val email: Boolean, + +) { + fun toMap(): Map = mapOf( + "totp" to totp as Any, + "phone" to phone as Any, + "email" to email as Any, + ) + + companion object { + + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = MfaProviders( + totp = map["totp"] as Boolean, + phone = map["phone"] as Boolean, + email = map["email"] as Boolean, + ) + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Notification.kt b/library/src/main/java/io/appwrite/models/Notification.kt new file mode 100644 index 0000000..f5b5f38 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Notification.kt @@ -0,0 +1,12 @@ +package io.appwrite.models + +data class Notification( + val title: String = "", + val body: String = "", + val clickAction: String = "", + val color: String = "", + val icon: String = "", + val imageURL: String = "", + val sound: String = "", + val data: Map = mapOf(), +) \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Session.kt b/library/src/main/java/io/appwrite/models/Session.kt index 7674d72..acf70cd 100644 --- a/library/src/main/java/io/appwrite/models/Session.kt +++ b/library/src/main/java/io/appwrite/models/Session.kt @@ -157,6 +157,18 @@ data class Session( @SerializedName("current") val current: Boolean, + /** + * Returns a list of active session factors. + */ + @SerializedName("factors") + val factors: Long, + + /** + * Secret used to authenticate the user. Only included if the request was made with an API key + */ + @SerializedName("secret") + val secret: String, + ) { fun toMap(): Map = mapOf( "\$id" to id as Any, @@ -184,6 +196,8 @@ data class Session( "countryCode" to countryCode as Any, "countryName" to countryName as Any, "current" to current as Any, + "factors" to factors as Any, + "secret" to secret as Any, ) companion object { @@ -217,6 +231,8 @@ data class Session( countryCode = map["countryCode"] as String, countryName = map["countryName"] as String, current = map["current"] as Boolean, + factors = (map["factors"] as Number).toLong(), + secret = map["secret"] as String, ) } } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Subscriber.kt b/library/src/main/java/io/appwrite/models/Subscriber.kt new file mode 100644 index 0000000..1920691 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Subscriber.kt @@ -0,0 +1,94 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * Subscriber + */ +data class Subscriber( + /** + * Subscriber ID. + */ + @SerializedName("\$id") + val id: String, + + /** + * Subscriber creation time in ISO 8601 format. + */ + @SerializedName("\$createdAt") + val createdAt: String, + + /** + * Subscriber update date in ISO 8601 format. + */ + @SerializedName("\$updatedAt") + val updatedAt: String, + + /** + * Target ID. + */ + @SerializedName("targetId") + val targetId: String, + + /** + * Target. + */ + @SerializedName("target") + val target: Target, + + /** + * Topic ID. + */ + @SerializedName("userId") + val userId: String, + + /** + * User Name. + */ + @SerializedName("userName") + val userName: String, + + /** + * Topic ID. + */ + @SerializedName("topicId") + val topicId: String, + + /** + * The target provider type. Can be one of the following: `email`, `sms` or `push`. + */ + @SerializedName("providerType") + val providerType: String, + +) { + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "\$createdAt" to createdAt as Any, + "\$updatedAt" to updatedAt as Any, + "targetId" to targetId as Any, + "target" to target.toMap() as Any, + "userId" to userId as Any, + "userName" to userName as Any, + "topicId" to topicId as Any, + "providerType" to providerType as Any, + ) + + companion object { + + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = Subscriber( + id = map["\$id"] as String, + createdAt = map["\$createdAt"] as String, + updatedAt = map["\$updatedAt"] as String, + targetId = map["targetId"] as String, + target = Target.from(map = map["target"] as Map), + userId = map["userId"] as String, + userName = map["userName"] as String, + topicId = map["topicId"] as String, + providerType = map["providerType"] as String, + ) + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Target.kt b/library/src/main/java/io/appwrite/models/Target.kt new file mode 100644 index 0000000..bd4d207 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Target.kt @@ -0,0 +1,86 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * Target + */ +data class Target( + /** + * Target ID. + */ + @SerializedName("\$id") + val id: String, + + /** + * Target creation time in ISO 8601 format. + */ + @SerializedName("\$createdAt") + val createdAt: String, + + /** + * Target update date in ISO 8601 format. + */ + @SerializedName("\$updatedAt") + val updatedAt: String, + + /** + * Target Name. + */ + @SerializedName("name") + val name: String, + + /** + * User ID. + */ + @SerializedName("userId") + val userId: String, + + /** + * Provider ID. + */ + @SerializedName("providerId") + var providerId: String?, + + /** + * The target provider type. Can be one of the following: `email`, `sms` or `push`. + */ + @SerializedName("providerType") + val providerType: String, + + /** + * The target identifier. + */ + @SerializedName("identifier") + val identifier: String, + +) { + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "\$createdAt" to createdAt as Any, + "\$updatedAt" to updatedAt as Any, + "name" to name as Any, + "userId" to userId as Any, + "providerId" to providerId as Any, + "providerType" to providerType as Any, + "identifier" to identifier as Any, + ) + + companion object { + + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = Target( + id = map["\$id"] as String, + createdAt = map["\$createdAt"] as String, + updatedAt = map["\$updatedAt"] as String, + name = map["name"] as String, + userId = map["userId"] as String, + providerId = map["providerId"] as? String?, + providerType = map["providerType"] as String, + identifier = map["identifier"] as String, + ) + } +} \ 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 index 8c0f0e0..e36d060 100644 --- a/library/src/main/java/io/appwrite/models/Token.kt +++ b/library/src/main/java/io/appwrite/models/Token.kt @@ -37,6 +37,12 @@ data class Token( @SerializedName("expire") val expire: String, + /** + * Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. + */ + @SerializedName("phrase") + val phrase: String, + ) { fun toMap(): Map = mapOf( "\$id" to id as Any, @@ -44,6 +50,7 @@ data class Token( "userId" to userId as Any, "secret" to secret as Any, "expire" to expire as Any, + "phrase" to phrase as Any, ) companion object { @@ -57,6 +64,7 @@ data class Token( userId = map["userId"] as String, secret = map["secret"] as String, expire = map["expire"] as String, + phrase = map["phrase"] as String, ) } } \ 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 9bf7eb4..4c776b9 100644 --- a/library/src/main/java/io/appwrite/models/User.kt +++ b/library/src/main/java/io/appwrite/models/User.kt @@ -97,12 +97,30 @@ data class User( @SerializedName("phoneVerification") val phoneVerification: Boolean, + /** + * Multi factor authentication status. + */ + @SerializedName("mfa") + val mfa: Boolean, + + /** + * TOTP status. + */ + @SerializedName("totp") + val totp: Boolean, + /** * User preferences as a key-value object */ @SerializedName("prefs") val prefs: Preferences, + /** + * A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. + */ + @SerializedName("targets") + val targets: List, + /** * Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. */ @@ -126,7 +144,10 @@ data class User( "phone" to phone as Any, "emailVerification" to emailVerification as Any, "phoneVerification" to phoneVerification as Any, + "mfa" to mfa as Any, + "totp" to totp as Any, "prefs" to prefs.toMap() as Any, + "targets" to targets.map { it.toMap() } as Any, "accessedAt" to accessedAt as Any, ) @@ -147,7 +168,10 @@ data class User( phone: String, emailVerification: Boolean, phoneVerification: Boolean, + mfa: Boolean, + totp: Boolean, prefs: Preferences>, + targets: List, accessedAt: String, ) = User>( id, @@ -165,7 +189,10 @@ data class User( phone, emailVerification, phoneVerification, + mfa, + totp, prefs, + targets, accessedAt, ) @@ -189,7 +216,10 @@ data class User( phone = map["phone"] as String, emailVerification = map["emailVerification"] as Boolean, phoneVerification = map["phoneVerification"] as Boolean, + mfa = map["mfa"] as Boolean, + totp = map["totp"] as Boolean, prefs = Preferences.from(map = map["prefs"] as Map, nestedType), + targets = (map["targets"] as List>).map { Target.from(map = it) }, accessedAt = map["accessedAt"] as String, ) } diff --git a/library/src/main/java/io/appwrite/services/Account.kt b/library/src/main/java/io/appwrite/services/Account.kt index 3c9cca1..1e12e94 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -3,6 +3,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client import io.appwrite.models.* +import io.appwrite.enums.* import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.classOf import io.appwrite.WebAuthComponent @@ -15,9 +16,7 @@ import java.io.File /** * The Account service allows you to authenticate and manage a user account. **/ -class Account : Service { - - public constructor (client: Client) : super(client) { } +class Account(client: Client) : Service(client) { /** * Get account @@ -37,6 +36,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.User = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( @@ -67,9 +67,9 @@ class Account : Service { * * Use this endpoint to allow a new user to register a new account in your project. After the user registration completes successfully, you can use the [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) route to start verifying the user email address. To allow the new user to login to their new account, you need to create a new [account session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). * - * @param userId Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. 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 User ID. Choose a custom ID or generate a random ID with `ID.unique()`. 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 New user password. Must be at least 8 chars. + * @param password New user password. Must be between 8 and 256 chars. * @param name User name. Max length: 128 chars. * @return [io.appwrite.models.User] */ @@ -93,6 +93,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.User = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( @@ -110,9 +111,9 @@ class Account : Service { * * Use this endpoint to allow a new user to register a new account in your project. After the user registration completes successfully, you can use the [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) route to start verifying the user email address. To allow the new user to login to their new account, you need to create a new [account session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). * - * @param userId Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. 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 User ID. Choose a custom ID or generate a random ID with `ID.unique()`. 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 New user password. Must be at least 8 chars. + * @param password New user password. Must be between 8 and 256 chars. * @param name User name. Max length: 128 chars. * @return [io.appwrite.models.User] */ @@ -155,6 +156,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.User = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( @@ -196,7 +198,7 @@ class Account : Service { */ @JvmOverloads suspend fun listIdentities( - queries: String? = null, + queries: List? = null, ): io.appwrite.models.IdentityList { val apiPath = "/account/identities" @@ -207,6 +209,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.IdentityList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.IdentityList.from(map = it as Map) } return client.call( @@ -221,7 +224,7 @@ class Account : Service { /** - * Delete Identity + * Delete identity * * Delete an identity by its unique ID. * @@ -266,6 +269,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Jwt = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Jwt.from(map = it as Map) } return client.call( @@ -300,6 +304,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.LogList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.LogList.from(map = it as Map) } return client.call( @@ -313,6 +318,299 @@ class Account : Service { } + /** + * Update MFA + * + * + * + * @param mfa Enable or disable MFA. + * @return [io.appwrite.models.User] + */ + suspend fun updateMFA( + mfa: Boolean, + nestedType: Class, + ): io.appwrite.models.User { + val apiPath = "/account/mfa" + + val apiParams = mutableMapOf( + "mfa" to mfa, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.User = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.User.from(map = it as Map, nestedType) + } + return client.call( + "PATCH", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Update MFA + * + * + * + * @param mfa Enable or disable MFA. + * @return [io.appwrite.models.User] + */ + @Throws(AppwriteException::class) + suspend fun updateMFA( + mfa: Boolean, + ): io.appwrite.models.User> = updateMFA( + mfa, + nestedType = classOf(), + ) + + /** + * Create MFA Challenge + * + * + * + * @param provider provider. + * @return [io.appwrite.models.MfaChallenge] + */ + suspend fun createChallenge( + provider: AuthenticatorProvider, + ): io.appwrite.models.MfaChallenge { + val apiPath = "/account/mfa/challenge" + + val apiParams = mutableMapOf( + "provider" to provider, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.MfaChallenge = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.MfaChallenge.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.MfaChallenge::class.java, + converter, + ) + } + + + /** + * Create MFA Challenge (confirmation) + * + * + * + * @param challengeId Valid verification token. + * @param otp Valid verification token. + * @return [Any] + */ + suspend fun updateChallenge( + challengeId: String, + otp: String, + ): Any { + val apiPath = "/account/mfa/challenge" + + val apiParams = mutableMapOf( + "challengeId" to challengeId, + "otp" to otp, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + return client.call( + "PUT", + apiPath, + apiHeaders, + apiParams, + responseType = Any::class.java, + ) + } + + + /** + * List Factors + * + * Get the currently logged in user. + * + * @return [io.appwrite.models.MfaProviders] + */ + suspend fun listFactors( + ): io.appwrite.models.MfaProviders { + val apiPath = "/account/mfa/factors" + + val apiParams = mutableMapOf( + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.MfaProviders = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.MfaProviders.from(map = it as Map) + } + return client.call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.MfaProviders::class.java, + converter, + ) + } + + + /** + * Add Authenticator + * + * + * + * @param factor Factor. + * @return [io.appwrite.models.MfaProvider] + */ + suspend fun addAuthenticator( + factor: AuthenticatorFactor, + ): io.appwrite.models.MfaProvider { + val apiPath = "/account/mfa/{factor}" + .replace("{factor}", factor.value) + + val apiParams = mutableMapOf( + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.MfaProvider = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.MfaProvider.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.MfaProvider::class.java, + converter, + ) + } + + + /** + * Verify Authenticator + * + * + * + * @param factor Factor. + * @param otp Valid verification token. + * @return [io.appwrite.models.User] + */ + suspend fun verifyAuthenticator( + factor: AuthenticatorFactor, + otp: String, + nestedType: Class, + ): io.appwrite.models.User { + val apiPath = "/account/mfa/{factor}" + .replace("{factor}", factor.value) + + val apiParams = mutableMapOf( + "otp" to otp, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.User = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.User.from(map = it as Map, nestedType) + } + return client.call( + "PUT", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Verify Authenticator + * + * + * + * @param factor Factor. + * @param otp Valid verification token. + * @return [io.appwrite.models.User] + */ + @Throws(AppwriteException::class) + suspend fun verifyAuthenticator( + factor: AuthenticatorFactor, + otp: String, + ): io.appwrite.models.User> = verifyAuthenticator( + factor, + otp, + nestedType = classOf(), + ) + + /** + * Delete Authenticator + * + * + * + * @param provider Provider. + * @param otp Valid verification token. + * @return [io.appwrite.models.User] + */ + suspend fun deleteAuthenticator( + provider: AuthenticatorProvider, + otp: String, + nestedType: Class, + ): io.appwrite.models.User { + val apiPath = "/account/mfa/{provider}" + .replace("{provider}", provider.value) + + val apiParams = mutableMapOf( + "otp" to otp, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.User = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.User.from(map = it as Map, nestedType) + } + return client.call( + "DELETE", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Delete Authenticator + * + * + * + * @param provider Provider. + * @param otp Valid verification token. + * @return [io.appwrite.models.User] + */ + @Throws(AppwriteException::class) + suspend fun deleteAuthenticator( + provider: AuthenticatorProvider, + otp: String, + ): io.appwrite.models.User> = deleteAuthenticator( + provider, + otp, + nestedType = classOf(), + ) + /** * Update name * @@ -334,6 +632,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.User = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( @@ -387,6 +686,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.User = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( @@ -443,6 +743,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.User = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( @@ -492,6 +793,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Preferences = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Preferences.from(map = it as Map, nestedType) } return client.call( @@ -538,6 +840,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.User = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( @@ -589,6 +892,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Token = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Token.from(map = it as Map) } return client.call( @@ -609,15 +913,13 @@ class Account : Service { * * @param userId User ID. * @param secret Valid reset token. - * @param password New user password. Must be at least 8 chars. - * @param passwordAgain Repeat new user password. Must be at least 8 chars. + * @param password New user password. Must be between 8 and 256 chars. * @return [io.appwrite.models.Token] */ suspend fun updateRecovery( userId: String, secret: String, password: String, - passwordAgain: String, ): io.appwrite.models.Token { val apiPath = "/account/recovery" @@ -625,12 +927,12 @@ class Account : Service { "userId" to userId, "secret" to secret, "password" to password, - "passwordAgain" to passwordAgain, ) val apiHeaders = mutableMapOf( "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Token = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Token.from(map = it as Map) } return client.call( @@ -661,6 +963,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.SessionList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.SessionList.from(map = it as Map) } return client.call( @@ -717,6 +1020,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Session = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Session.from(map = it as Map) } return client.call( @@ -731,7 +1035,7 @@ class Account : Service { /** - * Create email session + * Create email password session * * 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.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). * @@ -739,7 +1043,7 @@ class Account : Service { * @param password User password. Must be at least 8 chars. * @return [io.appwrite.models.Session] */ - suspend fun createEmailSession( + suspend fun createEmailPasswordSession( email: String, password: String, ): io.appwrite.models.Session { @@ -753,6 +1057,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Session = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Session.from(map = it as Map) } return client.call( @@ -767,51 +1072,11 @@ class Account : Service { /** - * Create magic URL session + * Create session (deprecated) * - * Sends the user an email with a secret key for creating a session. If the provided user ID has not been registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the [PUT /account/sessions/magic-url](https://appwrite.io/docs/references/cloud/client-web/account#updateMagicURLSession) endpoint to complete the login process. The link sent to the user's email address is valid for 1 hour. If you are on a mobile device you can leave the URL parameter empty, so that the login completion will be handled by your Appwrite instance by default.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). + * Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login. * - * @param userId Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. 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] - */ - @JvmOverloads - suspend fun createMagicURLSession( - userId: String, - email: String, - url: String? = null, - ): io.appwrite.models.Token { - val apiPath = "/account/sessions/magic-url" - - val apiParams = mutableMapOf( - "userId" to userId, - "email" to email, - "url" to url, - ) - val apiHeaders = mutableMapOf( - "content-type" to "application/json", - ) - val converter: (Any) -> io.appwrite.models.Token = { - io.appwrite.models.Token.from(map = it as Map) - } - return client.call( - "POST", - apiPath, - apiHeaders, - apiParams, - responseType = io.appwrite.models.Token::class.java, - converter, - ) - } - - - /** - * Create magic URL session (confirmation) - * - * Use this endpoint to complete creating the session with the Magic URL. Both the **userId** and **secret** arguments will be passed as query parameters to the redirect URL you have provided when sending your request to the [POST /account/sessions/magic-url](https://appwrite.io/docs/references/cloud/client-web/account#createMagicURLSession) endpoint.Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface. - * - * @param userId User ID. + * @param userId User ID. Choose a custom ID or generate a random ID with `ID.unique()`. 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 secret Valid verification token. * @return [io.appwrite.models.Session] */ @@ -829,6 +1094,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Session = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Session.from(map = it as Map) } return client.call( @@ -847,25 +1113,28 @@ class Account : Service { * * Allow the user to login to their account using the OAuth2 provider of their choice. Each OAuth2 provider should be enabled from the Appwrite console first. Use the success and failure arguments to provide a redirect URL's back to your app when login is completed.If there is already an active session, the new session will be attached to the logged-in account. If there are no active sessions, the server will attempt to look for a user with the same email address as the email received from the OAuth2 provider and attach the new session to the existing user. If no matching user is found - the server will create a new user.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). * - * @param provider OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoom. + * @param provider OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom. * @param success URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's 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's 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 token Include token credentials in the final redirect, useful for server-side integrations, or when cookies are not available. * @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 4096 characters long. */ @JvmOverloads suspend fun createOAuth2Session( activity: ComponentActivity, - provider: String, + provider: OAuthProvider, success: String? = null, failure: String? = null, + token: Boolean? = null, scopes: List? = null, ) { val apiPath = "/account/sessions/oauth2/{provider}" - .replace("{provider}", provider) + .replace("{provider}", provider.value) val apiParams = mutableMapOf( "success" to success, "failure" to failure, + "token" to token, "scopes" to scopes, "project" to client.config["project"], ) @@ -884,7 +1153,7 @@ class Account : Service { } } - val apiUrl = Uri.parse("${client.endPoint}${apiPath}?${apiQuery.joinToString("&")}") + val apiUrl = Uri.parse("${client.endpoint}${apiPath}?${apiQuery.joinToString("&")}") val callbackUrlScheme = "appwrite-callback-${client.config["project"]}" WebAuthComponent.authenticate(activity, apiUrl, callbackUrlScheme) { @@ -902,12 +1171,12 @@ class Account : Service { val cookie = Cookie.Builder() .name(key) .value(secret) - .domain(Uri.parse(client.endPoint).host!!) + .domain(Uri.parse(client.endpoint).host!!) .httpOnly() .build() client.http.cookieJar.saveFromResponse( - client.endPoint.toHttpUrl(), + client.endpoint.toHttpUrl(), listOf(cookie) ) } @@ -915,55 +1184,19 @@ class Account : Service { /** - * Create phone session + * Create session * - * Sends the user an SMS with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [PUT /account/sessions/phone](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneSession) endpoint to complete the login process. The secret sent to the user's phone is valid for 15 minutes.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). + * Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login. * - * @param userId Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. 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 phone Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. - * @return [io.appwrite.models.Token] - */ - suspend fun createPhoneSession( - userId: String, - phone: String, - ): io.appwrite.models.Token { - val apiPath = "/account/sessions/phone" - - val apiParams = mutableMapOf( - "userId" to userId, - "phone" to phone, - ) - val apiHeaders = mutableMapOf( - "content-type" to "application/json", - ) - val converter: (Any) -> io.appwrite.models.Token = { - io.appwrite.models.Token.from(map = it as Map) - } - return client.call( - "POST", - apiPath, - apiHeaders, - apiParams, - responseType = io.appwrite.models.Token::class.java, - converter, - ) - } - - - /** - * Create phone session (confirmation) - * - * Use this endpoint to complete creating a session with SMS. Use the **userId** from the [createPhoneSession](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneSession) endpoint and the **secret** received via SMS to successfully update and confirm the phone session. - * - * @param userId User ID. - * @param secret Valid verification token. + * @param userId User ID. Choose a custom ID or generate a random ID with `ID.unique()`. 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 secret Secret of a token generated by login methods. For example, the `createMagicURLToken` or `createPhoneToken` methods. * @return [io.appwrite.models.Session] */ - suspend fun updatePhoneSession( + suspend fun createSession( userId: String, secret: String, ): io.appwrite.models.Session { - val apiPath = "/account/sessions/phone" + val apiPath = "/account/sessions/token" val apiParams = mutableMapOf( "userId" to userId, @@ -973,10 +1206,11 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Session = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Session.from(map = it as Map) } return client.call( - "PUT", + "POST", apiPath, apiHeaders, apiParams, @@ -1006,6 +1240,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Session = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Session.from(map = it as Map) } return client.call( @@ -1020,9 +1255,9 @@ class Account : Service { /** - * Update OAuth session (refresh tokens) + * Update (or renew) a session * - * 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. + * Extend session's expiry to increase it's lifespan. Extending a session is useful when session length is short such as 5 minutes. * * @param sessionId Session ID. Use the string 'current' to update the current device session. * @return [io.appwrite.models.Session] @@ -1039,6 +1274,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Session = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Session.from(map = it as Map) } return client.call( @@ -1099,6 +1335,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.User = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( @@ -1124,6 +1361,235 @@ class Account : Service { nestedType = classOf(), ) + /** + * Create a push target + * + * + * + * @param targetId Target ID. Choose a custom ID or generate a random ID with `ID.unique()`. 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 identifier The target identifier (token, email, phone etc.) + * @param providerId Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used. + * @return [io.appwrite.models.Target] + */ + @JvmOverloads + suspend fun createPushTarget( + targetId: String, + identifier: String, + providerId: String? = null, + ): io.appwrite.models.Target { + val apiPath = "/account/targets/push" + + val apiParams = mutableMapOf( + "targetId" to targetId, + "identifier" to identifier, + "providerId" to providerId, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Target = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Target.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Target::class.java, + converter, + ) + } + + + /** + * Update a push target + * + * + * + * @param targetId Target ID. + * @param identifier The target identifier (token, email, phone etc.) + * @return [io.appwrite.models.Target] + */ + suspend fun updatePushTarget( + targetId: String, + identifier: String, + ): io.appwrite.models.Target { + val apiPath = "/account/targets/{targetId}/push" + .replace("{targetId}", targetId) + + val apiParams = mutableMapOf( + "identifier" to identifier, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Target = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Target.from(map = it as Map) + } + return client.call( + "PUT", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Target::class.java, + converter, + ) + } + + + /** + * Delete a push target + * + * + * + * @param targetId Target ID. + * @return [Any] + */ + suspend fun deletePushTarget( + targetId: String, + ): Any { + val apiPath = "/account/targets/{targetId}/push" + .replace("{targetId}", targetId) + + val apiParams = mutableMapOf( + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + return client.call( + "DELETE", + apiPath, + apiHeaders, + apiParams, + responseType = Any::class.java, + ) + } + + + /** + * Create email token (OTP) + * + * Sends the user an email with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The secret sent to the user's email is valid for 15 minutes.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). + * + * @param userId User ID. Choose a custom ID or generate a random ID with `ID.unique()`. 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 phrase Toggle for security phrase. If enabled, email will be send with a randomly generated phrase and the phrase will also be included in the response. Confirming phrases match increases the security of your authentication flow. + * @return [io.appwrite.models.Token] + */ + @JvmOverloads + suspend fun createEmailToken( + userId: String, + email: String, + phrase: Boolean? = null, + ): io.appwrite.models.Token { + val apiPath = "/account/tokens/email" + + val apiParams = mutableMapOf( + "userId" to userId, + "email" to email, + "phrase" to phrase, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Token = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Token.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Token::class.java, + converter, + ) + } + + + /** + * Create magic URL token + * + * Sends the user an email with a secret key for creating a session. If the provided user ID has not been registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The link sent to the user's email address is valid for 1 hour. If you are on a mobile device you can leave the URL parameter empty, so that the login completion will be handled by your Appwrite instance by default.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). + * + * @param userId User ID. Choose a custom ID or generate a random ID with `ID.unique()`. 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. + * @param phrase Toggle for security phrase. If enabled, email will be send with a randomly generated phrase and the phrase will also be included in the response. Confirming phrases match increases the security of your authentication flow. + * @return [io.appwrite.models.Token] + */ + @JvmOverloads + suspend fun createMagicURLToken( + userId: String, + email: String, + url: String? = null, + phrase: Boolean? = null, + ): io.appwrite.models.Token { + val apiPath = "/account/tokens/magic-url" + + val apiParams = mutableMapOf( + "userId" to userId, + "email" to email, + "url" to url, + "phrase" to phrase, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Token = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Token.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Token::class.java, + converter, + ) + } + + + /** + * Create phone token + * + * Sends the user an SMS with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The secret sent to the user's phone is valid for 15 minutes.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). + * + * @param userId Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. 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 phone Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. + * @return [io.appwrite.models.Token] + */ + suspend fun createPhoneToken( + userId: String, + phone: String, + ): io.appwrite.models.Token { + val apiPath = "/account/tokens/phone" + + val apiParams = mutableMapOf( + "userId" to userId, + "phone" to phone, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Token = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Token.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Token::class.java, + converter, + ) + } + + /** * Create email verification * @@ -1144,6 +1610,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Token = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Token.from(map = it as Map) } return client.call( @@ -1180,6 +1647,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Token = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Token.from(map = it as Map) } return client.call( @@ -1210,6 +1678,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Token = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Token.from(map = it as Map) } return client.call( @@ -1246,6 +1715,7 @@ class Account : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Token = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Token.from(map = it as Map) } return client.call( diff --git a/library/src/main/java/io/appwrite/services/Avatars.kt b/library/src/main/java/io/appwrite/services/Avatars.kt index 27b7cde..bdf97ae 100644 --- a/library/src/main/java/io/appwrite/services/Avatars.kt +++ b/library/src/main/java/io/appwrite/services/Avatars.kt @@ -3,6 +3,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client import io.appwrite.models.* +import io.appwrite.enums.* import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.classOf import okhttp3.Cookie @@ -13,9 +14,7 @@ import java.io.File /** * The Avatars service aims to help you complete everyday tasks related to your app image, icons, and avatars. **/ -class Avatars : Service { - - public constructor (client: Client) : super(client) { } +class Avatars(client: Client) : Service(client) { /** * Get browser icon @@ -30,13 +29,13 @@ class Avatars : Service { */ @JvmOverloads suspend fun getBrowser( - code: String, + code: Browser, width: Long? = null, height: Long? = null, quality: Long? = null, ): ByteArray { val apiPath = "/avatars/browsers/{code}" - .replace("{code}", code) + .replace("{code}", code.value) val apiParams = mutableMapOf( "width" to width, @@ -66,13 +65,13 @@ class Avatars : Service { */ @JvmOverloads suspend fun getCreditCard( - code: String, + code: CreditCard, width: Long? = null, height: Long? = null, quality: Long? = null, ): ByteArray { val apiPath = "/avatars/credit-cards/{code}" - .replace("{code}", code) + .replace("{code}", code.value) val apiParams = mutableMapOf( "width" to width, @@ -128,13 +127,13 @@ class Avatars : Service { */ @JvmOverloads suspend fun getFlag( - code: String, + code: Flag, width: Long? = null, height: Long? = null, quality: Long? = null, ): ByteArray { val apiPath = "/avatars/flags/{code}" - .replace("{code}", code) + .replace("{code}", code.value) val apiParams = mutableMapOf( "width" to width, diff --git a/library/src/main/java/io/appwrite/services/Databases.kt b/library/src/main/java/io/appwrite/services/Databases.kt index 4329b35..b95d6cc 100644 --- a/library/src/main/java/io/appwrite/services/Databases.kt +++ b/library/src/main/java/io/appwrite/services/Databases.kt @@ -3,6 +3,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client import io.appwrite.models.* +import io.appwrite.enums.* import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.classOf import okhttp3.Cookie @@ -11,9 +12,7 @@ import java.io.File /** * The Databases service allows you to create structured collections of documents, query and filter lists of documents **/ -class Databases : Service { - - public constructor (client: Client) : super(client) { } +class Databases(client: Client) : Service(client) { /** * List documents @@ -43,6 +42,7 @@ class Databases : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.DocumentList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.DocumentList.from(map = it as Map, nestedType) } return client.call( @@ -112,6 +112,7 @@ class Databases : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Document.from(map = it as Map, nestedType) } return client.call( @@ -161,7 +162,7 @@ class Databases : Service { * @param databaseId Database ID. * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @param documentId Document ID. - * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only method allowed is select. + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. * @return [io.appwrite.models.Document] */ @JvmOverloads @@ -184,6 +185,7 @@ class Databases : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Document.from(map = it as Map, nestedType) } return client.call( @@ -204,7 +206,7 @@ class Databases : Service { * @param databaseId Database ID. * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @param documentId Document ID. - * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only method allowed is select. + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. * @return [io.appwrite.models.Document] */ @JvmOverloads @@ -256,6 +258,7 @@ class Databases : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Document.from(map = it as Map, nestedType) } 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 257a130..286ec5d 100644 --- a/library/src/main/java/io/appwrite/services/Functions.kt +++ b/library/src/main/java/io/appwrite/services/Functions.kt @@ -3,6 +3,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client import io.appwrite.models.* +import io.appwrite.enums.* import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.classOf import okhttp3.Cookie @@ -11,9 +12,7 @@ import java.io.File /** * The Functions Service allows you view, create and manage your Cloud Functions. **/ -class Functions : Service { - - public constructor (client: Client) : super(client) { } +class Functions(client: Client) : Service(client) { /** * List executions @@ -42,6 +41,7 @@ class Functions : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.ExecutionList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.ExecutionList.from(map = it as Map) } return client.call( @@ -74,7 +74,7 @@ class Functions : Service { body: String? = null, async: Boolean? = null, path: String? = null, - method: String? = null, + method: ExecutionMethod? = null, headers: Any? = null, ): io.appwrite.models.Execution { val apiPath = "/functions/{functionId}/executions" @@ -91,6 +91,7 @@ class Functions : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Execution = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Execution.from(map = it as Map) } return client.call( @@ -127,6 +128,7 @@ class Functions : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Execution = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Execution.from(map = it as Map) } return client.call( diff --git a/library/src/main/java/io/appwrite/services/Graphql.kt b/library/src/main/java/io/appwrite/services/Graphql.kt index 3a925d5..b1a8254 100644 --- a/library/src/main/java/io/appwrite/services/Graphql.kt +++ b/library/src/main/java/io/appwrite/services/Graphql.kt @@ -3,6 +3,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client import io.appwrite.models.* +import io.appwrite.enums.* import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.classOf import okhttp3.Cookie @@ -11,9 +12,7 @@ import java.io.File /** * The GraphQL API allows you to query and mutate your Appwrite server using GraphQL. **/ -class Graphql : Service { - - public constructor (client: Client) : super(client) { } +class Graphql(client: Client) : Service(client) { /** * GraphQL endpoint diff --git a/library/src/main/java/io/appwrite/services/Locale.kt b/library/src/main/java/io/appwrite/services/Locale.kt index 510f451..ee26888 100644 --- a/library/src/main/java/io/appwrite/services/Locale.kt +++ b/library/src/main/java/io/appwrite/services/Locale.kt @@ -3,6 +3,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client import io.appwrite.models.* +import io.appwrite.enums.* import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.classOf import okhttp3.Cookie @@ -11,9 +12,7 @@ import java.io.File /** * The Locale service allows you to customize your app based on your users' location. **/ -class Locale : Service { - - public constructor (client: Client) : super(client) { } +class Locale(client: Client) : Service(client) { /** * Get user locale @@ -32,6 +31,7 @@ class Locale : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Locale = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Locale.from(map = it as Map) } return client.call( @@ -62,6 +62,7 @@ class Locale : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.LocaleCodeList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.LocaleCodeList.from(map = it as Map) } return client.call( @@ -92,6 +93,7 @@ class Locale : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.ContinentList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.ContinentList.from(map = it as Map) } return client.call( @@ -122,6 +124,7 @@ class Locale : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.CountryList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.CountryList.from(map = it as Map) } return client.call( @@ -152,6 +155,7 @@ class Locale : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.CountryList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.CountryList.from(map = it as Map) } return client.call( @@ -182,6 +186,7 @@ class Locale : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.PhoneList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.PhoneList.from(map = it as Map) } return client.call( @@ -212,6 +217,7 @@ class Locale : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.CurrencyList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.CurrencyList.from(map = it as Map) } return client.call( @@ -242,6 +248,7 @@ class Locale : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.LanguageList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.LanguageList.from(map = it as Map) } return client.call( diff --git a/library/src/main/java/io/appwrite/services/Messaging.kt b/library/src/main/java/io/appwrite/services/Messaging.kt new file mode 100644 index 0000000..2035dbf --- /dev/null +++ b/library/src/main/java/io/appwrite/services/Messaging.kt @@ -0,0 +1,89 @@ +package io.appwrite.services + +import android.net.Uri +import io.appwrite.Client +import io.appwrite.models.* +import io.appwrite.enums.* +import io.appwrite.exceptions.AppwriteException +import io.appwrite.extensions.classOf +import okhttp3.Cookie +import java.io.File + +/** + * The Messaging service allows you to send messages to any provider type (SMTP, push notification, SMS, etc.). +**/ +class Messaging(client: Client) : Service(client) { + + /** + * Create a subscriber. + * + * + * + * @param topicId Topic ID. The topic ID to subscribe to. + * @param subscriberId Subscriber ID. Choose a custom Subscriber ID or a new Subscriber ID. + * @param targetId Target ID. The target ID to link to the specified Topic ID. + * @return [io.appwrite.models.Subscriber] + */ + suspend fun createSubscriber( + topicId: String, + subscriberId: String, + targetId: String, + ): io.appwrite.models.Subscriber { + val apiPath = "/messaging/topics/{topicId}/subscribers" + .replace("{topicId}", topicId) + + val apiParams = mutableMapOf( + "subscriberId" to subscriberId, + "targetId" to targetId, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Subscriber = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Subscriber.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Subscriber::class.java, + converter, + ) + } + + + /** + * Delete a subscriber. + * + * + * + * @param topicId Topic ID. The topic ID subscribed to. + * @param subscriberId Subscriber ID. + * @return [Any] + */ + suspend fun deleteSubscriber( + topicId: String, + subscriberId: String, + ): Any { + val apiPath = "/messaging/topics/{topicId}/subscribers/{subscriberId}" + .replace("{topicId}", topicId) + .replace("{subscriberId}", subscriberId) + + val apiParams = mutableMapOf( + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + return client.call( + "DELETE", + apiPath, + apiHeaders, + apiParams, + responseType = Any::class.java, + ) + } + + +} \ 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 316054a..e3709e5 100644 --- a/library/src/main/java/io/appwrite/services/Realtime.kt +++ b/library/src/main/java/io/appwrite/services/Realtime.kt @@ -55,7 +55,7 @@ class Realtime(client: Client) : Service(client), CoroutineScope { } val request = Request.Builder() - .url("${client.endPointRealtime}/realtime?$queryParamBuilder") + .url("${client.endpointRealtime}/realtime?$queryParamBuilder") .build() if (socket != null) { diff --git a/library/src/main/java/io/appwrite/services/Storage.kt b/library/src/main/java/io/appwrite/services/Storage.kt index 2b49f56..3830e20 100644 --- a/library/src/main/java/io/appwrite/services/Storage.kt +++ b/library/src/main/java/io/appwrite/services/Storage.kt @@ -3,6 +3,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client import io.appwrite.models.* +import io.appwrite.enums.* import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.classOf import okhttp3.Cookie @@ -13,9 +14,7 @@ import java.io.File /** * The Storage service allows you to manage your project files. **/ -class Storage : Service { - - public constructor (client: Client) : super(client) { } +class Storage(client: Client) : Service(client) { /** * List files @@ -44,6 +43,7 @@ class Storage : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.FileList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.FileList.from(map = it as Map) } return client.call( @@ -88,6 +88,7 @@ class Storage : Service { "content-type" to "multipart/form-data", ) val converter: (Any) -> io.appwrite.models.File = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.File.from(map = it as Map) } val idParamName: String? = "fileId" @@ -128,6 +129,7 @@ class Storage : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.File = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.File.from(map = it as Map) } return client.call( @@ -171,6 +173,7 @@ class Storage : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.File = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.File.from(map = it as Map) } return client.call( @@ -271,7 +274,7 @@ class Storage : Service { fileId: String, width: Long? = null, height: Long? = null, - gravity: String? = null, + gravity: ImageGravity? = null, quality: Long? = null, borderWidth: Long? = null, borderColor: String? = null, @@ -279,7 +282,7 @@ class Storage : Service { opacity: Double? = null, rotation: Long? = null, background: String? = null, - output: String? = null, + output: ImageFormat? = null, ): ByteArray { val apiPath = "/storage/buckets/{bucketId}/files/{fileId}/preview" .replace("{bucketId}", bucketId) diff --git a/library/src/main/java/io/appwrite/services/Teams.kt b/library/src/main/java/io/appwrite/services/Teams.kt index 7f303ab..8c89184 100644 --- a/library/src/main/java/io/appwrite/services/Teams.kt +++ b/library/src/main/java/io/appwrite/services/Teams.kt @@ -3,6 +3,7 @@ package io.appwrite.services import android.net.Uri import io.appwrite.Client import io.appwrite.models.* +import io.appwrite.enums.* import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.classOf import okhttp3.Cookie @@ -11,16 +12,14 @@ import java.io.File /** * The Teams service allows you to group users of your project and to enable them to share read and write access to your project resources **/ -class Teams : Service { - - public constructor (client: Client) : super(client) { } +class Teams(client: Client) : Service(client) { /** * List teams * * Get a list of all the teams in which the current user is a member. You can use the parameters to filter your results. * - * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, total + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, total, billingPlan * @param search Search term to filter your list results. Max length: 256 chars. * @return [io.appwrite.models.TeamList] */ @@ -40,6 +39,7 @@ class Teams : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.TeamList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.TeamList.from(map = it as Map, nestedType) } return client.call( @@ -57,7 +57,7 @@ class Teams : Service { * * Get a list of all the teams in which the current user is a member. You can use the parameters to filter your results. * - * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, total + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, total, billingPlan * @param search Search term to filter your list results. Max length: 256 chars. * @return [io.appwrite.models.TeamList] */ @@ -100,6 +100,7 @@ class Teams : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Team = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Team.from(map = it as Map, nestedType) } return client.call( @@ -156,6 +157,7 @@ class Teams : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Team = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Team.from(map = it as Map, nestedType) } return client.call( @@ -208,6 +210,7 @@ class Teams : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Team = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Team.from(map = it as Map, nestedType) } return client.call( @@ -295,6 +298,7 @@ class Teams : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.MembershipList = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.MembershipList.from(map = it as Map) } return client.call( @@ -347,6 +351,7 @@ class Teams : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Membership = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Membership.from(map = it as Map) } return client.call( @@ -383,6 +388,7 @@ class Teams : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Membership = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Membership.from(map = it as Map) } return client.call( @@ -422,6 +428,7 @@ class Teams : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Membership = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Membership.from(map = it as Map) } return client.call( @@ -496,6 +503,7 @@ class Teams : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Membership = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Membership.from(map = it as Map) } return client.call( @@ -530,6 +538,7 @@ class Teams : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Preferences = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Preferences.from(map = it as Map, nestedType) } return client.call( @@ -582,6 +591,7 @@ class Teams : Service { "content-type" to "application/json", ) val converter: (Any) -> io.appwrite.models.Preferences = { + @Suppress("UNCHECKED_CAST") io.appwrite.models.Preferences.from(map = it as Map, nestedType) } return client.call( diff --git a/library/src/main/java/io/appwrite/services/Users.kt b/library/src/main/java/io/appwrite/services/Users.kt new file mode 100644 index 0000000..e425c70 --- /dev/null +++ b/library/src/main/java/io/appwrite/services/Users.kt @@ -0,0 +1,113 @@ +package io.appwrite.services + +import android.net.Uri +import io.appwrite.Client +import io.appwrite.models.* +import io.appwrite.enums.* +import io.appwrite.exceptions.AppwriteException +import io.appwrite.extensions.classOf +import okhttp3.Cookie +import java.io.File + +/** + * The Users service allows you to manage your project users. +**/ +class Users(client: Client) : Service(client) { + + /** + * Delete Authenticator + * + * + * + * @param userId User ID. + * @param provider Provider. + * @param otp Valid verification token. + * @return [io.appwrite.models.User] + */ + suspend fun deleteAuthenticator( + userId: String, + provider: AuthenticatorProvider, + otp: String, + nestedType: Class, + ): io.appwrite.models.User { + val apiPath = "/users/{userId}/mfa/{provider}" + .replace("{userId}", userId) + .replace("{provider}", provider.value) + + val apiParams = mutableMapOf( + "otp" to otp, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.User = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.User.from(map = it as Map, nestedType) + } + return client.call( + "DELETE", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Delete Authenticator + * + * + * + * @param userId User ID. + * @param provider Provider. + * @param otp Valid verification token. + * @return [io.appwrite.models.User] + */ + @Throws(AppwriteException::class) + suspend fun deleteAuthenticator( + userId: String, + provider: AuthenticatorProvider, + otp: String, + ): io.appwrite.models.User> = deleteAuthenticator( + userId, + provider, + otp, + nestedType = classOf(), + ) + + /** + * List Providers + * + * + * + * @param userId User ID. + * @return [io.appwrite.models.MfaProviders] + */ + suspend fun listProviders( + userId: String, + ): io.appwrite.models.MfaProviders { + val apiPath = "/users/{userId}/providers" + .replace("{userId}", userId) + + val apiParams = mutableMapOf( + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.MfaProviders = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.MfaProviders.from(map = it as Map) + } + return client.call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.MfaProviders::class.java, + converter, + ) + } + + +} \ No newline at end of file diff --git a/scripts/publish-module.gradle b/scripts/publish-module.gradle index e32ff84..96b31b2 100644 --- a/scripts/publish-module.gradle +++ b/scripts/publish-module.gradle @@ -63,7 +63,8 @@ publishing { configurations .getByName("releaseCompileClasspath") .resolvedConfiguration - .firstLevelModuleDependencies.forEach { + .firstLevelModuleDependencies + .forEach { def dependency = dependencies.appendNode("dependency") dependency.appendNode("groupId", it.moduleGroup) dependency.appendNode("artifactId", it.moduleName) diff --git a/settings.gradle b/settings.gradle index 73c359b..423c64e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,3 @@ rootProject.name = "Appwrite Android SDK" include ':example' -include ':library' -include ':example-java' \ No newline at end of file +include ':library' \ No newline at end of file