Class: SolrMakr::SolrAPI::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/solr_makr/solr_api/response.rb

Direct Known Subclasses

ClusterResponse, ListResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response = {}) ⇒ Response

Returns a new instance of Response.

Parameters:

  • raw_response (Hash) (defaults to: {})


5
6
7
# File 'lib/solr_makr/solr_api/response.rb', line 5

def initialize(raw_response = {})
  @raw_response = raw_response.with_indifferent_access
end

Instance Attribute Details

#failureString (readonly)

Returns:

  • (String)


42
43
44
45
46
# File 'lib/solr_makr/solr_api/response.rb', line 42

attr_lazy_reader :failure do
  unless success?
    exception.fetch(:msg) or error.fetch(:msg) or 'unknown failure'
  end
end

#raw_responseActiveSupport::HashWithIndifferentAccess (readonly)

Returns:

  • (ActiveSupport::HashWithIndifferentAccess)


11
12
13
# File 'lib/solr_makr/solr_api/response.rb', line 11

def raw_response
  @raw_response
end

#response_headerActiveSupport::HashWithIndifferentAccess (readonly)

Returns:

  • (ActiveSupport::HashWithIndifferentAccess)


36
37
38
# File 'lib/solr_makr/solr_api/response.rb', line 36

attr_lazy_reader :response_header do
  dig :responseHeader
end

Instance Method Details

#array(*keys) ⇒ Array

Parameters:

  • keys (<String, Symbol>)

    path to the desired array

Returns:

  • (Array)


17
18
19
# File 'lib/solr_makr/solr_api/response.rb', line 17

def array(*keys)
  Array(dig(*keys))
end

#dig(*keys) ⇒ Object, ActiveSupport::HashWithIndifferentAccess Also known as: []

Dig into the response data by a given path.

Parameters:

  • keys (<String, Symbol>)

    path to the desired value

Returns:

  • (Object)

    if non-hashlike

  • (ActiveSupport::HashWithIndifferentAccess)

    if hash-like



26
27
28
29
30
# File 'lib/solr_makr/solr_api/response.rb', line 26

def dig(*keys)
  keys.reduce raw_response do |hsh, key|
    hsh[key] if hsh.respond_to?(:[])
  end
end

#success?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/solr_makr/solr_api/response.rb', line 56

def success?
  status == 0
end

#to_sObject



64
65
66
# File 'lib/solr_makr/solr_api/response.rb', line 64

def to_s
  "#<#{self.class.name} #{JSON.pretty_generate(raw_response)}>"
end