Class: Esearch::Request

Inherits:
Object
  • Object
show all
Includes:
Adamantium
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)


52
53
54
# File 'lib/esearch/request.rb', line 52

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)


31
32
33
# File 'lib/esearch/request.rb', line 31

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)


39
40
41
# File 'lib/esearch/request.rb', line 39

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)


23
24
25
# File 'lib/esearch/request.rb', line 23

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)


15
16
17
# File 'lib/esearch/request.rb', line 15

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)


62
63
64
# File 'lib/esearch/request.rb', line 62

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)


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

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