class DiscoClient
Constants
- DEFAULT_CONTAINER
Public Class Methods
new(options = {})
click to toggle source
# File lib/disco_client.rb, line 17 def initialize(options = {}) @base_uri = options[:base_uri] || ENV['DISCO_BASE_URI'] end
Public Instance Methods
get_configuration(id = nil)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/disco_client.rb, line 32 def get_service(id) URI.encode_www_form_component(id) request('get', "1/services/#{id}") end
get_services()
click to toggle source
# File lib/disco_client.rb, line 28 def get_services request('get', '1/services') end
register(service_id, options = {})
click to toggle source
# 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
Private Instance Methods
request(method, path, params = nil, body = nil)
click to toggle source
# File lib/disco_client.rb, line 49 def request(method, path, params = nil, body = nil) uri = URI.join(@base_uri, path) options = {} options[:query] = params if params options[:body] = JSON.generate(body) if body res = self.class.send(method, uri, options) # 1xx should be handled by httparty # 2xx - success if res.code < 300 return nil unless res.body && res.body.length return JSON.parse(res.body, symbolize_names: true, create_additions: false) end # 3xx redirections are handled by httparty # 304 is raised as an error res.error! end