class Syncano::QueryBuilder

Proxy class for creating proper requests to api through ActiveRecord pattern

Attributes

client[RW]
resource_class[RW]
scope_parameters[RW]

Public Class Methods

new(client, resource_class, scope_parameters = {}) click to toggle source

Constructor for Syncano::QueryBuilder object @param [Syncano::Clients::Base] client @param [String] resource_class @param [Hash] scope_parameters

# File lib/syncano/query_builder.rb, line 8
def initialize(client, resource_class, scope_parameters = {})
  self.client = client
  self.resource_class = resource_class
  self.scope_parameters = scope_parameters
end

Public Instance Methods

all(conditions = {}) click to toggle source

Proxy for calling “all” method on the resource object @param [Hash] conditions @return [Array] collection of Syncano::Resources::Base objects

# File lib/syncano/query_builder.rb, line 25
def all(conditions = {})
  resource_class.all(client, conditions.merge(scope_parameters))
end
batch() click to toggle source

Proxy for preparing batch requests ie. query_builder.batch.create will prepare BatchQueueElement which invokes batch_create method on query builder object @return [Syncano::BatchQueueElement]

# File lib/syncano/query_builder.rb, line 18
def batch
  ::Syncano::BatchQueueElement.new(self)
end
batch_copy(batch_client, ids) click to toggle source

Proxy for calling “batch_copy” method on the resource object @param [Jimson::Client] batch_client @param [Array] ids @return [Syncano::Response]

# File lib/syncano/query_builder.rb, line 115
def batch_copy(batch_client, ids)
  resource_class.batch_copy(batch_client, scope_parameters, ids)
end
batch_create(batch_client, attributes) click to toggle source

Proxy for calling “batch_create” method on the resource object @param [Jimson::Client] batch_client @param [Hash] attributes @return [Syncano::Response]

# File lib/syncano/query_builder.rb, line 100
def batch_create(batch_client, attributes)
  resource_class.batch_create(batch_client, client, attributes.merge(scope_parameters))
end
batch_move(batch_client, ids, conditions = {}, new_folder = nil, new_state = nil) click to toggle source

Proxy for calling “batch_move” method on the resource object @param [Jimson::Client] batch_client @param [Array] ids @param [Hash] conditions @param [String] new_folder @param [String] new_state @return [Syncano::Response]

# File lib/syncano/query_builder.rb, line 136
def batch_move(batch_client, ids, conditions = {}, new_folder = nil, new_state = nil)
  resource_class.batch_move(batch_client, scope_parameters, ids, conditions, new_folder, new_state)
end
copy(ids) click to toggle source

Proxy for calling “copy” method on the resource object @param [Array] ids @return [Array] collection of Syncano::Resource objects

# File lib/syncano/query_builder.rb, line 107
def copy(ids)
  resource_class.copy(client, scope_parameters, ids)
end
count(conditions = {}) click to toggle source

Proxy for calling “count” method on the resource object @param [Hash] conditions @return [Integer]

# File lib/syncano/query_builder.rb, line 32
def count(conditions = {})
  resource_class.count(client, conditions.merge(scope_parameters))
end
create(attributes) click to toggle source

Proxy for calling “create” method on the resource object @param [Hash] attributes @return [Syncano::Resources::Base]

# File lib/syncano/query_builder.rb, line 92
def create(attributes)
  resource_class.create(client, attributes.merge(scope_parameters))
end
find(key = nil, conditions = {}) click to toggle source

Proxy for calling “find” method on the resource object @param [Integer, String] key @param [Hash] conditions @return [Syncano::Resources::Base]

# File lib/syncano/query_builder.rb, line 54
def find(key = nil, conditions = {})
  resource_class.find(client, key, scope_parameters, conditions)
end
find_by_email(email, conditions = {}) click to toggle source

Proxy for calling “find_by_email” method on the resource object @param [String] email @param [Hash] conditions @return [Syncano::Resources::Base]

# File lib/syncano/query_builder.rb, line 78
def find_by_email(email, conditions = {})
  resource_class.find_by_email(client, email, scope_parameters, conditions)
end
find_by_key(key, conditions = {}) click to toggle source

Proxy for calling “find_by_key” method on the resource object @param [String] key @param [Hash] conditions @return [Syncano::Resources::Base]

# File lib/syncano/query_builder.rb, line 62
def find_by_key(key, conditions = {})
  resource_class.find_by_key(client, key, scope_parameters, conditions)
end
find_by_name(name, conditions = {}) click to toggle source

Proxy for calling “find_by_name” method on the resource object @param [String] name @param [Hash] conditions @return [Syncano::Resources::Base]

# File lib/syncano/query_builder.rb, line 70
def find_by_name(name, conditions = {})
  resource_class.find_by_name(client, name, scope_parameters, conditions)
end
first(conditions = {}) click to toggle source

Returns first element from all returned by “all” method @param [Hash] conditions @return [Syncano::Resources::Base]

# File lib/syncano/query_builder.rb, line 39
def first(conditions = {})
  all(conditions).first
end
last(conditions = {}) click to toggle source

Returns last element from all returned by “all” method @param [Hash] conditions @return [Syncano::Resources::Base]

# File lib/syncano/query_builder.rb, line 46
def last(conditions = {})
  all(conditions).last
end
login(username = nil, password = nil) click to toggle source

Proxy for calling “login” method on the resource object @param [String] username @param [String] password @return [Array] collection of Syncano::Resource objects

# File lib/syncano/query_builder.rb, line 144
def login(username = nil, password = nil)
  resource_class.login(client, username, password)
end
move(ids, conditions = {}, new_folder = nil, new_state = nil) click to toggle source

Proxy for calling “move” method on the resource object @param [Array] ids @param [Hash] conditions @param [String] new_folder @param [String] new_state @return [Array] collection of Syncano::Resource objects

# File lib/syncano/query_builder.rb, line 125
def move(ids, conditions = {}, new_folder = nil, new_state = nil)
  resource_class.move(client, scope_parameters, ids, conditions, new_folder, new_state)
end
new(attributes = {}) click to toggle source

Proxy for calling “new” method on the resource object @param [Hash] attributes @return [Syncano::Resources::Base]

# File lib/syncano/query_builder.rb, line 85
def new(attributes = {})
  resource_class.new(client, attributes.merge(scope_parameters))
end