From 4ec6a521bae8f7fb8f737b4aeeefde532ea59627 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 May 2025 05:14:35 +0000 Subject: [PATCH 1/3] chore: add setDevKey and upsertDocument methods --- CHANGELOG.md | 9 ++- README.md | 4 +- .../java/databases/create-documents.md | 24 ++++++++ .../kotlin/databases/create-documents.md | 15 +++++ library/src/main/java/io/appwrite/Client.kt | 2 +- .../java/io/appwrite/services/Databases.kt | 58 +++++++++++++++++++ 6 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 docs/examples/java/databases/create-documents.md create mode 100644 docs/examples/kotlin/databases/create-documents.md diff --git a/CHANGELOG.md b/CHANGELOG.md index fa4d35e..8406e63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,8 @@ -# Change Log \ No newline at end of file +# Change Log + +## 8.0.0 + +* Add `token` param to `getFilePreview` and `getFileView` for File tokens usage +* Update default `quality` for `getFilePreview` from 0 to -1 +* Remove `Gif` from ImageFormat enum +* Remove `search` param from `listExecutions` method \ No newline at end of file diff --git a/README.md b/README.md index f00352f..1eee246 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.0.0") +implementation("io.appwrite:sdk-for-android:8.0.1") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 8.0.0 + 8.0.1 ``` diff --git a/docs/examples/java/databases/create-documents.md b/docs/examples/java/databases/create-documents.md new file mode 100644 index 0000000..dbdc64f --- /dev/null +++ b/docs/examples/java/databases/create-documents.md @@ -0,0 +1,24 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Databases; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setKey(""); // + +Databases databases = new Databases(client); + +databases.createDocuments( + "", // databaseId + "", // collectionId + listOf(), // documents + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + diff --git a/docs/examples/kotlin/databases/create-documents.md b/docs/examples/kotlin/databases/create-documents.md new file mode 100644 index 0000000..33635b4 --- /dev/null +++ b/docs/examples/kotlin/databases/create-documents.md @@ -0,0 +1,15 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Databases + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setKey("") // + +val databases = Databases(client) + +val result = databases.createDocuments( + databaseId = "", + collectionId = "", + documents = listOf(), +) \ 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 7905e40..6ea42ae 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.0.0", + "x-sdk-version" to "8.0.1", "x-appwrite-response-format" to "1.7.0" ) config = mutableMapOf() diff --git a/library/src/main/java/io/appwrite/services/Databases.kt b/library/src/main/java/io/appwrite/services/Databases.kt index b6559a9..73384a1 100644 --- a/library/src/main/java/io/appwrite/services/Databases.kt +++ b/library/src/main/java/io/appwrite/services/Databases.kt @@ -146,6 +146,64 @@ class Databases(client: Client) : Service(client) { nestedType = classOf(), ) + /** + * Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * + * @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). Make sure to define attributes before creating documents. + * @param documents Array of documents data as JSON objects. + * @return [io.appwrite.models.DocumentList] + */ + suspend fun createDocuments( + databaseId: String, + collectionId: String, + documents: List, + nestedType: Class, + ): io.appwrite.models.DocumentList { + val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + + val apiParams = mutableMapOf( + "documents" to documents, + ) + val apiHeaders = mutableMapOf( + "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( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * + * @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). Make sure to define attributes before creating documents. + * @param documents Array of documents data as JSON objects. + * @return [io.appwrite.models.DocumentList] + */ + @Throws(AppwriteException::class) + suspend fun createDocuments( + databaseId: String, + collectionId: String, + documents: List, + ): io.appwrite.models.DocumentList> = createDocuments( + databaseId, + collectionId, + documents, + nestedType = classOf(), + ) + /** * Get a document by its unique ID. This endpoint response returns a JSON object with the document data. * From 881da2e1b1662f1c965d7d816308ecf725bc9497 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 May 2025 05:16:30 +0000 Subject: [PATCH 2/3] chore: add setDevkey and upsertDocument methods --- ...create-documents.md => upsert-document.md} | 8 +- ...create-documents.md => upsert-document.md} | 8 +- library/src/main/java/io/appwrite/Client.kt | 15 ++++ .../java/io/appwrite/services/Databases.kt | 84 +++++++++++-------- 4 files changed, 74 insertions(+), 41 deletions(-) rename docs/examples/java/databases/{create-documents.md => upsert-document.md} (73%) rename docs/examples/kotlin/databases/{create-documents.md => upsert-document.md} (60%) diff --git a/docs/examples/java/databases/create-documents.md b/docs/examples/java/databases/upsert-document.md similarity index 73% rename from docs/examples/java/databases/create-documents.md rename to docs/examples/java/databases/upsert-document.md index dbdc64f..868576b 100644 --- a/docs/examples/java/databases/create-documents.md +++ b/docs/examples/java/databases/upsert-document.md @@ -4,14 +4,16 @@ import io.appwrite.services.Databases; Client client = new Client(context) .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setKey(""); // + .setProject(""); // Your project ID Databases databases = new Databases(client); -databases.createDocuments( +databases.upsertDocument( "", // databaseId "", // collectionId - listOf(), // documents + "", // documentId + mapOf( "a" to "b" ), // data + listOf("read("any")"), // permissions (optional) new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); diff --git a/docs/examples/kotlin/databases/create-documents.md b/docs/examples/kotlin/databases/upsert-document.md similarity index 60% rename from docs/examples/kotlin/databases/create-documents.md rename to docs/examples/kotlin/databases/upsert-document.md index 33635b4..a31dfc8 100644 --- a/docs/examples/kotlin/databases/create-documents.md +++ b/docs/examples/kotlin/databases/upsert-document.md @@ -4,12 +4,14 @@ import io.appwrite.services.Databases val client = Client(context) .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setKey("") // + .setProject("") // Your project ID val databases = Databases(client) -val result = databases.createDocuments( +val result = databases.upsertDocument( databaseId = "", collectionId = "", - documents = listOf(), + documentId = "", + data = mapOf( "a" to "b" ), + permissions = listOf("read("any")"), // (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 6ea42ae..f223cef 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -153,6 +153,21 @@ class Client @JvmOverloads constructor( return this } + /** + * Set DevKey + * + * Your secret dev API key + * + * @param {string} devkey + * + * @return this + */ + fun setDevKey(value: String): Client { + config["devKey"] = value + addHeader("x-appwrite-dev-key", value) + return this + } + /** * Set self Signed * diff --git a/library/src/main/java/io/appwrite/services/Databases.kt b/library/src/main/java/io/appwrite/services/Databases.kt index 73384a1..2601af2 100644 --- a/library/src/main/java/io/appwrite/services/Databases.kt +++ b/library/src/main/java/io/appwrite/services/Databases.kt @@ -147,35 +147,38 @@ class Databases(client: Client) : Service(client) { ) /** - * Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * Get a document by its unique ID. This endpoint response returns a JSON object with the document data. * * @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). Make sure to define attributes before creating documents. - * @param documents Array of documents data as JSON objects. - * @return [io.appwrite.models.DocumentList] + * @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/queries). Maximum of 100 queries are allowed, each 4096 characters long. + * @return [io.appwrite.models.Document] */ - suspend fun createDocuments( + @JvmOverloads + suspend fun getDocument( databaseId: String, collectionId: String, - documents: List, + documentId: String, + queries: List? = null, nestedType: Class, - ): io.appwrite.models.DocumentList { - val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents" + ): io.appwrite.models.Document { + val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}" .replace("{databaseId}", databaseId) .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) val apiParams = mutableMapOf( - "documents" to documents, + "queries" to queries, ) val apiHeaders = mutableMapOf( - "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.DocumentList = { + val converter: (Any) -> io.appwrite.models.Document = { @Suppress("UNCHECKED_CAST") - io.appwrite.models.DocumentList.from(map = it as Map, nestedType) + io.appwrite.models.Document.from(map = it as Map, nestedType) } return client.call( - "POST", + "GET", apiPath, apiHeaders, apiParams, @@ -185,40 +188,46 @@ class Databases(client: Client) : Service(client) { } /** - * Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * Get a document by its unique ID. This endpoint response returns a JSON object with the document data. * * @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). Make sure to define attributes before creating documents. - * @param documents Array of documents data as JSON objects. - * @return [io.appwrite.models.DocumentList] + * @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/queries). Maximum of 100 queries are allowed, each 4096 characters long. + * @return [io.appwrite.models.Document] */ + @JvmOverloads @Throws(AppwriteException::class) - suspend fun createDocuments( + suspend fun getDocument( databaseId: String, collectionId: String, - documents: List, - ): io.appwrite.models.DocumentList> = createDocuments( + documentId: String, + queries: List? = null, + ): io.appwrite.models.Document> = getDocument( databaseId, collectionId, - documents, + documentId, + queries, nestedType = classOf(), ) /** - * Get a document by its unique ID. This endpoint response returns a JSON object with the document data. + * Create or update a Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. * * @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 collectionId Collection ID. * @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/queries). Maximum of 100 queries are allowed, each 4096 characters long. + * @param data Document data as JSON object. Include all required attributes of the document to be created or updated. + * @param permissions An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). * @return [io.appwrite.models.Document] */ @JvmOverloads - suspend fun getDocument( + suspend fun upsertDocument( databaseId: String, collectionId: String, documentId: String, - queries: List? = null, + data: Any, + permissions: List? = null, nestedType: Class, ): io.appwrite.models.Document { val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}" @@ -227,16 +236,18 @@ class Databases(client: Client) : Service(client) { .replace("{documentId}", documentId) val apiParams = mutableMapOf( - "queries" to queries, + "data" to data, + "permissions" to permissions, ) val apiHeaders = mutableMapOf( + "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( - "GET", + "PUT", apiPath, apiHeaders, apiParams, @@ -246,26 +257,29 @@ class Databases(client: Client) : Service(client) { } /** - * Get a document by its unique ID. This endpoint response returns a JSON object with the document data. + * Create or update a Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. * * @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 collectionId Collection ID. * @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/queries). Maximum of 100 queries are allowed, each 4096 characters long. + * @param data Document data as JSON object. Include all required attributes of the document to be created or updated. + * @param permissions An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). * @return [io.appwrite.models.Document] */ @JvmOverloads @Throws(AppwriteException::class) - suspend fun getDocument( + suspend fun upsertDocument( databaseId: String, collectionId: String, documentId: String, - queries: List? = null, - ): io.appwrite.models.Document> = getDocument( + data: Any, + permissions: List? = null, + ): io.appwrite.models.Document> = upsertDocument( databaseId, collectionId, documentId, - queries, + data, + permissions, nestedType = classOf(), ) From 151e7a021f87bb3dceeec3e0a007779f9b6a2a24 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 May 2025 06:27:29 +0000 Subject: [PATCH 3/3] chore: bump to minor 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 1eee246..6bfc46c 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.0.1") +implementation("io.appwrite:sdk-for-android:8.1.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 8.0.1 + 8.1.0 ``` diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index f223cef..5f12d7f 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.0.1", + "x-sdk-version" to "8.1.0", "x-appwrite-response-format" to "1.7.0" ) config = mutableMapOf()