Class: Groonga::Client::Response::Base
- Inherits:
-
Object
- Object
- Groonga::Client::Response::Base
- Defined in:
- lib/groonga/client/response/base.rb
Direct Known Subclasses
CacheLimit, Check, ColumnCreate, ColumnList, ColumnRemove, ColumnRename, Defrag, Delete, Dump, Error, Load, LockClear, LogLevel, LogPut, LogReopen, Quit, Register, Schema, Select, Status, TableCreate, TableList, TableRemove
Instance Attribute Summary collapse
-
#body ⇒ ::Hash
The body of response.
-
#command ⇒ Groonga::Command
The command for the request.
-
#header ⇒ ::Array<Integer, Float, Float>
The header of response.
-
#raw ⇒ String
The unparsed response.
Class Method Summary collapse
Instance Method Summary collapse
-
#elapsed_time ⇒ Time
The elapsed time of the request.
-
#error_message ⇒ String?
The error message of the response.
-
#initialize(command, header, body) ⇒ Base
constructor
A new instance of Base.
-
#start_time ⇒ Time
The time of the request is accepted.
-
#status_code ⇒ Integer
The status code of the response.
-
#success? ⇒ Boolean
true
if the request is processed successfully,false
otherwise.
Constructor Details
#initialize(command, header, body) ⇒ Base
Returns a new instance of Base.
150 151 152 153 154 155 |
# File 'lib/groonga/client/response/base.rb', line 150 def initialize(command, header, body) self.command = command self.header = header self.body = body self.raw = nil end |
Instance Attribute Details
#body ⇒ ::Hash
Returns The body of response. Its content is depends on command.
145 146 147 |
# File 'lib/groonga/client/response/base.rb', line 145 def body @body end |
#command ⇒ Groonga::Command
Returns The command for the request.
131 132 133 |
# File 'lib/groonga/client/response/base.rb', line 131 def command @command end |
#header ⇒ ::Array<Integer, Float, Float>
Returns The header of response.
It consists of [return_code, start_time, elapsed_time_in_seconds]
for success case.
It consists of
[return_code, start_time, elapsed_time_in_seconds, error_message, error_location]
for error case.
140 141 142 |
# File 'lib/groonga/client/response/base.rb', line 140 def header @header end |
#raw ⇒ String
Returns The unparsed response. It may be JSON, XML or groonga command format.
148 149 150 |
# File 'lib/groonga/client/response/base.rb', line 148 def raw @raw end |
Class Method Details
.parse(command, raw_response) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/groonga/client/response/base.rb', line 63 def parse(command, raw_response) case command.output_type when :json header, body = JSON.parse(raw_response) when :xml header, body = parse_xml(raw_response) else header = nil body = raw_response end if header.nil? or header[0].zero? response = new(command, header, body) else response = Error.new(command, header, body) end response.raw = raw_response response end |
Instance Method Details
#elapsed_time ⇒ Time
Returns The elapsed time of the request.
171 172 173 |
# File 'lib/groonga/client/response/base.rb', line 171 def elapsed_time (header || [0, 0, 0.0])[2] end |
#error_message ⇒ String?
Returns The error message of the response.
177 178 179 |
# File 'lib/groonga/client/response/base.rb', line 177 def (header || [0, 0, 0.0, nil])[3] end |
#start_time ⇒ Time
Returns The time of the request is accepted.
165 166 167 |
# File 'lib/groonga/client/response/base.rb', line 165 def start_time Time.at((header || [0, 0])[1]) end |
#status_code ⇒ Integer
Returns The status code of the response.
159 160 161 |
# File 'lib/groonga/client/response/base.rb', line 159 def status_code (header || [0])[0] end |
#success? ⇒ Boolean
Returns true
if the request is processed successfully,
false
otherwise.
184 185 186 |
# File 'lib/groonga/client/response/base.rb', line 184 def success? status_code.zero? end |