Class: TempoIQ::WriteResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/tempoiq/models/write_response.rb

Overview

WriteResponse is used to track the status of a write. Because writes are bulk in nature (writing to multiple devices and sensors at once), there are instances where some writes device writes may succeed and some might fail in the same write call.

High level introspection
  • #success?

  • #partial_success?

Device level introspection
  • #failures

  • #created

  • #existing

  • #modified

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status = nil) ⇒ WriteResponse

Returns a new instance of WriteResponse.



19
20
21
# File 'lib/tempoiq/models/write_response.rb', line 19

def initialize(status = nil)
  @status = status
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



17
18
19
# File 'lib/tempoiq/models/write_response.rb', line 17

def status
  @status
end

Instance Method Details

#createdObject

Devices that were created during the write



49
50
51
# File 'lib/tempoiq/models/write_response.rb', line 49

def created
  status.select { |device_key, v| v["device_state"] == "created" }
end

#existingObject

Devices that already existed before the write



44
45
46
# File 'lib/tempoiq/models/write_response.rb', line 44

def existing
  status.select { |device_key, v| v["device_state"] == "existing" }
end

#failuresObject

Retrieve the failures, key => message [Hash]



39
40
41
# File 'lib/tempoiq/models/write_response.rb', line 39

def failures
  status.select { |device_key, v| v["successful"] == false }
end

#modifiedObject

Devices that were modified (eg - sensors added) during the write



54
55
56
# File 'lib/tempoiq/models/write_response.rb', line 54

def modified
  status.select { |device_key, v| v["device_state"] == "modified" }
end

#partial_success?Boolean

Did the write have partial failures?

Returns:

  • (Boolean)


34
35
36
# File 'lib/tempoiq/models/write_response.rb', line 34

def partial_success?
  !success?
end

#success?Boolean

Was the write a total success?

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
# File 'lib/tempoiq/models/write_response.rb', line 24

def success?
  status.each do |key,device_status|
    if device_status['successful'] == false
      return false
    end
  end
  true
end