Class: Jimson::Response
- Inherits:
-
Object
- Object
- Jimson::Response
- Defined in:
- lib/jimson/response.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#id ⇒ Object
Returns the value of attribute id.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(id) ⇒ Response
constructor
A new instance of Response.
- #is_error? ⇒ Boolean
- #populate!(data) ⇒ Object
- #succeeded? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(id) ⇒ Response
Returns a new instance of Response.
5 6 7 |
# File 'lib/jimson/response.rb', line 5 def initialize(id) @id = id end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
3 4 5 |
# File 'lib/jimson/response.rb', line 3 def error @error end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/jimson/response.rb', line 3 def id @id end |
#result ⇒ Object
Returns the value of attribute result.
3 4 5 |
# File 'lib/jimson/response.rb', line 3 def result @result end |
Instance Method Details
#is_error? ⇒ Boolean
16 17 18 |
# File 'lib/jimson/response.rb', line 16 def is_error? !!@error end |
#populate!(data) ⇒ Object
24 25 26 27 |
# File 'lib/jimson/response.rb', line 24 def populate!(data) @error = data['error'] if !!data['error'] @result = data['result'] if !!data['result'] end |
#succeeded? ⇒ Boolean
20 21 22 |
# File 'lib/jimson/response.rb', line 20 def succeeded? !!@result end |
#to_h ⇒ Object
9 10 11 12 13 14 |
# File 'lib/jimson/response.rb', line 9 def to_h h = {'jsonrpc' => '2.0'} h.merge!('result' => @result) if !!@result h.merge!('error' => @error) if !!@error h.merge!('id' => @id) end |