Class: DiscoClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/disco_client.rb

Constant Summary collapse

DEFAULT_CONTAINER =
{
	id: ENV['CONTAINER_NAME'],
	type: 'http',
	port: 3000
}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DiscoClient

Returns a new instance of DiscoClient.



17
18
19
# File 'lib/disco_client.rb', line 17

def initialize(options = {})
	@base_uri = options[:base_uri] || ENV['DISCO_BASE_URI']
end

Instance Method Details

#get_configuration(id = nil) ⇒ Object



42
43
44
45
# File 'lib/disco_client.rb', line 42

def get_configuration(id = nil)
	id = URI.encode_www_form_component(id || @container[:id])
	request('get', "1/containers/#{id}/configuration")
end

#get_container(id = nil) ⇒ Object



37
38
39
40
# File 'lib/disco_client.rb', line 37

def get_container(id = nil)
	id = URI.encode_www_form_component(id || @container[:id])
	request('get', "1/containers/#{id}")
end

#get_service(id) ⇒ Object



32
33
34
35
# File 'lib/disco_client.rb', line 32

def get_service(id)
	URI.encode_www_form_component(id)
	request('get', "1/services/#{id}")
end

#get_servicesObject



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

def get_services
	request('get', '1/services')
end

#register(service_id, options = {}) ⇒ Object



21
22
23
24
25
26
# File 'lib/disco_client.rb', line 21

def register(service_id, options = {})
	body = DEFAULT_CONTAINER.merge(options)
	body[:service] = { id: service_id };

	@container = request('post', '1/containers', nil, body)
end