class Syncano::Clients::Base
Base
class for representing clients
Attributes
Public Class Methods
Constructor for Syncano::Clients::Base
object @param [String] instance_name
@param [String] api_key
# File lib/syncano/clients/base.rb, line 11 def initialize(instance_name, api_key, auth_key) super() self.instance_name = instance_name self.api_key = api_key self.auth_key = auth_key if auth_key.present? end
Private Class Methods
Parses Syncano
api response and returns Syncano::Response
object @param [String] response_key @param [Hash] raw_response @return [Syncano::Response]
# File lib/syncano/clients/base.rb, line 108 def self.parse_response(response_key, raw_response) status = raw_response.nil? || raw_response['result'] != 'NOK' if raw_response.nil? data = nil elsif raw_response[response_key.to_s].present? data = raw_response[response_key.to_s] else data = raw_response['count'] end errors = status ? [] : raw_response['error'] ::Syncano::Response.new(status, data, errors) end
Public Instance Methods
Returns query builder for Syncano::Resources::Admin
objects @return [Syncano::QueryBuilder]
# File lib/syncano/clients/base.rb, line 28 def admins ::Syncano::QueryBuilder.new(self, ::Syncano::Resources::Admin) end
Returns query builder for Syncano::Resources::ApiKey
objects @return [Syncano::QueryBuilder]
# File lib/syncano/clients/base.rb, line 34 def api_keys ::Syncano::QueryBuilder.new(self, ::Syncano::Resources::ApiKey) end
Returns query builder for Syncano::Resources::Project
objects @param [Integer, String] project_id @return [Syncano::QueryBuilder]
# File lib/syncano/clients/base.rb, line 53 def collections(project_id) ::Syncano::QueryBuilder.new(self, ::Syncano::Resources::Collection, project_id: project_id) end
Returns query builder for Syncano::Resources::DataObject
objects @param [Integer, String] project_id @param [Integer, String] collection_id @return [Syncano::QueryBuilder]
# File lib/syncano/clients/base.rb, line 69 def data_objects(project_id, collection_id) ::Syncano::QueryBuilder.new(self, ::Syncano::Resources::DataObject, project_id: project_id, collection_id: collection_id) end
Returns query builder for Syncano::Resources::Folder
objects @param [Integer, String] project_id @param [Integer, String] collection_id @return [Syncano::QueryBuilder]
# File lib/syncano/clients/base.rb, line 61 def folders(project_id, collection_id) ::Syncano::QueryBuilder.new(self, ::Syncano::Resources::Collection, project_id: project_id, collection_id: collection_id) end
Deletes saved auth_key
@return [TrueClass, FalseClass]
# File lib/syncano/clients/base.rb, line 21 def logout self.auth_key = nil self.auth_key.nil? end
Performs batch request to Syncano
api This should be overwritten in inherited classes @param [Jimson::BatchClient] batch_client @param [String] resource_name @param [String] method_name @param [Hash] params additional params sent in the request
# File lib/syncano/clients/base.rb, line 97 def make_batch_request(batch_client, resource_name, method_name, params = {}) end
Performs request to Syncano
api This should be overwritten in inherited classes @param [String] resource_name @param [String] method_name @param [Hash] params additional params sent in the request @param [String] response_key for cases when response from api is incompatible with the convention @return [Syncano::Response]
# File lib/syncano/clients/base.rb, line 88 def make_request(resource_name, method_name, params = {}, response_key = nil) end
Returns query builder for Syncano::Resources::Project
objects @return [Syncano::QueryBuilder]
# File lib/syncano/clients/base.rb, line 46 def projects ::Syncano::QueryBuilder.new(self, ::Syncano::Resources::Project) end
Returns query builder for Syncano::Resources::Role
objects @return [Syncano::QueryBuilder]
# File lib/syncano/clients/base.rb, line 40 def roles ::Syncano::QueryBuilder.new(self, ::Syncano::Resources::Role) end
Returns query builder for Syncano::Resources::User
objects @param [Integer, String] project_id @param [Integer, String] collection_id @return [Syncano::QueryBuilder]
# File lib/syncano/clients/base.rb, line 77 def users ::Syncano::QueryBuilder.new(self, ::Syncano::Resources::User) end