Class: Druid::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/druid/connection.rb

Constant Summary collapse

CONTENT_TYPE =
'application/json'.freeze
VERB_MAP =
{
  :get    => ::Net::HTTP::Get,
  :post   => ::Net::HTTP::Post,
  :put    => ::Net::HTTP::Put,
  :delete => ::Net::HTTP::Delete
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ Connection

Returns a new instance of Connection.



16
17
18
19
20
21
22
23
24
25
# File 'lib/druid/connection.rb', line 16

def initialize(endpoint)
  if endpoint.is_a? String
    uri = URI.parse(endpoint)
    host, port = uri.host, uri.port
  else
    host, port = endpoint.values_at(:host, :port)
  end

  @http = ::Net::HTTP.new(host, port)
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



14
15
16
# File 'lib/druid/connection.rb', line 14

def http
  @http
end

Instance Method Details

#delete(path, params = {}) ⇒ Object



39
40
41
# File 'lib/druid/connection.rb', line 39

def delete(path, params = {})
  request :delete, path, params
end

#get(path, params = {}) ⇒ Object



27
28
29
# File 'lib/druid/connection.rb', line 27

def get(path, params = {})
  request :get, path, params
end

#post(path, params = {}) ⇒ Object



31
32
33
# File 'lib/druid/connection.rb', line 31

def post(path, params = {})
  request :post, path, params
end

#put(path, params = {}) ⇒ Object



35
36
37
# File 'lib/druid/connection.rb', line 35

def put(path, params = {})
  request :put, path, params
end