Class: Clients::ProxyListClient

Inherits:
Object
  • Object
show all
Defined in:
lib/clients/proxy_list_client.rb

Constant Summary collapse

DEFAULT_LIST_PATH =
"/tmp/clients_proxy_list.txt".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = DEFAULT_LIST_PATH) ⇒ ProxyListClient

Returns a new instance of ProxyListClient.



13
14
15
16
# File 'lib/clients/proxy_list_client.rb', line 13

def initialize(path = DEFAULT_LIST_PATH)
  @path = path
  select_proxy_from_list
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/clients/proxy_list_client.rb', line 5

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



5
6
7
# File 'lib/clients/proxy_list_client.rb', line 5

def password
  @password
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'lib/clients/proxy_list_client.rb', line 5

def user
  @user
end

Class Method Details

.cache_list(list_url, list_path = DEFAULT_LIST_PATH) ⇒ Object



7
8
9
10
11
# File 'lib/clients/proxy_list_client.rb', line 7

def self.cache_list(list_url, list_path = DEFAULT_LIST_PATH)
  response = HTTP.get(list_url)
  fail "Invalid list response: #{response.status}" unless response.status.success?
  File.open(list_path, "w") { |f| f << response.to_s }
end

Instance Method Details

#portObject



18
19
20
# File 'lib/clients/proxy_list_client.rb', line 18

def port
  @port.to_i
end

#reset!Object



26
27
28
# File 'lib/clients/proxy_list_client.rb', line 26

def reset!
  select_proxy_from_list
end

#to_sObject



22
23
24
# File 'lib/clients/proxy_list_client.rb', line 22

def to_s
  [host, port, user, password].compact.join(":")
end