vmfloaty/lib/vmfloaty/http.rb
Brian Cain c1689da3c4 (#13) Raise exception when required params are missing
Instead of doing a system exit and printing to stderr, raise an
exception if parameters are missing when attempting to make an http
connection.
2015-11-15 13:33:21 -08:00

37 lines
880 B
Ruby

require 'faraday'
class Http
def self.get_conn(verbose, url)
if url.nil?
raise "Did not provide a url to connect to"
end
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
faraday.request :url_encoded
faraday.response :logger if verbose
faraday.adapter Faraday.default_adapter
end
return conn
end
def self.get_conn_with_auth(verbose, url, user, password)
if url.nil?
raise "Did not provide a url to connect to"
end
if user.nil?
raise "You did not provide a user to authenticate with"
end
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
faraday.request :url_encoded
faraday.request :basic_auth, user, password
faraday.response :logger if verbose
faraday.adapter Faraday.default_adapter
end
return conn
end
end