Class: Proxied::Utilities
- Inherits:
-
Object
- Object
- Proxied::Utilities
- Defined in:
- lib/proxied/utilities.rb
Class Method Summary collapse
- .encode_credential(credential) ⇒ Object
- .format_proxy_address(host:, port: 80, username: nil, password: nil, include_http: false) ⇒ Object
- .format_proxy_credentials(username, password) ⇒ Object
- .proxy_options_for_faraday(host:, port: 80, username: nil, password: nil, auth_mode: :credentials) ⇒ Object
- .socks_proxy_credentials(username: nil, password: nil) ⇒ Object
Class Method Details
.encode_credential(credential) ⇒ Object
17 18 19 |
# File 'lib/proxied/utilities.rb', line 17 def encode_credential(credential) CGI::escape(credential) end |
.format_proxy_address(host:, port: 80, username: nil, password: nil, include_http: false) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/proxied/utilities.rb', line 5 def format_proxy_address(host:, port: 80, username: nil, password: nil, include_http: false) address = "#{host.strip}:#{port}" address = "#{format_proxy_credentials(username, password)}@#{address}" if !username.to_s.empty? && !password.to_s.empty? address = (include_http && !address.start_with?("http://")) ? "http://#{address}" : address return address end |
.format_proxy_credentials(username, password) ⇒ Object
13 14 15 |
# File 'lib/proxied/utilities.rb', line 13 def format_proxy_credentials(username, password) return "#{encode_credential(username)}:#{encode_credential(password)}" end |
.proxy_options_for_faraday(host:, port: 80, username: nil, password: nil, auth_mode: :credentials) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/proxied/utilities.rb', line 30 def (host:, port: 80, username: nil, password: nil, auth_mode: :credentials) = {} username = encode_credential(username) password = encode_credential(password) = {host: host, port: port, include_http: true} [:username] = username if !username.to_s.empty? && auth_mode&.to_sym&.eql?(:basic_auth) [:password] = password if !password.to_s.empty? && auth_mode&.to_sym&.eql?(:basic_auth) [:uri] = format_proxy_address() [:user] = username if !username.to_s.empty? && auth_mode&.to_sym&.eql?(:credentials) [:password] = password if !password.to_s.empty? && auth_mode&.to_sym&.eql?(:credentials) return end |
.socks_proxy_credentials(username: nil, password: nil) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/proxied/utilities.rb', line 21 def socks_proxy_credentials(username: nil, password: nil) credentials = {} credentials[:user] = username if !username.to_s.empty? credentials[:password] = password if !password.to_s.empty? return credentials end |