proxtopus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzU2ZTBiNDFiYTNmNDBmMzFlZmQxMDhhZTRiNjgxMTFkNTM1MGNjMA==
5
+ data.tar.gz: !binary |-
6
+ ODQ4ZTYwZGY2MzQ0MGI3YmE2OTIwNWNiNDE5ZWY5NzM0ZTUxMmEzZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MGU0MTZjOGVlOGU5MjkxYjZiZGQwZmM1ZTc4NWM1NTQyNmFmMjhiNDEwMjE2
10
+ YTg1NzljZGJlYmE4ZmNkMmY1YmE5YjU0ZDcxMDI2OWM5ODUyOTQ4NjJlNjll
11
+ NTU5NWYyZmViYmFmMDdjYWM0NzQxZTI3YjEwZWM1NGM0MmUyZGU=
12
+ data.tar.gz: !binary |-
13
+ YmQ3NmMwYTYzNjlkYTRhMmQ4NTZiMTE2YmUwNGI0Y2Y3ZDNmZDdjNzRlMDJh
14
+ ZTNkNjliY2E5MTk2OTY2OTVkODBlYmExNDM1MjkwN2MzOWE2NTQwYmVkYmFk
15
+ YjFkN2Y3YTJmYmE2MTQyMjQ3ZTE0YTg5ZTFmNDM3MDI1ODIyMTk=
@@ -0,0 +1,53 @@
1
+ module Proxtopus
2
+
3
+ class Client
4
+ attr_accessor :api_url, :api_options
5
+ attr_reader :proxies
6
+
7
+ # called by Proxtopus.configure, returns self
8
+ #def initialize(&block)
9
+ # @agent = Mechanize.new
10
+ # @proxies = ProxySet.new
11
+ # instance_eval(&block) if block_given?
12
+ # self
13
+ #end
14
+ def initialize(api_url, api_options)
15
+ @api_url = api_url
16
+ @api_options = api_options
17
+ @agent = Mechanize.new
18
+ @proxies = ProxySet.new
19
+ self
20
+ end
21
+
22
+ # p.collect({:cs => ['US'], etc...})
23
+ # if no options are supplied, api_options will be used
24
+ def collect(opts=nil)
25
+ use_opts = (opts.nil?)? api_options : opts
26
+ get(use_opts)
27
+ end
28
+
29
+ def random_proxy
30
+ proxies = @proxies.clone
31
+ proxies.shuffle
32
+ proxy = proxies.last
33
+ @proxies.delete(proxy)
34
+ proxy
35
+ end
36
+
37
+ private
38
+
39
+ def get(opts)
40
+ begin
41
+ json = @agent.get(Request.build(api_url, opts)).body
42
+ JSON.parse(json)["data"].each do |p|
43
+ @proxies.push(p)
44
+ end
45
+ rescue => e
46
+ puts "[FAIL] Unexpected exception when trying to get proxy: #{e.inspect}"
47
+ puts
48
+ exit
49
+ end
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,27 @@
1
+ module Proxtopus
2
+ class Proxy
3
+
4
+ attr_accessor :host, :port, :protocol, :country, :anonymity
5
+
6
+ def initialize(host, port, protocol, country, anonymity)
7
+ @host = host.to_s
8
+ @port = port.to_i
9
+ @protocol = protocol.to_s
10
+ @country = country.to_s
11
+ @anonymity = anonymity.to_s
12
+ end
13
+
14
+ def ==(other)
15
+ if other.is_a?(Proxtopus::Proxy)
16
+ if @host == other.host && @port == other.port && @protocol == other.protocol
17
+ true
18
+ else
19
+ false
20
+ end
21
+ else
22
+ false
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ module Proxtopus
2
+ class ProxySet < Array
3
+
4
+ def push(proxy)
5
+ if !proxy.is_a?(Proxtopus::Proxy) && !proxy.is_a?(Hash)
6
+ raise ArgumentError, "A ProxySet may only contain Proxy or Hash objects!"
7
+ end
8
+
9
+ if proxy.is_a?(Hash)
10
+ proxy = Proxy.new(proxy['host'], proxy['port'], proxy['protocol'], proxy['country'], proxy['anonymity'])
11
+ end
12
+
13
+ super(proxy) if !include?(proxy)
14
+ self
15
+ end
16
+
17
+ def shift(proxy)
18
+ if !proxy.is_a?(Proxtopus::Proxy) && !proxy.is_a?(Hash)
19
+ raise ArgumentError, "A ProxySet may only contain Proxy or Hash objects!"
20
+ end
21
+
22
+ if proxy.is_a?(Hash)
23
+ proxy = Proxy.new(proxy['host'], proxy['port'], proxy['protocol'], proxy['country'], proxy['anonymity'])
24
+ end
25
+
26
+ super(proxy) if !include?(proxy)
27
+ self
28
+ end
29
+
30
+ def include?(proxy)
31
+ if proxy.is_a?(Proxtopus::Proxy)
32
+ each do |p|
33
+ return true if proxy == p
34
+ end
35
+ false
36
+ else
37
+ false
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,14 @@
1
+ module Proxtopus
2
+ module Request
3
+
4
+ class << self
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
12
+
13
+ end
14
+ end
data/lib/proxtopus.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'bundler'
2
+ Bundler.require(:default)
3
+
4
+ require 'uri'
5
+
6
+ require_relative './proxtopus/client'
7
+ require_relative './proxtopus/proxy'
8
+ require_relative './proxtopus/proxy_set'
9
+ require_relative './proxtopus/request'
10
+
11
+ module Proxtopus
12
+
13
+ class << self
14
+ # p = Proxtopus.new_client do
15
+ # api_url = 'http://letushide.com/fpapi',
16
+ # api_options = {
17
+ # :key => '60cae5a16971178be16daa02',
18
+ # :cs => ['US'],
19
+ # etc...
20
+ # }
21
+ #
22
+ # returns a Proxtopus::Client object
23
+ #def new_client(&block)
24
+ # Client.new(&block) if block_given?
25
+ #end
26
+ def client(api_url, api_options)
27
+ Client.new(api_url, api_options)
28
+ end
29
+ end
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proxtopus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ethan Barron
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A high-level API for retrieving active proxies.
14
+ email: ebarron@uco.edu
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/proxtopus.rb
20
+ - lib/proxtopus/client.rb
21
+ - lib/proxtopus/proxy.rb
22
+ - lib/proxtopus/proxy_set.rb
23
+ - lib/proxtopus/request.rb
24
+ homepage:
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.2.1
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: A high-level API for retrieving active proxies.
48
+ test_files: []