Class: TheMask::ProxyList::Proxy
- Inherits:
-
Object
- Object
- TheMask::ProxyList::Proxy
- Defined in:
- lib/the_mask/proxy_list.rb
Constant Summary collapse
- HTTP_PROXY =
:http
- SOCKS_PROXY =
:socks
- SUPPORTED_SOCKS_VERSIONS =
['4', '5']
Instance Attribute Summary collapse
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#socks_version ⇒ Object
Returns the value of attribute socks_version.
-
#type ⇒ Object
Returns the value of attribute type.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(input_string = '') ⇒ Proxy
constructor
A new instance of Proxy.
- #is_HTTP? ⇒ Boolean
- #is_SOCKS? ⇒ Boolean
Constructor Details
#initialize(input_string = '') ⇒ Proxy
Returns a new instance of Proxy.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/the_mask/proxy_list.rb', line 9 def initialize(input_string = '') unless input_string.empty? # Proxy string format = ip:port:username:password split_str = input_string.split(':') last_element = split_str[-1].to_s.downcase # Check if proxy has SOCKS parameter enabled, by default a proxy will always be a HTTP/s proxy if last_element.eql?(SOCKS_PROXY.to_s) && (split_str.length == 3 || split_str.length == 5) @type = SOCKS_PROXY socks_version = last_element[-1] if SUPPORTED_SOCKS_VERSIONS.include?(socks_version) @socks_version = socks_version.to_i else # Default version is the latest SOCKS, in this case ver. 5s @socks_version = SUPPORTED_SOCKS_VERSIONS[-1].to_i end else @type = HTTP_PROXY end @ip = split_str[0].to_s @port = split_str[1].to_i @username = split_str[2].to_s unless split_str[2].nil? @password = split_str[3].to_s unless split_str[3].nil? else @ip = nil @port = 0 @username = nil @password = nil end end |
Instance Attribute Details
#ip ⇒ Object
Returns the value of attribute ip.
4 5 6 |
# File 'lib/the_mask/proxy_list.rb', line 4 def ip @ip end |
#password ⇒ Object
Returns the value of attribute password.
4 5 6 |
# File 'lib/the_mask/proxy_list.rb', line 4 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/the_mask/proxy_list.rb', line 4 def port @port end |
#socks_version ⇒ Object
Returns the value of attribute socks_version.
4 5 6 |
# File 'lib/the_mask/proxy_list.rb', line 4 def socks_version @socks_version end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/the_mask/proxy_list.rb', line 4 def type @type end |
#username ⇒ Object
Returns the value of attribute username.
4 5 6 |
# File 'lib/the_mask/proxy_list.rb', line 4 def username @username end |
Instance Method Details
#is_HTTP? ⇒ Boolean
44 45 46 |
# File 'lib/the_mask/proxy_list.rb', line 44 def is_HTTP? @type == HTTP_PROXY end |
#is_SOCKS? ⇒ Boolean
40 41 42 |
# File 'lib/the_mask/proxy_list.rb', line 40 def is_SOCKS? @type == SOCKS_PROXY end |