Class: Syncano::QueryBuilder
- Inherits:
-
Object
- Object
- Syncano::QueryBuilder
- Defined in:
- lib/syncano/query_builder.rb
Overview
Proxy class for creating proper requests to api through ActiveRecord pattern
Instance Method Summary collapse
-
#all(conditions = {}) ⇒ Array
Proxy for calling “all” method on the resource object.
-
#batch ⇒ Syncano::BatchQueueElement
Proxy for preparing batch requests ie.
-
#batch_copy(batch_client, ids) ⇒ Syncano::Response
Proxy for calling “batch_copy” method on the resource object.
-
#batch_create(batch_client, attributes) ⇒ Syncano::Response
Proxy for calling “batch_create” method on the resource object.
-
#batch_move(batch_client, ids, conditions = {}, new_folder = nil, new_state = nil) ⇒ Syncano::Response
Proxy for calling “batch_move” method on the resource object.
-
#copy(ids) ⇒ Array
Proxy for calling “copy” method on the resource object.
-
#count(conditions = {}) ⇒ Integer
Proxy for calling “count” method on the resource object.
-
#create(attributes) ⇒ Syncano::Resources::Base
Proxy for calling “create” method on the resource object.
-
#find(key = nil, conditions = {}) ⇒ Syncano::Resources::Base
Proxy for calling “find” method on the resource object.
-
#find_by_email(email, conditions = {}) ⇒ Syncano::Resources::Base
Proxy for calling “find_by_email” method on the resource object.
-
#find_by_key(key, conditions = {}) ⇒ Syncano::Resources::Base
Proxy for calling “find_by_key” method on the resource object.
-
#find_by_name(name, conditions = {}) ⇒ Syncano::Resources::Base
Proxy for calling “find_by_name” method on the resource object.
-
#first(conditions = {}) ⇒ Syncano::Resources::Base
Returns first element from all returned by “all” method.
-
#initialize(client, resource_class, scope_parameters = {}) ⇒ QueryBuilder
constructor
Constructor for Syncano::QueryBuilder object.
-
#last(conditions = {}) ⇒ Syncano::Resources::Base
Returns last element from all returned by “all” method.
-
#login(username = nil, password = nil) ⇒ Array
Proxy for calling “login” method on the resource object.
-
#move(ids, conditions = {}, new_folder = nil, new_state = nil) ⇒ Array
Proxy for calling “move” method on the resource object.
-
#new(attributes = {}) ⇒ Syncano::Resources::Base
Proxy for calling “new” method on the resource object.
Constructor Details
#initialize(client, resource_class, scope_parameters = {}) ⇒ QueryBuilder
Constructor for Syncano::QueryBuilder object
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
25 26 27 |
# File 'lib/syncano/query_builder.rb', line 25 def all(conditions = {}) resource_class.all(client, conditions.merge(scope_parameters)) end |
#batch ⇒ Syncano::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
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
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
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
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
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
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
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
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
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
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
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
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
144 145 146 |
# 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) ⇒ Array
Proxy for calling “move” method on the resource object
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
85 86 87 |
# File 'lib/syncano/query_builder.rb', line 85 def new(attributes = {}) resource_class.new(client, attributes.merge(scope_parameters)) end |