proxy_pool 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 78ea0558c9c726da9a0ab591716246ae7b313d4f58e277661595edb5e52374f6
4
+ data.tar.gz: 5bc6e6de2724d8c605d5785eec02a56f08ca5f01ffd6698db7d1a080ba0a482f
5
+ SHA512:
6
+ metadata.gz: 814a8c138f52168e3baacdcc0362ede1f2c741533169086360740bd74d0aa920bcc934c7311541d898a654dc770983d14d3770afd92a5d2d6258213e3873846a
7
+ data.tar.gz: 002e2b3630aeb72e2b5a6bcd6f8ac8520e229d6cdbbf017614b3b688c1f3455042a099bbbf4009af555fbdefcb830cf9facc936fb03a9906e553f103b2b9cf09
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea/
@@ -0,0 +1 @@
1
+ proxy_pool
@@ -0,0 +1 @@
1
+ ruby-2.6.3
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in proxy_pool.gemspec
4
+ gemspec
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ proxy_pool (0.1.0)
5
+ http (~> 4.1, >= 4.1.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.6.0)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ domain_name (0.5.20190701)
13
+ unf (>= 0.0.5, < 1.0.0)
14
+ http (4.1.1)
15
+ addressable (~> 2.3)
16
+ http-cookie (~> 1.0)
17
+ http-form_data (~> 2.0)
18
+ http_parser.rb (~> 0.6.0)
19
+ http-cookie (1.0.3)
20
+ domain_name (~> 0.5)
21
+ http-form_data (2.1.1)
22
+ http_parser.rb (0.6.0)
23
+ minitest (5.11.3)
24
+ public_suffix (3.1.1)
25
+ rake (10.5.0)
26
+ unf (0.1.4)
27
+ unf_ext
28
+ unf_ext (0.0.7.6)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 2.0)
35
+ minitest (~> 5.0)
36
+ proxy_pool!
37
+ rake (~> 10.0)
38
+
39
+ BUNDLED WITH
40
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # ProxyPool
2
+
3
+ ProxyPool is a wrapper for [fate0/proxylist](https://github.com/fate0/proxylist)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'proxy_pool'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install proxy_pool
20
+
21
+ ## Usage
22
+
23
+ Get anonymous proxy randomly:
24
+
25
+ ```ruby
26
+ require 'proxy_pool'
27
+
28
+ ProxyPool.get_anonymous_proxy
29
+ => {"country"=>"RU", "anonymity"=>"high_anonymous", "from"=>"txt", "type"=>"https", "export_address"=>["94.242.58.14", "94.242.58.14"], "port"=>1448, "host"=>"94.242.58.14", "response_time"=>1.7}
30
+ ```
31
+
32
+ Get transparent proxy randomly:
33
+
34
+ ```ruby
35
+ require 'proxy_pool'
36
+
37
+ ProxyPool.get_transparent_proxy
38
+ => {"country"=>"ID", "anonymity"=>"anonymous", "from"=>"txt", "type"=>"http", "export_address"=>["35.192.136.167", "118.97.191.162", "35.192.136.167"], "port"=>80, "host"=>"118.97.191.162", "response_time"=>3.04}
39
+ ```
40
+
41
+ Use filter:
42
+
43
+ ```ruby
44
+ require 'proxy_pool'
45
+
46
+ ProxyPool.get_anonymous_proxy(type: 'https', country: 'ID', port: 80, from: 'txt')
47
+ ```
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zt2/proxy_pool.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "proxy_pool"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ module ProxyPool
2
+ #
3
+ # Errors
4
+ #
5
+
6
+ # Base error
7
+ class Error < StandardError;
8
+ end
9
+
10
+ require 'proxy_pool/version'
11
+ require 'proxy_pool/dealer'
12
+
13
+ class << self
14
+ # Get anonymous proxy from pool randomly
15
+ #
16
+ # @param filter [Hash] Filter
17
+ # @return [Hash] Proxy
18
+ def get_anonymous_proxy(filter={})
19
+ ProxyPool::Dealer.instance.get(true, filter)
20
+ end
21
+
22
+ # Get transparent proxy from pool randomly
23
+ #
24
+ # @param filter [Hash] Filter
25
+ # @return [Hash] Proxy
26
+ def get_transparent_proxy(filter={})
27
+ ProxyPool::Dealer.instance.get(false, filter)
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,87 @@
1
+ #
2
+ # Standard library
3
+ #
4
+ require 'json'
5
+ require 'singleton'
6
+
7
+ #
8
+ # Third-party library
9
+ #
10
+ require 'http'
11
+
12
+ module ProxyPool
13
+ #
14
+ # Pool
15
+ #
16
+ class Dealer
17
+ include Singleton
18
+
19
+ # HTTP error
20
+ class HTTPError < Error;
21
+ end
22
+
23
+ # Parse error
24
+ class ParseError < Error;
25
+ end
26
+
27
+ # Filter error
28
+ class FilterError < Error;
29
+ end
30
+
31
+ attr_reader :transparent_pools, :anonymous_pools
32
+
33
+ # Update to latest proxy list from fate0/proxylist
34
+ #
35
+ def update
36
+ @transparent_pools = []
37
+ @anonymous_pools = []
38
+
39
+ res = HTTP.get 'https://raw.githubusercontent.com/fate0/proxylist/master/proxy.list'
40
+ raise HTTPError, "invalid http code #{res.code}" if res.code != 200
41
+
42
+ res.body.to_s.split("\n").each {|line| _pool_parse(line)}
43
+ end
44
+
45
+ # Get a random proxy
46
+ #
47
+ # @param anonymous [TrueClass | FalseClass] Return high anonymous proxy if true
48
+ # @param filter [Hash] Filter
49
+ # @return [Hash] Proxy
50
+ def get(anonymous=true, filter={})
51
+ update if @transparent_pools.nil? && @anonymous_pools.nil?
52
+
53
+ target_pools = if anonymous
54
+ @anonymous_pools
55
+ else
56
+ @transparent_pools
57
+ end
58
+ filter.each_pair { |k, v| target_pools = _pool_filter(target_pools, k.to_s, v) }
59
+
60
+ target_pools.sample
61
+ end
62
+
63
+ private
64
+
65
+ def _pool_parse(line)
66
+ proxy = JSON.parse(line)
67
+ raise ParseError, "no anonymity field: #{line}" unless proxy.key?('anonymity')
68
+
69
+ case proxy['anonymity']
70
+ when 'high_anonymous'
71
+ @anonymous_pools << proxy
72
+ else
73
+ @transparent_pools << proxy
74
+ end
75
+ rescue JSON::ParserError
76
+ raise ParseError, "JSON parser error when parsing #{line}"
77
+ end
78
+
79
+ def _pool_filter(proxy_pools, key, value)
80
+ proxy_pools.select do |proxy|
81
+ raise FilterError, "invalid filter: #{key}" unless proxy.key?(key)
82
+ proxy[key] == value
83
+ end
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module ProxyPool
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "proxy_pool/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "proxy_pool"
7
+ spec.version = ProxyPool::VERSION
8
+ spec.authors = ["hi_ztz"]
9
+ spec.email = ["hi_ztz@protonmail.com"]
10
+
11
+ spec.summary = %q{select a ip from proxy list randomly}
12
+ spec.description = %q{proxy_pool can give you free and random proxy ip}
13
+ spec.homepage = "https://github.com/zt2/proxy_pool"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 2.0"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+
34
+ spec.add_runtime_dependency 'http', '~> 4.1', '>= 4.1.1'
35
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proxy_pool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - hi_ztz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: http
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.1'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 4.1.1
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '4.1'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 4.1.1
75
+ description: proxy_pool can give you free and random proxy ip
76
+ email:
77
+ - hi_ztz@protonmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".ruby-gemset"
84
+ - ".ruby-version"
85
+ - ".travis.yml"
86
+ - Gemfile
87
+ - Gemfile.lock
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/console
92
+ - bin/setup
93
+ - lib/proxy_pool.rb
94
+ - lib/proxy_pool/dealer.rb
95
+ - lib/proxy_pool/version.rb
96
+ - proxy_pool.gemspec
97
+ homepage: https://github.com/zt2/proxy_pool
98
+ licenses:
99
+ - MIT
100
+ metadata:
101
+ allowed_push_host: https://rubygems.org
102
+ homepage_uri: https://github.com/zt2/proxy_pool
103
+ source_code_uri: https://github.com/zt2/proxy_pool
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubygems_version: 3.0.3
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: select a ip from proxy list randomly
123
+ test_files: []