From 6761dcac106e906548f579b95701c97651157f3b Mon Sep 17 00:00:00 2001 From: root Date: Fri, 25 Jul 2025 11:45:58 +0000 Subject: [PATCH 1/5] update readme --- README.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 745f21c..c15bc26 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ In order to capture the Appwrite OAuth callback url, the following activity need - + @@ -91,8 +91,8 @@ import io.appwrite.Client import io.appwrite.services.Account val client = Client(context) - .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint - .setProject("5df5acd0d48c2") // Your project ID + .setEndpoint("https:///v1") // Your API Endpoint + .setProject("") // Your project ID .setSelfSigned(true) // Remove in production ``` @@ -123,8 +123,8 @@ import io.appwrite.services.Account import io.appwrite.ID val client = Client(context) - .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint - .setProject("5df5acd0d48c2") // Your project ID + .setEndpoint("https:///v1") // Your API Endpoint + .setProject("") // Your project ID .setSelfSigned(true) // Remove in production val account = Account(client) @@ -136,7 +136,79 @@ val user = account.create( ) ``` +### Type Safety with Models + +The Appwrite Android SDK provides type safety when working with database documents through generic methods. Methods like `listDocuments`, `getDocument`, and others accept a `nestedType` parameter that allows you to specify your custom model type for full type safety. + +```kotlin +data class Book( + val name: String, + val author: String, + val releaseYear: String? = null, + val category: String? = null, + val genre: List? = null, + val isCheckedOut: Boolean +) + +val databases = Databases(client) + +try { + val documents = databases.listDocuments( + databaseId = "your-database-id", + collectionId = "your-collection-id", + nestedType = Book::class.java // Pass in your custom model type + ) + + for (book in documents.documents) { + Log.d("Appwrite", "Book: ${book.name} by ${book.author}") // Now you have full type safety + } +} catch (e: AppwriteException) { + Log.e("Appwrite", e.message ?: "Unknown error") +} +``` + +**Tip**: You can use the `appwrite types` command to automatically generate model definitions based on your Appwrite database schema. Learn more about [type generation](https://appwrite.io/docs/products/databases/type-generation). + +### Working with Model Methods + +All Appwrite models come with built-in methods for data conversion and manipulation: + +**`toMap()`** - Converts a model instance to a Map format, useful for debugging or manual data manipulation: +```kotlin +val account = Account(client) +val user = account.get() +val userMap = user.toMap() +Log.d("Appwrite", userMap.toString()) // Prints all user properties as a Map +``` + +**`from(map:, nestedType:)`** - Creates a model instance from a Map, useful when working with raw data: +```kotlin +val userData: Map = mapOf( + "\$id" to "123", + "name" to "John", + "email" to "john@example.com" +) +val user = User.from(userData, User::class.java) +``` + +**JSON Serialization** - Models can be easily converted to/from JSON using Gson (which the SDK uses internally): +```kotlin +import com.google.gson.Gson + +val account = Account(client) +val user = account.get() + +// Convert to JSON +val gson = Gson() +val jsonString = gson.toJson(user) +Log.d("Appwrite", "User JSON: $jsonString") + +// Convert from JSON +val userFromJson = gson.fromJson(jsonString, User::class.java) +``` + ### Error Handling + The Appwrite Android SDK raises an `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example. ```kotlin From bfe1e1730b9bbd2c91bdeb6140528d9412c0bb13 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 6 Aug 2025 07:46:00 +0000 Subject: [PATCH 2/5] update maven deployment --- README.md | 59 ++++++++++++++++++- .../java/functions/create-execution.md | 2 +- .../kotlin/functions/create-execution.md | 2 +- library/src/main/java/io/appwrite/Client.kt | 2 +- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c15bc26..db65d39 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:8.2.0") +implementation("io.appwrite:sdk-for-android:8.2.2") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 8.2.0 + 8.2.2 ``` @@ -140,6 +140,7 @@ val user = account.create( The Appwrite Android SDK provides type safety when working with database documents through generic methods. Methods like `listDocuments`, `getDocument`, and others accept a `nestedType` parameter that allows you to specify your custom model type for full type safety. +**Kotlin:** ```kotlin data class Book( val name: String, @@ -167,6 +168,60 @@ try { } ``` +**Java:** +```java +public class Book { + private String name; + private String author; + private String releaseYear; + private String category; + private List genre; + private boolean isCheckedOut; + + // Constructor + public Book(String name, String author, boolean isCheckedOut) { + this.name = name; + this.author = author; + this.isCheckedOut = isCheckedOut; + } + + // Getters and setters + public String getName() { return name; } + public void setName(String name) { this.name = name; } + + public String getAuthor() { return author; } + public void setAuthor(String author) { this.author = author; } + + public String getReleaseYear() { return releaseYear; } + public void setReleaseYear(String releaseYear) { this.releaseYear = releaseYear; } + + public String getCategory() { return category; } + public void setCategory(String category) { this.category = category; } + + public List getGenre() { return genre; } + public void setGenre(List genre) { this.genre = genre; } + + public boolean isCheckedOut() { return isCheckedOut; } + public void setCheckedOut(boolean checkedOut) { isCheckedOut = checkedOut; } +} + +Databases databases = new Databases(client); + +try { + DocumentList documents = databases.listDocuments( + "your-database-id", + "your-collection-id", + Book.class // Pass in your custom model type + ); + + for (Book book : documents.getDocuments()) { + Log.d("Appwrite", "Book: " + book.getName() + " by " + book.getAuthor()); // Now you have full type safety + } +} catch (AppwriteException e) { + Log.e("Appwrite", e.getMessage() != null ? e.getMessage() : "Unknown error"); +} +``` + **Tip**: You can use the `appwrite types` command to automatically generate model definitions based on your Appwrite database schema. Learn more about [type generation](https://appwrite.io/docs/products/databases/type-generation). ### Working with Model Methods diff --git a/docs/examples/java/functions/create-execution.md b/docs/examples/java/functions/create-execution.md index c138b0e..06c5027 100644 --- a/docs/examples/java/functions/create-execution.md +++ b/docs/examples/java/functions/create-execution.md @@ -15,7 +15,7 @@ functions.createExecution( "", // path (optional) ExecutionMethod.GET, // method (optional) mapOf( "a" to "b" ), // headers (optional) - "", // scheduledAt (optional) + "", // scheduledAt (optional) new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); diff --git a/docs/examples/kotlin/functions/create-execution.md b/docs/examples/kotlin/functions/create-execution.md index cb7c60b..5e1950b 100644 --- a/docs/examples/kotlin/functions/create-execution.md +++ b/docs/examples/kotlin/functions/create-execution.md @@ -15,5 +15,5 @@ val result = functions.createExecution( path = "", // (optional) method = ExecutionMethod.GET, // (optional) headers = mapOf( "a" to "b" ), // (optional) - scheduledAt = "", // (optional) + scheduledAt = "", // (optional) ) \ 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 bf0480f..1dbeda8 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -87,7 +87,7 @@ class Client @JvmOverloads constructor( "x-sdk-name" to "Android", "x-sdk-platform" to "client", "x-sdk-language" to "android", - "x-sdk-version" to "8.2.0", + "x-sdk-version" to "8.2.2", "x-appwrite-response-format" to "1.7.0" ) config = mutableMapOf() From 9e72610cfd498873dc4becb666ac36fb64dc11c0 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 6 Aug 2025 07:52:59 +0000 Subject: [PATCH 3/5] chore: update maven dependencies --- scripts/publish-config.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/publish-config.gradle b/scripts/publish-config.gradle index 299c6c4..5934f92 100644 --- a/scripts/publish-config.gradle +++ b/scripts/publish-config.gradle @@ -30,8 +30,8 @@ nexusPublishing { stagingProfileId = sonatypeStagingProfileId username = ossrhUsername password = ossrhPassword - nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) - snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/")) + snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/")) } } } \ No newline at end of file From 7b68746eae35c38d362c7107ff913abbaa369cdd Mon Sep 17 00:00:00 2001 From: root Date: Wed, 6 Aug 2025 08:09:33 +0000 Subject: [PATCH 4/5] chore: regenerate sdk --- README.md | 4 ++-- library/src/main/java/io/appwrite/Client.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index db65d39..234943c 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:8.2.2") +implementation("io.appwrite:sdk-for-android:8.2.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 8.2.2 + 8.2.0 ``` diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 1dbeda8..bf0480f 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -87,7 +87,7 @@ class Client @JvmOverloads constructor( "x-sdk-name" to "Android", "x-sdk-platform" to "client", "x-sdk-language" to "android", - "x-sdk-version" to "8.2.2", + "x-sdk-version" to "8.2.0", "x-appwrite-response-format" to "1.7.0" ) config = mutableMapOf() From 2f6378fda4b246cf0d15f63b22d651ab8a82dfec Mon Sep 17 00:00:00 2001 From: root Date: Wed, 6 Aug 2025 08:22:53 +0000 Subject: [PATCH 5/5] update version --- README.md | 4 ++-- library/src/main/java/io/appwrite/Client.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 234943c..db65d39 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:8.2.0") +implementation("io.appwrite:sdk-for-android:8.2.2") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 8.2.0 + 8.2.2 ``` diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index bf0480f..1dbeda8 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -87,7 +87,7 @@ class Client @JvmOverloads constructor( "x-sdk-name" to "Android", "x-sdk-platform" to "client", "x-sdk-language" to "android", - "x-sdk-version" to "8.2.0", + "x-sdk-version" to "8.2.2", "x-appwrite-response-format" to "1.7.0" ) config = mutableMapOf()