diff --git a/.travis.yml b/.travis.yml index a4013ef..d407637 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ jobs: api_key: $RUBYGEMS_TOKEN gem: appwrite on: - tags: true + tags: true \ No newline at end of file diff --git a/README.md b/README.md index 46d36e2..7b57099 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # Appwrite Ruby SDK -![License](https://img.shields.io/github/license/appwrite/sdk-for-ruby.svg?v=1) -![Version](https://img.shields.io/badge/api%20version-0.7.0-blue.svg?v=1) +![License](https://img.shields.io/github/license/appwrite/sdk-for-ruby.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-0.8.0-blue.svg?style=flat-square) +[![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.7.0. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-ruby/releases).** +**This SDK is compatible with Appwrite server version 0.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-ruby/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 Ruby SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. @@ -19,6 +21,73 @@ To install via [Gem](https://rubygems.org/): gem install appwrite --save ``` + +## Getting Started + +### Init your SDK +Initialize your SDK code with your project ID which can be found in your project settings page and your new API secret Key from project's API keys section. + +```ruby +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint(ENV["APPWRITE_ENDPOINT"]) # Your API Endpoint + .set_project(ENV["APPWRITE_PROJECT"]) # Your project ID + .set_key(ENV["APPWRITE_SECRET"]) # Your secret API key + .setSelfSigned() # Use only on dev mode with a self-signed SSL cert +; +``` + +### Make Your First Request +Once your SDK object is set, create any of the Appwrite service objects and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the API References section. + +```ruby +users = Appwrite::Users.new(client); + +result = users.create(email: 'email@example.com', password: 'password'); +``` + +### Full Example +```ruby +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint(ENV["APPWRITE_ENDPOINT"]) # Your API Endpoint + .set_project(ENV["APPWRITE_PROJECT"]) # Your project ID + .set_key(ENV["APPWRITE_SECRET"]) # Your secret API key + .setSelfSigned() # Use only on dev mode with a self-signed SSL cert +; + +users = Appwrite::Users.new(client); + +result = users.create(email: 'email@example.com', password: 'password'); +``` + +### Error Handling +The Appwrite Ruby SDK raises `Appwrite::Exception` object with `message`, `code` and `response` properties. You can handle any errors by catching `Appwrite::Exception` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example. + +```ruby +users = Appwrite::Users.new(client); + +begin + result = users.create(email: 'email@example.com', password: 'password'); +rescue Appwrite::Exception => error + puts error.message +end +``` + +### Learn more +You can use followng resources to learn more and get help +- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-server) +- 📜 [Appwrite Docs](https://appwrite.io/docs) +- 💬 [Discord Community](https://appwrite.io/discord) +- 🚂 [Appwrite Ruby Playground](https://github.com/appwrite/playground-for-ruby) + + ## Contribution This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request. diff --git a/appwrite.gemspec b/appwrite.gemspec index f6f0b77..7723961 100644 --- a/appwrite.gemspec +++ b/appwrite.gemspec @@ -1,11 +1,11 @@ Gem::Specification.new do |s| s.name = 'appwrite' - s.version = '2.0.2' + s.version = '2.1.0' s.summary = "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API" s.author = 'Appwrite Team' s.homepage = 'https://appwrite.io/support' s.email = 'team@appwrite.io' s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) -end +end \ No newline at end of file diff --git a/docs/examples/account/create-recovery.md b/docs/examples/account/create-recovery.md new file mode 100644 index 0000000..7d20fe2 --- /dev/null +++ b/docs/examples/account/create-recovery.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.create_recovery(email: 'email@example.com', url: 'https://example.com'); + +puts response \ No newline at end of file diff --git a/docs/examples/account/create-verification.md b/docs/examples/account/create-verification.md new file mode 100644 index 0000000..e0264f3 --- /dev/null +++ b/docs/examples/account/create-verification.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.create_verification(url: 'https://example.com'); + +puts response \ No newline at end of file diff --git a/docs/examples/account/delete-session.md b/docs/examples/account/delete-session.md new file mode 100644 index 0000000..65f86ad --- /dev/null +++ b/docs/examples/account/delete-session.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.delete_session(session_id: '[SESSION_ID]'); + +puts response \ No newline at end of file diff --git a/docs/examples/account/delete-sessions.md b/docs/examples/account/delete-sessions.md new file mode 100644 index 0000000..6162d87 --- /dev/null +++ b/docs/examples/account/delete-sessions.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.delete_sessions(); + +puts response \ No newline at end of file diff --git a/docs/examples/account/delete.md b/docs/examples/account/delete.md new file mode 100644 index 0000000..3194362 --- /dev/null +++ b/docs/examples/account/delete.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.delete(); + +puts response \ No newline at end of file diff --git a/docs/examples/account/get-logs.md b/docs/examples/account/get-logs.md new file mode 100644 index 0000000..286a0e0 --- /dev/null +++ b/docs/examples/account/get-logs.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.get_logs(); + +puts response \ No newline at end of file diff --git a/docs/examples/account/get-prefs.md b/docs/examples/account/get-prefs.md new file mode 100644 index 0000000..d63509e --- /dev/null +++ b/docs/examples/account/get-prefs.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.get_prefs(); + +puts response \ No newline at end of file diff --git a/docs/examples/account/get-sessions.md b/docs/examples/account/get-sessions.md new file mode 100644 index 0000000..43af95b --- /dev/null +++ b/docs/examples/account/get-sessions.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.get_sessions(); + +puts response \ No newline at end of file diff --git a/docs/examples/account/get.md b/docs/examples/account/get.md new file mode 100644 index 0000000..7169349 --- /dev/null +++ b/docs/examples/account/get.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.get(); + +puts response \ No newline at end of file diff --git a/docs/examples/account/update-email.md b/docs/examples/account/update-email.md new file mode 100644 index 0000000..a30c84b --- /dev/null +++ b/docs/examples/account/update-email.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.update_email(email: 'email@example.com', password: 'password'); + +puts response \ No newline at end of file diff --git a/docs/examples/account/update-name.md b/docs/examples/account/update-name.md new file mode 100644 index 0000000..f9b0966 --- /dev/null +++ b/docs/examples/account/update-name.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.update_name(name: '[NAME]'); + +puts response \ No newline at end of file diff --git a/docs/examples/account/update-password.md b/docs/examples/account/update-password.md new file mode 100644 index 0000000..9cd7608 --- /dev/null +++ b/docs/examples/account/update-password.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.update_password(password: 'password'); + +puts response \ No newline at end of file diff --git a/docs/examples/account/update-prefs.md b/docs/examples/account/update-prefs.md new file mode 100644 index 0000000..b1133dc --- /dev/null +++ b/docs/examples/account/update-prefs.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.update_prefs(prefs: {}); + +puts response \ No newline at end of file diff --git a/docs/examples/account/update-recovery.md b/docs/examples/account/update-recovery.md new file mode 100644 index 0000000..f402da9 --- /dev/null +++ b/docs/examples/account/update-recovery.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.update_recovery(user_id: '[USER_ID]', secret: '[SECRET]', password: 'password', password_again: 'password'); + +puts response \ No newline at end of file diff --git a/docs/examples/account/update-verification.md b/docs/examples/account/update-verification.md new file mode 100644 index 0000000..2504589 --- /dev/null +++ b/docs/examples/account/update-verification.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +account = Appwrite::Account.new(client); + +response = account.update_verification(user_id: '[USER_ID]', secret: '[SECRET]'); + +puts response \ No newline at end of file diff --git a/docs/examples/database/create-document.md b/docs/examples/database/create-document.md index 0101c74..3fcdf04 100644 --- a/docs/examples/database/create-document.md +++ b/docs/examples/database/create-document.md @@ -10,6 +10,6 @@ client database = Appwrite::Database.new(client); -response = database.create_document(collection_id: '[COLLECTION_ID]', data: {}, read: [], write: []); +response = database.create_document(collection_id: '[COLLECTION_ID]', data: {}); puts response \ No newline at end of file diff --git a/docs/examples/database/update-collection.md b/docs/examples/database/update-collection.md index 3ecfbdb..67100bb 100644 --- a/docs/examples/database/update-collection.md +++ b/docs/examples/database/update-collection.md @@ -10,6 +10,6 @@ client database = Appwrite::Database.new(client); -response = database.update_collection(collection_id: '[COLLECTION_ID]', name: '[NAME]', read: [], write: []); +response = database.update_collection(collection_id: '[COLLECTION_ID]', name: '[NAME]'); puts response \ No newline at end of file diff --git a/docs/examples/database/update-document.md b/docs/examples/database/update-document.md index 492d4f3..8aa829c 100644 --- a/docs/examples/database/update-document.md +++ b/docs/examples/database/update-document.md @@ -10,6 +10,6 @@ client database = Appwrite::Database.new(client); -response = database.update_document(collection_id: '[COLLECTION_ID]', document_id: '[DOCUMENT_ID]', data: {}, read: [], write: []); +response = database.update_document(collection_id: '[COLLECTION_ID]', document_id: '[DOCUMENT_ID]', data: {}); puts response \ No newline at end of file diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index 87c4542..2fa05fb 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -10,6 +10,6 @@ client functions = Appwrite::Functions.new(client); -response = functions.create(name: '[NAME]', execute: [], env: 'node-14.5'); +response = functions.create(name: '[NAME]', execute: [], env: 'dotnet-3.1'); puts response \ No newline at end of file diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index 7062c3f..0b71965 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -10,6 +10,6 @@ client storage = Appwrite::Storage.new(client); -response = storage.create_file(file: Appwrite::File.new(), read: [], write: []); +response = storage.create_file(file: Appwrite::File.new()); puts response \ No newline at end of file diff --git a/docs/examples/teams/delete-membership.md b/docs/examples/teams/delete-membership.md index 545cacc..960261d 100644 --- a/docs/examples/teams/delete-membership.md +++ b/docs/examples/teams/delete-membership.md @@ -10,6 +10,6 @@ client teams = Appwrite::Teams.new(client); -response = teams.delete_membership(team_id: '[TEAM_ID]', invite_id: '[INVITE_ID]'); +response = teams.delete_membership(team_id: '[TEAM_ID]', membership_id: '[MEMBERSHIP_ID]'); puts response \ No newline at end of file diff --git a/docs/examples/teams/update-membership-roles.md b/docs/examples/teams/update-membership-roles.md new file mode 100644 index 0000000..4fbd42f --- /dev/null +++ b/docs/examples/teams/update-membership-roles.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key +; + +teams = Appwrite::Teams.new(client); + +response = teams.update_membership_roles(team_id: '[TEAM_ID]', membership_id: '[MEMBERSHIP_ID]', roles: []); + +puts response \ No newline at end of file diff --git a/docs/examples/teams/update-membership-status.md b/docs/examples/teams/update-membership-status.md new file mode 100644 index 0000000..ead789f --- /dev/null +++ b/docs/examples/teams/update-membership-status.md @@ -0,0 +1,15 @@ +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint + .set_project('5df5acd0d48c2') # Your project ID + .set_j_w_t('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token +; + +teams = Appwrite::Teams.new(client); + +response = teams.update_membership_status(team_id: '[TEAM_ID]', membership_id: '[MEMBERSHIP_ID]', user_id: '[USER_ID]', secret: '[SECRET]'); + +puts response \ No newline at end of file diff --git a/docs/examples/users/delete-user.md b/docs/examples/users/delete.md similarity index 85% rename from docs/examples/users/delete-user.md rename to docs/examples/users/delete.md index 3a0bcb0..2d86b9e 100644 --- a/docs/examples/users/delete-user.md +++ b/docs/examples/users/delete.md @@ -10,6 +10,6 @@ client users = Appwrite::Users.new(client); -response = users.delete_user(user_id: '[USER_ID]'); +response = users.delete(user_id: '[USER_ID]'); puts response \ No newline at end of file diff --git a/docs/examples/users/update-status.md b/docs/examples/users/update-status.md index 088ee38..40e80a0 100644 --- a/docs/examples/users/update-status.md +++ b/docs/examples/users/update-status.md @@ -10,6 +10,6 @@ client users = Appwrite::Users.new(client); -response = users.update_status(user_id: '[USER_ID]', status: '1'); +response = users.update_status(user_id: '[USER_ID]', status: 1); puts response \ No newline at end of file diff --git a/lib/appwrite.rb b/lib/appwrite.rb index fe2e1f0..f54c036 100644 --- a/lib/appwrite.rb +++ b/lib/appwrite.rb @@ -4,7 +4,9 @@ require 'mime/types' require_relative 'appwrite/client' require_relative 'appwrite/service' +require_relative 'appwrite/exception' require_relative 'appwrite/file' +require_relative 'appwrite/services/account' require_relative 'appwrite/services/avatars' require_relative 'appwrite/services/database' require_relative 'appwrite/services/functions' diff --git a/lib/appwrite/client.rb b/lib/appwrite/client.rb index ef44871..cbd8994 100644 --- a/lib/appwrite/client.rb +++ b/lib/appwrite/client.rb @@ -20,8 +20,8 @@ def initialize() @headers = { 'content-type' => '', 'user-agent' => RUBY_PLATFORM + ':ruby-' + RUBY_VERSION, - 'x-sdk-version' => 'appwrite:ruby:2.0.0' - + 'x-sdk-version' => 'appwrite:ruby:2.1.0', + 'X-Appwrite-Response-Format' => '0.8.0' } @endpoint = 'https://appwrite.io/v1'; end @@ -38,6 +38,12 @@ def set_key(value) return self end + def set_j_w_t(value) + add_header('x-appwrite-jwt', value) + + return self + end + def set_locale(value) add_header('x-appwrite-locale', value) @@ -89,7 +95,7 @@ def fetch(method, uri, headers, params, limit = 5) begin response = http.send_request(method.upcase, uri.request_uri, payload, headers) rescue => error - raise 'Request Failed: ' + error.message + raise Appwrite::Exception.new(error.message) end # Handle Redirects @@ -99,8 +105,18 @@ def fetch(method, uri, headers, params, limit = 5) return fetch(method, uri, headers, {}, limit - 1) end + + begin + res = JSON.parse(response.body); + rescue JSON::ParserError => e + raise Appwrite::Exception.new(response.body, response.code, nil) + end + + if(response.code.to_i >= 400) + raise Appwrite::Exception.new(res['message'], res['status'], res) + end - return JSON.parse(response.body); + return res; end def encodeFormData(value, key=nil) diff --git a/lib/appwrite/exception.rb b/lib/appwrite/exception.rb new file mode 100644 index 0000000..3a28f5a --- /dev/null +++ b/lib/appwrite/exception.rb @@ -0,0 +1,14 @@ +module Appwrite + class Exception < StandardError + @code = 0; + @response = nil; + + def initialize(message, code, response) + super(message) + @code = code + @response = response + end + attr_reader :code + attr_reader :response + end +end \ No newline at end of file diff --git a/lib/appwrite/services/account.rb b/lib/appwrite/services/account.rb new file mode 100644 index 0000000..bc4ee79 --- /dev/null +++ b/lib/appwrite/services/account.rb @@ -0,0 +1,190 @@ +module Appwrite + class Account < Service + + def get() + path = '/account' + + params = { + } + + return @client.call('get', path, { + 'content-type' => 'application/json', + }, params); + end + + def delete() + path = '/account' + + params = { + } + + return @client.call('delete', path, { + 'content-type' => 'application/json', + }, params); + end + + def update_email(email:, password:) + path = '/account/email' + + params = { + 'email': email, + 'password': password + } + + return @client.call('patch', path, { + 'content-type' => 'application/json', + }, params); + end + + def get_logs() + path = '/account/logs' + + params = { + } + + return @client.call('get', path, { + 'content-type' => 'application/json', + }, params); + end + + def update_name(name:) + path = '/account/name' + + params = { + 'name': name + } + + return @client.call('patch', path, { + 'content-type' => 'application/json', + }, params); + end + + def update_password(password:, old_password: '') + path = '/account/password' + + params = { + 'password': password, + 'oldPassword': old_password + } + + return @client.call('patch', path, { + 'content-type' => 'application/json', + }, params); + end + + def get_prefs() + path = '/account/prefs' + + params = { + } + + return @client.call('get', path, { + 'content-type' => 'application/json', + }, params); + end + + def update_prefs(prefs:) + path = '/account/prefs' + + params = { + 'prefs': prefs + } + + return @client.call('patch', path, { + 'content-type' => 'application/json', + }, params); + end + + def create_recovery(email:, url:) + path = '/account/recovery' + + params = { + 'email': email, + 'url': url + } + + return @client.call('post', path, { + 'content-type' => 'application/json', + }, params); + end + + def update_recovery(user_id:, secret:, password:, password_again:) + path = '/account/recovery' + + params = { + 'userId': user_id, + 'secret': secret, + 'password': password, + 'passwordAgain': password_again + } + + return @client.call('put', path, { + 'content-type' => 'application/json', + }, params); + end + + def get_sessions() + path = '/account/sessions' + + params = { + } + + return @client.call('get', path, { + 'content-type' => 'application/json', + }, params); + end + + def delete_sessions() + path = '/account/sessions' + + params = { + } + + return @client.call('delete', path, { + 'content-type' => 'application/json', + }, params); + end + + def delete_session(session_id:) + path = '/account/sessions/{sessionId}' + .gsub('{sessionId}', session_id) + + params = { + } + + return @client.call('delete', path, { + 'content-type' => 'application/json', + }, params); + end + + def create_verification(url:) + path = '/account/verification' + + params = { + 'url': url + } + + return @client.call('post', path, { + 'content-type' => 'application/json', + }, params); + end + + def update_verification(user_id:, secret:) + path = '/account/verification' + + params = { + 'userId': user_id, + 'secret': secret + } + + return @client.call('put', path, { + 'content-type' => 'application/json', + }, params); + end + + + protected + + private + end +end \ No newline at end of file diff --git a/lib/appwrite/services/database.rb b/lib/appwrite/services/database.rb index 41a151c..166a8b5 100644 --- a/lib/appwrite/services/database.rb +++ b/lib/appwrite/services/database.rb @@ -43,7 +43,7 @@ def get_collection(collection_id:) }, params); end - def update_collection(collection_id:, name:, read:, write:, rules: []) + def update_collection(collection_id:, name:, read: [], write: [], rules: []) path = '/database/collections/{collectionId}' .gsub('{collectionId}', collection_id) @@ -90,7 +90,7 @@ def list_documents(collection_id:, filters: [], limit: 25, offset: 0, order_fiel }, params); end - def create_document(collection_id:, data:, read:, write:, parent_document: '', parent_property: '', parent_property_type: 'assign') + def create_document(collection_id:, data:, read: [], write: [], parent_document: '', parent_property: '', parent_property_type: 'assign') path = '/database/collections/{collectionId}/documents' .gsub('{collectionId}', collection_id) @@ -121,7 +121,7 @@ def get_document(collection_id:, document_id:) }, params); end - def update_document(collection_id:, document_id:, data:, read:, write:) + def update_document(collection_id:, document_id:, data:, read: [], write: []) path = '/database/collections/{collectionId}/documents/{documentId}' .gsub('{collectionId}', collection_id) .gsub('{documentId}', document_id) diff --git a/lib/appwrite/services/functions.rb b/lib/appwrite/services/functions.rb index 8e98801..a942622 100644 --- a/lib/appwrite/services/functions.rb +++ b/lib/appwrite/services/functions.rb @@ -92,11 +92,12 @@ def list_executions(function_id:, search: '', limit: 25, offset: 0, order_type: }, params); end - def create_execution(function_id:) + def create_execution(function_id:, data: '') path = '/functions/{functionId}/executions' .gsub('{functionId}', function_id) params = { + 'data': data } return @client.call('post', path, { diff --git a/lib/appwrite/services/storage.rb b/lib/appwrite/services/storage.rb index 88445bc..e5a3b0f 100644 --- a/lib/appwrite/services/storage.rb +++ b/lib/appwrite/services/storage.rb @@ -16,7 +16,7 @@ def list_files(search: '', limit: 25, offset: 0, order_type: 'ASC') }, params); end - def create_file(file:, read:, write:) + def create_file(file:, read: [], write: []) path = '/storage/files' params = { @@ -80,7 +80,7 @@ def get_file_download(file_id:) }, params); end - def get_file_preview(file_id:, width: 0, height: 0, quality: 100, background: '', output: '') + def get_file_preview(file_id:, width: 0, height: 0, quality: 100, border_width: 0, border_color: '', border_radius: 0, opacity: 1, rotation: 0, background: '', output: '') path = '/storage/files/{fileId}/preview' .gsub('{fileId}', file_id) @@ -88,6 +88,11 @@ def get_file_preview(file_id:, width: 0, height: 0, quality: 100, background: '' 'width': width, 'height': height, 'quality': quality, + 'borderWidth': border_width, + 'borderColor': border_color, + 'borderRadius': border_radius, + 'opacity': opacity, + 'rotation': rotation, 'background': background, 'output': output } diff --git a/lib/appwrite/services/teams.rb b/lib/appwrite/services/teams.rb index 0480a45..2a14be9 100644 --- a/lib/appwrite/services/teams.rb +++ b/lib/appwrite/services/teams.rb @@ -98,10 +98,24 @@ def create_membership(team_id:, email:, roles:, url:, name: '') }, params); end - def delete_membership(team_id:, invite_id:) - path = '/teams/{teamId}/memberships/{inviteId}' + def update_membership_roles(team_id:, membership_id:, roles:) + path = '/teams/{teamId}/memberships/{membershipId}' .gsub('{teamId}', team_id) - .gsub('{inviteId}', invite_id) + .gsub('{membershipId}', membership_id) + + params = { + 'roles': roles + } + + return @client.call('patch', path, { + 'content-type' => 'application/json', + }, params); + end + + def delete_membership(team_id:, membership_id:) + path = '/teams/{teamId}/memberships/{membershipId}' + .gsub('{teamId}', team_id) + .gsub('{membershipId}', membership_id) params = { } @@ -111,6 +125,21 @@ def delete_membership(team_id:, invite_id:) }, params); end + def update_membership_status(team_id:, membership_id:, user_id:, secret:) + path = '/teams/{teamId}/memberships/{membershipId}/status' + .gsub('{teamId}', team_id) + .gsub('{membershipId}', membership_id) + + params = { + 'userId': user_id, + 'secret': secret + } + + return @client.call('patch', path, { + 'content-type' => 'application/json', + }, params); + end + protected diff --git a/lib/appwrite/services/users.rb b/lib/appwrite/services/users.rb index 3c70843..a724e89 100644 --- a/lib/appwrite/services/users.rb +++ b/lib/appwrite/services/users.rb @@ -42,7 +42,7 @@ def get(user_id:) }, params); end - def delete_user(user_id:) + def delete(user_id:) path = '/users/{userId}' .gsub('{userId}', user_id)