syncano 3.1.1.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +304 -0
- data/Rakefile +7 -0
- data/lib/generators/syncano/install_generator.rb +17 -0
- data/lib/generators/syncano/templates/initializers/syncano.rb +4 -0
- data/lib/syncano.rb +92 -0
- data/lib/syncano/batch_queue.rb +58 -0
- data/lib/syncano/batch_queue_element.rb +33 -0
- data/lib/syncano/clients/base.rb +115 -0
- data/lib/syncano/clients/rest.rb +69 -0
- data/lib/syncano/clients/sync.rb +132 -0
- data/lib/syncano/errors.rb +13 -0
- data/lib/syncano/jimson_client.rb +34 -0
- data/lib/syncano/packets/auth.rb +7 -0
- data/lib/syncano/packets/base.rb +64 -0
- data/lib/syncano/packets/call.rb +34 -0
- data/lib/syncano/packets/call_response.rb +33 -0
- data/lib/syncano/packets/error.rb +19 -0
- data/lib/syncano/packets/message.rb +30 -0
- data/lib/syncano/packets/notification.rb +39 -0
- data/lib/syncano/packets/ping.rb +12 -0
- data/lib/syncano/query_builder.rb +144 -0
- data/lib/syncano/resources/admin.rb +26 -0
- data/lib/syncano/resources/api_key.rb +46 -0
- data/lib/syncano/resources/base.rb +375 -0
- data/lib/syncano/resources/collection.rb +186 -0
- data/lib/syncano/resources/data_object.rb +304 -0
- data/lib/syncano/resources/folder.rb +34 -0
- data/lib/syncano/resources/notifications/base.rb +103 -0
- data/lib/syncano/resources/notifications/create.rb +20 -0
- data/lib/syncano/resources/notifications/destroy.rb +20 -0
- data/lib/syncano/resources/notifications/message.rb +9 -0
- data/lib/syncano/resources/notifications/update.rb +24 -0
- data/lib/syncano/resources/project.rb +42 -0
- data/lib/syncano/resources/role.rb +11 -0
- data/lib/syncano/resources/subscription.rb +12 -0
- data/lib/syncano/resources/user.rb +47 -0
- data/lib/syncano/response.rb +22 -0
- data/lib/syncano/sync_connection.rb +110 -0
- data/lib/syncano/version.rb +4 -0
- data/spec/admins_spec.rb +16 -0
- data/spec/api_keys_spec.rb +34 -0
- data/spec/collections_spec.rb +67 -0
- data/spec/data_objects_spec.rb +113 -0
- data/spec/folders_spec.rb +39 -0
- data/spec/notifications_spec.rb +43 -0
- data/spec/projects_spec.rb +35 -0
- data/spec/roles_spec.rb +13 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/sync_resources_spec.rb +35 -0
- data/spec/syncano_spec.rb +9 -0
- data/syncano.gemspec +32 -0
- metadata +250 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
class Syncano
|
|
2
|
+
# Module used as a scope for classes representing resources
|
|
3
|
+
module Resources
|
|
4
|
+
# Base resource used for inheritance
|
|
5
|
+
class Base
|
|
6
|
+
attr_accessor :attributes
|
|
7
|
+
attr_reader :id, :destroyed
|
|
8
|
+
|
|
9
|
+
# Constructor for base resource
|
|
10
|
+
# @param [Syncano::Clients::Base] client
|
|
11
|
+
# @param [Hash] attributes used in making requests to api (ie. parent id)
|
|
12
|
+
def initialize(client, attributes = {})
|
|
13
|
+
super()
|
|
14
|
+
|
|
15
|
+
@attributes = ActiveSupport::HashWithIndifferentAccess.new(attributes)
|
|
16
|
+
@saved_attributes = ActiveSupport::HashWithIndifferentAccess.new
|
|
17
|
+
self.id = @attributes.delete(:id)
|
|
18
|
+
|
|
19
|
+
self.client = client
|
|
20
|
+
|
|
21
|
+
mark_as_saved! if id.present?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Attributes setter
|
|
25
|
+
# @param [Hash] attributes
|
|
26
|
+
# @return [Hash]
|
|
27
|
+
def attributes=(attributes)
|
|
28
|
+
@attributes.merge!(attributes)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Single attribute getter
|
|
32
|
+
# @param [Symbol, String] attribute_name
|
|
33
|
+
# @return [Object]
|
|
34
|
+
def [](attribute_name)
|
|
35
|
+
attributes[attribute_name]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Single attribute setter
|
|
39
|
+
# @param [Symbol, String] attribute_name
|
|
40
|
+
# @param [Object] attribute_value
|
|
41
|
+
# @return [Object]
|
|
42
|
+
def []=(attribute_name, attribute_value)
|
|
43
|
+
attributes[attribute_name] = attribute_value
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Proxy for preparing batch requests
|
|
47
|
+
# ie. resource.batch.update will prepare BatchQueueElement
|
|
48
|
+
# which invokes batch_update method on resource object
|
|
49
|
+
# @return [Syncano::BatchQueueElement]
|
|
50
|
+
def batch
|
|
51
|
+
::Syncano::BatchQueueElement.new(self)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Wrapper for api "get" method
|
|
55
|
+
# Returns all objects from Syncano
|
|
56
|
+
# @param [Syncano::Clients::Base] client
|
|
57
|
+
# @param [Hash] scope_parameters
|
|
58
|
+
# @param [Hash] conditions
|
|
59
|
+
# @return [Array] which contains Syncano::Resources::Base objects
|
|
60
|
+
def self.all(client, scope_parameters = {}, conditions = {})
|
|
61
|
+
response = perform_all(client, scope_parameters, conditions)
|
|
62
|
+
response.data.to_a.collect do |attributes|
|
|
63
|
+
new(client, attributes.merge(scope_parameters))
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Returns amount of elements returned from all method
|
|
68
|
+
# @param [Syncano::Clients::Base] client
|
|
69
|
+
# @param [Hash] scope_parameters
|
|
70
|
+
# @param [Hash] conditions
|
|
71
|
+
# @return [Integer]
|
|
72
|
+
def self.count(client, scope_parameters = {}, conditions = {})
|
|
73
|
+
perform_count(client, scope_parameters, conditions)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Wrapper for api "get_one" method
|
|
77
|
+
# Returns one object from Syncano
|
|
78
|
+
# @param [Syncano::Clients::Base] client
|
|
79
|
+
# @param [Integer, String] key
|
|
80
|
+
# @param [Hash] scope_parameters
|
|
81
|
+
# @param [Hash] conditions
|
|
82
|
+
def self.find(client, key, scope_parameters = {}, conditions = {})
|
|
83
|
+
response = perform_find(client, primary_key_name, key, scope_parameters, conditions)
|
|
84
|
+
new(client, scope_parameters.merge(response.data))
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Wrapper for api "new" method
|
|
88
|
+
# Creates object in Syncano
|
|
89
|
+
# @param [Syncano::Clients::Base] client
|
|
90
|
+
# @param [Hash] attributes
|
|
91
|
+
# @return [Syncano::Resources::Base]
|
|
92
|
+
def self.create(client, attributes)
|
|
93
|
+
response = perform_create(client, nil, attributes)
|
|
94
|
+
new(client, map_to_scope_parameters(attributes).merge(response.data))
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Batch version of "create" method
|
|
98
|
+
# @param [Jimson::BatchClient] batch_client
|
|
99
|
+
# @param [Syncano::Clients::Base] client
|
|
100
|
+
# @param [Hash] attributes
|
|
101
|
+
# @return [Syncano::Response]
|
|
102
|
+
def self.batch_create(batch_client, client, attributes)
|
|
103
|
+
perform_create(client, batch_client, attributes)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Wrapper for api "update" method
|
|
107
|
+
# Updates object in Syncano
|
|
108
|
+
# @param [Hash] attributes
|
|
109
|
+
# @return [Syncano::Resources::Base]
|
|
110
|
+
def update(attributes)
|
|
111
|
+
response = perform_update(nil, attributes)
|
|
112
|
+
response.data.delete('id')
|
|
113
|
+
self.attributes = scope_parameters.merge(response.data)
|
|
114
|
+
mark_as_saved!
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Batch version of "update" method
|
|
118
|
+
# @param [Jimson::BatchClient] batch_client
|
|
119
|
+
# @param [Hash] attributes
|
|
120
|
+
# @return [Syncano::Response]
|
|
121
|
+
def batch_update(batch_client, attributes)
|
|
122
|
+
perform_update(batch_client, attributes)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Invokes create or update methods
|
|
126
|
+
# @return [Syncano::Resources::Base]
|
|
127
|
+
def save
|
|
128
|
+
response = perform_save(nil)
|
|
129
|
+
|
|
130
|
+
if new_record?
|
|
131
|
+
self.id = response.id
|
|
132
|
+
self.attributes = response.attributes
|
|
133
|
+
mark_as_saved!
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
self
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Batch version of "save" method
|
|
140
|
+
# @param [Jimson::BatchClient] batch_client
|
|
141
|
+
# @return [Syncano::Response]
|
|
142
|
+
def batch_save(batch_client)
|
|
143
|
+
perform_save(batch_client)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Wrapper for api "delete" method
|
|
147
|
+
# Destroys object in Syncano
|
|
148
|
+
# @return [Syncano::Resources::Base] marked as destroyed
|
|
149
|
+
def destroy
|
|
150
|
+
response = perform_destroy(nil)
|
|
151
|
+
self.destroyed = response.status
|
|
152
|
+
self
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Batch version of "destroy" method
|
|
156
|
+
# @param [Jimson::BatchClient] batch_client
|
|
157
|
+
# @return [Syncano::Response]
|
|
158
|
+
def batch_destroy(batch_client)
|
|
159
|
+
perform_destroy(batch_client)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Checks whether is newly initialized or not
|
|
163
|
+
# @return [TrueClass, FalseClass]
|
|
164
|
+
def new_record?
|
|
165
|
+
id.nil?
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# Checks whether record is different than stored in Syncano
|
|
169
|
+
# @return [TrueClass, FalseClass]
|
|
170
|
+
def saved?
|
|
171
|
+
!new_record? && attributes == saved_attributes
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# Checks whether record is marked as destroyed
|
|
175
|
+
# @return [TrueClass, FalseClass]
|
|
176
|
+
def destroyed?
|
|
177
|
+
!!destroyed
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Reloads record from Syncano
|
|
181
|
+
# @return [TrueClass, FalseClass]
|
|
182
|
+
def reload!(conditions = {})
|
|
183
|
+
unless new_record?
|
|
184
|
+
reloaded_object = self.class.find(client, primary_key, scope_parameters, conditions)
|
|
185
|
+
self.attributes.clear
|
|
186
|
+
self.attributes = reloaded_object.attributes
|
|
187
|
+
mark_as_saved!
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
self
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
private
|
|
194
|
+
|
|
195
|
+
class_attribute :syncano_model_name, :scope_parameters, :crud_class_methods, :crud_instance_methods, :primary_key
|
|
196
|
+
|
|
197
|
+
self.syncano_model_name = nil
|
|
198
|
+
self.scope_parameters = []
|
|
199
|
+
self.crud_class_methods = [:all, :find, :new, :create, :count]
|
|
200
|
+
self.crud_instance_methods = [:save, :update, :destroy]
|
|
201
|
+
self.primary_key = :id
|
|
202
|
+
|
|
203
|
+
attr_accessor :client, :saved_attributes
|
|
204
|
+
attr_writer :id, :destroyed
|
|
205
|
+
|
|
206
|
+
# Executes proper all request
|
|
207
|
+
# @param [Syncano::Clients::Base] client
|
|
208
|
+
# @param [Hash] scope_parameters
|
|
209
|
+
# @param [Hash] conditions
|
|
210
|
+
# @return [Syncano::Response]
|
|
211
|
+
def self.perform_all(client, scope_parameters, conditions)
|
|
212
|
+
check_class_method_existance!(:all)
|
|
213
|
+
make_request(client, nil, :all, conditions.merge(scope_parameters))
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# Executes proper count request
|
|
217
|
+
# @param [Syncano::Clients::Base] client
|
|
218
|
+
# @param [Hash] scope_parameters
|
|
219
|
+
# @param [Hash] conditions
|
|
220
|
+
# @return [Syncano::Response]
|
|
221
|
+
def self.perform_count(client, scope_parameters, conditions)
|
|
222
|
+
check_class_method_existance!(:count)
|
|
223
|
+
all(client, scope_parameters, conditions).count
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# Executes proper find request
|
|
227
|
+
# @param [Syncano::Clients::Base] client
|
|
228
|
+
# @param [Symbol, String] key_name
|
|
229
|
+
# @param [Integer, String] key
|
|
230
|
+
# @param [Hash] scope_parameters
|
|
231
|
+
# @param [Hash] conditions
|
|
232
|
+
# @return [Syncano::Response]
|
|
233
|
+
def self.perform_find(client, key_name, key, scope_parameters, conditions)
|
|
234
|
+
check_class_method_existance!(:find)
|
|
235
|
+
make_request(client, nil, :find, conditions.merge(scope_parameters.merge(key_name.to_sym => key)))
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# Executes proper create request
|
|
239
|
+
# @param [Syncano::Clients::Base] client
|
|
240
|
+
# @param [Jimson::BatchClient] batch_client
|
|
241
|
+
# @param [Hash] attributes
|
|
242
|
+
# @return [Syncano::Response]
|
|
243
|
+
def self.perform_create(client, batch_client, attributes)
|
|
244
|
+
check_class_method_existance!(:create)
|
|
245
|
+
make_request(client, batch_client, :create, attributes_to_sync(attributes))
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# Executes proper update request
|
|
249
|
+
# @param [Jimson::BatchClient] batch_client
|
|
250
|
+
# @param [Hash] attributes
|
|
251
|
+
# @return [Syncano::Response]
|
|
252
|
+
def perform_update(batch_client, attributes)
|
|
253
|
+
check_instance_method_existance!(:update)
|
|
254
|
+
self.class.make_request(client, batch_client, :update, scope_parameters.merge(self.class.attributes_to_sync(attributes).merge(self.class.primary_key_name => primary_key)))
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
# Executes proper save request
|
|
258
|
+
# @param [Jimson::BatchClient] batch_client
|
|
259
|
+
# @return [Syncano::Response]
|
|
260
|
+
def perform_save(batch_client)
|
|
261
|
+
check_instance_method_existance!(:save)
|
|
262
|
+
|
|
263
|
+
if new_record?
|
|
264
|
+
self.class.perform_create(client, batch_client, attributes)
|
|
265
|
+
else
|
|
266
|
+
perform_update(batch_client, attributes)
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
# Executes proper destroy request
|
|
271
|
+
# @param [Jimson::BatchClient] batch_client
|
|
272
|
+
# @return [Syncano::Response]
|
|
273
|
+
def perform_destroy(batch_client)
|
|
274
|
+
check_instance_method_existance!(:destroy)
|
|
275
|
+
self.class.make_request(client, batch_client, :destroy, scope_parameters.merge({ self.class.primary_key_name => primary_key }))
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
# Converts resource class name to corresponding Syncano resource name
|
|
279
|
+
# @return [String]
|
|
280
|
+
def self.api_resource
|
|
281
|
+
syncano_model_name || to_s.split('::').last.downcase
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
# Converts Syncano gem method to corresponding Syncano api method
|
|
285
|
+
# @param [String] method_name
|
|
286
|
+
# @return [String]
|
|
287
|
+
def self.api_method(method_name)
|
|
288
|
+
mapping = { all: :get, find: :get_one, create: :new, update: :update, destroy: :delete }
|
|
289
|
+
|
|
290
|
+
method_name = method_name.to_s.gsub('batch_', '')
|
|
291
|
+
mapping.keys.include?(method_name.to_sym) ? mapping[method_name.to_sym] : method_name
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
# Calls request to api through client object
|
|
295
|
+
# @param [Syncano::Clients::Base] client
|
|
296
|
+
# @param [Jimson::BatchClient] batch_client
|
|
297
|
+
# @param [String] method_name
|
|
298
|
+
# @param [Hash] attributes
|
|
299
|
+
# @param [String] response_key
|
|
300
|
+
# @return [Syncano::Response]
|
|
301
|
+
def self.make_request(client, batch_client, method_name, attributes = {}, response_key = nil)
|
|
302
|
+
if batch_client.nil?
|
|
303
|
+
client.make_request(api_resource, api_method(method_name), attributes, response_key)
|
|
304
|
+
else
|
|
305
|
+
client.make_batch_request(batch_client, api_resource, api_method(method_name), attributes)
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
# Returns scope parameters from provided hash with attributes
|
|
310
|
+
# @param [Hash] attributes
|
|
311
|
+
# @return [Hash]
|
|
312
|
+
def self.map_to_scope_parameters(attributes)
|
|
313
|
+
Hash[scope_parameters.map{ |sym| [sym, attributes[sym]]}]
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
# Returns scope parameters from object's attributes
|
|
317
|
+
# @return [Hash]
|
|
318
|
+
def scope_parameters
|
|
319
|
+
self.class.map_to_scope_parameters(attributes)
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# Returns name for primary key
|
|
323
|
+
# @return [Hash]
|
|
324
|
+
def self.primary_key_name
|
|
325
|
+
"#{api_resource}_#{primary_key}".to_sym
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
# Returns value of primary key
|
|
329
|
+
# @return [Integer, String]
|
|
330
|
+
def primary_key
|
|
331
|
+
self.class.primary_key == :id ? id : @saved_attributes[self.class.primary_key]
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# Marks record as saved, by copying attributes to saved_attributes
|
|
335
|
+
# @return [Integer, String]
|
|
336
|
+
def mark_as_saved!
|
|
337
|
+
self.saved_attributes = attributes.dup
|
|
338
|
+
self
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
# Prepares hash with attributes used in synchronization with Syncano
|
|
342
|
+
# @param [Hash] attributes
|
|
343
|
+
# @return [Hash]
|
|
344
|
+
def self.attributes_to_sync(attributes = {})
|
|
345
|
+
attributes
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
# Prepares hash with attributes used in synchronization with Syncano
|
|
349
|
+
# @return [Hash]
|
|
350
|
+
def attributes_to_sync
|
|
351
|
+
self.class.attributes_to_sync(attributes)
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
# Checks whether class method is implemented in the resource class
|
|
355
|
+
def self.check_class_method_existance!(method_name)
|
|
356
|
+
raise NoMethodError.new("undefined method `#{method_name}' for #{to_s}") unless crud_class_methods.include?(method_name.to_sym)
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# Checks whether class method is implemented in the resource class
|
|
360
|
+
def check_instance_method_existance!(method_name)
|
|
361
|
+
raise NoMethodError.new("undefined method `#{method_name}' for #{to_s}") unless crud_instance_methods.include?(method_name.to_sym)
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
# Checks if sync connection is used
|
|
365
|
+
def self.check_if_sync_client!(client)
|
|
366
|
+
raise Syncano::BaseError.new('Operation available only for Sync client') unless client.is_a?(::Syncano::Clients::Sync)
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
# Checks if object uses sync connection
|
|
370
|
+
def check_if_sync_client!
|
|
371
|
+
self.class.check_if_sync_client!(client)
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
end
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
class Syncano
|
|
2
|
+
module Resources
|
|
3
|
+
# Collection resource
|
|
4
|
+
class Collection < ::Syncano::Resources::Base
|
|
5
|
+
# Association has_many :folders
|
|
6
|
+
# @return [Syncano::QueryBuilder] query builder for resource Syncano::Resources::Folder
|
|
7
|
+
def folders
|
|
8
|
+
::Syncano::QueryBuilder.new(client, ::Syncano::Resources::Folder, scope_parameters.merge(collection_id: id))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Association has_many :data_objects
|
|
12
|
+
# @return [Syncano::QueryBuilder] query builder for resource Syncano::Resources::DataObject
|
|
13
|
+
def data_objects
|
|
14
|
+
::Syncano::QueryBuilder.new(client, ::Syncano::Resources::DataObject, scope_parameters.merge(collection_id: id))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Association has_many :users
|
|
18
|
+
# @return [Syncano::QueryBuilder] query builder for resource Syncano::Resources::User
|
|
19
|
+
def users
|
|
20
|
+
::Syncano::QueryBuilder.new(client, ::Syncano::Resources::User, scope_parameters.merge(collection_id: id))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Wrapper for api "get_one" method with collection_key as a key
|
|
24
|
+
# @param [Syncano::Clients::Base] client
|
|
25
|
+
# @param [String] key
|
|
26
|
+
# @param [Hash] scope_parameters
|
|
27
|
+
# @param [Hash] conditions
|
|
28
|
+
# @return [Syncano::Resources::Collection]
|
|
29
|
+
def self.find_by_key(client, key, scope_parameters = {}, conditions = {})
|
|
30
|
+
perform_find(client, :key, key, scope_parameters, conditions)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Wrapper for api "activate" method
|
|
34
|
+
# @param [TrueClass, FalseClass] force
|
|
35
|
+
# @return [Syncano::Resources::Collection]
|
|
36
|
+
def activate(force = false)
|
|
37
|
+
response = perform_activate(nil, force)
|
|
38
|
+
reload! if response.status
|
|
39
|
+
|
|
40
|
+
self
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Batch version of "activate" method
|
|
44
|
+
# @param [Jimson::BatchClient] batch_client
|
|
45
|
+
# @param [TrueClass, FalseClass] force
|
|
46
|
+
# @return [Syncano::Response]
|
|
47
|
+
def batch_activate(batch_client, force = false)
|
|
48
|
+
perform_activate(batch_client, force)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Wrapper for api "deactivate" method
|
|
52
|
+
# @return [Syncano::Resources::Collection]
|
|
53
|
+
def deactivate
|
|
54
|
+
response = perform_deactivate(nil)
|
|
55
|
+
reload! if response.status
|
|
56
|
+
|
|
57
|
+
self
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Batch version of "deactivate" method
|
|
61
|
+
# @param [Jimson::BatchClient] batch_client
|
|
62
|
+
# @return [Syncano::Response]
|
|
63
|
+
def batch_deactivate(batch_client)
|
|
64
|
+
perform_deactivate(batch_client)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Wrapper for api "add_tag" method
|
|
68
|
+
# @param [String, Array] tags
|
|
69
|
+
# @param [Numeric] weight
|
|
70
|
+
# @param [TrueClass, FalseClass] remove_other
|
|
71
|
+
# @return [Syncano::Resources::Collection]
|
|
72
|
+
def add_tag(tags, weight = 1, remove_other = false)
|
|
73
|
+
response = perform_add_tag(nil, tags, weight, remove_other)
|
|
74
|
+
reload! if response.status
|
|
75
|
+
|
|
76
|
+
self
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Batch version of "add_tags" method
|
|
80
|
+
# @param [Jimson::BatchClient] batch_client
|
|
81
|
+
# @param [String, Array] tags
|
|
82
|
+
# @param [Numeric] weight
|
|
83
|
+
# @param [TrueClass, FalseClass] remove_other
|
|
84
|
+
# @return [Syncano::Response]
|
|
85
|
+
def batch_add_tags(batch_client, tags, weight = 1, remove_other = false)
|
|
86
|
+
perform_add_tag(batch_client, tags, weight, remove_other)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Wrapper for api "delete_tag" method
|
|
90
|
+
# @param [String, Array] tags
|
|
91
|
+
# @return [Syncano::Resources::Collection]
|
|
92
|
+
def delete_tags(tags)
|
|
93
|
+
response = perform_delete_tag(nil, tags)
|
|
94
|
+
reload! if response.status
|
|
95
|
+
|
|
96
|
+
self
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Batch version of "delete_tag" method
|
|
100
|
+
# @param [Jimson::BatchClient] batch_client
|
|
101
|
+
# @param [String, Array] tags
|
|
102
|
+
# @return [Syncano::Response]
|
|
103
|
+
def batch_delete_tag(batch_client, tags)
|
|
104
|
+
perform_delete_tag(batch_client, tags)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Wrapper for api "subscription.subscribe_collection" method
|
|
108
|
+
# @return [Syncano::Resource::Collection]
|
|
109
|
+
def subscribe
|
|
110
|
+
perform_subscribe
|
|
111
|
+
reload!
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Wrapper for api "subscription.unsubscribe_collection" method
|
|
115
|
+
# @return [Syncano::Resource::Collection]
|
|
116
|
+
def unsubscribe
|
|
117
|
+
perform_unsubscribe
|
|
118
|
+
reload!
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
private
|
|
122
|
+
|
|
123
|
+
self.scope_parameters = [:project_id]
|
|
124
|
+
|
|
125
|
+
# Executes proper activate request
|
|
126
|
+
# @param [Jimson::BatchClient] batch_client
|
|
127
|
+
# @param [TrueClass, FalseClass] force
|
|
128
|
+
# @return [Syncano::Response]
|
|
129
|
+
def perform_activate(batch_client, force)
|
|
130
|
+
self.class.make_request(client, batch_client, :activate, scope_parameters.merge(
|
|
131
|
+
self.class.primary_key_name => primary_key,
|
|
132
|
+
force: force
|
|
133
|
+
))
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Executes proper deactivate request
|
|
137
|
+
# @param [Jimson::BatchClient] batch_client
|
|
138
|
+
# @return [Syncano::Response]
|
|
139
|
+
def perform_deactivate(batch_client)
|
|
140
|
+
self.class.make_request(client, batch_client, :deactivate, scope_parameters.merge(
|
|
141
|
+
self.class.primary_key_name => primary_key
|
|
142
|
+
))
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Executes proper add_tags request
|
|
146
|
+
# @param [Jimson::BatchClient] batch_client
|
|
147
|
+
# @param [String, Array] tags
|
|
148
|
+
# @param [Numeric] weight
|
|
149
|
+
# @param [TrueClass, FalseClass] remove_other
|
|
150
|
+
# @return [Syncano::Response]
|
|
151
|
+
def perform_add_tags(batch_client, tags, weight, remove_other)
|
|
152
|
+
self.class.make_request(client, batch_client, :add_tag, scope_parameters.merge(
|
|
153
|
+
self.class.primary_key_name => primary_key,
|
|
154
|
+
tags: tags,
|
|
155
|
+
weight: weight,
|
|
156
|
+
remove_other: remove_other
|
|
157
|
+
))
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Executes proper delete_tags request
|
|
161
|
+
# @param [Jimson::BatchClient] batch_client
|
|
162
|
+
# @param [String, Array] tags
|
|
163
|
+
# @return [Syncano::Response]
|
|
164
|
+
def perform_delete_tags(batch_client, tags)
|
|
165
|
+
self.class.make_request(client, batch_client, :delete_tag, scope_parameters.merge(
|
|
166
|
+
self.class.primary_key_name => primary_key,
|
|
167
|
+
tags: tags
|
|
168
|
+
))
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Executes proper subscribe request
|
|
172
|
+
# @return [Syncano::Response]
|
|
173
|
+
def perform_subscribe
|
|
174
|
+
check_if_sync_client!
|
|
175
|
+
client.make_request(:subscription, :subscribe_collection, scope_parameters.merge(collection_id: id))
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# Executes proper unsubscribe request
|
|
179
|
+
# @return [Syncano::Response]
|
|
180
|
+
def perform_unsubscribe
|
|
181
|
+
check_if_sync_client!
|
|
182
|
+
client.make_request(:subscription, :unsubscribe_collection, scope_parameters.merge(collection_id: id))
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|