Class: Consul::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/consul/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHttp

Returns a new instance of Http.



7
8
9
# File 'lib/consul/http.rb', line 7

def initialize
  load_config
end

Instance Attribute Details

#http_clientObject

Returns the value of attribute http_client.



5
6
7
# File 'lib/consul/http.rb', line 5

def http_client
  @http_client
end

Instance Method Details

#get(path) ⇒ Object



20
21
22
# File 'lib/consul/http.rb', line 20

def get(path)
  request('GET', path)
end

#load_configObject



24
25
26
# File 'lib/consul/http.rb', line 24

def load_config
  self.http_client = Net::HTTP.new(Consul::Client.config.host, Consul::Client.config.port, nil, nil)
end

#put(path, data = nil) ⇒ Object



16
17
18
# File 'lib/consul/http.rb', line 16

def put(path, data=nil)
  request('PUT', path, data)
end

#request(method, uri, data = nil) ⇒ Object



11
12
13
14
# File 'lib/consul/http.rb', line 11

def request(method, uri, data=nil)
  response = http_client.send_request(method, ("/v1" + uri), data)
  Response.new(response, uri.gsub(%r{^/kv/}, ''))
end