diff --git a/CHANGELOG.md b/CHANGELOG.md index b4dc1a6..b2a80f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.1.0] - TBD +## [0.2.0] - TBD ### Added - Initial release of Appwrite Rust SDK @@ -29,9 +29,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Databases service with 69 methods - Functions service with 26 methods - Graphql service with 2 methods -- Health service with 29 methods +- Health service with 24 methods - Locale service with 8 methods - Messaging service with 56 methods +- Project service with 5 methods - Sites service with 25 methods - Storage service with 13 methods - TablesDB service with 69 methods @@ -331,10 +332,7 @@ The Health service allows you to both validate and monitor your Appwrite server& - `get_db()` - Check the Appwrite database servers are up and connection is successful. - `get_pub_sub()` - Check the Appwrite pub-sub servers are up and connection is successful. - `get_queue_audits()` - Get the number of audit logs that are waiting to be processed in the Appwrite internal queue server. -- `get_queue_billing_project_aggregation()` - Get billing project aggregation queue. -- `get_queue_billing_team_aggregation()` - Get billing team aggregation queue. - `get_queue_builds()` - Get the number of builds that are waiting to be processed in the Appwrite internal queue server. -- `get_queue_priority_builds()` - Get the priority builds queue size. - `get_queue_certificates()` - Get the number of certificates that are waiting to be issued against [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue server. - `get_queue_databases()` - Get the number of database changes that are waiting to be processed in the Appwrite internal queue server. - `get_queue_deletes()` - Get the number of background destructive changes that are waiting to be processed in the Appwrite internal queue server. @@ -345,10 +343,8 @@ The Health service allows you to both validate and monitor your Appwrite server& - `get_queue_mails()` - Get the number of mails that are waiting to be processed in the Appwrite internal queue server. - `get_queue_messaging()` - Get the number of messages that are waiting to be processed in the Appwrite internal queue server. - `get_queue_migrations()` - Get the number of migrations that are waiting to be processed in the Appwrite internal queue server. -- `get_queue_region_manager()` - Get region manager queue. - `get_queue_stats_resources()` - Get the number of metrics that are waiting to be processed in the Appwrite stats resources queue. - `get_queue_usage()` - Get the number of metrics that are waiting to be processed in the Appwrite internal queue server. -- `get_queue_threats()` - Get threats queue. - `get_queue_webhooks()` - Get the number of webhooks that are waiting to be processed in the Appwrite internal queue server. - `get_storage()` - Check the Appwrite storage device is up and connection is successful. - `get_storage_local()` - Check the Appwrite local storage device is up and connection is successful. @@ -435,6 +431,14 @@ The Messaging service allows you to send messages to any provider type (SMTP, pu - `delete_subscriber()` - Delete a subscriber by its unique ID. +#### Project +The Project service allows you to manage all the projects in your Appwrite server. +- `list_variables()` - Get a list of all project environment variables. +- `create_variable()` - Create a new project environment variable. These variables can be accessed by all functions and sites in the project. +- `get_variable()` - Get a variable by its unique ID. +- `update_variable()` - Update variable by its unique ID. +- `delete_variable()` - Delete a variable by its unique ID. + #### Sites The Sites Service allows you view, create and manage your web applications. - `list()` - Get a list of all the project's sites. You can use the query params to filter your results. @@ -849,4 +853,4 @@ If you want to generate a token for a custom authentication flow, use the [POST - File upload examples - Query builder documentation -[0.1.0]: https://github.com/appwrite/sdk-for-rust/releases/tag/0.1.0 +[0.2.0]: https://github.com/appwrite/sdk-for-rust/releases/tag/0.2.0 diff --git a/Cargo.toml b/Cargo.toml index b705a6d..1d9a042 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "appwrite" -version = "0.1.0" +version = "0.2.0" edition = "2021" rust-version = "1.83" authors = ["appwrite"] diff --git a/README.md b/README.md index 0fd6227..3ebe30a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Crates.io](https://img.shields.io/crates/v/appwrite.svg)](https://crates.io/crates/appwrite) [![Documentation](https://docs.rs/appwrite/badge.svg)](https://docs.rs/appwrite) -**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-rust/releases).** +**This SDK is compatible with Appwrite server version 1.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-rust/releases).** Appwrite is an open-source backend as a service server that abstracts and simplifies 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 Rust 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) @@ -17,7 +17,7 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -appwrite = "0.1.0" +appwrite = "0.2.0" tokio = { version = "1.48", features = ["full"] } ``` diff --git a/src/client.rs b/src/client.rs index 40a0f55..42aadb3 100644 --- a/src/client.rs +++ b/src/client.rs @@ -89,11 +89,11 @@ impl Client { pub fn new() -> Self { let mut headers = HeaderMap::new(); headers.insert("X-Appwrite-Response-Format", "1.9.0".parse().unwrap()); - headers.insert("user-agent", format!("AppwriteRustSDK/0.1.0 ({}; {})", std::env::consts::OS, std::env::consts::ARCH).parse().unwrap()); + headers.insert("user-agent", format!("AppwriteRustSDK/0.2.0 ({}; {})", std::env::consts::OS, std::env::consts::ARCH).parse().unwrap()); headers.insert("x-sdk-name", "Rust".parse().unwrap()); headers.insert("x-sdk-platform", "server".parse().unwrap()); headers.insert("x-sdk-language", "rust".parse().unwrap()); - headers.insert("x-sdk-version", "0.1.0".parse().unwrap()); + headers.insert("x-sdk-version", "0.2.0".parse().unwrap()); let config = Config { endpoint: "https://cloud.appwrite.io/v1".to_string(), @@ -618,11 +618,7 @@ impl Client { if file_size <= chunk_size as u64 { let state = self.state.load_full(); - let url = if let Some(id) = &options.upload_id { - format!("{}{}/{}", state.config.endpoint, path, id) - } else { - format!("{}{}", state.config.endpoint, path) - }; + let url = format!("{}{}", state.config.endpoint, path); let result = self.single_file_upload(&url, headers, params, param_name, &input_file).await?; diff --git a/src/enums/backup_services.rs b/src/enums/backup_services.rs index 97b0a3c..62cfc48 100644 --- a/src/enums/backup_services.rs +++ b/src/enums/backup_services.rs @@ -5,6 +5,12 @@ pub enum BackupServices { #[serde(rename = "databases")] #[default] Databases, + #[serde(rename = "tablesdb")] + Tablesdb, + #[serde(rename = "documentsdb")] + Documentsdb, + #[serde(rename = "vectorsdb")] + Vectorsdb, #[serde(rename = "functions")] Functions, #[serde(rename = "storage")] @@ -16,6 +22,9 @@ impl BackupServices { pub fn as_str(&self) -> &str { match self { BackupServices::Databases => "databases", + BackupServices::Tablesdb => "tablesdb", + BackupServices::Documentsdb => "documentsdb", + BackupServices::Vectorsdb => "vectorsdb", BackupServices::Functions => "functions", BackupServices::Storage => "storage", } diff --git a/src/enums/build_runtime.rs b/src/enums/build_runtime.rs index 4114491..d392f98 100644 --- a/src/enums/build_runtime.rs +++ b/src/enums/build_runtime.rs @@ -175,178 +175,6 @@ pub enum BuildRuntime { Flutter335, #[serde(rename = "flutter-3.38")] Flutter338, - #[serde(rename = "node-14.5-rc")] - Node145Rc, - #[serde(rename = "node-16.0-rc")] - Node160Rc, - #[serde(rename = "node-18.0-rc")] - Node180Rc, - #[serde(rename = "node-19.0-rc")] - Node190Rc, - #[serde(rename = "node-20.0-rc")] - Node200Rc, - #[serde(rename = "node-21.0-rc")] - Node210Rc, - #[serde(rename = "node-22-rc")] - Node22Rc, - #[serde(rename = "node-23-rc")] - Node23Rc, - #[serde(rename = "node-24-rc")] - Node24Rc, - #[serde(rename = "node-25-rc")] - Node25Rc, - #[serde(rename = "php-8.0-rc")] - Php80Rc, - #[serde(rename = "php-8.1-rc")] - Php81Rc, - #[serde(rename = "php-8.2-rc")] - Php82Rc, - #[serde(rename = "php-8.3-rc")] - Php83Rc, - #[serde(rename = "php-8.4-rc")] - Php84Rc, - #[serde(rename = "ruby-3.0-rc")] - Ruby30Rc, - #[serde(rename = "ruby-3.1-rc")] - Ruby31Rc, - #[serde(rename = "ruby-3.2-rc")] - Ruby32Rc, - #[serde(rename = "ruby-3.3-rc")] - Ruby33Rc, - #[serde(rename = "ruby-3.4-rc")] - Ruby34Rc, - #[serde(rename = "ruby-4.0-rc")] - Ruby40Rc, - #[serde(rename = "python-3.8-rc")] - Python38Rc, - #[serde(rename = "python-3.9-rc")] - Python39Rc, - #[serde(rename = "python-3.10-rc")] - Python310Rc, - #[serde(rename = "python-3.11-rc")] - Python311Rc, - #[serde(rename = "python-3.12-rc")] - Python312Rc, - #[serde(rename = "python-3.13-rc")] - Python313Rc, - #[serde(rename = "python-3.14-rc")] - Python314Rc, - #[serde(rename = "python-ml-3.11-rc")] - PythonMl311Rc, - #[serde(rename = "python-ml-3.12-rc")] - PythonMl312Rc, - #[serde(rename = "python-ml-3.13-rc")] - PythonMl313Rc, - #[serde(rename = "deno-1.40-rc")] - Deno140Rc, - #[serde(rename = "deno-1.46-rc")] - Deno146Rc, - #[serde(rename = "deno-2.0-rc")] - Deno20Rc, - #[serde(rename = "deno-2.5-rc")] - Deno25Rc, - #[serde(rename = "deno-2.6-rc")] - Deno26Rc, - #[serde(rename = "dart-2.15-rc")] - Dart215Rc, - #[serde(rename = "dart-2.16-rc")] - Dart216Rc, - #[serde(rename = "dart-2.17-rc")] - Dart217Rc, - #[serde(rename = "dart-2.18-rc")] - Dart218Rc, - #[serde(rename = "dart-2.19-rc")] - Dart219Rc, - #[serde(rename = "dart-3.0-rc")] - Dart30Rc, - #[serde(rename = "dart-3.1-rc")] - Dart31Rc, - #[serde(rename = "dart-3.3-rc")] - Dart33Rc, - #[serde(rename = "dart-3.5-rc")] - Dart35Rc, - #[serde(rename = "dart-3.8-rc")] - Dart38Rc, - #[serde(rename = "dart-3.9-rc")] - Dart39Rc, - #[serde(rename = "dart-3.10-rc")] - Dart310Rc, - #[serde(rename = "dotnet-6.0-rc")] - Dotnet60Rc, - #[serde(rename = "dotnet-7.0-rc")] - Dotnet70Rc, - #[serde(rename = "dotnet-8.0-rc")] - Dotnet80Rc, - #[serde(rename = "dotnet-10-rc")] - Dotnet10Rc, - #[serde(rename = "java-8.0-rc")] - Java80Rc, - #[serde(rename = "java-11.0-rc")] - Java110Rc, - #[serde(rename = "java-17.0-rc")] - Java170Rc, - #[serde(rename = "java-18.0-rc")] - Java180Rc, - #[serde(rename = "java-21.0-rc")] - Java210Rc, - #[serde(rename = "java-22-rc")] - Java22Rc, - #[serde(rename = "java-25-rc")] - Java25Rc, - #[serde(rename = "swift-5.5-rc")] - Swift55Rc, - #[serde(rename = "swift-5.8-rc")] - Swift58Rc, - #[serde(rename = "swift-5.9-rc")] - Swift59Rc, - #[serde(rename = "swift-5.10-rc")] - Swift510Rc, - #[serde(rename = "swift-6.2-rc")] - Swift62Rc, - #[serde(rename = "kotlin-1.6-rc")] - Kotlin16Rc, - #[serde(rename = "kotlin-1.8-rc")] - Kotlin18Rc, - #[serde(rename = "kotlin-1.9-rc")] - Kotlin19Rc, - #[serde(rename = "kotlin-2.0-rc")] - Kotlin20Rc, - #[serde(rename = "kotlin-2.3-rc")] - Kotlin23Rc, - #[serde(rename = "cpp-17-rc")] - Cpp17Rc, - #[serde(rename = "cpp-20-rc")] - Cpp20Rc, - #[serde(rename = "bun-1.0-rc")] - Bun10Rc, - #[serde(rename = "bun-1.1-rc")] - Bun11Rc, - #[serde(rename = "bun-1.2-rc")] - Bun12Rc, - #[serde(rename = "bun-1.3-rc")] - Bun13Rc, - #[serde(rename = "go-1.23-rc")] - Go123Rc, - #[serde(rename = "go-1.24-rc")] - Go124Rc, - #[serde(rename = "go-1.25-rc")] - Go125Rc, - #[serde(rename = "go-1.26-rc")] - Go126Rc, - #[serde(rename = "static-1-rc")] - Static1Rc, - #[serde(rename = "flutter-3.24-rc")] - Flutter324Rc, - #[serde(rename = "flutter-3.27-rc")] - Flutter327Rc, - #[serde(rename = "flutter-3.29-rc")] - Flutter329Rc, - #[serde(rename = "flutter-3.32-rc")] - Flutter332Rc, - #[serde(rename = "flutter-3.35-rc")] - Flutter335Rc, - #[serde(rename = "flutter-3.38-rc")] - Flutter338Rc, } impl BuildRuntime { @@ -439,92 +267,6 @@ impl BuildRuntime { BuildRuntime::Flutter332 => "flutter-3.32", BuildRuntime::Flutter335 => "flutter-3.35", BuildRuntime::Flutter338 => "flutter-3.38", - BuildRuntime::Node145Rc => "node-14.5-rc", - BuildRuntime::Node160Rc => "node-16.0-rc", - BuildRuntime::Node180Rc => "node-18.0-rc", - BuildRuntime::Node190Rc => "node-19.0-rc", - BuildRuntime::Node200Rc => "node-20.0-rc", - BuildRuntime::Node210Rc => "node-21.0-rc", - BuildRuntime::Node22Rc => "node-22-rc", - BuildRuntime::Node23Rc => "node-23-rc", - BuildRuntime::Node24Rc => "node-24-rc", - BuildRuntime::Node25Rc => "node-25-rc", - BuildRuntime::Php80Rc => "php-8.0-rc", - BuildRuntime::Php81Rc => "php-8.1-rc", - BuildRuntime::Php82Rc => "php-8.2-rc", - BuildRuntime::Php83Rc => "php-8.3-rc", - BuildRuntime::Php84Rc => "php-8.4-rc", - BuildRuntime::Ruby30Rc => "ruby-3.0-rc", - BuildRuntime::Ruby31Rc => "ruby-3.1-rc", - BuildRuntime::Ruby32Rc => "ruby-3.2-rc", - BuildRuntime::Ruby33Rc => "ruby-3.3-rc", - BuildRuntime::Ruby34Rc => "ruby-3.4-rc", - BuildRuntime::Ruby40Rc => "ruby-4.0-rc", - BuildRuntime::Python38Rc => "python-3.8-rc", - BuildRuntime::Python39Rc => "python-3.9-rc", - BuildRuntime::Python310Rc => "python-3.10-rc", - BuildRuntime::Python311Rc => "python-3.11-rc", - BuildRuntime::Python312Rc => "python-3.12-rc", - BuildRuntime::Python313Rc => "python-3.13-rc", - BuildRuntime::Python314Rc => "python-3.14-rc", - BuildRuntime::PythonMl311Rc => "python-ml-3.11-rc", - BuildRuntime::PythonMl312Rc => "python-ml-3.12-rc", - BuildRuntime::PythonMl313Rc => "python-ml-3.13-rc", - BuildRuntime::Deno140Rc => "deno-1.40-rc", - BuildRuntime::Deno146Rc => "deno-1.46-rc", - BuildRuntime::Deno20Rc => "deno-2.0-rc", - BuildRuntime::Deno25Rc => "deno-2.5-rc", - BuildRuntime::Deno26Rc => "deno-2.6-rc", - BuildRuntime::Dart215Rc => "dart-2.15-rc", - BuildRuntime::Dart216Rc => "dart-2.16-rc", - BuildRuntime::Dart217Rc => "dart-2.17-rc", - BuildRuntime::Dart218Rc => "dart-2.18-rc", - BuildRuntime::Dart219Rc => "dart-2.19-rc", - BuildRuntime::Dart30Rc => "dart-3.0-rc", - BuildRuntime::Dart31Rc => "dart-3.1-rc", - BuildRuntime::Dart33Rc => "dart-3.3-rc", - BuildRuntime::Dart35Rc => "dart-3.5-rc", - BuildRuntime::Dart38Rc => "dart-3.8-rc", - BuildRuntime::Dart39Rc => "dart-3.9-rc", - BuildRuntime::Dart310Rc => "dart-3.10-rc", - BuildRuntime::Dotnet60Rc => "dotnet-6.0-rc", - BuildRuntime::Dotnet70Rc => "dotnet-7.0-rc", - BuildRuntime::Dotnet80Rc => "dotnet-8.0-rc", - BuildRuntime::Dotnet10Rc => "dotnet-10-rc", - BuildRuntime::Java80Rc => "java-8.0-rc", - BuildRuntime::Java110Rc => "java-11.0-rc", - BuildRuntime::Java170Rc => "java-17.0-rc", - BuildRuntime::Java180Rc => "java-18.0-rc", - BuildRuntime::Java210Rc => "java-21.0-rc", - BuildRuntime::Java22Rc => "java-22-rc", - BuildRuntime::Java25Rc => "java-25-rc", - BuildRuntime::Swift55Rc => "swift-5.5-rc", - BuildRuntime::Swift58Rc => "swift-5.8-rc", - BuildRuntime::Swift59Rc => "swift-5.9-rc", - BuildRuntime::Swift510Rc => "swift-5.10-rc", - BuildRuntime::Swift62Rc => "swift-6.2-rc", - BuildRuntime::Kotlin16Rc => "kotlin-1.6-rc", - BuildRuntime::Kotlin18Rc => "kotlin-1.8-rc", - BuildRuntime::Kotlin19Rc => "kotlin-1.9-rc", - BuildRuntime::Kotlin20Rc => "kotlin-2.0-rc", - BuildRuntime::Kotlin23Rc => "kotlin-2.3-rc", - BuildRuntime::Cpp17Rc => "cpp-17-rc", - BuildRuntime::Cpp20Rc => "cpp-20-rc", - BuildRuntime::Bun10Rc => "bun-1.0-rc", - BuildRuntime::Bun11Rc => "bun-1.1-rc", - BuildRuntime::Bun12Rc => "bun-1.2-rc", - BuildRuntime::Bun13Rc => "bun-1.3-rc", - BuildRuntime::Go123Rc => "go-1.23-rc", - BuildRuntime::Go124Rc => "go-1.24-rc", - BuildRuntime::Go125Rc => "go-1.25-rc", - BuildRuntime::Go126Rc => "go-1.26-rc", - BuildRuntime::Static1Rc => "static-1-rc", - BuildRuntime::Flutter324Rc => "flutter-3.24-rc", - BuildRuntime::Flutter327Rc => "flutter-3.27-rc", - BuildRuntime::Flutter329Rc => "flutter-3.29-rc", - BuildRuntime::Flutter332Rc => "flutter-3.32-rc", - BuildRuntime::Flutter335Rc => "flutter-3.35-rc", - BuildRuntime::Flutter338Rc => "flutter-3.38-rc", } } } diff --git a/src/enums/database_type.rs b/src/enums/database_type.rs index 80e5962..c70cf6a 100644 --- a/src/enums/database_type.rs +++ b/src/enums/database_type.rs @@ -7,6 +7,10 @@ pub enum DatabaseType { Legacy, #[serde(rename = "tablesdb")] Tablesdb, + #[serde(rename = "documentsdb")] + Documentsdb, + #[serde(rename = "vectorsdb")] + Vectorsdb, } impl DatabaseType { @@ -15,6 +19,8 @@ impl DatabaseType { match self { DatabaseType::Legacy => "legacy", DatabaseType::Tablesdb => "tablesdb", + DatabaseType::Documentsdb => "documentsdb", + DatabaseType::Vectorsdb => "vectorsdb", } } } diff --git a/src/enums/databases_index_type.rs b/src/enums/databases_index_type.rs new file mode 100644 index 0000000..1d165b5 --- /dev/null +++ b/src/enums/databases_index_type.rs @@ -0,0 +1,32 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)] +pub enum DatabasesIndexType { + #[serde(rename = "key")] + #[default] + Key, + #[serde(rename = "fulltext")] + Fulltext, + #[serde(rename = "unique")] + Unique, + #[serde(rename = "spatial")] + Spatial, +} + +impl DatabasesIndexType { + /// Get the string value of the enum + pub fn as_str(&self) -> &str { + match self { + DatabasesIndexType::Key => "key", + DatabasesIndexType::Fulltext => "fulltext", + DatabasesIndexType::Unique => "unique", + DatabasesIndexType::Spatial => "spatial", + } + } +} + +impl std::fmt::Display for DatabasesIndexType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.as_str()) + } +} diff --git a/src/enums/mod.rs b/src/enums/mod.rs index c6705a4..826028d 100644 --- a/src/enums/mod.rs +++ b/src/enums/mod.rs @@ -26,8 +26,8 @@ pub mod relationship_type; pub use relationship_type::RelationshipType; pub mod relation_mutate; pub use relation_mutate::RelationMutate; -pub mod index_type; -pub use index_type::IndexType; +pub mod databases_index_type; +pub use databases_index_type::DatabasesIndexType; pub mod order_by; pub use order_by::OrderBy; pub mod runtime; @@ -58,6 +58,8 @@ pub mod compression; pub use compression::Compression; pub mod image_gravity; pub use image_gravity::ImageGravity; +pub mod tables_db_index_type; +pub use tables_db_index_type::TablesDBIndexType; pub mod password_hash; pub use password_hash::PasswordHash; pub mod messaging_provider_type; diff --git a/src/enums/runtime.rs b/src/enums/runtime.rs index bce57ee..3fe6418 100644 --- a/src/enums/runtime.rs +++ b/src/enums/runtime.rs @@ -175,178 +175,6 @@ pub enum Runtime { Flutter335, #[serde(rename = "flutter-3.38")] Flutter338, - #[serde(rename = "node-14.5-rc")] - Node145Rc, - #[serde(rename = "node-16.0-rc")] - Node160Rc, - #[serde(rename = "node-18.0-rc")] - Node180Rc, - #[serde(rename = "node-19.0-rc")] - Node190Rc, - #[serde(rename = "node-20.0-rc")] - Node200Rc, - #[serde(rename = "node-21.0-rc")] - Node210Rc, - #[serde(rename = "node-22-rc")] - Node22Rc, - #[serde(rename = "node-23-rc")] - Node23Rc, - #[serde(rename = "node-24-rc")] - Node24Rc, - #[serde(rename = "node-25-rc")] - Node25Rc, - #[serde(rename = "php-8.0-rc")] - Php80Rc, - #[serde(rename = "php-8.1-rc")] - Php81Rc, - #[serde(rename = "php-8.2-rc")] - Php82Rc, - #[serde(rename = "php-8.3-rc")] - Php83Rc, - #[serde(rename = "php-8.4-rc")] - Php84Rc, - #[serde(rename = "ruby-3.0-rc")] - Ruby30Rc, - #[serde(rename = "ruby-3.1-rc")] - Ruby31Rc, - #[serde(rename = "ruby-3.2-rc")] - Ruby32Rc, - #[serde(rename = "ruby-3.3-rc")] - Ruby33Rc, - #[serde(rename = "ruby-3.4-rc")] - Ruby34Rc, - #[serde(rename = "ruby-4.0-rc")] - Ruby40Rc, - #[serde(rename = "python-3.8-rc")] - Python38Rc, - #[serde(rename = "python-3.9-rc")] - Python39Rc, - #[serde(rename = "python-3.10-rc")] - Python310Rc, - #[serde(rename = "python-3.11-rc")] - Python311Rc, - #[serde(rename = "python-3.12-rc")] - Python312Rc, - #[serde(rename = "python-3.13-rc")] - Python313Rc, - #[serde(rename = "python-3.14-rc")] - Python314Rc, - #[serde(rename = "python-ml-3.11-rc")] - PythonMl311Rc, - #[serde(rename = "python-ml-3.12-rc")] - PythonMl312Rc, - #[serde(rename = "python-ml-3.13-rc")] - PythonMl313Rc, - #[serde(rename = "deno-1.40-rc")] - Deno140Rc, - #[serde(rename = "deno-1.46-rc")] - Deno146Rc, - #[serde(rename = "deno-2.0-rc")] - Deno20Rc, - #[serde(rename = "deno-2.5-rc")] - Deno25Rc, - #[serde(rename = "deno-2.6-rc")] - Deno26Rc, - #[serde(rename = "dart-2.15-rc")] - Dart215Rc, - #[serde(rename = "dart-2.16-rc")] - Dart216Rc, - #[serde(rename = "dart-2.17-rc")] - Dart217Rc, - #[serde(rename = "dart-2.18-rc")] - Dart218Rc, - #[serde(rename = "dart-2.19-rc")] - Dart219Rc, - #[serde(rename = "dart-3.0-rc")] - Dart30Rc, - #[serde(rename = "dart-3.1-rc")] - Dart31Rc, - #[serde(rename = "dart-3.3-rc")] - Dart33Rc, - #[serde(rename = "dart-3.5-rc")] - Dart35Rc, - #[serde(rename = "dart-3.8-rc")] - Dart38Rc, - #[serde(rename = "dart-3.9-rc")] - Dart39Rc, - #[serde(rename = "dart-3.10-rc")] - Dart310Rc, - #[serde(rename = "dotnet-6.0-rc")] - Dotnet60Rc, - #[serde(rename = "dotnet-7.0-rc")] - Dotnet70Rc, - #[serde(rename = "dotnet-8.0-rc")] - Dotnet80Rc, - #[serde(rename = "dotnet-10-rc")] - Dotnet10Rc, - #[serde(rename = "java-8.0-rc")] - Java80Rc, - #[serde(rename = "java-11.0-rc")] - Java110Rc, - #[serde(rename = "java-17.0-rc")] - Java170Rc, - #[serde(rename = "java-18.0-rc")] - Java180Rc, - #[serde(rename = "java-21.0-rc")] - Java210Rc, - #[serde(rename = "java-22-rc")] - Java22Rc, - #[serde(rename = "java-25-rc")] - Java25Rc, - #[serde(rename = "swift-5.5-rc")] - Swift55Rc, - #[serde(rename = "swift-5.8-rc")] - Swift58Rc, - #[serde(rename = "swift-5.9-rc")] - Swift59Rc, - #[serde(rename = "swift-5.10-rc")] - Swift510Rc, - #[serde(rename = "swift-6.2-rc")] - Swift62Rc, - #[serde(rename = "kotlin-1.6-rc")] - Kotlin16Rc, - #[serde(rename = "kotlin-1.8-rc")] - Kotlin18Rc, - #[serde(rename = "kotlin-1.9-rc")] - Kotlin19Rc, - #[serde(rename = "kotlin-2.0-rc")] - Kotlin20Rc, - #[serde(rename = "kotlin-2.3-rc")] - Kotlin23Rc, - #[serde(rename = "cpp-17-rc")] - Cpp17Rc, - #[serde(rename = "cpp-20-rc")] - Cpp20Rc, - #[serde(rename = "bun-1.0-rc")] - Bun10Rc, - #[serde(rename = "bun-1.1-rc")] - Bun11Rc, - #[serde(rename = "bun-1.2-rc")] - Bun12Rc, - #[serde(rename = "bun-1.3-rc")] - Bun13Rc, - #[serde(rename = "go-1.23-rc")] - Go123Rc, - #[serde(rename = "go-1.24-rc")] - Go124Rc, - #[serde(rename = "go-1.25-rc")] - Go125Rc, - #[serde(rename = "go-1.26-rc")] - Go126Rc, - #[serde(rename = "static-1-rc")] - Static1Rc, - #[serde(rename = "flutter-3.24-rc")] - Flutter324Rc, - #[serde(rename = "flutter-3.27-rc")] - Flutter327Rc, - #[serde(rename = "flutter-3.29-rc")] - Flutter329Rc, - #[serde(rename = "flutter-3.32-rc")] - Flutter332Rc, - #[serde(rename = "flutter-3.35-rc")] - Flutter335Rc, - #[serde(rename = "flutter-3.38-rc")] - Flutter338Rc, } impl Runtime { @@ -439,92 +267,6 @@ impl Runtime { Runtime::Flutter332 => "flutter-3.32", Runtime::Flutter335 => "flutter-3.35", Runtime::Flutter338 => "flutter-3.38", - Runtime::Node145Rc => "node-14.5-rc", - Runtime::Node160Rc => "node-16.0-rc", - Runtime::Node180Rc => "node-18.0-rc", - Runtime::Node190Rc => "node-19.0-rc", - Runtime::Node200Rc => "node-20.0-rc", - Runtime::Node210Rc => "node-21.0-rc", - Runtime::Node22Rc => "node-22-rc", - Runtime::Node23Rc => "node-23-rc", - Runtime::Node24Rc => "node-24-rc", - Runtime::Node25Rc => "node-25-rc", - Runtime::Php80Rc => "php-8.0-rc", - Runtime::Php81Rc => "php-8.1-rc", - Runtime::Php82Rc => "php-8.2-rc", - Runtime::Php83Rc => "php-8.3-rc", - Runtime::Php84Rc => "php-8.4-rc", - Runtime::Ruby30Rc => "ruby-3.0-rc", - Runtime::Ruby31Rc => "ruby-3.1-rc", - Runtime::Ruby32Rc => "ruby-3.2-rc", - Runtime::Ruby33Rc => "ruby-3.3-rc", - Runtime::Ruby34Rc => "ruby-3.4-rc", - Runtime::Ruby40Rc => "ruby-4.0-rc", - Runtime::Python38Rc => "python-3.8-rc", - Runtime::Python39Rc => "python-3.9-rc", - Runtime::Python310Rc => "python-3.10-rc", - Runtime::Python311Rc => "python-3.11-rc", - Runtime::Python312Rc => "python-3.12-rc", - Runtime::Python313Rc => "python-3.13-rc", - Runtime::Python314Rc => "python-3.14-rc", - Runtime::PythonMl311Rc => "python-ml-3.11-rc", - Runtime::PythonMl312Rc => "python-ml-3.12-rc", - Runtime::PythonMl313Rc => "python-ml-3.13-rc", - Runtime::Deno140Rc => "deno-1.40-rc", - Runtime::Deno146Rc => "deno-1.46-rc", - Runtime::Deno20Rc => "deno-2.0-rc", - Runtime::Deno25Rc => "deno-2.5-rc", - Runtime::Deno26Rc => "deno-2.6-rc", - Runtime::Dart215Rc => "dart-2.15-rc", - Runtime::Dart216Rc => "dart-2.16-rc", - Runtime::Dart217Rc => "dart-2.17-rc", - Runtime::Dart218Rc => "dart-2.18-rc", - Runtime::Dart219Rc => "dart-2.19-rc", - Runtime::Dart30Rc => "dart-3.0-rc", - Runtime::Dart31Rc => "dart-3.1-rc", - Runtime::Dart33Rc => "dart-3.3-rc", - Runtime::Dart35Rc => "dart-3.5-rc", - Runtime::Dart38Rc => "dart-3.8-rc", - Runtime::Dart39Rc => "dart-3.9-rc", - Runtime::Dart310Rc => "dart-3.10-rc", - Runtime::Dotnet60Rc => "dotnet-6.0-rc", - Runtime::Dotnet70Rc => "dotnet-7.0-rc", - Runtime::Dotnet80Rc => "dotnet-8.0-rc", - Runtime::Dotnet10Rc => "dotnet-10-rc", - Runtime::Java80Rc => "java-8.0-rc", - Runtime::Java110Rc => "java-11.0-rc", - Runtime::Java170Rc => "java-17.0-rc", - Runtime::Java180Rc => "java-18.0-rc", - Runtime::Java210Rc => "java-21.0-rc", - Runtime::Java22Rc => "java-22-rc", - Runtime::Java25Rc => "java-25-rc", - Runtime::Swift55Rc => "swift-5.5-rc", - Runtime::Swift58Rc => "swift-5.8-rc", - Runtime::Swift59Rc => "swift-5.9-rc", - Runtime::Swift510Rc => "swift-5.10-rc", - Runtime::Swift62Rc => "swift-6.2-rc", - Runtime::Kotlin16Rc => "kotlin-1.6-rc", - Runtime::Kotlin18Rc => "kotlin-1.8-rc", - Runtime::Kotlin19Rc => "kotlin-1.9-rc", - Runtime::Kotlin20Rc => "kotlin-2.0-rc", - Runtime::Kotlin23Rc => "kotlin-2.3-rc", - Runtime::Cpp17Rc => "cpp-17-rc", - Runtime::Cpp20Rc => "cpp-20-rc", - Runtime::Bun10Rc => "bun-1.0-rc", - Runtime::Bun11Rc => "bun-1.1-rc", - Runtime::Bun12Rc => "bun-1.2-rc", - Runtime::Bun13Rc => "bun-1.3-rc", - Runtime::Go123Rc => "go-1.23-rc", - Runtime::Go124Rc => "go-1.24-rc", - Runtime::Go125Rc => "go-1.25-rc", - Runtime::Go126Rc => "go-1.26-rc", - Runtime::Static1Rc => "static-1-rc", - Runtime::Flutter324Rc => "flutter-3.24-rc", - Runtime::Flutter327Rc => "flutter-3.27-rc", - Runtime::Flutter329Rc => "flutter-3.29-rc", - Runtime::Flutter332Rc => "flutter-3.32-rc", - Runtime::Flutter335Rc => "flutter-3.35-rc", - Runtime::Flutter338Rc => "flutter-3.38-rc", } } } diff --git a/src/enums/scopes.rs b/src/enums/scopes.rs index 1cdc0c1..f062a3a 100644 --- a/src/enums/scopes.rs +++ b/src/enums/scopes.rs @@ -121,6 +121,10 @@ pub enum Scopes { WebhooksRead, #[serde(rename = "webhooks.write")] WebhooksWrite, + #[serde(rename = "project.read")] + ProjectRead, + #[serde(rename = "project.write")] + ProjectWrite, #[serde(rename = "policies.write")] PoliciesWrite, #[serde(rename = "policies.read")] @@ -204,6 +208,8 @@ impl Scopes { Scopes::TokensWrite => "tokens.write", Scopes::WebhooksRead => "webhooks.read", Scopes::WebhooksWrite => "webhooks.write", + Scopes::ProjectRead => "project.read", + Scopes::ProjectWrite => "project.write", Scopes::PoliciesWrite => "policies.write", Scopes::PoliciesRead => "policies.read", Scopes::ArchivesRead => "archives.read", diff --git a/src/enums/index_type.rs b/src/enums/tables_db_index_type.rs similarity index 64% rename from src/enums/index_type.rs rename to src/enums/tables_db_index_type.rs index f0f4679..c7f3f0d 100644 --- a/src/enums/index_type.rs +++ b/src/enums/tables_db_index_type.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)] -pub enum IndexType { +pub enum TablesDBIndexType { #[serde(rename = "key")] #[default] Key, @@ -13,19 +13,19 @@ pub enum IndexType { Spatial, } -impl IndexType { +impl TablesDBIndexType { /// Get the string value of the enum pub fn as_str(&self) -> &str { match self { - IndexType::Key => "key", - IndexType::Fulltext => "fulltext", - IndexType::Unique => "unique", - IndexType::Spatial => "spatial", + TablesDBIndexType::Key => "key", + TablesDBIndexType::Fulltext => "fulltext", + TablesDBIndexType::Unique => "unique", + TablesDBIndexType::Spatial => "spatial", } } } -impl std::fmt::Display for IndexType { +impl std::fmt::Display for TablesDBIndexType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.as_str()) } diff --git a/src/enums/template_reference_type.rs b/src/enums/template_reference_type.rs index 69a3dcd..853b5e3 100644 --- a/src/enums/template_reference_type.rs +++ b/src/enums/template_reference_type.rs @@ -2,11 +2,11 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)] pub enum TemplateReferenceType { - #[serde(rename = "branch")] - #[default] - Branch, #[serde(rename = "commit")] + #[default] Commit, + #[serde(rename = "branch")] + Branch, #[serde(rename = "tag")] Tag, } @@ -15,8 +15,8 @@ impl TemplateReferenceType { /// Get the string value of the enum pub fn as_str(&self) -> &str { match self { - TemplateReferenceType::Branch => "branch", TemplateReferenceType::Commit => "commit", + TemplateReferenceType::Branch => "branch", TemplateReferenceType::Tag => "tag", } } diff --git a/src/lib.rs b/src/lib.rs index 88050cb..891dc1b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ //! //! ```toml //! [dependencies] -//! appwrite = "0.1.0" +//! appwrite = "0.2.0" //! ``` //! //! ## Usage @@ -51,7 +51,7 @@ pub use input_file::InputFile; pub type Result = std::result::Result; /// SDK version -pub const VERSION: &str = "0.1.0"; +pub const VERSION: &str = "0.2.0"; /// SDK name pub const SDK_NAME: &str = "Rust"; diff --git a/src/models/attribute_list.rs b/src/models/attribute_list.rs index d105e9e..e76e2b0 100644 --- a/src/models/attribute_list.rs +++ b/src/models/attribute_list.rs @@ -11,7 +11,7 @@ pub struct AttributeList { pub total: i64, /// List of attributes. #[serde(rename = "attributes")] - pub attributes: Vec, + pub attributes: Vec, } impl AttributeList { @@ -21,7 +21,7 @@ impl AttributeList { } /// Get attributes - pub fn attributes(&self) -> &Vec { + pub fn attributes(&self) -> &Vec { &self.attributes } diff --git a/src/models/collection.rs b/src/models/collection.rs index a1c6f2c..5dcefb8 100644 --- a/src/models/collection.rs +++ b/src/models/collection.rs @@ -36,7 +36,7 @@ pub struct Collection { pub document_security: bool, /// Collection attributes. #[serde(rename = "attributes")] - pub attributes: Vec, + pub attributes: Vec, /// Collection indexes. #[serde(rename = "indexes")] pub indexes: Vec, @@ -90,7 +90,7 @@ impl Collection { } /// Get attributes - pub fn attributes(&self) -> &Vec { + pub fn attributes(&self) -> &Vec { &self.attributes } diff --git a/src/models/column_list.rs b/src/models/column_list.rs index 51d4d43..921ac76 100644 --- a/src/models/column_list.rs +++ b/src/models/column_list.rs @@ -11,7 +11,7 @@ pub struct ColumnList { pub total: i64, /// List of columns. #[serde(rename = "columns")] - pub columns: Vec, + pub columns: Vec, } impl ColumnList { @@ -21,7 +21,7 @@ impl ColumnList { } /// Get columns - pub fn columns(&self) -> &Vec { + pub fn columns(&self) -> &Vec { &self.columns } diff --git a/src/models/table.rs b/src/models/table.rs index e7af5b6..85a02fb 100644 --- a/src/models/table.rs +++ b/src/models/table.rs @@ -36,7 +36,7 @@ pub struct Table { pub row_security: bool, /// Table columns. #[serde(rename = "columns")] - pub columns: Vec, + pub columns: Vec, /// Table indexes. #[serde(rename = "indexes")] pub indexes: Vec, @@ -90,7 +90,7 @@ impl Table { } /// Get columns - pub fn columns(&self) -> &Vec { + pub fn columns(&self) -> &Vec { &self.columns } diff --git a/src/services/avatars.rs b/src/services/avatars.rs index c82e8bd..fa30f48 100644 --- a/src/services/avatars.rs +++ b/src/services/avatars.rs @@ -259,7 +259,7 @@ impl Avatars { longitude: Option, accuracy: Option, touch: Option, - permissions: Option, + permissions: Option>, sleep: Option, width: Option, height: Option, diff --git a/src/services/backups.rs b/src/services/backups.rs index da96e2d..d30965b 100644 --- a/src/services/backups.rs +++ b/src/services/backups.rs @@ -38,7 +38,7 @@ impl Backups { /// Create a new archive asynchronously for a project. pub async fn create_archive( &self, - services: crate::enums::BackupServices, + services: Vec, resource_id: Option<&str>, ) -> crate::error::Result { let mut params = HashMap::new(); @@ -100,7 +100,7 @@ impl Backups { pub async fn create_policy( &self, policy_id: impl Into, - services: crate::enums::BackupServices, + services: Vec, retention: i64, schedule: impl Into, name: Option<&str>, @@ -189,7 +189,7 @@ impl Backups { pub async fn create_restoration( &self, archive_id: impl Into, - services: crate::enums::BackupServices, + services: Vec, new_resource_id: Option<&str>, new_resource_name: Option<&str>, ) -> crate::error::Result { diff --git a/src/services/databases.rs b/src/services/databases.rs index 56e5656..bb4376f 100644 --- a/src/services/databases.rs +++ b/src/services/databases.rs @@ -1746,9 +1746,9 @@ impl Databases { database_id: impl Into, collection_id: impl Into, key: impl Into, - r#type: crate::enums::IndexType, + r#type: crate::enums::DatabasesIndexType, attributes: impl IntoIterator>, - orders: Option, + orders: Option>, lengths: Option>, ) -> crate::error::Result { let mut params = HashMap::new(); diff --git a/src/services/functions.rs b/src/services/functions.rs index e9a7981..ccd8e27 100644 --- a/src/services/functions.rs +++ b/src/services/functions.rs @@ -64,7 +64,7 @@ impl Functions { logging: Option, entrypoint: Option<&str>, commands: Option<&str>, - scopes: Option, + scopes: Option>, installation_id: Option<&str>, provider_repository_id: Option<&str>, provider_branch: Option<&str>, @@ -186,7 +186,7 @@ impl Functions { logging: Option, entrypoint: Option<&str>, commands: Option<&str>, - scopes: Option, + scopes: Option>, installation_id: Option<&str>, provider_repository_id: Option<&str>, provider_branch: Option<&str>, diff --git a/src/services/health.rs b/src/services/health.rs index 35cfa99..00ab438 100644 --- a/src/services/health.rs +++ b/src/services/health.rs @@ -129,36 +129,6 @@ impl Health { self.client.call(Method::GET, &path, None, Some(params)).await } - /// Get billing project aggregation queue. - pub async fn get_queue_billing_project_aggregation( - &self, - threshold: Option, - ) -> crate::error::Result { - let mut params = HashMap::new(); - if let Some(value) = threshold { - params.insert("threshold".to_string(), json!(value)); - } - - let path = "/health/queue/billing-project-aggregation".to_string(); - - self.client.call(Method::GET, &path, None, Some(params)).await - } - - /// Get billing team aggregation queue. - pub async fn get_queue_billing_team_aggregation( - &self, - threshold: Option, - ) -> crate::error::Result { - let mut params = HashMap::new(); - if let Some(value) = threshold { - params.insert("threshold".to_string(), json!(value)); - } - - let path = "/health/queue/billing-team-aggregation".to_string(); - - self.client.call(Method::GET, &path, None, Some(params)).await - } - /// Get the number of builds that are waiting to be processed in the Appwrite /// internal queue server. pub async fn get_queue_builds( @@ -175,21 +145,6 @@ impl Health { self.client.call(Method::GET, &path, None, Some(params)).await } - /// Get the priority builds queue size. - pub async fn get_queue_priority_builds( - &self, - threshold: Option, - ) -> crate::error::Result { - let mut params = HashMap::new(); - if let Some(value) = threshold { - params.insert("threshold".to_string(), json!(value)); - } - - let path = "/health/queue/builds-priority".to_string(); - - self.client.call(Method::GET, &path, None, Some(params)).await - } - /// Get the number of certificates that are waiting to be issued against /// [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue /// server. @@ -339,21 +294,6 @@ impl Health { self.client.call(Method::GET, &path, None, Some(params)).await } - /// Get region manager queue. - pub async fn get_queue_region_manager( - &self, - threshold: Option, - ) -> crate::error::Result { - let mut params = HashMap::new(); - if let Some(value) = threshold { - params.insert("threshold".to_string(), json!(value)); - } - - let path = "/health/queue/region-manager".to_string(); - - self.client.call(Method::GET, &path, None, Some(params)).await - } - /// Get the number of metrics that are waiting to be processed in the Appwrite /// stats resources queue. pub async fn get_queue_stats_resources( @@ -386,21 +326,6 @@ impl Health { self.client.call(Method::GET, &path, None, Some(params)).await } - /// Get threats queue. - pub async fn get_queue_threats( - &self, - threshold: Option, - ) -> crate::error::Result { - let mut params = HashMap::new(); - if let Some(value) = threshold { - params.insert("threshold".to_string(), json!(value)); - } - - let path = "/health/queue/threats".to_string(); - - self.client.call(Method::GET, &path, None, Some(params)).await - } - /// Get the number of webhooks that are waiting to be processed in the Appwrite /// internal queue server. pub async fn get_queue_webhooks( diff --git a/src/services/mod.rs b/src/services/mod.rs index 5ed69ab..b03de46 100644 --- a/src/services/mod.rs +++ b/src/services/mod.rs @@ -20,6 +20,8 @@ pub mod locale; pub use locale::Locale; pub mod messaging; pub use messaging::Messaging; +pub mod project; +pub use project::Project; pub mod sites; pub use sites::Sites; pub mod storage; @@ -56,6 +58,7 @@ pub struct Services { health: Health, locale: Locale, messaging: Messaging, + project: Project, sites: Sites, storage: Storage, tables_db: TablesDB, @@ -79,6 +82,7 @@ impl Services { health: Health::new(&client), locale: Locale::new(&client), messaging: Messaging::new(&client), + project: Project::new(&client), sites: Sites::new(&client), storage: Storage::new(&client), tables_db: TablesDB::new(&client), @@ -135,6 +139,10 @@ impl Services { pub fn messaging(&self) -> &Messaging { &self.messaging } + /// Get Project service + pub fn project(&self) -> &Project { + &self.project + } /// Get Sites service pub fn sites(&self) -> &Sites { &self.sites diff --git a/src/services/project.rs b/src/services/project.rs new file mode 100644 index 0000000..8de92b0 --- /dev/null +++ b/src/services/project.rs @@ -0,0 +1,138 @@ +//! Project service for Appwrite SDK + +use crate::client::Client; + +use reqwest::Method; +use serde_json::json; +use std::collections::HashMap; + +/// The Project service allows you to manage all the projects in your Appwrite +/// server. +#[derive(Debug, Clone)] +pub struct Project { + client: Client, +} + +impl Project { + pub fn new(client: &Client) -> Self { + Self { client: client.clone() } + } + + pub fn client(&self) -> &Client { + &self.client + } + + /// Get a list of all project environment variables. + pub async fn list_variables( + &self, + queries: Option>, + total: Option, + ) -> crate::error::Result { + let mut params = HashMap::new(); + if let Some(value) = queries { + params.insert("queries".to_string(), json!(value.into_iter().map(|s| s.into()).collect::>())); + } + if let Some(value) = total { + params.insert("total".to_string(), json!(value)); + } + + let path = "/project/variables".to_string(); + + self.client.call(Method::GET, &path, None, Some(params)).await + } + + /// Create a new project environment variable. These variables can be accessed + /// by all functions and sites in the project. + pub async fn create_variable( + &self, + variable_id: impl Into, + key: impl Into, + value: impl Into, + secret: Option, + ) -> crate::error::Result { + let mut params = HashMap::new(); + params.insert("variableId".to_string(), json!(variable_id.into())); + params.insert("key".to_string(), json!(key.into())); + params.insert("value".to_string(), json!(value.into())); + if let Some(value) = secret { + params.insert("secret".to_string(), json!(value)); + } + let mut api_headers = HashMap::new(); + api_headers.insert("content-type".to_string(), "application/json".to_string()); + + let path = "/project/variables".to_string(); + + self.client.call(Method::POST, &path, Some(api_headers), Some(params)).await + } + + /// Get a variable by its unique ID. + pub async fn get_variable( + &self, + variable_id: impl Into, + ) -> crate::error::Result { + let params = HashMap::new(); + + let path = "/project/variables/{variableId}".to_string().replace("{variableId}", &variable_id.into().to_string()); + + self.client.call(Method::GET, &path, None, Some(params)).await + } + + /// Update variable by its unique ID. + pub async fn update_variable( + &self, + variable_id: impl Into, + key: Option<&str>, + value: Option<&str>, + secret: Option, + ) -> crate::error::Result { + let mut params = HashMap::new(); + if let Some(value) = key { + params.insert("key".to_string(), json!(value)); + } + if let Some(value) = value { + params.insert("value".to_string(), json!(value)); + } + if let Some(value) = secret { + params.insert("secret".to_string(), json!(value)); + } + let mut api_headers = HashMap::new(); + api_headers.insert("content-type".to_string(), "application/json".to_string()); + + let path = "/project/variables/{variableId}".to_string().replace("{variableId}", &variable_id.into().to_string()); + + self.client.call(Method::PUT, &path, Some(api_headers), Some(params)).await + } + + /// Delete a variable by its unique ID. + pub async fn delete_variable( + &self, + variable_id: impl Into, + ) -> crate::error::Result<()> { + let params = HashMap::new(); + let mut api_headers = HashMap::new(); + api_headers.insert("content-type".to_string(), "application/json".to_string()); + + let path = "/project/variables/{variableId}".to_string().replace("{variableId}", &variable_id.into().to_string()); + + self.client.call(Method::DELETE, &path, Some(api_headers), Some(params)).await + } + +} + +impl crate::services::Service for Project { + fn client(&self) -> &Client { + &self.client + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_project_creation() { + let client = Client::new(); + let service = Project::new(&client); + assert!(service.client().endpoint().contains("cloud.appwrite.io/v1")); + } +} diff --git a/src/services/tables_db.rs b/src/services/tables_db.rs index 9a014dc..92b2c80 100644 --- a/src/services/tables_db.rs +++ b/src/services/tables_db.rs @@ -1420,9 +1420,9 @@ impl TablesDB { database_id: impl Into, table_id: impl Into, key: impl Into, - r#type: crate::enums::IndexType, + r#type: crate::enums::TablesDBIndexType, columns: impl IntoIterator>, - orders: Option, + orders: Option>, lengths: Option>, ) -> crate::error::Result { let mut params = HashMap::new();