proxtopus 0.0.3 → 0.0.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/proxtopus/client.rb +20 -8
- data/lib/proxtopus/proxy_set.rb +20 -11
- data/lib/proxtopus/request.rb +11 -9
- data/lib/proxtopus/resource.rb +52 -0
- data/lib/proxtopus/resource_set.rb +50 -0
- data/lib/proxtopus/response.rb +28 -0
- data/lib/proxtopus/response_parser.rb +42 -0
- data/lib/proxtopus.rb +8 -3
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzBmMDU3N2E2MzY1YmZkM2Q3ZjI0ZWE5OGUxZTQ5MzlmNTg0NDA4Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2I3OTMxMzUxYjExMTQwNjJiMWY2MmVjOTdkZWQ2ZDdlYzZhYjBhZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2Q5ZGUzZjZlYWRkMjQzNjAwODcwMTZmYTE2ZjM0MDRjMWZlZjgwZDliNDNi
|
10
|
+
MWIxZDY2MGI1M2JhMjdmYTQ2YjhlOWExZTAzYThlM2RlYTc5OWZkZmRlZDk0
|
11
|
+
NWIzOWQzMDhhYjViOGUxODgwOGVhMjViOTJjNmRkYmYyYmUxZDE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDk5MTQyMGQ3M2ZhYjVmZjQ3MDZmMjcyZDJhYjkxMmU1ZGE0NzllODc3MDcx
|
14
|
+
ZGUwMWZlNWRkMzY4MDI4NzVjMjBlY2NhZTMzMGZjMmRkMjZiMWZiZjRjM2Jk
|
15
|
+
NWYzODgwOWQ1MTcyNTNlNWNmODkzZTUyNmMwMzEyYjhjYmY1NjE=
|
data/lib/proxtopus/client.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module Proxtopus
|
2
2
|
|
3
3
|
class Client
|
4
|
-
attr_accessor :
|
5
|
-
attr_reader :proxies
|
4
|
+
attr_accessor :resources, :proxies
|
6
5
|
|
7
6
|
# called by Proxtopus.configure, returns self
|
8
7
|
#def initialize(&block)
|
@@ -11,31 +10,43 @@ module Proxtopus
|
|
11
10
|
# instance_eval(&block) if block_given?
|
12
11
|
# self
|
13
12
|
#end
|
14
|
-
def initialize(
|
15
|
-
|
16
|
-
|
17
|
-
@
|
13
|
+
def initialize(resources)
|
14
|
+
#@api_url = api_url
|
15
|
+
#@api_options = api_options
|
16
|
+
@resources = ResourceSet.new(resources)
|
18
17
|
@proxies = ProxySet.new
|
19
18
|
self
|
19
|
+
rescue => e
|
20
|
+
puts "Proxtopus::Client -- #{e.inspect}"
|
20
21
|
end
|
21
22
|
|
22
23
|
# p.collect({:cs => ['US'], etc...})
|
23
24
|
# if no options are supplied, api_options will be used
|
24
25
|
def collect(opts=nil)
|
25
|
-
use_opts = (opts.nil?)? api_options : opts
|
26
|
-
get(use_opts)
|
26
|
+
#use_opts = (opts.nil?)? api_options : opts
|
27
|
+
#get(use_opts)
|
28
|
+
@resources.each do |resource|
|
29
|
+
@proxies.push(resource.collect)
|
30
|
+
end
|
31
|
+
rescue => e
|
32
|
+
puts "Proxtopus::Client -- #{e.inspect}"
|
27
33
|
end
|
28
34
|
|
29
35
|
def random_proxy
|
30
36
|
@proxies[rand(0..(@proxies.count-1))]
|
37
|
+
rescue => e
|
38
|
+
puts "Proxtopus::Client -- #{e.inspect}"
|
31
39
|
end
|
32
40
|
|
33
41
|
def delete_proxy(proxy)
|
34
42
|
@proxies.delete(proxy)
|
43
|
+
rescue => e
|
44
|
+
puts "Proxtopus::Client -- #{e.inspect}"
|
35
45
|
end
|
36
46
|
|
37
47
|
private
|
38
48
|
|
49
|
+
=begin
|
39
50
|
def get(opts)
|
40
51
|
begin
|
41
52
|
json = @agent.get(Request.build(api_url, opts)).body
|
@@ -48,6 +59,7 @@ module Proxtopus
|
|
48
59
|
exit
|
49
60
|
end
|
50
61
|
end
|
62
|
+
=end
|
51
63
|
end
|
52
64
|
|
53
65
|
end
|
data/lib/proxtopus/proxy_set.rb
CHANGED
@@ -2,15 +2,20 @@ module Proxtopus
|
|
2
2
|
class ProxySet < Array
|
3
3
|
|
4
4
|
def push(proxy)
|
5
|
-
|
6
|
-
|
5
|
+
#puts proxy.class
|
6
|
+
if !proxy.is_a?(Proxtopus::Proxy) && !proxy.is_a?(Proxtopus::ProxySet) && !proxy.is_a?(Hash)
|
7
|
+
raise ArgumentError, "A ProxySet may only contain Proxy, ProxySet, or Hash objects!"
|
7
8
|
end
|
8
9
|
|
9
|
-
if proxy.is_a?(
|
10
|
-
proxy
|
10
|
+
if !proxy.is_a?(Proxtopus::ProxySet)
|
11
|
+
if proxy.is_a?(Hash)
|
12
|
+
proxy = Proxy.new(proxy['host'], proxy['port'], proxy['protocol'], proxy['country'], proxy['anonymity'])
|
13
|
+
end
|
14
|
+
|
15
|
+
super(proxy) if !include?(proxy)
|
16
|
+
else
|
17
|
+
proxy.each { |p| super(p) }
|
11
18
|
end
|
12
|
-
|
13
|
-
super(proxy) if !include?(proxy)
|
14
19
|
self
|
15
20
|
end
|
16
21
|
|
@@ -18,12 +23,16 @@ module Proxtopus
|
|
18
23
|
if !proxy.is_a?(Proxtopus::Proxy) && !proxy.is_a?(Hash)
|
19
24
|
raise ArgumentError, "A ProxySet may only contain Proxy or Hash objects!"
|
20
25
|
end
|
21
|
-
|
22
|
-
if proxy.is_a?(
|
23
|
-
proxy
|
26
|
+
|
27
|
+
if !proxy.is_a?(Proxtopus::ProxySet)
|
28
|
+
if proxy.is_a?(Hash)
|
29
|
+
proxy = Proxy.new(proxy['host'], proxy['port'], proxy['protocol'], proxy['country'], proxy['anonymity'])
|
30
|
+
end
|
31
|
+
|
32
|
+
super(proxy) if !include?(proxy)
|
33
|
+
else
|
34
|
+
proxy.each { |p| super(p) }
|
24
35
|
end
|
25
|
-
|
26
|
-
super(proxy) if !include?(proxy)
|
27
36
|
self
|
28
37
|
end
|
29
38
|
|
data/lib/proxtopus/request.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
module Proxtopus
|
2
|
-
|
2
|
+
class Request# < Mechanize
|
3
3
|
|
4
|
-
|
5
|
-
def build(url, opt)
|
6
|
-
puts url
|
7
|
-
uri = URI(url.to_s)
|
8
|
-
uri.query = URI.encode_www_form(opt)
|
9
|
-
uri.to_s
|
10
|
-
end
|
11
|
-
end
|
4
|
+
attr_reader :resource, :response
|
12
5
|
|
6
|
+
def initialize(resource)
|
7
|
+
#puts "to request"
|
8
|
+
raise ArgumentError, "Request.new() requires resource to be of type Proxtopus::Resource!" if !resource.is_a?(Proxtopus::Resource)
|
9
|
+
|
10
|
+
@resource = resource
|
11
|
+
page = Mechanize.new.get(@resource.uri.to_s)
|
12
|
+
@response = Response.new(page.body, @resource.format, @resource.elements)
|
13
|
+
end
|
14
|
+
|
13
15
|
end
|
14
16
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Proxtopus
|
2
|
+
class Resource
|
3
|
+
|
4
|
+
attr_reader :request, :response, :url, :params, :format, :elements
|
5
|
+
|
6
|
+
def initialize(resource)
|
7
|
+
#puts resource.class
|
8
|
+
#puts
|
9
|
+
#puts resource.inspect
|
10
|
+
if resource.is_a?(Proxtopus::Resource)
|
11
|
+
@request = resource.request
|
12
|
+
@response = resource.response
|
13
|
+
@url = resource.url
|
14
|
+
@params = resource.params
|
15
|
+
@format = resource.format
|
16
|
+
@elements = resource.elements
|
17
|
+
elsif resource.is_a?(Hash)
|
18
|
+
@request = resource[:request] || raise(ArgumentError, "Resource must have a specified request hash!")
|
19
|
+
@response = resource[:response] || raise(ArgumentError, "Resource must have a specified resource hash!")
|
20
|
+
@url = resource[:request][:url] || raise(ArgumentError, "Resource must have a specified request url!")
|
21
|
+
@params = resource[:request][:params] || raise(ArgumentError, "Resource must have a specified request param!")
|
22
|
+
@format = resource[:response][:format] || raise(ArgumentError, "Resource must have a specified resource format!")
|
23
|
+
@elements = resource[:response][:elements] || raise(ArgumentError, "Resource must have a specified resource set of elemenra!")
|
24
|
+
else
|
25
|
+
raise ArgumentError, "Resource.new() expects resource as a Proxtopus::Resource or Hash!"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def collect
|
30
|
+
Request.new(self).response.parsed
|
31
|
+
end
|
32
|
+
|
33
|
+
def uri
|
34
|
+
uri = URI(@url.to_s)
|
35
|
+
uri.query = URI.encode_www_form(@params)
|
36
|
+
uri
|
37
|
+
end
|
38
|
+
|
39
|
+
def ==(other)
|
40
|
+
if other.is_a?(Proxtopus::Resource)
|
41
|
+
if @url == other.url && @params == other.params
|
42
|
+
true
|
43
|
+
else
|
44
|
+
false
|
45
|
+
end
|
46
|
+
else
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Proxtopus
|
2
|
+
class ResourceSet < Array
|
3
|
+
|
4
|
+
def initialize(resources=nil)
|
5
|
+
if resources
|
6
|
+
resources.each { |r| self.push(r) }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def push(resource)
|
11
|
+
if !resource.is_a?(Proxtopus::Resource) && !resource.is_a?(Hash)
|
12
|
+
raise ArgumentError, "A ResourceSet may only contain Resource or Hash objects!"
|
13
|
+
end
|
14
|
+
|
15
|
+
if resource.is_a?(Hash)
|
16
|
+
resource = Resource.new(resource)
|
17
|
+
end
|
18
|
+
|
19
|
+
super(resource) if !include?(resource)
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
=begin
|
24
|
+
def shift(resource)
|
25
|
+
if !resource.is_a?(Proxtopus::Resource) && !resource.is_a?(Hash)
|
26
|
+
raise ArgumentError, "A ResourceSet may only contain Resource or Hash objects!"
|
27
|
+
end
|
28
|
+
|
29
|
+
if resource.is_a?(Hash)
|
30
|
+
resource = Resource.new(resource['host'], resource['port'], resource['protocol'], resource['country'], resource['anonymity'])
|
31
|
+
end
|
32
|
+
|
33
|
+
super(resource) if !include?(resource)
|
34
|
+
self
|
35
|
+
end
|
36
|
+
=end
|
37
|
+
|
38
|
+
def include?(resource)
|
39
|
+
if resource.is_a?(Proxtopus::Resource)
|
40
|
+
each do |p|
|
41
|
+
return true if resource == p
|
42
|
+
end
|
43
|
+
false
|
44
|
+
else
|
45
|
+
false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Proxtopus
|
2
|
+
class Response
|
3
|
+
|
4
|
+
attr_reader :body, :format, :parsed
|
5
|
+
|
6
|
+
def initialize(page, format, elements)
|
7
|
+
#puts "to response"
|
8
|
+
#raise ArgumentError, "Response.new() expects page to be of type Mechanize::Page!" if !page.is_a?(Mechanize::Page)
|
9
|
+
#raise ArgumentError, "Response.new() expects format to be of type Symbol!" if !format.is_a?(Symbol)
|
10
|
+
#raise ArgumentError, "Response.new() expects elements to be of type Symbol!" if !format.is_a?(Symbol)
|
11
|
+
|
12
|
+
@body = page
|
13
|
+
@format = format
|
14
|
+
@elements = elements
|
15
|
+
|
16
|
+
if format == :json
|
17
|
+
@parsed = Parser.json(@body, @elements)
|
18
|
+
elsif format == :xml
|
19
|
+
@parsed = Parser.xml(@body, @elements)
|
20
|
+
#elsif format == :rss
|
21
|
+
# @parsed = Parser.rss(@body, @elements)
|
22
|
+
else
|
23
|
+
puts "Format #{format} is currenly unsupported... consider adding it =]"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Proxtopus
|
2
|
+
class Response
|
3
|
+
module Parser
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def json(body, elements)
|
7
|
+
ret = ProxySet.new
|
8
|
+
els = JSON.parse(body)[elements[:root]]
|
9
|
+
els.each do |el|
|
10
|
+
host = el[elements[:host]]
|
11
|
+
port = el[elements[:port]]
|
12
|
+
anonymity = el[elements[:anonymity]]
|
13
|
+
protocol = el[elements[:protocol]]
|
14
|
+
country = el[elements[:country]]
|
15
|
+
ret.push(Proxy.new(host, port, anonymity, protocol, country))
|
16
|
+
end
|
17
|
+
ret
|
18
|
+
end
|
19
|
+
|
20
|
+
def xml(body, elements)
|
21
|
+
ret = ProxySet.new
|
22
|
+
doc = Nokogiri::HTML(body)
|
23
|
+
els = doc.xpath(elements[:root])
|
24
|
+
els.each do |el|
|
25
|
+
host = el.xpath(elements[:host]).text
|
26
|
+
port = el.xpath(elements[:port]).text
|
27
|
+
anonymity = el.xpath(elements[:anonymity]).text
|
28
|
+
protocol = el.xpath(elements[:protocol]).text
|
29
|
+
country = el.xpath(elements[:country]).text
|
30
|
+
ret.push(Proxy.new(host, port, anonymity, protocol, country))
|
31
|
+
end
|
32
|
+
ret
|
33
|
+
end
|
34
|
+
|
35
|
+
#def rss(body, elements)
|
36
|
+
# ProxySet.new
|
37
|
+
#end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/proxtopus.rb
CHANGED
@@ -4,9 +4,13 @@ Bundler.require(:default)
|
|
4
4
|
require 'uri'
|
5
5
|
|
6
6
|
require_relative './proxtopus/client'
|
7
|
+
require_relative './proxtopus/request'
|
8
|
+
require_relative './proxtopus/response_parser'
|
9
|
+
require_relative './proxtopus/response'
|
10
|
+
require_relative './proxtopus/resource'
|
11
|
+
require_relative './proxtopus/resource_set'
|
7
12
|
require_relative './proxtopus/proxy'
|
8
13
|
require_relative './proxtopus/proxy_set'
|
9
|
-
require_relative './proxtopus/request'
|
10
14
|
|
11
15
|
module Proxtopus
|
12
16
|
|
@@ -23,8 +27,9 @@ module Proxtopus
|
|
23
27
|
#def new_client(&block)
|
24
28
|
# Client.new(&block) if block_given?
|
25
29
|
#end
|
26
|
-
def client(
|
27
|
-
|
30
|
+
def client(resources_file)
|
31
|
+
resources = "[#{File.read(resources_file)}]".gsub!(/\r|\n|\s/,'')
|
32
|
+
Client.new(eval(resources))
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proxtopus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.31
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan Barron
|
@@ -21,6 +21,10 @@ files:
|
|
21
21
|
- lib/proxtopus/proxy.rb
|
22
22
|
- lib/proxtopus/proxy_set.rb
|
23
23
|
- lib/proxtopus/request.rb
|
24
|
+
- lib/proxtopus/resource.rb
|
25
|
+
- lib/proxtopus/resource_set.rb
|
26
|
+
- lib/proxtopus/response.rb
|
27
|
+
- lib/proxtopus/response_parser.rb
|
24
28
|
homepage:
|
25
29
|
licenses:
|
26
30
|
- MIT
|