Class: Syncano::QueryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/syncano/query_builder.rb

Overview

Proxy class for creating proper requests to api through ActiveRecord pattern

Instance Method Summary collapse

Constructor Details

#initialize(client, resource_class, scope_parameters = {}) ⇒ QueryBuilder

Constructor for Syncano::QueryBuilder object

Parameters:



8
9
10
11
12
# 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

Instance Method Details

#all(conditions = {}) ⇒ Array

Proxy for calling “all” method on the resource object

Parameters:

  • conditions (Hash) (defaults to: {})

Returns:

  • (Array)

    collection of Syncano::Resources::Base objects



25
26
27
# File 'lib/syncano/query_builder.rb', line 25

def all(conditions = {})
  resource_class.all(client, conditions.merge(scope_parameters))
end

#batchSyncano::BatchQueueElement

Proxy for preparing batch requests ie. query_builder.batch.create will prepare BatchQueueElement which invokes batch_create method on query builder object



18
19
20
# File 'lib/syncano/query_builder.rb', line 18

def batch
  ::Syncano::BatchQueueElement.new(self)
end

#batch_copy(batch_client, ids) ⇒ Syncano::Response

Proxy for calling “batch_copy” method on the resource object

Parameters:

  • batch_client (Jimson::Client)
  • ids (Array)

Returns:



115
116
117
# 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) ⇒ Syncano::Response

Proxy for calling “batch_create” method on the resource object

Parameters:

  • batch_client (Jimson::Client)
  • attributes (Hash)

Returns:



100
101
102
# 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) ⇒ Syncano::Response

Proxy for calling “batch_move” method on the resource object

Parameters:

  • batch_client (Jimson::Client)
  • ids (Array)
  • conditions (Hash) (defaults to: {})
  • new_folder (String) (defaults to: nil)
  • new_state (String) (defaults to: nil)

Returns:



136
137
138
# 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) ⇒ Array

Proxy for calling “copy” method on the resource object

Parameters:

  • ids (Array)

Returns:

  • (Array)

    collection of Syncano::Resource objects



107
108
109
# File 'lib/syncano/query_builder.rb', line 107

def copy(ids)
  resource_class.copy(client, scope_parameters, ids)
end

#count(conditions = {}) ⇒ Integer

Proxy for calling “count” method on the resource object

Parameters:

  • conditions (Hash) (defaults to: {})

Returns:

  • (Integer)


32
33
34
# File 'lib/syncano/query_builder.rb', line 32

def count(conditions = {})
  resource_class.count(client, conditions.merge(scope_parameters))
end

#create(attributes) ⇒ Syncano::Resources::Base

Proxy for calling “create” method on the resource object

Parameters:

  • attributes (Hash)

Returns:



92
93
94
# File 'lib/syncano/query_builder.rb', line 92

def create(attributes)
  resource_class.create(client, attributes.merge(scope_parameters))
end

#find(key = nil, conditions = {}) ⇒ Syncano::Resources::Base

Proxy for calling “find” method on the resource object

Parameters:

  • key (Integer, String) (defaults to: nil)
  • conditions (Hash) (defaults to: {})

Returns:



54
55
56
# 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 = {}) ⇒ Syncano::Resources::Base

Proxy for calling “find_by_email” method on the resource object

Parameters:

  • email (String)
  • conditions (Hash) (defaults to: {})

Returns:



78
79
80
# 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 = {}) ⇒ Syncano::Resources::Base

Proxy for calling “find_by_key” method on the resource object

Parameters:

  • key (String)
  • conditions (Hash) (defaults to: {})

Returns:



62
63
64
# 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 = {}) ⇒ Syncano::Resources::Base

Proxy for calling “find_by_name” method on the resource object

Parameters:

  • name (String)
  • conditions (Hash) (defaults to: {})

Returns:



70
71
72
# 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 = {}) ⇒ Syncano::Resources::Base

Returns first element from all returned by “all” method

Parameters:

  • conditions (Hash) (defaults to: {})

Returns:



39
40
41
# File 'lib/syncano/query_builder.rb', line 39

def first(conditions = {})
  all(conditions).first
end

#last(conditions = {}) ⇒ Syncano::Resources::Base

Returns last element from all returned by “all” method

Parameters:

  • conditions (Hash) (defaults to: {})

Returns:



46
47
48
# File 'lib/syncano/query_builder.rb', line 46

def last(conditions = {})
  all(conditions).last
end

#login(username = nil, password = nil) ⇒ Array

Proxy for calling “login” method on the resource object

Parameters:

  • username (String) (defaults to: nil)
  • password (String) (defaults to: nil)

Returns:

  • (Array)

    collection of Syncano::Resource objects



144
145
146
# File 'lib/syncano/query_builder.rb', line 144

def (username = nil, password = nil)
  resource_class.(client, username, password)
end

#move(ids, conditions = {}, new_folder = nil, new_state = nil) ⇒ Array

Proxy for calling “move” method on the resource object

Parameters:

  • ids (Array)
  • conditions (Hash) (defaults to: {})
  • new_folder (String) (defaults to: nil)
  • new_state (String) (defaults to: nil)

Returns:

  • (Array)

    collection of Syncano::Resource objects



125
126
127
# 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 = {}) ⇒ Syncano::Resources::Base

Proxy for calling “new” method on the resource object

Parameters:

  • attributes (Hash) (defaults to: {})

Returns:



85
86
87
# File 'lib/syncano/query_builder.rb', line 85

def new(attributes = {})
  resource_class.new(client, attributes.merge(scope_parameters))
end