Skip to content

Instantly share code, notes, and snippets.

@renier
Created November 17, 2014 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renier/538cbfe1e0fecc8c5e59 to your computer and use it in GitHub Desktop.
Save renier/538cbfe1e0fecc8c5e59 to your computer and use it in GitHub Desktop.
Make HTTParty pick out basic auth credentials from URL
module HTTParty
module ClassMethods
private
alias_method :orig_perform_request, :perform_request
def perform_request(http_method, path, options, &block)
if path.include? '@'
options ||= {}
scheme_auth, host_uri = path.split('@')
scheme, creds = scheme_auth.split('//')
path = "#{scheme}//#{host_uri}"
username, password = creds.split(':')
options[:basic_auth] = { username: username, password: password }
end
orig_perform_request(http_method, path, options, &block)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment