vmfloaty/lib/vmfloaty/http.rb
Brian Cain 98741e5e4a Fix token auth for methods
Properly set the header to be X-AUTH-TOKEN for requests to the pooler.
2015-09-25 14:03:47 -07:00

40 lines
927 B
Ruby

require 'faraday'
class Http
def self.get_conn(verbose, url)
if url.nil?
STDERR.puts "The url you provided was empty"
exit 1
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?
STDERR.puts "The url you provided was empty"
exit 1
end
if user.nil?
STDERR.puts "You did not provide a user to authenticate with"
exit 1
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