From b042d40f611f75b595da17f2939f3d1566451747 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 30 Jun 2021 20:30:55 +0530 Subject: [PATCH 1/4] feat: bug fixes on android SDK --- README.md | 4 ++-- .../appwrite/android/ui/accounts/AccountsFragment.kt | 7 +++---- library/build.gradle | 4 ++-- library/src/main/java/io/appwrite/Client.kt | 11 +++++++++-- library/src/main/java/io/appwrite/services/Account.kt | 3 ++- library/src/main/java/io/appwrite/services/Storage.kt | 3 +++ 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 296212c..66da83e 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ ![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-android.svg?color=green&style=flat-square) ![License](https://img.shields.io/github/license/appwrite/sdk-for-android.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-0.8.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-0.9.0-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite_io?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite_io) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 0.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).** +**This SDK is compatible with Appwrite server version 0.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).** Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Android SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) diff --git a/example/src/main/java/io/appwrite/android/ui/accounts/AccountsFragment.kt b/example/src/main/java/io/appwrite/android/ui/accounts/AccountsFragment.kt index 746cb7e..a31cced 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 @@ -8,8 +8,8 @@ import android.widget.Toast import androidx.activity.ComponentActivity import androidx.databinding.DataBindingUtil import androidx.fragment.app.Fragment +import androidx.fragment.app.viewModels import androidx.lifecycle.Observer -import androidx.lifecycle.ViewModelProvider import io.appwrite.android.R import io.appwrite.android.databinding.FragmentAccountBinding @@ -17,14 +17,13 @@ import io.appwrite.android.databinding.FragmentAccountBinding class AccountsFragment : Fragment() { private lateinit var binding: FragmentAccountBinding - private lateinit var viewModel: AccountsViewModel + private val viewModel: AccountsViewModel by viewModels() override fun onCreateView( inflater: LayoutInflater , container: ViewGroup? , savedInstanceState: Bundle? - ): View? { - viewModel = ViewModelProvider(this).get(AccountsViewModel::class.java) + ): View { binding = DataBindingUtil.inflate( inflater, R.layout.fragment_account, diff --git a/library/build.gradle b/library/build.gradle index 02a49aa..d5e9a7c 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -28,13 +28,13 @@ android { targetSdkVersion(30) versionCode = 1 versionName = "1.0" - + buildConfigField "String", "SDK_VERSION", "\"${PUBLISH_VERSION}\"" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles("consumer-rules.pro") } buildTypes { - named("release") { + release { minifyEnabled false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 045c61a..c9063fb 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -3,6 +3,7 @@ package io.appwrite import android.content.Context import android.content.pm.PackageManager import com.google.gson.Gson +import io.appwrite.appwrite.BuildConfig import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.JsonExtensions.fromJson import io.appwrite.models.Error @@ -69,7 +70,7 @@ class Client @JvmOverloads constructor( "content-type" to "application/json", "origin" to "appwrite-android://${context.packageName}", "user-agent" to "${context.packageName}/${appVersion}, ${System.getProperty("http.agent")}", - "x-sdk-version" to "appwrite:android:0.0.1", + "x-sdk-version" to "appwrite:android:${BuildConfig.SDK_VERSION}", "x-appwrite-response-format" to "0.8.0" ) config = mutableMapOf() @@ -227,7 +228,13 @@ class Client @JvmOverloads constructor( return@forEach } is List<*> -> { - httpBuilder.addQueryParameter(it.key + "[]", it.value.toString()) + val list = it.value as List<*> + for (index in list.indices) { + httpBuilder.addQueryParameter( + "${it.key}[]", + list[index].toString() + ) + } } else -> { httpBuilder.addQueryParameter(it.key, it.value.toString()) diff --git a/library/src/main/java/io/appwrite/services/Account.kt b/library/src/main/java/io/appwrite/services/Account.kt index ddc78d3..757d32e 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -134,7 +134,8 @@ class Account(private val client: Client) : BaseService(client) { * Use this endpoint to create a JSON Web Token. You can use the resulting JWT * to authenticate on behalf of the current user when working with the * Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes - * from its creation and will be invalid if the user will logout. + * from its creation and will be invalid if the user will logout in that time + * frame. * * @return [Response] */ diff --git a/library/src/main/java/io/appwrite/services/Storage.kt b/library/src/main/java/io/appwrite/services/Storage.kt index 7437f90..6b053d0 100644 --- a/library/src/main/java/io/appwrite/services/Storage.kt +++ b/library/src/main/java/io/appwrite/services/Storage.kt @@ -195,6 +195,7 @@ class Storage(private val client: Client) : BaseService(client) { * @param fileId * @param width * @param height + * @param gravity * @param quality * @param borderWidth * @param borderColor @@ -211,6 +212,7 @@ class Storage(private val client: Client) : BaseService(client) { fileId: String, width: Int? = null, height: Int? = null, + gravity: String? = null, quality: Int? = null, borderWidth: Int? = null, borderColor: String? = null, @@ -224,6 +226,7 @@ class Storage(private val client: Client) : BaseService(client) { val params = mapOf( "width" to width, "height" to height, + "gravity" to gravity, "quality" to quality, "borderWidth" to borderWidth, "borderColor" to borderColor, From 90240313a58663875e672c5643b610642b684696 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 1 Jul 2021 12:15:04 +0530 Subject: [PATCH 2/4] feat: update the spec --- docs/examples/account/get-session.md | 26 +++++++++++++++ library/src/main/java/io/appwrite/Client.kt | 2 +- .../main/java/io/appwrite/services/Account.kt | 32 +++++++++++++++++-- 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 docs/examples/account/get-session.md diff --git a/docs/examples/account/get-session.md b/docs/examples/account/get-session.md new file mode 100644 index 0000000..8451d23 --- /dev/null +++ b/docs/examples/account/get-session.md @@ -0,0 +1,26 @@ +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import io.appwrite.Client +import io.appwrite.services.Account + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val client = Client(applicationContext) + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + + val account = Account(client) + + GlobalScope.launch { + val response = account.getSession( + sessionId = "[SESSION_ID]" + ) + val json = response.body?.string() + } + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index c9063fb..e15f2a5 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -71,7 +71,7 @@ class Client @JvmOverloads constructor( "origin" to "appwrite-android://${context.packageName}", "user-agent" to "${context.packageName}/${appVersion}, ${System.getProperty("http.agent")}", "x-sdk-version" to "appwrite:android:${BuildConfig.SDK_VERSION}", - "x-appwrite-response-format" to "0.8.0" + "x-appwrite-response-format" to "0.9.0" ) config = mutableMapOf() diff --git a/library/src/main/java/io/appwrite/services/Account.kt b/library/src/main/java/io/appwrite/services/Account.kt index 757d32e..bad36e5 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -432,9 +432,10 @@ class Account(private val client: Client) : BaseService(client) { * * Use this endpoint to allow a new user to register an anonymous account in * your project. This route will also create a new session for the user. To - * allow the new user to convert an anonymous account to a normal account - * account, you need to update its [email and - * password](/docs/client/account#accountUpdateEmail). + * allow the new user to convert an anonymous account to a normal account, you + * need to update its [email and + * password](/docs/client/account#accountUpdateEmail) or create an [OAuth2 + * session](/docs/client/account#accountCreateOAuth2Session). * * @return [Response] */ @@ -528,6 +529,31 @@ class Account(private val client: Client) : BaseService(client) { } + /** + * Get Session By ID + * + * Use this endpoint to get a logged in user's session using a Session ID. + * Inputting 'current' will return the current session being used. + * + * @param sessionId + * @return [Response] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun getSession( + sessionId: String + ): Response { + val path = "/account/sessions/{sessionId}".replace("{sessionId}", sessionId) + val params = mapOf( + ) + + val headers = mapOf( + "content-type" to "application/json" + ) + + return client.call("GET", path, headers, params) + } + /** * Delete Account Session * From 6e73cb7558769eb13df21f4d589439b9bb86a252 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 2 Jul 2021 13:01:41 +0530 Subject: [PATCH 3/4] feat: snapshot release --- README.md | 4 ++-- build.gradle | 2 +- library/build.gradle | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 66da83e..f29fa1a 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:0.0.1") +implementation("io.appwrite:sdk-for-android:0.0.1-SNAPSHOT") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 0.0.1 + 0.0.1-SNAPSHOT ``` diff --git a/build.gradle b/build.gradle index ee004cf..5f191ce 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'io.github.gradle-nexus.publish-plugin' // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = "1.4.31" - version '0.0.1' + version '0.0.1-SNAPSHOT' repositories { maven { url "https://plugins.gradle.org/m2/" } google() diff --git a/library/build.gradle b/library/build.gradle index d5e9a7c..c9289ab 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -7,7 +7,7 @@ plugins { ext { PUBLISH_GROUP_ID = 'io.appwrite' PUBLISH_ARTIFACT_ID = 'sdk-for-android' - PUBLISH_VERSION = '0.0.1' + PUBLISH_VERSION = '0.0.1-SNAPSHOT' POM_URL = 'https://github.com/appwrite/sdk-for-android' POM_SCM_URL = 'https://github.com/appwrite/sdk-for-android' POM_ISSUE_URL = 'https://github.com/appwrite/sdk-for-android/issues' From ab3029bdb5fab421a9194f6aa69b71f186099c75 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 2 Jul 2021 17:24:06 +0530 Subject: [PATCH 4/4] feat: update android versions --- README.md | 4 ++-- build.gradle | 2 +- library/build.gradle | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f29fa1a..66da83e 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:0.0.1-SNAPSHOT") +implementation("io.appwrite:sdk-for-android:0.0.1") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 0.0.1-SNAPSHOT + 0.0.1 ``` diff --git a/build.gradle b/build.gradle index 5f191ce..ee004cf 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'io.github.gradle-nexus.publish-plugin' // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = "1.4.31" - version '0.0.1-SNAPSHOT' + version '0.0.1' repositories { maven { url "https://plugins.gradle.org/m2/" } google() diff --git a/library/build.gradle b/library/build.gradle index c9289ab..d5e9a7c 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -7,7 +7,7 @@ plugins { ext { PUBLISH_GROUP_ID = 'io.appwrite' PUBLISH_ARTIFACT_ID = 'sdk-for-android' - PUBLISH_VERSION = '0.0.1-SNAPSHOT' + PUBLISH_VERSION = '0.0.1' POM_URL = 'https://github.com/appwrite/sdk-for-android' POM_SCM_URL = 'https://github.com/appwrite/sdk-for-android' POM_ISSUE_URL = 'https://github.com/appwrite/sdk-for-android/issues'