Class: Reolink::HTTP::Response
- Inherits:
-
Object
- Object
- Reolink::HTTP::Response
- Defined in:
- lib/reolink/http.rb
Overview
Represents a response from the device.
cmd -- name of command
code -- status code. 0 means no errors.
initial -- initial value of attribute, for Get* requests when `verbose` is true
range -- range of possible values for attribute, for Get* requests when `verbose` is true
current -- current value of attribute, for Get* requests
error -- error code and details. nil if no error.
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#initial ⇒ Object
readonly
Returns the value of attribute initial.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.from_json(str) ⇒ Object
Parse a JSON string from the device and return *an array* of Response objects.
Instance Method Summary collapse
-
#initialize(cmd:, code:, initial: nil, range: nil, value: nil, error: nil) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(cmd:, code:, initial: nil, range: nil, value: nil, error: nil) ⇒ Response
Returns a new instance of Response.
91 92 93 94 95 96 97 98 |
# File 'lib/reolink/http.rb', line 91 def initialize(cmd:, code:, initial: nil, range: nil, value: nil, error: nil) @cmd = cmd @code = code @initial = initial&.[](cmd.delete_prefix("Get")) || initial @range = range&.[](cmd.delete_prefix("Get")) || range @value = value&.[](cmd.delete_prefix("Get")) || value @error = error end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
89 90 91 |
# File 'lib/reolink/http.rb', line 89 def cmd @cmd end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
89 90 91 |
# File 'lib/reolink/http.rb', line 89 def code @code end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
89 90 91 |
# File 'lib/reolink/http.rb', line 89 def error @error end |
#initial ⇒ Object (readonly)
Returns the value of attribute initial.
89 90 91 |
# File 'lib/reolink/http.rb', line 89 def initial @initial end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
89 90 91 |
# File 'lib/reolink/http.rb', line 89 def range @range end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
89 90 91 |
# File 'lib/reolink/http.rb', line 89 def value @value end |
Class Method Details
.from_json(str) ⇒ Object
Parse a JSON string from the device and return *an array* of Response objects.
82 83 84 85 86 87 |
# File 'lib/reolink/http.rb', line 82 def self.from_json(str) JSON.parse(str) .map do |response| new(**response.transform_keys(&:to_sym)) end end |