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.



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.

Returns:

  • (::Hash)

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

See Also:



145
146
147
# File 'lib/groonga/client/response/base.rb', line 145

def body
  @body
end

#commandGroonga::Command

Returns The command for the request.

Returns:

  • (Groonga::Command)

    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.

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:



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

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.



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_timeTime

Returns The elapsed time of the request.

Returns:

  • (Time)

    The elapsed time of the request.

Since:

  • 0.1.0



171
172
173
# File 'lib/groonga/client/response/base.rb', line 171

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

#error_messageString?

Returns The error message of the response.

Returns:

  • (String, nil)

    The error message of the response.

Since:

  • 0.2.4



177
178
179
# File 'lib/groonga/client/response/base.rb', line 177

def error_message
  (header || [0, 0, 0.0, nil])[3]
end

#start_timeTime

Returns The time of the request is accepted.

Returns:

  • (Time)

    The time of the request is accepted.

Since:

  • 0.1.0



165
166
167
# File 'lib/groonga/client/response/base.rb', line 165

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



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.

Returns:

  • (Boolean)

    true if the request is processed successfully, false otherwise.

Since:

  • 0.1.0



184
185
186
# File 'lib/groonga/client/response/base.rb', line 184

def success?
  status_code.zero?
end