Class: Foundry::Sources::URI

Inherits:
Object
  • Object
show all
Defined in:
lib/foundry/sources/uri.rb

Instance Method Summary collapse

Instance Method Details

#load(root_path, relative_path, opts) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/foundry/sources/uri.rb', line 9

def load(root_path, relative_path, opts)
  uri = ::URI.join(root_path, relative_path)
  client = Net::HTTP.new(uri.host, uri.port)
  if uri.scheme == 'https'
    client.use_ssl = true
    client.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  request = Net::HTTP::Get.new(uri.request_uri)
  if (username = opts[:username]) && (password = opts[:password])
    request.basic_auth(username, password)
  end
  response = client.request(request)
  raise "Unknown configuration file: #{uri}" \
    unless response.is_a?(Net::HTTPSuccess)
  response.body
end