class Proxy::Hdm::Api

Private Instance Methods

get_from_hdm(path) click to toggle source
# File lib/smart_proxy_hdm/api.rb, line 28
def get_from_hdm(path)
  content_type :json
  begin
    result = perform_request(path)
    return result.body if result.is_a?(Net::HTTPSuccess)

    log_halt result.code.to_i, "HDM server at #{hdm_uri} returned an error: '#{result.message}'"
  rescue SocketError, Errno::ECONNREFUSED => e
    log_halt 503, "Communication error with '#{hdm_uri.host}': #{e.message}"
  end
end
hdm_uri() click to toggle source
# File lib/smart_proxy_hdm/api.rb, line 53
def hdm_uri
  @hdm_uri ||= URI.parse(Plugin.settings.hdm_url.to_s)
end
http() click to toggle source
# File lib/smart_proxy_hdm/api.rb, line 47
def http
  http = Net::HTTP.new(hdm_uri.host, hdm_uri.port)
  http.use_ssl = hdm_uri.scheme == 'https'
  http
end
perform_request(path) click to toggle source
# File lib/smart_proxy_hdm/api.rb, line 40
def perform_request(path)
  req = Net::HTTP::Get.new(URI.join("#{hdm_uri.to_s.chomp('/')}/", path))
  req['Accept'] = 'application/json'
  req.basic_auth Plugin.settings.hdm_user, Plugin.settings.hdm_password
  http.request(req)
end