Class: Selenium::WebDriver::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/common/proxy.rb

Constant Summary collapse

TYPES =
{
  :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).
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Proxy

Returns a new instance of Proxy.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/selenium/webdriver/common/proxy.rb', line 23

def initialize(opts = {})
  opts = opts.dup

  self.type           = opts.delete(:type) if opts.has_key? :type
  self.ftp            = opts.delete(:ftp) if opts.has_key? :ftp
  self.http           = opts.delete(:http) if opts.has_key? :http
  self.no_proxy       = opts.delete(:no_proxy) if opts.has_key? :no_proxy
  self.ssl            = opts.delete(:ssl) if opts.has_key? :ssl
  self.pac            = opts.delete(:pac) if opts.has_key? :pac
  self.auto_detect    = opts.delete(:auto_detect) if opts.has_key? :auto_detect
  self.socks          = opts.delete(:socks) if opts.has_key? :socks
  self.socks_username = opts.delete(:socks_username) if opts.has_key? :socks_username
  self.socks_password = opts.delete(:socks_password) if opts.has_key? :socks_password

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

Instance Attribute Details

#auto_detectObject

Returns the value of attribute auto_detect.



12
13
14
# File 'lib/selenium/webdriver/common/proxy.rb', line 12

def auto_detect
  @auto_detect
end

#ftpObject

Returns the value of attribute ftp.



12
13
14
# File 'lib/selenium/webdriver/common/proxy.rb', line 12

def ftp
  @ftp
end

#httpObject

Returns the value of attribute http.



12
13
14
# File 'lib/selenium/webdriver/common/proxy.rb', line 12

def http
  @http
end

#no_proxyObject

Returns the value of attribute no_proxy.



12
13
14
# File 'lib/selenium/webdriver/common/proxy.rb', line 12

def no_proxy
  @no_proxy
end

#pacObject

Returns the value of attribute pac.



12
13
14
# File 'lib/selenium/webdriver/common/proxy.rb', line 12

def pac
  @pac
end

#socksObject

Returns the value of attribute socks.



12
13
14
# File 'lib/selenium/webdriver/common/proxy.rb', line 12

def socks
  @socks
end

#socks_passwordObject

Returns the value of attribute socks_password.



12
13
14
# File 'lib/selenium/webdriver/common/proxy.rb', line 12

def socks_password
  @socks_password
end

#socks_usernameObject

Returns the value of attribute socks_username.



12
13
14
# File 'lib/selenium/webdriver/common/proxy.rb', line 12

def socks_username
  @socks_username
end

#sslObject

Returns the value of attribute ssl.



12
13
14
# File 'lib/selenium/webdriver/common/proxy.rb', line 12

def ssl
  @ssl
end

#typeObject

Returns the value of attribute type.



12
13
14
# File 'lib/selenium/webdriver/common/proxy.rb', line 12

def type
  @type
end

Class Method Details

.json_create(data) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/selenium/webdriver/common/proxy.rb', line 127

def json_create(data)
  return if data['proxyType'] == 'UNSPECIFIED'

  proxy = new

  proxy.type           = data['proxyType'].downcase.to_sym if data.has_key? 'proxyType'
  proxy.ftp            = data['ftpProxy'] if data.has_key? 'ftpProxy'
  proxy.http           = data['httpProxy'] if data.has_key? 'httpProxy'
  proxy.no_proxy       = data['noProxy'] if data.has_key? 'noProxy'
  proxy.pac            = data['proxyAutoconfigUrl'] if data.has_key? 'proxyAutoconfigUrl'
  proxy.ssl            = data['sslProxy'] if data.has_key? 'sslProxy'
  proxy.auto_detect    = data['autodetect'] if data.has_key? 'autodetect'
  proxy.socks          = data['socksProxy'] if data.has_key? 'socksProxy'
  proxy.socks_username = data['socksUsername'] if data.has_key? 'socksUsername'
  proxy.socks_password = data['socksPassword'] if data.has_key? 'socksPassword'

  proxy
end

Instance Method Details

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



42
43
44
# File 'lib/selenium/webdriver/common/proxy.rb', line 42

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

#as_json(opts = nil) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/selenium/webdriver/common/proxy.rb', line 104

def as_json(opts = nil)
  json_result = {
    "proxyType" => TYPES[type]
  }

  json_result["ftpProxy"]           = ftp if ftp
  json_result["httpProxy"]          = http if http
  json_result["noProxy"]            = no_proxy if no_proxy
  json_result["proxyAutoconfigUrl"] = pac if pac
  json_result["sslProxy"]           = ssl if ssl
  json_result["autodetect"]         = auto_detect if auto_detect
  json_result["socksProxy"]         = socks if socks
  json_result["socksUsername"]      = socks_username if socks_username
  json_result["socksPassword"]      = socks_password if socks_password

  json_result if json_result.length > 1
end

#to_json(*args) ⇒ Object



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

def to_json(*args)
  WebDriver.json_dump as_json
end