Class: CoreLibrary::ProxySettings
- Inherits:
-
Object
- Object
- CoreLibrary::ProxySettings
- Defined in:
- lib/apimatic-core/http/configurations/proxy_settings.rb
Overview
ProxySettings encapsulates HTTP proxy configuration for Faraday, including optional basic authentication.
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(address:, port: nil, username: nil, password: nil) ⇒ ProxySettings
constructor
A new instance of ProxySettings.
-
#to_h ⇒ Hash
Converts the proxy settings into a Faraday-compatible hash.
Constructor Details
#initialize(address:, port: nil, username: nil, password: nil) ⇒ ProxySettings
Returns a new instance of ProxySettings.
17 18 19 20 21 22 23 24 |
# File 'lib/apimatic-core/http/configurations/proxy_settings.rb', line 17 def initialize(address:, port: nil, username: nil, password: nil) raise ArgumentError, 'Proxy address must be a non-empty string' unless address.is_a?(String) && !address.empty? @address = address @port = port @username = username @password = password end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
7 8 9 |
# File 'lib/apimatic-core/http/configurations/proxy_settings.rb', line 7 def address @address end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/apimatic-core/http/configurations/proxy_settings.rb', line 7 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/apimatic-core/http/configurations/proxy_settings.rb', line 7 def port @port end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/apimatic-core/http/configurations/proxy_settings.rb', line 7 def username @username end |
Instance Method Details
#to_h ⇒ Hash
Converts the proxy settings into a Faraday-compatible hash.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/apimatic-core/http/configurations/proxy_settings.rb', line 31 def to_h uri_str = port ? "#{address}:#{port}" : address { uri: uri_str }.tap do |hash| hash[:user] = username if username hash[:password] = password if password end end |