Class: Selenium::WebDriver::Proxy
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Proxy
- 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). }.freeze
- ALLOWED =
{type: 'proxyType', ftp: 'ftpProxy', http: 'httpProxy', no_proxy: 'noProxy', pac: 'proxyAutoconfigUrl', ssl: 'sslProxy', auto_detect: 'autodetect', socks: 'socksProxy', socks_username: 'socksUsername', socks_password: 'socksPassword'}.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #as_json ⇒ Object
- #auto_detect=(bool) ⇒ Object
- #ftp=(value) ⇒ Object
- #http=(value) ⇒ Object
-
#initialize(opts = {}) ⇒ Proxy
constructor
A new instance of Proxy.
- #no_proxy=(value) ⇒ Object
- #pac=(url) ⇒ Object
- #socks=(value) ⇒ Object
- #socks_password=(value) ⇒ Object
- #socks_username=(value) ⇒ Object
- #ssl=(value) ⇒ Object
- #to_json ⇒ Object
- #type=(type) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Proxy
Returns a new instance of Proxy.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 55 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) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 42 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 Method Details
#==(other) ⇒ Object Also known as: eql?
70 71 72 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 70 def ==(other) other.is_a?(self.class) && as_json == other.as_json end |
#as_json ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 132 def as_json(*) json_result = { 'proxyType' => TYPES[type], 'ftpProxy' => ftp, 'httpProxy' => http, 'noProxy' => no_proxy, 'proxyAutoconfigUrl' => pac, 'sslProxy' => ssl, 'autodetect' => auto_detect, 'socksProxy' => socks, 'socksUsername' => socks_username, 'socksPassword' => socks_password }.delete_if { |_k, v| v.nil? } json_result if json_result.length > 1 end |
#auto_detect=(bool) ⇒ Object
100 101 102 103 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 100 def auto_detect=(bool) self.type = :auto_detect @auto_detect = bool end |
#ftp=(value) ⇒ Object
75 76 77 78 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 75 def ftp=(value) self.type = :manual @ftp = value end |
#http=(value) ⇒ Object
80 81 82 83 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 80 def http=(value) self.type = :manual @http = value end |
#no_proxy=(value) ⇒ Object
85 86 87 88 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 85 def no_proxy=(value) self.type = :manual @no_proxy = value end |
#pac=(url) ⇒ Object
95 96 97 98 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 95 def pac=(url) self.type = :pac @pac = url end |
#socks=(value) ⇒ Object
105 106 107 108 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 105 def socks=(value) self.type = :manual @socks = value end |
#socks_password=(value) ⇒ Object
115 116 117 118 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 115 def socks_password=(value) self.type = :manual @socks_password = value end |
#socks_username=(value) ⇒ Object
110 111 112 113 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 110 def socks_username=(value) self.type = :manual @socks_username = value end |
#ssl=(value) ⇒ Object
90 91 92 93 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 90 def ssl=(value) self.type = :manual @ssl = value end |
#to_json ⇒ Object
149 150 151 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 149 def to_json(*) JSON.generate as_json end |
#type=(type) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/selenium/webdriver/common/proxy.rb', line 120 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 |