class TempoIQ::WriteResponse

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
Device level introspection

Attributes

status[R]

Public Class Methods

new(status = nil) click to toggle source
# File lib/tempoiq/models/write_response.rb, line 19
def initialize(status = nil)
  @status = status
end

Public Instance Methods

created() click to toggle source

Devices that were created during the write

# File lib/tempoiq/models/write_response.rb, line 49
def created
  status.select { |device_key, v| v["device_state"] == "created" }
end
existing() click to toggle source

Devices that already existed before the write

# File lib/tempoiq/models/write_response.rb, line 44
def existing
  status.select { |device_key, v| v["device_state"] == "existing" }
end
failures() click to toggle source

Retrieve the failures, key => message [Hash]

# File lib/tempoiq/models/write_response.rb, line 39
def failures
  status.select { |device_key, v| v["successful"] == false }
end
modified() click to toggle source

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

# File lib/tempoiq/models/write_response.rb, line 54
def modified
  status.select { |device_key, v| v["device_state"] == "modified" }
end
partial_success?() click to toggle source

Did the write have partial failures?

# File lib/tempoiq/models/write_response.rb, line 34
def partial_success?
  !success?
end
success?() click to toggle source

Was the write a total success?

# 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