diff --git a/lib/vmfloaty/http.rb b/lib/vmfloaty/http.rb index 07a8a2d..656b732 100644 --- a/lib/vmfloaty/http.rb +++ b/lib/vmfloaty/http.rb @@ -1,11 +1,30 @@ require 'faraday' +require 'uri' class Http + def self.is_url(url) + # This method exists because it seems like Farady + # has no handling around if a user gives us a URI + # with no protocol on the beginning of the URL + + uri = URI.parse(url) + + if uri.kind_of?(URI::HTTP) or uri.kind_of?(URI::HTTPS) + return true + end + + return false + end + def self.get_conn(verbose, url) if url.nil? raise "Did not provide a url to connect to" end + unless is_url(url) + url = "https://#{url}" + end + conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday| faraday.request :url_encoded faraday.response :logger if verbose @@ -24,6 +43,10 @@ class Http raise "You did not provide a user to authenticate with" end + unless is_url(url) + url = "https://#{url}" + end + conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday| faraday.request :url_encoded faraday.request :basic_auth, user, password