Class: Solr::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/solr/response.rb,
lib/solr/response/header.rb,
lib/solr/response/parser.rb,
lib/solr/response/solr_error.rb,
lib/solr/response/http_status.rb

Defined Under Namespace

Classes: Header, HttpStatus, Parser, SolrError

Constant Summary collapse

OK =
'OK'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header:, http_status: HttpStatus.ok, solr_error: SolrError.none, body: {}) ⇒ Response

Returns a new instance of Response.



12
13
14
15
16
17
18
# File 'lib/solr/response.rb', line 12

def initialize(header:, http_status: HttpStatus.ok, solr_error: SolrError.none, body: {})
  @header = header
  @http_status = http_status
  @solr_error = solr_error
  @body = body
  freeze
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



10
11
12
# File 'lib/solr/response.rb', line 10

def body
  @body
end

#headerObject (readonly)

Returns the value of attribute header.



10
11
12
# File 'lib/solr/response.rb', line 10

def header
  @header
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



10
11
12
# File 'lib/solr/response.rb', line 10

def http_status
  @http_status
end

#solr_errorObject (readonly)

Returns the value of attribute solr_error.



10
11
12
# File 'lib/solr/response.rb', line 10

def solr_error
  @solr_error
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/solr/response.rb', line 24

def error?
  !ok?
end

#error_messageObject



36
37
38
39
# File 'lib/solr/response.rb', line 36

def error_message
  return if ok?
  solr_error ? solr_error.message : http_status.inspect
end

#inspectObject



41
42
43
44
45
46
# File 'lib/solr/response.rb', line 41

def inspect
  return OK if ok?
  str = "Error: #{http_status.inspect}"
  str << "\n#{solr_error.inspect}" if solr_error
  str
end

#ok?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/solr/response.rb', line 20

def ok?
  header.ok?
end

#statusObject



28
29
30
31
32
33
34
# File 'lib/solr/response.rb', line 28

def status
  if header.status.zero?
    OK
  else
    header.status
  end
end