class MingleEvents::MingleBasicAuthAccess
Supports fetching of Mingle resources using HTTP basic auth. Please only use this class to access resources over HTTPS so as not to send credentials over plain-text connections.
Constants
- BASIC_AUTH_HTTP_WARNING
Attributes
base_url[R]
Public Class Methods
new(base_url, username, password, http=Http)
click to toggle source
# File lib/mingle_events/mingle_basic_auth_access.rb 17 def initialize(base_url, username, password, http=Http) 18 @base_url = base_url 19 @username = username 20 @password = password 21 @http = http 22 end
Public Instance Methods
fetch_page(location)
click to toggle source
# File lib/mingle_events/mingle_basic_auth_access.rb 24 def fetch_page(location) 25 location = @base_url + location if location[0..0] == '/' 26 @http.get(location) do |req| 27 MingleEvents.log.warn(BASIC_AUTH_HTTP_WARNING) if URI.parse(location).scheme == 'http' 28 req['authorization'] = basic_encode(@username, @password) 29 end 30 end
Private Instance Methods
basic_encode(account, password)
click to toggle source
# File lib/mingle_events/mingle_basic_auth_access.rb 33 def basic_encode(account, password) 34 'Basic ' + ["#{account}:#{password}"].pack('m').delete("\r\n") 35 end