From b7913a49ce5d11bb3fc2e760bd329ba9d48687a6 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Aug 2024 11:03:34 +0000 Subject: [PATCH] chore: update SDKs to new RC version --- appwrite.gemspec | 2 +- docs/examples/functions/create.md | 3 +- .../examples/functions/list-specifications.md | 12 +++++ docs/examples/functions/update.md | 3 +- lib/appwrite.rb | 2 + lib/appwrite/client.rb | 2 +- lib/appwrite/models/function.rb | 11 +++-- lib/appwrite/models/specification.rb | 42 ++++++++++++++++++ lib/appwrite/models/specification_list.rb | 32 ++++++++++++++ lib/appwrite/services/functions.rb | 44 +++++++++++++++---- 10 files changed, 137 insertions(+), 16 deletions(-) create mode 100644 docs/examples/functions/list-specifications.md create mode 100644 lib/appwrite/models/specification.rb create mode 100644 lib/appwrite/models/specification_list.rb diff --git a/appwrite.gemspec b/appwrite.gemspec index e287a56..d0ab93a 100644 --- a/appwrite.gemspec +++ b/appwrite.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |spec| spec.name = 'appwrite' - spec.version = '12.0.0-rc.1' + spec.version = '12.0.0-rc.2' 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' diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index 44fb39b..2a09462 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -31,5 +31,6 @@ result = functions.create( template_repository: '', # optional template_owner: '', # optional template_root_directory: '', # optional - template_version: '' # optional + template_version: '', # optional + specification: '' # optional ) diff --git a/docs/examples/functions/list-specifications.md b/docs/examples/functions/list-specifications.md new file mode 100644 index 0000000..b8e2a76 --- /dev/null +++ b/docs/examples/functions/list-specifications.md @@ -0,0 +1,12 @@ +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 + .set_key('<YOUR_API_KEY>') # Your secret API key + +functions = Functions.new(client) + +result = functions.list_specifications() diff --git a/docs/examples/functions/update.md b/docs/examples/functions/update.md index 7111a48..8dc60bf 100644 --- a/docs/examples/functions/update.md +++ b/docs/examples/functions/update.md @@ -26,5 +26,6 @@ result = functions.update( provider_repository_id: '', # optional provider_branch: '', # optional provider_silent_mode: false, # optional - provider_root_directory: '' # optional + provider_root_directory: '', # optional + specification: '' # optional ) diff --git a/lib/appwrite.rb b/lib/appwrite.rb index 0ee7b52..cdc85ea 100644 --- a/lib/appwrite.rb +++ b/lib/appwrite.rb @@ -41,6 +41,7 @@ require_relative 'appwrite/models/topic_list' require_relative 'appwrite/models/subscriber_list' require_relative 'appwrite/models/target_list' +require_relative 'appwrite/models/specification_list' require_relative 'appwrite/models/database' require_relative 'appwrite/models/collection' require_relative 'appwrite/models/attribute_list' @@ -96,6 +97,7 @@ require_relative 'appwrite/models/health_certificate' require_relative 'appwrite/models/health_time' require_relative 'appwrite/models/headers' +require_relative 'appwrite/models/specification' require_relative 'appwrite/models/mfa_challenge' require_relative 'appwrite/models/mfa_recovery_codes' require_relative 'appwrite/models/mfa_type' diff --git a/lib/appwrite/client.rb b/lib/appwrite/client.rb index 3b6e106..2c6b672 100644 --- a/lib/appwrite/client.rb +++ b/lib/appwrite/client.rb @@ -15,7 +15,7 @@ def initialize 'x-sdk-name'=> 'Ruby', 'x-sdk-platform'=> 'server', 'x-sdk-language'=> 'ruby', - 'x-sdk-version'=> '12.0.0-rc.1', + 'x-sdk-version'=> '12.0.0-rc.2', 'X-Appwrite-Response-Format' => '1.6.0' } @endpoint = 'https://cloud.appwrite.io/v1' diff --git a/lib/appwrite/models/function.rb b/lib/appwrite/models/function.rb index bdb4d43..29f829d 100644 --- a/lib/appwrite/models/function.rb +++ b/lib/appwrite/models/function.rb @@ -26,6 +26,7 @@ class Function attr_reader :provider_branch attr_reader :provider_root_directory attr_reader :provider_silent_mode + attr_reader :specification def initialize( id:, @@ -50,7 +51,8 @@ def initialize( provider_repository_id:, provider_branch:, provider_root_directory:, - provider_silent_mode: + provider_silent_mode:, + specification: ) @id = id @created_at = created_at @@ -75,6 +77,7 @@ def initialize( @provider_branch = provider_branch @provider_root_directory = provider_root_directory @provider_silent_mode = provider_silent_mode + @specification = specification end def self.from(map:) @@ -101,7 +104,8 @@ def self.from(map:) provider_repository_id: map["providerRepositoryId"], provider_branch: map["providerBranch"], provider_root_directory: map["providerRootDirectory"], - provider_silent_mode: map["providerSilentMode"] + provider_silent_mode: map["providerSilentMode"], + specification: map["specification"] ) end @@ -129,7 +133,8 @@ def to_map "providerRepositoryId": @provider_repository_id, "providerBranch": @provider_branch, "providerRootDirectory": @provider_root_directory, - "providerSilentMode": @provider_silent_mode + "providerSilentMode": @provider_silent_mode, + "specification": @specification } end end diff --git a/lib/appwrite/models/specification.rb b/lib/appwrite/models/specification.rb new file mode 100644 index 0000000..00c5554 --- /dev/null +++ b/lib/appwrite/models/specification.rb @@ -0,0 +1,42 @@ +#frozen_string_literal: true + +module Appwrite + module Models + class Specification + attr_reader :memory + attr_reader :cpus + attr_reader :enabled + attr_reader :slug + + def initialize( + memory:, + cpus:, + enabled:, + slug: + ) + @memory = memory + @cpus = cpus + @enabled = enabled + @slug = slug + end + + def self.from(map:) + Specification.new( + memory: map["memory"], + cpus: map["cpus"], + enabled: map["enabled"], + slug: map["slug"] + ) + end + + def to_map + { + "memory": @memory, + "cpus": @cpus, + "enabled": @enabled, + "slug": @slug + } + end + end + end +end diff --git a/lib/appwrite/models/specification_list.rb b/lib/appwrite/models/specification_list.rb new file mode 100644 index 0000000..8a21f36 --- /dev/null +++ b/lib/appwrite/models/specification_list.rb @@ -0,0 +1,32 @@ +#frozen_string_literal: true + +module Appwrite + module Models + class SpecificationList + attr_reader :total + attr_reader :specifications + + def initialize( + total:, + specifications: + ) + @total = total + @specifications = specifications + end + + def self.from(map:) + SpecificationList.new( + total: map["total"], + specifications: map["specifications"].map { |it| Specification.from(map: it) } + ) + end + + def to_map + { + "total": @total, + "specifications": @specifications.map { |it| it.to_map } + } + end + end + end +end diff --git a/lib/appwrite/services/functions.rb b/lib/appwrite/services/functions.rb index 80b9e02..abfa4c6 100644 --- a/lib/appwrite/services/functions.rb +++ b/lib/appwrite/services/functions.rb @@ -62,9 +62,10 @@ def list(queries: nil, search: nil) # @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_version Version (tag) for the repo linked to the function template. + # @param [String] specification Runtime specification for the function and builds. # # @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_version: 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, specification: nil) api_path = '/functions' if function_id.nil? @@ -101,6 +102,7 @@ def create(function_id:, name:, runtime:, execute: nil, events: nil, schedule: n templateOwner: template_owner, templateRootDirectory: template_root_directory, templateVersion: template_version, + specification: specification, } api_headers = { @@ -141,6 +143,31 @@ def list_runtimes() end + # List allowed function specifications for this instance. + # + # + # + # @return [SpecificationList] + def list_specifications() + api_path = '/functions/specifications' + + api_params = { + } + + api_headers = { + "content-type": 'application/json', + } + + @client.call( + method: 'GET', + path: api_path, + headers: api_headers, + params: api_params, + response_type: Models::SpecificationList + ) + end + + # List available function templates. You can use template details in # [createFunction](/docs/references/cloud/server-nodejs/functions#create) # method. @@ -256,9 +283,10 @@ def get(function_id:) # @param [String] provider_branch Production branch for the repo linked to the function # @param [] provider_silent_mode Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests. # @param [String] provider_root_directory Path to function code in the linked repo. + # @param [String] specification Runtime specification for the function and builds. # # @return [Function] - def update(function_id:, name:, runtime: nil, 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) + def update(function_id:, name:, runtime: nil, 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, specification: nil) api_path = '/functions/{functionId}' .gsub('{functionId}', function_id) @@ -287,6 +315,7 @@ def update(function_id:, name:, runtime: nil, execute: nil, events: nil, schedul providerBranch: provider_branch, providerSilentMode: provider_silent_mode, providerRootDirectory: provider_root_directory, + specification: specification, } api_headers = { @@ -694,7 +723,7 @@ def list_executions(function_id:, queries: nil, search: nil) # @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, on_progress: nil) + def create_execution(function_id:, body: nil, async: nil, xpath: nil, method: nil, headers: nil, scheduled_at: nil) api_path = '/functions/{functionId}/executions' .gsub('{functionId}', function_id) @@ -712,17 +741,14 @@ def create_execution(function_id:, body: nil, async: nil, xpath: nil, method: ni } api_headers = { - "content-type": 'multipart/form-data', + "content-type": 'application/json', } - id_param_name = nil - @client.chunked_upload( + @client.call( + method: 'POST', 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