Module: Alula::DcpOperations::Save::InstanceMethods

Includes:
Alula::Dcp::ErrorHandler
Defined in:
lib/alula/dcp_operations/save.rb

Overview

Instance methods for saving a model

Instance Method Summary collapse

Methods included from Alula::Dcp::ErrorHandler

#handle_errors

Instance Method Details

#createObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/alula/dcp_operations/save.rb', line 29

def create
  payload = {
    data: as_patchable_json
  }

  response = Alula::Client.request(:post, self.class.resource_url, payload, {})

  if response.ok?
    index = response.data['index']
    construct_from(device_id, index, response.data)
    return true
  end

  handle_errors(response)
end

#saveObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/alula/dcp_operations/save.rb', line 14

def save
  payload = as_patchable_json
  response = Alula::Client.request(:patch, "#{resource_url}/staged", payload, {})

  if response.ok?
    construct_from(device_id, index, response.data)
    return true
  end
  handle_errors(response)
end

#save!Object



25
26
27
# File 'lib/alula/dcp_operations/save.rb', line 25

def save!
  save || raise(ValidationError, errors)
end