Class: Syncano::Resources::DataObject

Inherits:
Base
  • Object
show all
Defined in:
lib/syncano/resources/data_object.rb

Overview

Data object resource - corresponds to Syncano data resource

Instance Attribute Summary

Attributes inherited from Base

#attributes, #destroyed, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, all, #batch, batch_create, #batch_destroy, #batch_save, #batch_update, create, #destroy, #destroyed?, find, #new_record?, #reload!, #save, #saved?, #update

Constructor Details

#initialize(client, attributes = {}) ⇒ DataObject

Overwritten constructor with recursive initializing associated children objects

Parameters:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/syncano/resources/data_object.rb', line 8

def initialize(client, attributes = {})
  super(client, attributes)
  if self.attributes[:children].present?
    self.attributes[:children] = self.attributes[:children].collect do |child|
      if child.is_a?(Hash)
        self.class.new(client, child)
      else
        child
      end
    end
  end

  if self.attributes[:user].is_a?(Hash)
    self.attributes[:user] = ::Syncano::Resources::User.new(client, self.attributes[:user])
  end

  if self.attributes[:additional].is_a?(Hash)
    self.attributes.merge!(self.attributes.delete(:additional))
  end
end

Class Method Details

.batch_copy(batch_client, client, scope_parameters = {}, data_ids = []) ⇒ Syncano::Response

Batch version of “move” method

Parameters:

  • batch_client (Jimson::BatchClient)
  • client (Syncano::Clients::Base)
  • scope_parameters (Hash) (defaults to: {})
  • data_ids (Array) (defaults to: [])

Returns:



109
110
111
# File 'lib/syncano/resources/data_object.rb', line 109

def self.batch_copy(batch_client, client, scope_parameters = {}, data_ids = [])
  perform_copy(client, batch_client, scope_parameters, data_ids)
end

.batch_move(batch_client, client, scope_parameters = {}, data_ids = [], conditions = {}, new_folder = nil, new_state = nil) ⇒ Syncano::Response

Batch version of “move” method

Parameters:

  • batch_client (Jimson::BatchClient)
  • client (Syncano::Clients::Base)
  • scope_parameters (Hash) (defaults to: {})
  • data_ids (Array) (defaults to: [])
  • conditions (Hash) (defaults to: {})
  • new_folder (String) (defaults to: nil)
  • new_state (String) (defaults to: nil)

Returns:



71
72
73
# File 'lib/syncano/resources/data_object.rb', line 71

def self.batch_move(batch_client, client, scope_parameters = {}, data_ids = [], conditions = {}, new_folder = nil, new_state = nil)
  perform_move(client, batch_client, scope_parameters, data_ids, conditions, new_folder, new_state)
end

.copy(client, scope_parameters = {}, data_ids = []) ⇒ Array

Wrapper for api “copy” method

Parameters:

  • client (Syncano::Clients::Base)
  • scope_parameters (Hash) (defaults to: {})
  • data_ids (Array) (defaults to: [])

Returns:

  • (Array)

    collection of Syncano::Resource::DataObject objects



98
99
100
101
# File 'lib/syncano/resources/data_object.rb', line 98

def self.copy(client, scope_parameters = {}, data_ids = [])
  response = perform_copy(client, nil, scope_parameters, data_ids)
  response.data.collect { |attributes| self.new(client, attributes.merge(scope_parameters)) }
end

.count(client, scope_parameters = {}, conditions = {}) ⇒ Integer

Wrapper for api “count” method

Parameters:

  • client (Syncano::Clients::Base)
  • scope_parameters (Hash) (defaults to: {})
  • conditions (Hash) (defaults to: {})

Returns:

  • (Integer)


44
45
46
47
# File 'lib/syncano/resources/data_object.rb', line 44

def self.count(client, scope_parameters = {}, conditions = {})
  response = perform_count(client, scope_parameters, conditions)
  response.data
end

.find_by_key(client, key, scope_parameters = {}, conditions = {}) ⇒ Syncano::Resources::DataObject

Wrapper for api “get_one” method with data_key as a key

Parameters:

  • client (Syncano::Clients::Base)
  • key (String)
  • scope_parameters (Hash) (defaults to: {})
  • conditions (Hash) (defaults to: {})

Returns:



35
36
37
# File 'lib/syncano/resources/data_object.rb', line 35

def self.find_by_key(client, key, scope_parameters = {}, conditions = {})
  perform_find(client, :key, key, scope_parameters, conditions)
end

.move(client, scope_parameters = {}, data_ids = [], conditions = {}, new_folder = nil, new_state = nil) ⇒ Array

Wrapper for api “move” method

Parameters:

  • client (Syncano::Clients::Base)
  • scope_parameters (Hash) (defaults to: {})
  • data_ids (Array) (defaults to: [])
  • conditions (Hash) (defaults to: {})
  • new_folder (String) (defaults to: nil)
  • new_state (String) (defaults to: nil)

Returns:

  • (Array)

    collection of Syncano::Resource::DataObject objects



57
58
59
60
# File 'lib/syncano/resources/data_object.rb', line 57

def self.move(client, scope_parameters = {}, data_ids = [], conditions = {}, new_folder = nil, new_state = nil)
  response = perform_move(client, nil, scope_parameters, data_ids, conditions, new_folder, new_state)
  all(client, scope_parameters, data_ids: data_ids)
end

Instance Method Details

#add_child(child_id, remove_other = false) ⇒ Syncano::Resources::DataObject

Wrapper for api “add_child” method

Parameters:

  • child_id (Integer)
  • remove_other (TrueClass, FalseClass) (defaults to: false)

Returns:



164
165
166
167
# File 'lib/syncano/resources/data_object.rb', line 164

def add_child(child_id, remove_other = false)
  perform_add_child(nil, child_id, remove_other)
  reload!
end

#add_parent(parent_id, remove_other = false) ⇒ Syncano::Resources::DataObject

Wrapper for api “add_parent” method

Parameters:

  • parent_id (Integer)
  • remove_other (TrueClass, FalseClass) (defaults to: false)

Returns:



130
131
132
133
# File 'lib/syncano/resources/data_object.rb', line 130

def add_parent(parent_id, remove_other = false)
  response = perform_add_parent(nil, parent_id, remove_other)
  reload!
end

#batch_add_child(batch_client, child_id, remove_other = false) ⇒ Syncano::Response

Batch version of “add_child” method

Parameters:

  • batch_client (Jimson::BatchClient)
  • child_id (Integer)
  • remove_other (TrueClass, FalseClass) (defaults to: false)

Returns:



174
175
176
# File 'lib/syncano/resources/data_object.rb', line 174

def batch_add_child(batch_client, child_id, remove_other = false)
  perform_add_child(batch_client, child_id, remove_other)
end

#batch_add_parent(batch_client, parent_id, remove_other = false) ⇒ Syncano::Response

Batch version of “add_parent” method

Parameters:

  • batch_client (Jimson::BatchClient)
  • parent_id (Integer)
  • remove_other (TrueClass, FalseClass) (defaults to: false)

Returns:



140
141
142
# File 'lib/syncano/resources/data_object.rb', line 140

def batch_add_parent(batch_client, parent_id, remove_other = false)
  perform_add_parent(batch_client, parent_id, remove_other)
end

#batch_copy(batch_client) ⇒ Syncano::Response

Batch version of “copy” method

Parameters:

  • batch_client (Jimson::BatchClient)

Returns:



122
123
124
# File 'lib/syncano/resources/data_object.rb', line 122

def batch_copy(batch_client)
  self.class.batch_copy(batch_client, client, scope_parameters, id.to_s)
end

#batch_move(batch_client, new_folder = nil, new_state = nil) ⇒ Syncano::Response

Batch version of “move” method

Parameters:

  • batch_client (Jimson::BatchClient)
  • new_folder (String) (defaults to: nil)
  • new_state (String) (defaults to: nil)

Returns:



89
90
91
# File 'lib/syncano/resources/data_object.rb', line 89

def batch_move(batch_client, new_folder = nil, new_state = nil)
  perform_move(client, batch_client, scope_parameters, [id], {}, new_folder, new_state)
end

#batch_remove_child(batch_client, child_id = nil) ⇒ Syncano::Response

Batch version of “remove_child” method

Parameters:

  • batch_client (Jimson::BatchClient)
  • child_id (Integer) (defaults to: nil)

Returns:



190
191
192
# File 'lib/syncano/resources/data_object.rb', line 190

def batch_remove_child(batch_client, child_id = nil)
  perform_remove_child(batch_client, child_id)
end

#batch_remove_parent(batch_client, parent_id = nil) ⇒ Syncano::Response

Batch version of “remove_parent” method

Parameters:

  • batch_client (Jimson::BatchClient)
  • parent_id (Integer) (defaults to: nil)

Returns:



156
157
158
# File 'lib/syncano/resources/data_object.rb', line 156

def batch_remove_parent(batch_client, parent_id = nil)
  perform_remove_parent(batch_client, parent_id)
end

#copySyncano::Resource::DataObject

Wrapper for api “copy” method

Returns:

  • (Syncano::Resource::DataObject)


115
116
117
# File 'lib/syncano/resources/data_object.rb', line 115

def copy
  self.class.copy(client, scope_parameters, id.to_s).try(:first)
end

#move(new_folder = nil, new_state = nil) ⇒ Syncano::Resource::DataObject

Wrapper for api “move” method

Parameters:

  • new_folder (String) (defaults to: nil)
  • new_state (String) (defaults to: nil)

Returns:

  • (Syncano::Resource::DataObject)


79
80
81
82
# File 'lib/syncano/resources/data_object.rb', line 79

def move(new_folder = nil, new_state = nil)
  perform_move(client, nil, scope_parameters, [id], {}, new_folder, new_state)
  reload!
end

#remove_child(child_id = nil) ⇒ Syncano::Resources::DataObject

Wrapper for api “remove_child” method

Parameters:

  • child_id (Integer) (defaults to: nil)

Returns:



181
182
183
184
# File 'lib/syncano/resources/data_object.rb', line 181

def remove_child(child_id = nil)
  perform_remove_child(nil, child_id)
  reload!
end

#remove_parent(parent_id = nil) ⇒ Syncano::Resources::DataObject

Wrapper for api “remove_parent” method

Parameters:

  • parent_id (Integer) (defaults to: nil)

Returns:



147
148
149
150
# File 'lib/syncano/resources/data_object.rb', line 147

def remove_parent(parent_id = nil)
  response = perform_remove_parent(nil, parent_id)
  reload!
end