syncano 3.1.4 → 4.0.0.alpha
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 +4 -1
- data/.rspec +2 -0
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -0
- data/Gemfile +25 -1
- data/Guardfile +22 -4
- data/README.md +68 -447
- data/Rakefile +48 -5
- data/circle.yml +10 -0
- data/lib/active_attr/dirty.rb +3 -17
- data/lib/active_attr/typecasting/hash_typecaster.rb +34 -0
- data/lib/active_attr/typecasting_override.rb +29 -0
- data/lib/syncano.rb +53 -92
- data/lib/syncano/api.rb +13 -0
- data/lib/syncano/connection.rb +97 -0
- data/lib/syncano/model/associations.rb +121 -0
- data/lib/syncano/{active_record/association → model/associations}/base.rb +5 -5
- data/lib/syncano/{active_record/association → model/associations}/belongs_to.rb +6 -6
- data/lib/syncano/{active_record/association → model/associations}/has_many.rb +15 -9
- data/lib/syncano/{active_record/association → model/associations}/has_one.rb +4 -4
- data/lib/syncano/model/base.rb +257 -0
- data/lib/syncano/{active_record → model}/callbacks.rb +16 -13
- data/lib/syncano/{active_record → model}/scope_builder.rb +53 -69
- data/lib/syncano/query_builder.rb +19 -129
- data/lib/syncano/resources.rb +126 -0
- data/lib/syncano/resources/base.rb +304 -300
- data/lib/syncano/resources/collection.rb +19 -223
- data/lib/syncano/resources/space.rb +29 -0
- data/lib/syncano/schema.rb +86 -0
- data/lib/syncano/schema/attribute_definition.rb +83 -0
- data/lib/syncano/schema/resource_definition.rb +36 -0
- data/lib/syncano/scope.rb +10 -0
- data/lib/syncano/version.rb +3 -4
- data/spec/integration/syncano_spec.rb +228 -0
- data/spec/spec_helper.rb +15 -9
- data/spec/unit/api_spec.rb +5 -0
- data/spec/unit/connection_spec.rb +137 -0
- data/spec/unit/query_builder_spec.rb +75 -0
- data/spec/unit/resources/collection_spec.rb +36 -0
- data/spec/unit/resources/space_spec.rb +28 -0
- data/spec/unit/resources_base_spec.rb +185 -0
- data/spec/unit/schema/attribute_definition_spec.rb +18 -0
- data/spec/unit/schema/resource_definition_spec.rb +25 -0
- data/spec/unit/schema_spec.rb +3532 -0
- data/spec/unit/syncano_spec.rb +63 -0
- data/syncano.gemspec +8 -14
- metadata +85 -210
- data/lib/generators/syncano/install_generator.rb +0 -17
- data/lib/generators/syncano/templates/initializers/syncano.rb +0 -7
- data/lib/syncano/active_record/associations.rb +0 -112
- data/lib/syncano/active_record/base.rb +0 -318
- data/lib/syncano/batch_queue.rb +0 -58
- data/lib/syncano/batch_queue_element.rb +0 -33
- data/lib/syncano/clients/base.rb +0 -123
- data/lib/syncano/clients/rest.rb +0 -79
- data/lib/syncano/clients/sync.rb +0 -164
- data/lib/syncano/errors.rb +0 -17
- data/lib/syncano/jimson_client.rb +0 -66
- data/lib/syncano/packets/auth.rb +0 -27
- data/lib/syncano/packets/base.rb +0 -70
- data/lib/syncano/packets/call.rb +0 -34
- data/lib/syncano/packets/call_response.rb +0 -33
- data/lib/syncano/packets/error.rb +0 -19
- data/lib/syncano/packets/message.rb +0 -30
- data/lib/syncano/packets/notification.rb +0 -39
- data/lib/syncano/packets/ping.rb +0 -12
- data/lib/syncano/resources/admin.rb +0 -26
- data/lib/syncano/resources/api_key.rb +0 -108
- data/lib/syncano/resources/data_object.rb +0 -316
- data/lib/syncano/resources/folder.rb +0 -88
- data/lib/syncano/resources/notifications/base.rb +0 -103
- data/lib/syncano/resources/notifications/create.rb +0 -20
- data/lib/syncano/resources/notifications/destroy.rb +0 -20
- data/lib/syncano/resources/notifications/message.rb +0 -9
- data/lib/syncano/resources/notifications/update.rb +0 -24
- data/lib/syncano/resources/project.rb +0 -96
- data/lib/syncano/resources/role.rb +0 -11
- data/lib/syncano/resources/subscription.rb +0 -12
- data/lib/syncano/resources/user.rb +0 -65
- data/lib/syncano/response.rb +0 -22
- data/lib/syncano/sync_connection.rb +0 -133
- data/spec/admins_spec.rb +0 -16
- data/spec/api_keys_spec.rb +0 -34
- data/spec/collections_spec.rb +0 -67
- data/spec/data_objects_spec.rb +0 -113
- data/spec/folders_spec.rb +0 -39
- data/spec/notifications_spec.rb +0 -43
- data/spec/projects_spec.rb +0 -35
- data/spec/roles_spec.rb +0 -13
- data/spec/sync_resources_spec.rb +0 -35
- data/spec/syncano_spec.rb +0 -9
@@ -1,316 +0,0 @@
|
|
1
|
-
class Syncano
|
2
|
-
module Resources
|
3
|
-
# Data object resource - corresponds to Syncano data resource
|
4
|
-
class DataObject < ::Syncano::Resources::Base
|
5
|
-
# Overwritten constructor with recursive initializing associated children objects
|
6
|
-
# @param [Syncano::Clients::Base] client
|
7
|
-
# @param [Hash] attributes
|
8
|
-
def initialize(client, attributes = {})
|
9
|
-
super(client, attributes)
|
10
|
-
if self.attributes[:children].present?
|
11
|
-
self.attributes[:children] = self.attributes[:children].collect do |child|
|
12
|
-
if child.is_a?(Hash)
|
13
|
-
self.class.new(client, child)
|
14
|
-
else
|
15
|
-
child
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
if self.attributes[:user].is_a?(Hash)
|
21
|
-
self.attributes[:user] = ::Syncano::Resources::User.new(client, self.attributes[:user])
|
22
|
-
end
|
23
|
-
|
24
|
-
if self.attributes[:additional].is_a?(Hash)
|
25
|
-
self.attributes.merge!(self.attributes.delete(:additional))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Wrapper for api "get_one" method with data_key as a key
|
30
|
-
# @param [Syncano::Clients::Base] client
|
31
|
-
# @param [String] key
|
32
|
-
# @param [Hash] scope_parameters
|
33
|
-
# @param [Hash] conditions
|
34
|
-
# @return [Syncano::Resources::DataObject]
|
35
|
-
def self.find_by_key(client, key, scope_parameters = {}, conditions = {})
|
36
|
-
perform_find(client, :key, key, scope_parameters, conditions)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Wrapper for api "count" method
|
40
|
-
# @param [Syncano::Clients::Base] client
|
41
|
-
# @param [Hash] scope_parameters
|
42
|
-
# @param [Hash] conditions
|
43
|
-
# @return [Integer]
|
44
|
-
def self.count(client, scope_parameters = {}, conditions = {})
|
45
|
-
response = perform_count(client, scope_parameters, conditions)
|
46
|
-
response.data
|
47
|
-
end
|
48
|
-
|
49
|
-
# Wrapper for api "move" method
|
50
|
-
# @param [Syncano::Clients::Base] client
|
51
|
-
# @param [Hash] scope_parameters
|
52
|
-
# @param [Array] data_ids
|
53
|
-
# @param [Hash] conditions
|
54
|
-
# @param [String] new_folder
|
55
|
-
# @param [String] new_state
|
56
|
-
# @return [Array] collection of Syncano::Resource::DataObject objects
|
57
|
-
def self.move(client, scope_parameters = {}, data_ids = [], conditions = {}, new_folder = nil, new_state = nil)
|
58
|
-
response = perform_move(client, nil, scope_parameters, data_ids, conditions, new_folder, new_state)
|
59
|
-
all(client, scope_parameters, data_ids: data_ids)
|
60
|
-
end
|
61
|
-
|
62
|
-
# Batch version of "move" method
|
63
|
-
# @param [Jimson::BatchClient] batch_client
|
64
|
-
# @param [Syncano::Clients::Base] client
|
65
|
-
# @param [Hash] scope_parameters
|
66
|
-
# @param [Array] data_ids
|
67
|
-
# @param [Hash] conditions
|
68
|
-
# @param [String] new_folder
|
69
|
-
# @param [String] new_state
|
70
|
-
# @return [Syncano::Response]
|
71
|
-
def self.batch_move(batch_client, client, scope_parameters = {}, data_ids = [], conditions = {}, new_folder = nil, new_state = nil)
|
72
|
-
perform_move(client, batch_client, scope_parameters, data_ids, conditions, new_folder, new_state)
|
73
|
-
end
|
74
|
-
|
75
|
-
# Wrapper for api "move" method
|
76
|
-
# @param [String] new_folder
|
77
|
-
# @param [String] new_state
|
78
|
-
# @return [Syncano::Resource::DataObject]
|
79
|
-
def move(new_folder = nil, new_state = nil)
|
80
|
-
perform_move(client, nil, scope_parameters, [id], {}, new_folder, new_state)
|
81
|
-
reload!
|
82
|
-
end
|
83
|
-
|
84
|
-
# Batch version of "move" method
|
85
|
-
# @param [Jimson::BatchClient] batch_client
|
86
|
-
# @param [String] new_folder
|
87
|
-
# @param [String] new_state
|
88
|
-
# @return [Syncano::Response]
|
89
|
-
def batch_move(batch_client, new_folder = nil, new_state = nil)
|
90
|
-
perform_move(client, batch_client, scope_parameters, [id], {}, new_folder, new_state)
|
91
|
-
end
|
92
|
-
|
93
|
-
# Wrapper for api "copy" method
|
94
|
-
# @param [Syncano::Clients::Base] client
|
95
|
-
# @param [Hash] scope_parameters
|
96
|
-
# @param [Array] data_ids
|
97
|
-
# @return [Array] collection of Syncano::Resource::DataObject objects
|
98
|
-
def self.copy(client, scope_parameters = {}, data_ids = [])
|
99
|
-
response = perform_copy(client, nil, scope_parameters, data_ids)
|
100
|
-
response.data.collect { |attributes| self.new(client, attributes.merge(scope_parameters)) }
|
101
|
-
end
|
102
|
-
|
103
|
-
# Batch version of "move" method
|
104
|
-
# @param [Jimson::BatchClient] batch_client
|
105
|
-
# @param [Syncano::Clients::Base] client
|
106
|
-
# @param [Hash] scope_parameters
|
107
|
-
# @param [Array] data_ids
|
108
|
-
# @return [Syncano::Response]
|
109
|
-
def self.batch_copy(batch_client, client, scope_parameters = {}, data_ids = [])
|
110
|
-
perform_copy(client, batch_client, scope_parameters, data_ids)
|
111
|
-
end
|
112
|
-
|
113
|
-
# Wrapper for api "copy" method
|
114
|
-
# @return [Syncano::Resource::DataObject]
|
115
|
-
def copy
|
116
|
-
self.class.copy(client, scope_parameters, id.to_s).try(:first)
|
117
|
-
end
|
118
|
-
|
119
|
-
# Batch version of "copy" method
|
120
|
-
# @param [Jimson::BatchClient] batch_client
|
121
|
-
# @return [Syncano::Response]
|
122
|
-
def batch_copy(batch_client)
|
123
|
-
self.class.batch_copy(batch_client, client, scope_parameters, id.to_s)
|
124
|
-
end
|
125
|
-
|
126
|
-
# Wrapper for api "add_parent" method
|
127
|
-
# @param [Integer] parent_id
|
128
|
-
# @param [TrueClass, FalseClass] remove_other
|
129
|
-
# @return [Syncano::Resources::DataObject]
|
130
|
-
def add_parent(parent_id, remove_other = false)
|
131
|
-
response = perform_add_parent(nil, parent_id, remove_other)
|
132
|
-
reload!
|
133
|
-
end
|
134
|
-
|
135
|
-
# Batch version of "add_parent" method
|
136
|
-
# @param [Jimson::BatchClient] batch_client
|
137
|
-
# @param [Integer] parent_id
|
138
|
-
# @param [TrueClass, FalseClass] remove_other
|
139
|
-
# @return [Syncano::Response]
|
140
|
-
def batch_add_parent(batch_client, parent_id, remove_other = false)
|
141
|
-
perform_add_parent(batch_client, parent_id, remove_other)
|
142
|
-
end
|
143
|
-
|
144
|
-
# Wrapper for api "remove_parent" method
|
145
|
-
# @param [Integer] parent_id
|
146
|
-
# @return [Syncano::Resources::DataObject]
|
147
|
-
def remove_parent(parent_id = nil)
|
148
|
-
response = perform_remove_parent(nil, parent_id)
|
149
|
-
reload!
|
150
|
-
end
|
151
|
-
|
152
|
-
# Batch version of "remove_parent" method
|
153
|
-
# @param [Jimson::BatchClient] batch_client
|
154
|
-
# @param [Integer] parent_id
|
155
|
-
# @return [Syncano::Response]
|
156
|
-
def batch_remove_parent(batch_client, parent_id = nil)
|
157
|
-
perform_remove_parent(batch_client, parent_id)
|
158
|
-
end
|
159
|
-
|
160
|
-
# Wrapper for api "add_child" method
|
161
|
-
# @param [Integer] child_id
|
162
|
-
# @param [TrueClass, FalseClass] remove_other
|
163
|
-
# @return [Syncano::Resources::DataObject]
|
164
|
-
def add_child(child_id, remove_other = false)
|
165
|
-
perform_add_child(nil, child_id, remove_other)
|
166
|
-
reload!
|
167
|
-
end
|
168
|
-
|
169
|
-
# Batch version of "add_child" method
|
170
|
-
# @param [Jimson::BatchClient] batch_client
|
171
|
-
# @param [Integer] child_id
|
172
|
-
# @param [TrueClass, FalseClass] remove_other
|
173
|
-
# @return [Syncano::Response]
|
174
|
-
def batch_add_child(batch_client, child_id, remove_other = false)
|
175
|
-
perform_add_child(batch_client, child_id, remove_other)
|
176
|
-
end
|
177
|
-
|
178
|
-
# Wrapper for api "remove_child" method
|
179
|
-
# @param [Integer] child_id
|
180
|
-
# @return [Syncano::Resources::DataObject]
|
181
|
-
def remove_child(child_id = nil)
|
182
|
-
perform_remove_child(nil, child_id)
|
183
|
-
reload!
|
184
|
-
end
|
185
|
-
|
186
|
-
# Batch version of "remove_child" method
|
187
|
-
# @param [Jimson::BatchClient] batch_client
|
188
|
-
# @param [Integer] child_id
|
189
|
-
# @return [Syncano::Response]
|
190
|
-
def batch_remove_child(batch_client, child_id = nil)
|
191
|
-
perform_remove_child(batch_client, child_id)
|
192
|
-
end
|
193
|
-
|
194
|
-
private
|
195
|
-
|
196
|
-
self.syncano_model_name = 'data'
|
197
|
-
self.scope_parameters = [:project_id, :collection_id]
|
198
|
-
|
199
|
-
# Prepares hash with attributes used in synchronization with Syncano
|
200
|
-
# @return [Hash]
|
201
|
-
def self.attributes_to_sync(attributes)
|
202
|
-
attributes = attributes.dup
|
203
|
-
|
204
|
-
if attributes.keys.map(&:to_sym).include?(:image)
|
205
|
-
if attributes[:image].blank?
|
206
|
-
attributes[:image] = ''
|
207
|
-
elsif attributes[:image].is_a?(String)
|
208
|
-
attributes[:image] = Base64.encode64(File.read(attributes[:image]))
|
209
|
-
else
|
210
|
-
attributes.delete(:image)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
if attributes.keys.map(&:to_sym).include?(:folders) && !attributes.keys.map(&:to_sym).include?(:folder)
|
215
|
-
attributes[:folder] = attributes[:folders]
|
216
|
-
attributes.delete(:folders)
|
217
|
-
end
|
218
|
-
|
219
|
-
attributes.delete(:user)
|
220
|
-
attributes.delete(:created_at)
|
221
|
-
attributes.delete(:updated_at)
|
222
|
-
attributes.delete(:children_count)
|
223
|
-
|
224
|
-
attributes
|
225
|
-
end
|
226
|
-
|
227
|
-
# Overwritten destroy request with non-standard primary key
|
228
|
-
# @param [Jimson::BatchClient] batch_client
|
229
|
-
# @return [Syncano::Response]
|
230
|
-
def perform_destroy(batch_client)
|
231
|
-
self.class.make_request(client, batch_client, :destroy, scope_parameters.merge({ data_ids: [primary_key] }))
|
232
|
-
end
|
233
|
-
|
234
|
-
# Executes proper count request
|
235
|
-
# @param [Syncano::Clients::Base] client
|
236
|
-
# @param [Hash] scope_parameters
|
237
|
-
# @param [Hash] conditions
|
238
|
-
# @return [Syncano::Response]
|
239
|
-
def self.perform_count(client, scope_parameters, conditions)
|
240
|
-
make_request(client, nil, :count, conditions.merge(scope_parameters))
|
241
|
-
end
|
242
|
-
|
243
|
-
# Executes proper move request
|
244
|
-
# @param [Syncano::Clients::Base] client
|
245
|
-
# @param [Jimson::BatchClient] batch_client
|
246
|
-
# @param [Hash] scope_parameters
|
247
|
-
# @param [Array] data_ids
|
248
|
-
# @param [Hash] conditions
|
249
|
-
# @param [String] new_folder
|
250
|
-
# @param [String] new_state
|
251
|
-
# @return [Syncano::Response]
|
252
|
-
def self.perform_move(client, batch_client, scope_parameters, data_ids, conditions, new_folder, new_state)
|
253
|
-
move_params = { new_folder: new_folder, new_state: new_state }.delete_if { |k, v| v.nil? }
|
254
|
-
make_request(client, batch_client, :save, [conditions, { data_ids: data_ids }, move_params, scope_parameters].inject(&:merge))
|
255
|
-
end
|
256
|
-
|
257
|
-
# Executes proper copy request
|
258
|
-
# @param [Syncano::Clients::Base] client
|
259
|
-
# @param [Jimson::BatchClient] batch_client
|
260
|
-
# @param [Hash] scope_parameters
|
261
|
-
# @param [Array] data_ids
|
262
|
-
# @return [Syncano::Response]
|
263
|
-
def self.perform_copy(client, batch_client, scope_parameters, data_ids)
|
264
|
-
make_request(client, batch_client, :copy, { data_ids: data_ids }.merge(scope_parameters))
|
265
|
-
end
|
266
|
-
|
267
|
-
# Executes proper add_parent request
|
268
|
-
# @param [Jimson::BatchClient] batch_client
|
269
|
-
# @param [Integer] parent_id
|
270
|
-
# @param [TrueClass, FalseClass] remove_other
|
271
|
-
# @return [Syncano::Response]
|
272
|
-
def perform_add_parent(batch_client, parent_id, remove_other = false)
|
273
|
-
self.class.make_request(client, batch_client, :add_parent, scope_parameters.merge(
|
274
|
-
self.class.primary_key_name => primary_key,
|
275
|
-
parent_id: parent_id,
|
276
|
-
remove_other: remove_other
|
277
|
-
))
|
278
|
-
end
|
279
|
-
|
280
|
-
# Executes proper remove_parent request
|
281
|
-
# @param [Jimson::BatchClient] batch_client
|
282
|
-
# @param [Integer] parent_id
|
283
|
-
# @return [Syncano::Response]
|
284
|
-
def perform_remove_parent(batch_client, parent_id)
|
285
|
-
self.class.make_request(client, batch_client, :remove_parent, scope_parameters.merge(
|
286
|
-
self.class.primary_key_name => primary_key,
|
287
|
-
parent_id: parent_id
|
288
|
-
))
|
289
|
-
end
|
290
|
-
|
291
|
-
# Executes proper add_child request
|
292
|
-
# @param [Jimson::BatchClient] batch_client
|
293
|
-
# @param [Integer] child_id
|
294
|
-
# @param [TrueClass, FalseClass] remove_other
|
295
|
-
# @return [Syncano::Response]
|
296
|
-
def perform_add_child(batch_client, child_id, remove_other = false)
|
297
|
-
self.class.make_request(client, batch_client, :add_child, scope_parameters.merge(
|
298
|
-
self.class.primary_key_name => primary_key,
|
299
|
-
child_id: child_id,
|
300
|
-
remove_other: remove_other
|
301
|
-
))
|
302
|
-
end
|
303
|
-
|
304
|
-
# Executes proper remove_child request
|
305
|
-
# @param [Jimson::BatchClient] batch_client
|
306
|
-
# @param [Integer] child_id
|
307
|
-
# @return [Syncano::Response]
|
308
|
-
def perform_remove_child(batch_client, child_id)
|
309
|
-
self.class.make_request(client, batch_client, :remove_child, scope_parameters.merge(
|
310
|
-
self.class.primary_key_name => primary_key,
|
311
|
-
child_id: child_id
|
312
|
-
))
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
class Syncano
|
2
|
-
module Resources
|
3
|
-
# Folder resource
|
4
|
-
class Folder < ::Syncano::Resources::Base
|
5
|
-
# Association has_many :data_objects
|
6
|
-
# @return [Syncano::QueryBuilder] query builder for resource Syncano::Resources::DataObject
|
7
|
-
def data_objects
|
8
|
-
::Syncano::QueryBuilder.new(client, ::Syncano::Resources::DataObject, scope_parameters.merge(folders: @saved_attributes[:name]))
|
9
|
-
end
|
10
|
-
|
11
|
-
# Wrapper for api "get_one" method with folder_name as a key
|
12
|
-
# @param [Syncano::Clients::Base] client
|
13
|
-
# @param [String] name
|
14
|
-
# @param [Hash] scope_parameters
|
15
|
-
# @param [Hash] conditions
|
16
|
-
# @return [Syncano::Resources::Folder]
|
17
|
-
def self.find_by_name(client, name, scope_parameters = {}, conditions = {})
|
18
|
-
find(client, name, scope_parameters, conditions)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Wrapper for api "authorize" method
|
22
|
-
# @param [Integer] api_client_id
|
23
|
-
# @param [String] permission
|
24
|
-
# @return [Syncano::Resources::Base]
|
25
|
-
def authorize(api_client_id, permission)
|
26
|
-
perform_authorize(nil, api_client_id: api_client_id, permission: permission)
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
|
-
# Wrapper for api "authorize" method
|
31
|
-
# @param [Jimson::BatchClient] batch_client
|
32
|
-
# @param [Integer] api_client_id
|
33
|
-
# @param [String] permission
|
34
|
-
# @return [Syncano::Resources::Base]
|
35
|
-
def batch_authorize(batch_client, api_client_id, permission)
|
36
|
-
perform_authorize(batch_client, api_client_id: api_client_id, permission: permission)
|
37
|
-
self
|
38
|
-
end
|
39
|
-
|
40
|
-
# Wrapper for api "deauthorize" method
|
41
|
-
# @param [Integer] api_client_id
|
42
|
-
# @param [String] permission
|
43
|
-
# @return [Syncano::Resources::Base]
|
44
|
-
def deauthorize(api_client_id, permission)
|
45
|
-
perform_deauthorize(nil, api_client_id: api_client_id, permission: permission)
|
46
|
-
self
|
47
|
-
end
|
48
|
-
|
49
|
-
# Wrapper for api "deauthorize" method
|
50
|
-
# @param [Jimson::BatchClient] batch_client
|
51
|
-
# @param [Integer] api_client_id
|
52
|
-
# @param [String] permission
|
53
|
-
# @return [Syncano::Resources::Base]
|
54
|
-
def batch_deauthorize(batch_client, api_client_id, permission)
|
55
|
-
perform_deauthorize(batch_client, api_client_id: api_client_id, permission: permission)
|
56
|
-
self
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
self.primary_key = :name
|
62
|
-
self.scope_parameters = [:project_id, :collection_id]
|
63
|
-
|
64
|
-
# Executes proper destroy request
|
65
|
-
# @param [Jimson::BatchClient] batch_client
|
66
|
-
# @return [Syncano::Response]
|
67
|
-
def perform_destroy(batch_client)
|
68
|
-
self.class.make_request(client, batch_client, :destroy, scope_parameters.merge(name: primary_key))
|
69
|
-
end
|
70
|
-
|
71
|
-
# Executes proper authorize request
|
72
|
-
# @param [Jimson::BatchClient] batch_client
|
73
|
-
# @param [Hash] parameters
|
74
|
-
# @return [Syncano::Response]
|
75
|
-
def perform_authorize(batch_client, parameters)
|
76
|
-
self.class.make_request(client, batch_client, :authorize, scope_parameters.merge(parameters.merge(self.class.primary_key_name.to_sym => primary_key)))
|
77
|
-
end
|
78
|
-
|
79
|
-
# Executes proper deauthorize request
|
80
|
-
# @param [Jimson::BatchClient] batch_client
|
81
|
-
# @param [Hash] parameters
|
82
|
-
# @return [Syncano::Response]
|
83
|
-
def perform_deauthorize(batch_client, parameters)
|
84
|
-
self.class.make_request(client, batch_client, :deauthorize, scope_parameters.merge(parameters.merge(self.class.primary_key_name.to_sym => primary_key)))
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
class Syncano
|
2
|
-
module Resources
|
3
|
-
# Module used as a scope for classes representing notifications
|
4
|
-
module Notifications
|
5
|
-
# Base notification class used for inheritance
|
6
|
-
class Base < Syncano::Resources::Base
|
7
|
-
# Constructor for Syncano::Notifications::Base object
|
8
|
-
# @param [Syncano::Clients::Base] client
|
9
|
-
# @param [Hash] attributes
|
10
|
-
def initialize(client, attributes)
|
11
|
-
if attributes.is_a?(::Syncano::Packets::Base)
|
12
|
-
super(client, {})
|
13
|
-
self.attributes = { source: attributes.source, target: attributes.target, data: attributes.data }
|
14
|
-
else
|
15
|
-
super(client, attributes)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Proxy method for creating instance of proper subclass
|
20
|
-
# @param [Syncano::Clients::Base] client
|
21
|
-
# @param [Syncano::Packets::Base] packet
|
22
|
-
# @return [Syncano::Notifications::Base]
|
23
|
-
def self.instantize_notification(client, packet)
|
24
|
-
if packet.message?
|
25
|
-
::Syncano::Resources::Notifications::Message.new(client, packet)
|
26
|
-
else
|
27
|
-
mapping = {
|
28
|
-
new: ::Syncano::Resources::Notifications::Create,
|
29
|
-
change: ::Syncano::Resources::Notifications::Update,
|
30
|
-
delete: ::Syncano::Resources::Notifications::Destroy
|
31
|
-
}
|
32
|
-
|
33
|
-
mapping[packet.type.to_sym].new(client, packet)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Wrapper for api "get" method
|
38
|
-
# Returns all objects from Syncano
|
39
|
-
# @param [Syncano::Clients::Base] client
|
40
|
-
# @param [Hash] scope_parameters
|
41
|
-
# @param [Hash] conditions
|
42
|
-
# @return [Array] which contains Syncano::Resources::Base objects
|
43
|
-
def self.all(client, scope_parameters = {}, conditions = {})
|
44
|
-
mapping = {
|
45
|
-
new: ::Syncano::Resources::Notifications::Create,
|
46
|
-
change: ::Syncano::Resources::Notifications::Update,
|
47
|
-
delete: ::Syncano::Resources::Notifications::Destroy,
|
48
|
-
message: ::Syncano::Resources::Notifications::Message
|
49
|
-
}
|
50
|
-
|
51
|
-
response = perform_all(client, scope_parameters, conditions)
|
52
|
-
response.data.to_a.collect do |attributes|
|
53
|
-
type = attributes.delete(:type)
|
54
|
-
mapping[type.to_sym].new(client, attributes.merge(scope_parameters))
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Wrapper for api "send" method
|
59
|
-
# Creates object in Syncano
|
60
|
-
# @param [Syncano::Clients::Base] client
|
61
|
-
# @param [Hash] attributes
|
62
|
-
# @return [Syncano::Resources::Base]
|
63
|
-
def self.create(client, attributes)
|
64
|
-
perform_create(client, nil, attributes)
|
65
|
-
::Syncano::Resources::Notifications::Message.new(client, map_to_scope_parameters(attributes))
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
self.syncano_model_name = 'notification'
|
71
|
-
self.crud_class_methods = [:all, :new, :create]
|
72
|
-
self.crud_instance_methods = [:save]
|
73
|
-
|
74
|
-
# Executes proper all request
|
75
|
-
# @param [Syncano::Clients::Base] client
|
76
|
-
# @param [Hash] scope_parameters
|
77
|
-
# @param [Hash] conditions
|
78
|
-
# @return [Syncano::Response]
|
79
|
-
def self.perform_all(client, scope_parameters, conditions)
|
80
|
-
make_request(client, nil, :get_history, conditions.merge(scope_parameters), :history)
|
81
|
-
end
|
82
|
-
|
83
|
-
# Executes proper create request
|
84
|
-
# @param [Syncano::Clients::Base] client
|
85
|
-
# @param [Jimson::BatchClient] batch_client
|
86
|
-
# @param [Hash] attributes
|
87
|
-
# @return [Syncano::Response]
|
88
|
-
def self.perform_create(client, batch_client, attributes)
|
89
|
-
make_request(client, batch_client, :send, attributes_to_sync(attributes))
|
90
|
-
end
|
91
|
-
|
92
|
-
# Executes proper save request
|
93
|
-
# @param [Jimson::BatchClient] batch_client
|
94
|
-
# @return [Syncano::Response]
|
95
|
-
def perform_save(batch_client)
|
96
|
-
if new_record?
|
97
|
-
self.class.perform_create(client, batch_client, attributes)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|