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.
Class Method Summary collapse
-
.from_hash(hash) ⇒ ProxySettings?
Creates a ProxySettings instance from a hash.
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 |
Class Method Details
.from_hash(hash) ⇒ ProxySettings?
Creates a ProxySettings instance from a hash.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/apimatic-core/http/configurations/proxy_settings.rb', line 48 def self.from_hash(hash) return nil if hash.nil? || hash.empty? # Support both symbol and string keys address = hash[:address] || hash['address'] port = hash[:port] || hash['port'] username = hash[:username] || hash['username'] password = hash[:password] || hash['password'] return nil if address.nil? || address.strip.empty? new(address: address, port: port, username: username, password: password) 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 |