Class: Groonga::Client::Response::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/client/response/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, header, body) ⇒ Base

Returns a new instance of Base.



139
140
141
142
143
144
# File 'lib/groonga/client/response/base.rb', line 139

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.

Returns:

  • (::Hash)

    The body of response. Its content is depends on command.

See Also:



134
135
136
# File 'lib/groonga/client/response/base.rb', line 134

def body
  @body
end

#commandGroonga::Command

Returns The command for the request.

Returns:

  • (Groonga::Command)

    The command for the request.



120
121
122
# File 'lib/groonga/client/response/base.rb', line 120

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.

Returns:

  • (::Array<Integer, Float, Float>)

    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.

See Also:



129
130
131
# File 'lib/groonga/client/response/base.rb', line 129

def header
  @header
end

#rawString

Returns The unparsed response. It may be JSON, XML or groonga command format.

Returns:

  • (String)

    The unparsed response. It may be JSON, XML or groonga command format.



137
138
139
# File 'lib/groonga/client/response/base.rb', line 137

def raw
  @raw
end

Class Method Details

.parse(command, raw_response) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/groonga/client/response/base.rb', line 52

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_timeTime

Returns The elapsed time of the request.

Returns:

  • (Time)

    The elapsed time of the request.

Since:

  • 0.1.0



160
161
162
# File 'lib/groonga/client/response/base.rb', line 160

def elapsed_time
  (header || [0, 0, 0.0])[2]
end

#start_timeTime

Returns The time of the request is accepted.

Returns:

  • (Time)

    The time of the request is accepted.

Since:

  • 0.1.0



154
155
156
# File 'lib/groonga/client/response/base.rb', line 154

def start_time
  Time.at((header || [0, 0])[1])
end

#status_codeInteger

Returns The status code of the response.

Returns:

  • (Integer)

    The status code of the response.

Since:

  • 0.1.0



148
149
150
# File 'lib/groonga/client/response/base.rb', line 148

def status_code
  (header || [0])[0]
end

#success?Boolean

Returns true if the request is processed successfully, false otherwise.

Returns:

  • (Boolean)

    true if the request is processed successfully, false otherwise.

Since:

  • 0.1.0



167
168
169
# File 'lib/groonga/client/response/base.rb', line 167

def success?
  status_code.zero?
end