Class: KStor::Response
Overview
Response to a user request.
Instance Attribute Summary collapse
-
#session_id ⇒ Object
Returns the value of attribute session_id.
Attributes inherited from Message
Class Method Summary collapse
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(type, args) ⇒ Response
constructor
A new instance of Response.
- #to_h ⇒ Object
Methods inherited from Message
Constructor Details
#initialize(type, args) ⇒ Response
Returns a new instance of Response.
110 111 112 113 |
# File 'lib/kstor/message.rb', line 110 def initialize(type, args) @session_id = nil super end |
Instance Attribute Details
#session_id ⇒ Object
Returns the value of attribute session_id.
108 109 110 |
# File 'lib/kstor/message.rb', line 108 def session_id @session_id end |
Class Method Details
.parse(str) ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/kstor/message.rb', line 115 def self.parse(str) data = JSON.parse(str) resp = new(data['type'], data['args']) resp.session_id = data['session_id'] resp rescue JSON::ParserError => e raise UnparsableResponse, e. end |
Instance Method Details
#error? ⇒ Boolean
124 125 126 |
# File 'lib/kstor/message.rb', line 124 def error? @type == 'error' end |
#to_h ⇒ Object
128 129 130 |
# File 'lib/kstor/message.rb', line 128 def to_h super.merge('session_id' => @session_id) end |