Class: Http
- Inherits:
-
Object
- Object
- Http
- Defined in:
- lib/vmfloaty/http.rb
Class Method Summary collapse
- .get_conn(verbose, url) ⇒ Object
- .get_conn_with_auth(verbose, url, user, password) ⇒ Object
- .is_url(url) ⇒ Object
Class Method Details
.get_conn(verbose, url) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vmfloaty/http.rb', line 19 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 faraday.adapter Faraday.default_adapter end return conn end |
.get_conn_with_auth(verbose, url, user, password) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vmfloaty/http.rb', line 37 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 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 faraday.response :logger if verbose faraday.adapter Faraday.default_adapter end return conn end |
.is_url(url) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/vmfloaty/http.rb', line 5 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 |