Class: DruidDB::Connection
- Inherits:
-
Object
- Object
- DruidDB::Connection
- 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
-
#http ⇒ Object
readonly
Returns the value of attribute http.
Instance Method Summary collapse
- #delete(path, params = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(endpoint) ⇒ Connection
constructor
A new instance of Connection.
- #post(path, params = {}) ⇒ Object
- #put(path, params = {}) ⇒ Object
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
#http ⇒ Object (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 |