Class: Esearch::Request

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/esearch/request.rb

Overview

Request used to interface elasticsearch

Constant Summary collapse

EMPTY_HASH =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verb, path, body = EMPTY_HASH, params = EMPTY_HASH) ⇒ undefined

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.

Initialize object

Parameters:

  • verb (Symbol)
  • path (String)
  • body (Hash) (defaults to: EMPTY_HASH)
  • params (Hash) (defaults to: EMPTY_HASH)


54
55
56
# File 'lib/esearch/request.rb', line 54

def initialize(verb, path, body = EMPTY_HASH, params = EMPTY_HASH)
  @verb, @path, @body, @params = verb, path.to_s, body, params
end

Instance Attribute Details

#bodyHash (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.

Return body

Returns:

  • (Hash)


33
34
35
# File 'lib/esearch/request.rb', line 33

def body
  @body
end

#paramsHash (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.

Return params

Returns:

  • (Hash)


41
42
43
# File 'lib/esearch/request.rb', line 41

def params
  @params
end

#pathString (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.

Return path

Returns:

  • (String)


25
26
27
# File 'lib/esearch/request.rb', line 25

def path
  @path
end

#verbSymbol (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.

Return http verb

Returns:

  • (Symbol)


17
18
19
# File 'lib/esearch/request.rb', line 17

def verb
  @verb
end

Instance Method Details

#log_stringString

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.

Return log string

Returns:

  • (String)


64
65
66
# File 'lib/esearch/request.rb', line 64

def log_string
  "#{verb.upcase} #{path} : #{params} : #{body}"
end

#run(connection) ⇒ Faraday::Response

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.

Run request on connection

Parameters:

  • (Faraday::Connection)

Returns:

  • (Faraday::Response)


77
78
79
80
81
82
83
# File 'lib/esearch/request.rb', line 77

def run(connection)
  connection.public_send(verb, path) do |request|
    request.params = params
    request.headers[:content_type] = Command::JSON_CONTENT_TYPE
    request.body = MultiJson.dump(body)
  end
end