proxy_pool 0.2.1 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f243fa31c78f740c8d2394018c2764e0339199e974b0a1bc4500096d140686c
4
- data.tar.gz: 20ce8673f9d3d36fcf7af47ba7a37136d9fc18ab310d6fab25bfee5b0ca4f1ad
3
+ metadata.gz: bfdca897a821cc17460a3390ae5001b9a5a6d66467a15c11d8b11ecfd3ff1600
4
+ data.tar.gz: 6738b5666d7b76f845580e990c70d73b3accae13bf910f2a0c73b7bda727c396
5
5
  SHA512:
6
- metadata.gz: 6c767171bb9c2e9b9379437eebf0b7f2959b0023e024a6559eb3e60d5dc4bf318ad9944ea782efd7d63907f1b7733de19fb7231c0ce2d2a2d88fd40e29eb69e3
7
- data.tar.gz: d934249d61c03f69bc2e7efd6fe3aa8b20a4e79b1fa56c9429f12d1f6103c46271bc3b1448541f9d11ead71aba8dc6fabdebf2ff5f94a540232dc956bbf20315
6
+ metadata.gz: e6a7e9af649a85b82278c100092dfff975fa609196e9932866dd38a38e132171fc89f855400f54de24923bb312b327e0219ba30d485404f8c5aa316b71fc26e0
7
+ data.tar.gz: 4728d8442b1acc9bc51681fb2d04d0add0042a8130963d80d8070cbeaa90d358c814126a70a0d66701d73c599208bab4143c6ca281a6ec808ea0ffc2bbdeadc9
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- proxy_pool (0.2.0)
4
+ proxy_pool (0.2.1)
5
5
  http (~> 4.4, >= 4.4.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -20,30 +20,35 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Get anonymous proxy randomly:
23
+ Require
24
24
 
25
25
  ```ruby
26
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
27
  ```
31
28
 
32
- Get transparent proxy randomly:
29
+ Get proxy randomly:
33
30
 
34
31
  ```ruby
35
- require 'proxy_pool'
32
+ ProxyPool.get
33
+ ```
36
34
 
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}
35
+ Or you can create any condition in block
36
+
37
+ ```ruby
38
+ # Select proxy by response time
39
+ ProxyPool.get { |proxy| proxy['response_time'] < 2 }
39
40
  ```
40
41
 
41
- Use filter:
42
+ Get high anonymous proxy:
42
43
 
43
44
  ```ruby
44
- require 'proxy_pool'
45
+ ProxyPool.get_high_anonymous_proxy
46
+ ```
45
47
 
46
- ProxyPool.get_anonymous_proxy(type: 'https', country: 'ID', port: 80, from: 'txt')
48
+ Get proxy by country
49
+
50
+ ```ruby
51
+ ProxyPool.get_by_country('us')
47
52
  ```
48
53
 
49
54
  ## Development
@@ -38,7 +38,11 @@ module ProxyPool
38
38
 
39
39
  @updated_at = Time.now
40
40
 
41
- res.body.to_s.split("\n").each { |line| _pool_parse(line) }
41
+ res.body.to_s.split("\n").each do |line|
42
+ _pool_parse(line)
43
+ rescue ParseError
44
+ next
45
+ end
42
46
  end
43
47
 
44
48
  # Get a random proxy
@@ -83,8 +87,10 @@ module ProxyPool
83
87
  # @param line [String]
84
88
  def _pool_parse(line)
85
89
  proxy = JSON.parse(line)
86
- unless proxy.key?('anonymity')
87
- raise ParseError, "no anonymity field: #{line}"
90
+ if proxy['anonymity'].nil? ||
91
+ proxy['type'].nil? ||
92
+ proxy['country'].nil?
93
+ raise ParseError
88
94
  end
89
95
 
90
96
  @pools << proxy
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProxyPool
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_pool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - hi_ztz