Class: DruidDB::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/druiddb/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
}.freeze

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
26
# File 'lib/druiddb/connection.rb', line 16

def initialize(endpoint)
  if endpoint.is_a? String
    uri = URI.parse(endpoint)
    host = uri.host
    port = 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/druiddb/connection.rb', line 14

def http
  @http
end

Instance Method Details

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



40
41
42
# File 'lib/druiddb/connection.rb', line 40

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

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



28
29
30
# File 'lib/druiddb/connection.rb', line 28

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

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



32
33
34
# File 'lib/druiddb/connection.rb', line 32

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

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



36
37
38
# File 'lib/druiddb/connection.rb', line 36

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