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 ⇒ Float
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.
-
#return_code ⇒ Integer
The return code of the response.
-
#start_time ⇒ Time
The time of the request is accepted.
-
#status_code ⇒ Integer
deprecated
Deprecated.
since 0.2.6. Use #return_code instead.
-
#success? ⇒ Boolean
true
if the request is processed successfully,false
otherwise.
Constructor Details
#initialize(command, header, body) ⇒ Base
Returns a new instance of Base.
154 155 156 157 158 159 |
# File 'lib/groonga/client/response/base.rb', line 154 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.
149 150 151 |
# File 'lib/groonga/client/response/base.rb', line 149 def body @body end |
#command ⇒ Groonga::Command
Returns The command for the request.
135 136 137 |
# File 'lib/groonga/client/response/base.rb', line 135 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.
144 145 146 |
# File 'lib/groonga/client/response/base.rb', line 144 def header @header end |
#raw ⇒ String
Returns The unparsed response. It may be JSON, XML or Groonga command format.
152 153 154 |
# File 'lib/groonga/client/response/base.rb', line 152 def raw @raw end |
Class Method Details
.parse(command, raw_response) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/groonga/client/response/base.rb', line 65 def parse(command, raw_response) return_code = nil case command.output_type when :json response = JSON.parse(raw_response) if response.is_a?(::Array) header, body = response return_code = header[0] if header else header = response["header"] body = response["body"] return_code = header["return_code"] if header end when :xml header, body = parse_xml(raw_response) return_code = header[0] if header else header = nil body = raw_response end if header.nil? or return_code == 0 response = new(command, header, body) else response = Error.new(command, header, body) end response.raw = raw_response response end |
Instance Method Details
#elapsed_time ⇒ Float
Returns The elapsed time of the request.
195 196 197 198 199 200 201 202 203 |
# File 'lib/groonga/client/response/base.rb', line 195 def elapsed_time if header.nil? 0.0 elsif header_v1? header[2] else header["elapsed_time"] end end |
#error_message ⇒ String?
Returns The error message of the response.
207 208 209 210 211 212 213 214 215 |
# File 'lib/groonga/client/response/base.rb', line 207 def if header.nil? nil elsif header_v1? header[3] else (header["error"] || {})["message"] end end |
#return_code ⇒ Integer
Returns The return code of the response.
163 164 165 166 167 168 169 170 171 |
# File 'lib/groonga/client/response/base.rb', line 163 def return_code if header.nil? 0 elsif header_v1? header[0] else header["return_code"] || 0 end end |
#start_time ⇒ Time
Returns The time of the request is accepted.
183 184 185 186 187 188 189 190 191 |
# File 'lib/groonga/client/response/base.rb', line 183 def start_time if header.nil? Time.at(0) elsif header_v1? Time.at(header[1]) else Time.at(header["start_time"]) end end |
#status_code ⇒ Integer
since 0.2.6. Use #return_code instead.
Returns The status code of the response.
177 178 179 |
# File 'lib/groonga/client/response/base.rb', line 177 def status_code return_code end |
#success? ⇒ Boolean
Returns true
if the request is processed successfully,
false
otherwise.
220 221 222 |
# File 'lib/groonga/client/response/base.rb', line 220 def success? return_code.zero? end |