From 35e13f6537baabf00819d5b29b08f02d17b67f0b Mon Sep 17 00:00:00 2001 From: root Date: Sat, 17 Aug 2024 08:50:07 +0000 Subject: [PATCH] chore: release rc --- README.md | 2 +- appwrite.gemspec | 4 +- .../account/delete-mfa-authenticator.md | 3 +- docs/examples/functions/create.md | 2 +- ...ployment.md => get-deployment-download.md} | 4 +- docs/examples/functions/get-template.md | 13 +++ docs/examples/functions/list-templates.md | 16 +++ lib/appwrite.rb | 4 + lib/appwrite/client.rb | 4 +- lib/appwrite/models/execution.rb | 11 +- lib/appwrite/models/runtime.rb | 5 + lib/appwrite/models/template_function.rb | 107 ++++++++++++++++++ lib/appwrite/models/template_function_list.rb | 32 ++++++ lib/appwrite/models/template_runtime.rb | 42 +++++++ lib/appwrite/models/template_variable.rb | 52 +++++++++ lib/appwrite/services/account.rb | 8 +- lib/appwrite/services/avatars.rb | 2 + lib/appwrite/services/functions.rb | 89 +++++++++++++-- 18 files changed, 370 insertions(+), 30 deletions(-) rename docs/examples/functions/{download-deployment.md => get-deployment-download.md} (74%) create mode 100644 docs/examples/functions/get-template.md create mode 100644 docs/examples/functions/list-templates.md create mode 100644 lib/appwrite/models/template_function.rb create mode 100644 lib/appwrite/models/template_function_list.rb create mode 100644 lib/appwrite/models/template_runtime.rb create mode 100644 lib/appwrite/models/template_variable.rb diff --git a/README.md b/README.md index 8d1aea7..f52f9c1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Appwrite Ruby SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-ruby.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.5.7-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.6.0-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) diff --git a/appwrite.gemspec b/appwrite.gemspec index 146b77c..e287a56 100644 --- a/appwrite.gemspec +++ b/appwrite.gemspec @@ -1,12 +1,12 @@ Gem::Specification.new do |spec| spec.name = 'appwrite' - spec.version = '11.0.2' + spec.version = '12.0.0-rc.1' spec.license = 'BSD-3-Clause' spec.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' spec.author = 'Appwrite Team' spec.homepage = 'https://appwrite.io/support' - spec.email = 'team@appwrite.io' + spec.email = 'team@localhost.test' spec.files = Dir['lib/**/*.rb'] spec.add_dependency 'mime-types', '~> 3.4.1' diff --git a/docs/examples/account/delete-mfa-authenticator.md b/docs/examples/account/delete-mfa-authenticator.md index 9b694ff..1d21a5c 100644 --- a/docs/examples/account/delete-mfa-authenticator.md +++ b/docs/examples/account/delete-mfa-authenticator.md @@ -11,6 +11,5 @@ client = Client.new account = Account.new(client) result = account.delete_mfa_authenticator( - type: AuthenticatorType::TOTP, - otp: '' + type: AuthenticatorType::TOTP ) diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index 975f985..44fb39b 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -31,5 +31,5 @@ result = functions.create( template_repository: '', # optional template_owner: '', # optional template_root_directory: '', # optional - template_branch: '' # optional + template_version: '' # optional ) diff --git a/docs/examples/functions/download-deployment.md b/docs/examples/functions/get-deployment-download.md similarity index 74% rename from docs/examples/functions/download-deployment.md rename to docs/examples/functions/get-deployment-download.md index 5736928..d4910ee 100644 --- a/docs/examples/functions/download-deployment.md +++ b/docs/examples/functions/get-deployment-download.md @@ -5,11 +5,11 @@ include Appwrite client = Client.new .set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint .set_project('<YOUR_PROJECT_ID>') # Your project ID - .set_key('<YOUR_API_KEY>') # Your secret API key + .set_session('') # The user session to authenticate with functions = Functions.new(client) -result = functions.download_deployment( +result = functions.get_deployment_download( function_id: '', deployment_id: '' ) diff --git a/docs/examples/functions/get-template.md b/docs/examples/functions/get-template.md new file mode 100644 index 0000000..84fad8e --- /dev/null +++ b/docs/examples/functions/get-template.md @@ -0,0 +1,13 @@ +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint + .set_project('<YOUR_PROJECT_ID>') # Your project ID + +functions = Functions.new(client) + +result = functions.get_template( + template_id: '' +) diff --git a/docs/examples/functions/list-templates.md b/docs/examples/functions/list-templates.md new file mode 100644 index 0000000..da77dd1 --- /dev/null +++ b/docs/examples/functions/list-templates.md @@ -0,0 +1,16 @@ +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint + .set_project('<YOUR_PROJECT_ID>') # Your project ID + +functions = Functions.new(client) + +result = functions.list_templates( + runtimes: [], # optional + use_cases: [], # optional + limit: 1, # optional + offset: 0 # optional +) diff --git a/lib/appwrite.rb b/lib/appwrite.rb index 95161f1..0ee7b52 100644 --- a/lib/appwrite.rb +++ b/lib/appwrite.rb @@ -25,6 +25,7 @@ require_relative 'appwrite/models/team_list' require_relative 'appwrite/models/membership_list' require_relative 'appwrite/models/function_list' +require_relative 'appwrite/models/template_function_list' require_relative 'appwrite/models/runtime_list' require_relative 'appwrite/models/deployment_list' require_relative 'appwrite/models/execution_list' @@ -76,6 +77,9 @@ require_relative 'appwrite/models/team' require_relative 'appwrite/models/membership' require_relative 'appwrite/models/function' +require_relative 'appwrite/models/template_function' +require_relative 'appwrite/models/template_runtime' +require_relative 'appwrite/models/template_variable' require_relative 'appwrite/models/runtime' require_relative 'appwrite/models/deployment' require_relative 'appwrite/models/execution' diff --git a/lib/appwrite/client.rb b/lib/appwrite/client.rb index 92817c9..3b6e106 100644 --- a/lib/appwrite/client.rb +++ b/lib/appwrite/client.rb @@ -15,8 +15,8 @@ def initialize 'x-sdk-name'=> 'Ruby', 'x-sdk-platform'=> 'server', 'x-sdk-language'=> 'ruby', - 'x-sdk-version'=> '11.0.2', - 'X-Appwrite-Response-Format' => '1.5.0' + 'x-sdk-version'=> '12.0.0-rc.1', + 'X-Appwrite-Response-Format' => '1.6.0' } @endpoint = 'https://cloud.appwrite.io/v1' end diff --git a/lib/appwrite/models/execution.rb b/lib/appwrite/models/execution.rb index dd69b83..066ae71 100644 --- a/lib/appwrite/models/execution.rb +++ b/lib/appwrite/models/execution.rb @@ -19,6 +19,7 @@ class Execution attr_reader :logs attr_reader :errors attr_reader :duration + attr_reader :scheduled_at def initialize( id:, @@ -36,7 +37,8 @@ def initialize( response_headers:, logs:, errors:, - duration: + duration:, + scheduled_at: ) @id = id @created_at = created_at @@ -54,6 +56,7 @@ def initialize( @logs = logs @errors = errors @duration = duration + @scheduled_at = scheduled_at end def self.from(map:) @@ -73,7 +76,8 @@ def self.from(map:) response_headers: map["responseHeaders"].map { |it| Headers.from(map: it) }, logs: map["logs"], errors: map["errors"], - duration: map["duration"] + duration: map["duration"], + scheduled_at: map["scheduledAt"] ) end @@ -94,7 +98,8 @@ def to_map "responseHeaders": @response_headers.map { |it| it.to_map }, "logs": @logs, "errors": @errors, - "duration": @duration + "duration": @duration, + "scheduledAt": @scheduled_at } end end diff --git a/lib/appwrite/models/runtime.rb b/lib/appwrite/models/runtime.rb index 2c21f8b..4158038 100644 --- a/lib/appwrite/models/runtime.rb +++ b/lib/appwrite/models/runtime.rb @@ -4,6 +4,7 @@ module Appwrite module Models class Runtime attr_reader :id + attr_reader :key attr_reader :name attr_reader :version attr_reader :base @@ -13,6 +14,7 @@ class Runtime def initialize( id:, + key:, name:, version:, base:, @@ -21,6 +23,7 @@ def initialize( supports: ) @id = id + @key = key @name = name @version = version @base = base @@ -32,6 +35,7 @@ def initialize( def self.from(map:) Runtime.new( id: map["$id"], + key: map["key"], name: map["name"], version: map["version"], base: map["base"], @@ -44,6 +48,7 @@ def self.from(map:) def to_map { "$id": @id, + "key": @key, "name": @name, "version": @version, "base": @base, diff --git a/lib/appwrite/models/template_function.rb b/lib/appwrite/models/template_function.rb new file mode 100644 index 0000000..2e85b11 --- /dev/null +++ b/lib/appwrite/models/template_function.rb @@ -0,0 +1,107 @@ +#frozen_string_literal: true + +module Appwrite + module Models + class TemplateFunction + attr_reader :icon + attr_reader :id + attr_reader :name + attr_reader :tagline + attr_reader :permissions + attr_reader :events + attr_reader :cron + attr_reader :timeout + attr_reader :use_cases + attr_reader :runtimes + attr_reader :instructions + attr_reader :vcs_provider + attr_reader :provider_repository_id + attr_reader :provider_owner + attr_reader :provider_version + attr_reader :variables + attr_reader :scopes + + def initialize( + icon:, + id:, + name:, + tagline:, + permissions:, + events:, + cron:, + timeout:, + use_cases:, + runtimes:, + instructions:, + vcs_provider:, + provider_repository_id:, + provider_owner:, + provider_version:, + variables:, + scopes: + ) + @icon = icon + @id = id + @name = name + @tagline = tagline + @permissions = permissions + @events = events + @cron = cron + @timeout = timeout + @use_cases = use_cases + @runtimes = runtimes + @instructions = instructions + @vcs_provider = vcs_provider + @provider_repository_id = provider_repository_id + @provider_owner = provider_owner + @provider_version = provider_version + @variables = variables + @scopes = scopes + end + + def self.from(map:) + TemplateFunction.new( + icon: map["icon"], + id: map["id"], + name: map["name"], + tagline: map["tagline"], + permissions: map["permissions"], + events: map["events"], + cron: map["cron"], + timeout: map["timeout"], + use_cases: map["useCases"], + runtimes: map["runtimes"].map { |it| TemplateRuntime.from(map: it) }, + instructions: map["instructions"], + vcs_provider: map["vcsProvider"], + provider_repository_id: map["providerRepositoryId"], + provider_owner: map["providerOwner"], + provider_version: map["providerVersion"], + variables: map["variables"].map { |it| TemplateVariable.from(map: it) }, + scopes: map["scopes"] + ) + end + + def to_map + { + "icon": @icon, + "id": @id, + "name": @name, + "tagline": @tagline, + "permissions": @permissions, + "events": @events, + "cron": @cron, + "timeout": @timeout, + "useCases": @use_cases, + "runtimes": @runtimes.map { |it| it.to_map }, + "instructions": @instructions, + "vcsProvider": @vcs_provider, + "providerRepositoryId": @provider_repository_id, + "providerOwner": @provider_owner, + "providerVersion": @provider_version, + "variables": @variables.map { |it| it.to_map }, + "scopes": @scopes + } + end + end + end +end diff --git a/lib/appwrite/models/template_function_list.rb b/lib/appwrite/models/template_function_list.rb new file mode 100644 index 0000000..20033db --- /dev/null +++ b/lib/appwrite/models/template_function_list.rb @@ -0,0 +1,32 @@ +#frozen_string_literal: true + +module Appwrite + module Models + class TemplateFunctionList + attr_reader :total + attr_reader :templates + + def initialize( + total:, + templates: + ) + @total = total + @templates = templates + end + + def self.from(map:) + TemplateFunctionList.new( + total: map["total"], + templates: map["templates"].map { |it| TemplateFunction.from(map: it) } + ) + end + + def to_map + { + "total": @total, + "templates": @templates.map { |it| it.to_map } + } + end + end + end +end diff --git a/lib/appwrite/models/template_runtime.rb b/lib/appwrite/models/template_runtime.rb new file mode 100644 index 0000000..33d96a2 --- /dev/null +++ b/lib/appwrite/models/template_runtime.rb @@ -0,0 +1,42 @@ +#frozen_string_literal: true + +module Appwrite + module Models + class TemplateRuntime + attr_reader :name + attr_reader :commands + attr_reader :entrypoint + attr_reader :provider_root_directory + + def initialize( + name:, + commands:, + entrypoint:, + provider_root_directory: + ) + @name = name + @commands = commands + @entrypoint = entrypoint + @provider_root_directory = provider_root_directory + end + + def self.from(map:) + TemplateRuntime.new( + name: map["name"], + commands: map["commands"], + entrypoint: map["entrypoint"], + provider_root_directory: map["providerRootDirectory"] + ) + end + + def to_map + { + "name": @name, + "commands": @commands, + "entrypoint": @entrypoint, + "providerRootDirectory": @provider_root_directory + } + end + end + end +end diff --git a/lib/appwrite/models/template_variable.rb b/lib/appwrite/models/template_variable.rb new file mode 100644 index 0000000..8a5d6e0 --- /dev/null +++ b/lib/appwrite/models/template_variable.rb @@ -0,0 +1,52 @@ +#frozen_string_literal: true + +module Appwrite + module Models + class TemplateVariable + attr_reader :name + attr_reader :description + attr_reader :value + attr_reader :placeholder + attr_reader :required + attr_reader :type + + def initialize( + name:, + description:, + value:, + placeholder:, + required:, + type: + ) + @name = name + @description = description + @value = value + @placeholder = placeholder + @required = required + @type = type + end + + def self.from(map:) + TemplateVariable.new( + name: map["name"], + description: map["description"], + value: map["value"], + placeholder: map["placeholder"], + required: map["required"], + type: map["type"] + ) + end + + def to_map + { + "name": @name, + "description": @description, + "value": @value, + "placeholder": @placeholder, + "required": @required, + "type": @type + } + end + end + end +end diff --git a/lib/appwrite/services/account.rb b/lib/appwrite/services/account.rb index 1a74d41..aff062d 100644 --- a/lib/appwrite/services/account.rb +++ b/lib/appwrite/services/account.rb @@ -338,10 +338,9 @@ def update_mfa_authenticator(type:, otp:) # Delete an authenticator for a user by ID. # # @param [AuthenticatorType] type Type of authenticator. - # @param [String] otp Valid verification token. # # @return [] - def delete_mfa_authenticator(type:, otp:) + def delete_mfa_authenticator(type:) api_path = '/account/mfa/authenticators/{type}' .gsub('{type}', type) @@ -349,12 +348,7 @@ def delete_mfa_authenticator(type:, otp:) raise Appwrite::Exception.new('Missing required parameter: "type"') end - if otp.nil? - raise Appwrite::Exception.new('Missing required parameter: "otp"') - end - api_params = { - otp: otp, } api_headers = { diff --git a/lib/appwrite/services/avatars.rb b/lib/appwrite/services/avatars.rb index 5e49f03..60c3f68 100644 --- a/lib/appwrite/services/avatars.rb +++ b/lib/appwrite/services/avatars.rb @@ -97,6 +97,7 @@ def get_credit_card(code:, width: nil, height: nil, quality: nil) # Use this endpoint to fetch the favorite icon (AKA favicon) of any remote # website URL. # + # This endpoint does not follow HTTP redirects. # # @param [String] url Website URL which you want to fetch the favicon from. # @@ -179,6 +180,7 @@ def get_flag(code:, width: nil, height: nil, quality: nil) # image at source quality. If dimensions are not specified, the default size # of image returned is 400x400px. # + # This endpoint does not follow HTTP redirects. # # @param [String] url Image URL which you want to crop. # @param [Integer] width Resize preview image width, Pass an integer between 0 to 2000. Defaults to 400. diff --git a/lib/appwrite/services/functions.rb b/lib/appwrite/services/functions.rb index 87fcbdc..80b9e02 100644 --- a/lib/appwrite/services/functions.rb +++ b/lib/appwrite/services/functions.rb @@ -61,10 +61,10 @@ def list(queries: nil, search: nil) # @param [String] template_repository Repository name of the template. # @param [String] template_owner The name of the owner of the template. # @param [String] template_root_directory Path to function code in the template repo. - # @param [String] template_branch Production branch for the repo linked to the function template. + # @param [String] template_version Version (tag) for the repo linked to the function template. # # @return [Function] - def create(function_id:, name:, runtime:, execute: nil, events: nil, schedule: nil, timeout: nil, enabled: nil, logging: nil, entrypoint: nil, commands: nil, scopes: nil, installation_id: nil, provider_repository_id: nil, provider_branch: nil, provider_silent_mode: nil, provider_root_directory: nil, template_repository: nil, template_owner: nil, template_root_directory: nil, template_branch: nil) + def create(function_id:, name:, runtime:, execute: nil, events: nil, schedule: nil, timeout: nil, enabled: nil, logging: nil, entrypoint: nil, commands: nil, scopes: nil, installation_id: nil, provider_repository_id: nil, provider_branch: nil, provider_silent_mode: nil, provider_root_directory: nil, template_repository: nil, template_owner: nil, template_root_directory: nil, template_version: nil) api_path = '/functions' if function_id.nil? @@ -100,7 +100,7 @@ def create(function_id:, name:, runtime:, execute: nil, events: nil, schedule: n templateRepository: template_repository, templateOwner: template_owner, templateRootDirectory: template_root_directory, - templateBranch: template_branch, + templateVersion: template_version, } api_headers = { @@ -141,6 +141,72 @@ def list_runtimes() end + # List available function templates. You can use template details in + # [createFunction](/docs/references/cloud/server-nodejs/functions#create) + # method. + # + # @param [Array] runtimes List of runtimes allowed for filtering function templates. Maximum of 100 runtimes are allowed. + # @param [Array] use_cases List of use cases allowed for filtering function templates. Maximum of 100 use cases are allowed. + # @param [Integer] limit Limit the number of templates returned in the response. Default limit is 25, and maximum limit is 5000. + # @param [Integer] offset Offset the list of returned templates. Maximum offset is 5000. + # + # @return [TemplateFunctionList] + def list_templates(runtimes: nil, use_cases: nil, limit: nil, offset: nil) + api_path = '/functions/templates' + + api_params = { + runtimes: runtimes, + useCases: use_cases, + limit: limit, + offset: offset, + } + + api_headers = { + "content-type": 'application/json', + } + + @client.call( + method: 'GET', + path: api_path, + headers: api_headers, + params: api_params, + response_type: Models::TemplateFunctionList + ) + end + + + # Get a function template using ID. You can use template details in + # [createFunction](/docs/references/cloud/server-nodejs/functions#create) + # method. + # + # @param [String] template_id Template ID. + # + # @return [TemplateFunction] + def get_template(template_id:) + api_path = '/functions/templates/{templateId}' + .gsub('{templateId}', template_id) + + if template_id.nil? + raise Appwrite::Exception.new('Missing required parameter: "templateId"') + end + + api_params = { + } + + api_headers = { + "content-type": 'application/json', + } + + @client.call( + method: 'GET', + path: api_path, + headers: api_headers, + params: api_params, + response_type: Models::TemplateFunction + ) + end + + # Get a function by its unique ID. # # @param [String] function_id Function ID. @@ -270,7 +336,7 @@ def delete(function_id:) # params to filter your results. # # @param [String] function_id Function ID. - # @param [Array] 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. You may filter on the following attributes: size, buildId, activate, entrypoint, commands + # @param [Array] 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. You may filter on the following attributes: size, buildId, activate, entrypoint, commands, type, size # @param [String] search Search term to filter your list results. Max length: 256 chars. # # @return [DeploymentList] @@ -550,7 +616,7 @@ def update_deployment_build(function_id:, deployment_id:) # @param [String] deployment_id Deployment ID. # # @return [] - def download_deployment(function_id:, deployment_id:) + def get_deployment_download(function_id:, deployment_id:) api_path = '/functions/{functionId}/deployments/{deploymentId}/download' .gsub('{functionId}', function_id) .gsub('{deploymentId}', deployment_id) @@ -625,10 +691,10 @@ def list_executions(function_id:, queries: nil, search: nil) # @param [String] xpath HTTP path of execution. Path can include query params. Default value is / # @param [ExecutionMethod] method HTTP method of execution. Default value is GET. # @param [Hash] headers HTTP headers of execution. Defaults to empty. - # @param [String] scheduled_at Scheduled execution time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future. + # @param [String] scheduled_at Scheduled execution time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future with precision in minutes. # # @return [Execution] - def create_execution(function_id:, body: nil, async: nil, xpath: nil, method: nil, headers: nil, scheduled_at: nil) + def create_execution(function_id:, body: nil, async: nil, xpath: nil, method: nil, headers: nil, scheduled_at: nil, on_progress: nil) api_path = '/functions/{functionId}/executions' .gsub('{functionId}', function_id) @@ -646,14 +712,17 @@ def create_execution(function_id:, body: nil, async: nil, xpath: nil, method: ni } api_headers = { - "content-type": 'application/json', + "content-type": 'multipart/form-data', } - @client.call( - method: 'POST', + id_param_name = nil + @client.chunked_upload( path: api_path, headers: api_headers, params: api_params, + param_name: param_name, + id_param_name: id_param_name, + on_progress: on_progress, response_type: Models::Execution ) end