class Syncano::Clients::Base

Base class for representing clients

Attributes

api_key[RW]
auth_key[RW]
instance_name[RW]

Public Class Methods

new(instance_name, api_key, auth_key) click to toggle source

Constructor for Syncano::Clients::Base object @param [String] instance_name @param [String] api_key

Calls superclass method
# 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

parse_response(response_key, raw_response) click to toggle source

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

admins() click to toggle source

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
api_keys() click to toggle source

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
collections(project_id) click to toggle source

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
data_objects(project_id, collection_id) click to toggle source

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
folders(project_id, collection_id) click to toggle source

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
logout() click to toggle source

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
make_batch_request(batch_client, resource_name, method_name, params = {}) click to toggle source

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
make_request(resource_name, method_name, params = {}, response_key = nil) click to toggle source

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
projects() click to toggle source

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
roles() click to toggle source

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
users() click to toggle source

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