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.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/selenium/webdriver/common/proxy.rb', line 42

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.



31
32
33
# File 'lib/selenium/webdriver/common/proxy.rb', line 31

def auto_detect
  @auto_detect
end

#ftpObject

Returns the value of attribute ftp.



31
32
33
# File 'lib/selenium/webdriver/common/proxy.rb', line 31

def ftp
  @ftp
end

#httpObject

Returns the value of attribute http.



31
32
33
# File 'lib/selenium/webdriver/common/proxy.rb', line 31

def http
  @http
end

#no_proxyObject

Returns the value of attribute no_proxy.



31
32
33
# File 'lib/selenium/webdriver/common/proxy.rb', line 31

def no_proxy
  @no_proxy
end

#pacObject

Returns the value of attribute pac.



31
32
33
# File 'lib/selenium/webdriver/common/proxy.rb', line 31

def pac
  @pac
end

#socksObject

Returns the value of attribute socks.



31
32
33
# File 'lib/selenium/webdriver/common/proxy.rb', line 31

def socks
  @socks
end

#socks_passwordObject

Returns the value of attribute socks_password.



31
32
33
# File 'lib/selenium/webdriver/common/proxy.rb', line 31

def socks_password
  @socks_password
end

#socks_usernameObject

Returns the value of attribute socks_username.



31
32
33
# File 'lib/selenium/webdriver/common/proxy.rb', line 31

def socks_username
  @socks_username
end

#sslObject

Returns the value of attribute ssl.



31
32
33
# File 'lib/selenium/webdriver/common/proxy.rb', line 31

def ssl
  @ssl
end

#typeObject

Returns the value of attribute type.



31
32
33
# File 'lib/selenium/webdriver/common/proxy.rb', line 31

def type
  @type
end

Class Method Details

.json_create(data) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/selenium/webdriver/common/proxy.rb', line 146

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?



61
62
63
# File 'lib/selenium/webdriver/common/proxy.rb', line 61

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

#as_json(opts = nil) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/selenium/webdriver/common/proxy.rb', line 123

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



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

def to_json(*args)
  WebDriver.json_dump as_json
end