Class: SolrMakr::SolrAPI::RequestParams

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

Overview

Wrapper around parameters passed to solr api requests.

Solr requests are not really RESTful, and instead take the action name in a parameter on the query string.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action:) ⇒ RequestParams

Returns a new instance of RequestParams.

Parameters:

  • action (String)

    (see #action)



9
10
11
12
13
# File 'lib/solr_makr/solr_api/request_params.rb', line 9

def initialize(action:)
  @action = action
  @query  = {}.with_indifferent_access
  @params = {}.with_indifferent_access
end

Instance Attribute Details

#actionString (readonly)

The name of the solr action, which is automatically applied to the query string parameters when the request is made.

Returns:

  • (String)


19
20
21
# File 'lib/solr_makr/solr_api/request_params.rb', line 19

def action
  @action
end

#paramsActiveSupport::HashWithIndifferentAccess (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (ActiveSupport::HashWithIndifferentAccess)


24
25
26
# File 'lib/solr_makr/solr_api/request_params.rb', line 24

def params
  @params
end

#queryActiveSupport::HashWithIndifferentAccess (readonly)

Returns:

  • (ActiveSupport::HashWithIndifferentAccess)


28
29
30
# File 'lib/solr_makr/solr_api/request_params.rb', line 28

def query
  @query
end

Instance Method Details

#body(request_body) ⇒ void

This method returns an undefined value.

Set the body for the request.

Parameters:

  • (String, #to_s)


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

def body(request_body)
  @params[:body] = request_body
end

#to_h(options = nil) ⇒ Object Also known as: to_hash, as_json



40
41
42
43
44
# File 'lib/solr_makr/solr_api/request_params.rb', line 40

def to_h(options = nil)
  query[:action] = @action

  @params.to_h.merge(query: query)
end