Class: Proxtopus::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/proxtopus/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resources) ⇒ Client

called by Proxtopus.configure, returns self def initialize(&block)

@agent = Mechanize.new
@proxies = ProxySet.new
instance_eval(&block) if block_given?
self

end



13
14
15
16
17
18
19
20
21
# File 'lib/proxtopus/client.rb', line 13

def initialize(resources)
  #@api_url = api_url
  #@api_options = api_options
  @resources = ResourceSet.new(resources)
  @proxies = ProxySet.new
  self
rescue => e
  puts "Proxtopus::Client -- #{e.inspect}"
end

Instance Attribute Details

#proxiesObject

Returns the value of attribute proxies.



4
5
6
# File 'lib/proxtopus/client.rb', line 4

def proxies
  @proxies
end

#resourcesObject

Returns the value of attribute resources.



4
5
6
# File 'lib/proxtopus/client.rb', line 4

def resources
  @resources
end

Instance Method Details

#collect(opts = nil) ⇒ Object

p.collect(=> [‘US’], etc…) if no options are supplied, api_options will be used



25
26
27
28
29
30
31
32
33
# File 'lib/proxtopus/client.rb', line 25

def collect(opts=nil)
  #use_opts = (opts.nil?)? api_options : opts
  #get(use_opts)
  @resources.each do |resource|
    @proxies.push(resource.collect)
  end
rescue => e
  puts "Proxtopus::Client -- #{e.inspect}"
end

#delete_proxy(proxy) ⇒ Object



41
42
43
44
45
# File 'lib/proxtopus/client.rb', line 41

def delete_proxy(proxy)
  @proxies.delete(proxy)
rescue => e
  puts "Proxtopus::Client -- #{e.inspect}"
end

#random_proxyObject



35
36
37
38
39
# File 'lib/proxtopus/client.rb', line 35

def random_proxy
  @proxies[rand(0..(@proxies.count-1))]
rescue => e
  puts "Proxtopus::Client -- #{e.inspect}"
end