123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::Proxy

Relationships & Source Files
Inherits: Object
Defined in: rb/lib/selenium/webdriver/common/proxy.rb

Constant Summary

  • ALLOWED =
    # File 'rb/lib/selenium/webdriver/common/proxy.rb', line 31
    {type: 'proxyType',
    ftp: 'ftpProxy',
    http: 'httpProxy',
    no_proxy: 'noProxy',
    pac: 'proxyAutoconfigUrl',
    ssl: 'sslProxy',
    auto_detect: 'autodetect',
    socks: 'socksProxy',
    socks_username: 'socksUsername',
    socks_password: 'socksPassword',
    socks_version: 'socksVersion'}.freeze
  • TYPES =
    # File 'rb/lib/selenium/webdriver/common/proxy.rb', line 23
    {
      direct: 'DIRECT', # Direct connection, no proxy (default on Windows).
      manual: 'MANUAL', # Manual proxy settings (e.g., for httpProxy).
      pac: 'PAC', # Proxy autoconfiguration from URL.
      auto_detect: 'AUTODETECT', # Proxy autodetection (presumably with WPAD).
      system: 'SYSTEM' # Use system settings (default on Linux).
    }.freeze

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(opts = {}) ⇒ Proxy

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 58

def initialize(opts = {})
  not_allowed = []

  opts.each do |k, v|
    if ALLOWED.key?(k)
      send(:"#{k}=", v)
    else
      not_allowed << k
    end
  end

  return if not_allowed.empty?

  raise ArgumentError, "unknown option#{'s' if not_allowed.size != 1}: #{not_allowed.inspect}"
end

Class Method Details

.json_create(data)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 45

def self.json_create(data)
  data['proxyType'] = data['proxyType'].downcase.to_sym
  return if data['proxyType'] == :unspecified

  proxy = new

  ALLOWED.each do |k, v|
    proxy.send(:"#{k}=", data[v]) if data.key?(v)
  end

  proxy
end

Instance Attribute Details

#auto_detect=(bool) (writeonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 104

def auto_detect=(bool)
  self.type = :auto_detect
  @auto_detect = bool
end

#ftp=(value) (writeonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 79

def ftp=(value)
  self.type = :manual
  @ftp = value
end

#http=(value) (writeonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 84

def http=(value)
  self.type = :manual
  @http = value
end

#no_proxy=(value) (writeonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 89

def no_proxy=(value)
  self.type = :manual
  @no_proxy = value
end

#pac=(url) (writeonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 99

def pac=(url)
  self.type = :pac
  @pac = url
end

#socks=(value) (writeonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 109

def socks=(value)
  self.type = :manual
  @socks = value
end

#socks_password=(value) (writeonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 119

def socks_password=(value)
  self.type = :manual
  @socks_password = value
end

#socks_username=(value) (writeonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 114

def socks_username=(value)
  self.type = :manual
  @socks_username = value
end

#socks_version=(value) (writeonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 124

def socks_version=(value)
  self.type = :manual
  @socks_version = value
end

#ssl=(value) (writeonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 94

def ssl=(value)
  self.type = :manual
  @ssl = value
end

#type=(type) (writeonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 129

def type=(type)
  unless TYPES.key? type
    raise ArgumentError,
          "invalid proxy type: #{type.inspect}, expected one of #{TYPES.keys.inspect}"
  end

  if defined?(@type) && type != @type
    raise ArgumentError, "incompatible proxy type #{type.inspect} (already set to #{@type.inspect})"
  end

  @type = type
end

Instance Method Details

#==(other) Also known as: #eql?

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 74

def ==(other)
  other.is_a?(self.class) && as_json == other.as_json
end

#as_json

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 142

def as_json(*)
  json_result = {
    'proxyType' => TYPES[type].downcase,
    'ftpProxy' => ftp,
    'httpProxy' => http,
    'noProxy' => no_proxy.is_a?(String) ? no_proxy.split(', ') : no_proxy,
    'proxyAutoconfigUrl' => pac,
    'sslProxy' => ssl,
    'autodetect' => auto_detect,
    'socksProxy' => socks,
    'socksUsername' => socks_username,
    'socksPassword' => socks_password,
    'socksVersion' => socks_version
  }.compact

  json_result if json_result.length > 1
end

#eql?(other)

Alias for #==.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 77

alias eql? ==

#to_json

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/proxy.rb', line 160

def to_json(*)
  JSON.generate as_json
end