proxy_fetcher 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a36eb7a048bc985836e08d8e380412ceadd6e4b
4
- data.tar.gz: cdceec65f99f25a4bfe8b8ae3531a9d203fb8710
3
+ metadata.gz: 24b80ab944bf6a891aa4a22db877cdd19250fbcf
4
+ data.tar.gz: e5a0a514f316ee3cc098d264980ead131d64c276
5
5
  SHA512:
6
- metadata.gz: 39954c3255c4ea3642023b4ceb0a9c03d4623d2cecd2b75237f4b219af71a292408583602ca5d7e3ce06ec54a8ac39c4e0c83b7d98ecceaea76ca8d86ddc5f81
7
- data.tar.gz: 362d73388a1ed8b9d674e571c55763c265d808415efbc5db8c96e94c8ab110fffde2b137436ffe521f54b9940805df2c846a392c2a3316153f235a47f47ae96f
6
+ metadata.gz: 24c86d79b5a749c5c0b221562200936fbd099a481530fab31b85005652dc54f3dd67d17161119d32500da0a267b38ee56f2c44c2a52f6329e4ad1b83f2eb5cd8
7
+ data.tar.gz: 0e4b04ed465e17fdd2967f2fac0734219c119ad2f224b2b436cd449efdf83e5896673a81da07e4e70cae02d856ee3630f27ca759bc4a933c252e161864fe8508
data/README.md CHANGED
@@ -4,8 +4,11 @@
4
4
  [![Coverage Status](https://coveralls.io/repos/github/nbulaj/proxy_fetcher/badge.svg)](https://coveralls.io/github/nbulaj/proxy_fetcher)
5
5
  [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg)](#license)
6
6
 
7
- This gem can help your Ruby application to make HTTP(S) requests from proxy server, fetching and validating
8
- current proxy lists from the different proxy services like [HideMyAss](http://hidemyass.com/) or Hide My Name.
7
+ This gem can help your Ruby application to make HTTP(S) requests from proxy by fetching and validating actual
8
+ proxy lists from the different providers like [HideMyAss](http://hidemyass.com/) or Hide My Name.
9
+
10
+ It gives you a `Manager` class that can load proxy list, validate it and return random or specific proxy entry. Take a look
11
+ at the documentation below to find all the gem features.
9
12
 
10
13
  **IMPORTANT** currently HideMyAss service closed free proxy list service, but it will be open soon and gem will be updated.
11
14
 
@@ -44,7 +47,7 @@ manager = ProxyFetcher::Manager.new # will immediately load proxy list from the
44
47
  manager.proxies
45
48
 
46
49
  #=> [#<ProxyFetcher::Proxy:0x00000002879680 @addr="97.77.104.22", @port=3128, @country="USA",
47
- # @response_time=5217, @speed=48, @connection_time=100, @type="HTTP", @anonymity="High">, ... ]
50
+ # @response_time=5217, @speed=48, @type="HTTP", @anonymity="High">, ... ]
48
51
  ```
49
52
 
50
53
  You can initialize proxy manager without loading proxy list from the remote server by passing `refresh: false` on initialization:
@@ -72,21 +75,20 @@ If `ProxyFetcher::Manager` was already initialized somewhere, you can refresh th
72
75
  manager.refresh_list! # or manager.fetch!
73
76
 
74
77
  #=> [#<ProxyFetcher::Proxy:0x00000002879680 @addr="97.77.104.22", @port=3128, @country="USA",
75
- # @response_time=5217, @speed=48, @connection_time=100, @type="HTTP", @anonymity="High">, ... ]
78
+ # @response_time=5217, @speed=48, @type="HTTP", @anonymity="High">, ... ]
76
79
  ```
77
80
 
78
- Every proxy is a `ProxyFetcher::Proxy` object that has next readers:
81
+ Every proxy is a `ProxyFetcher::Proxy` object that has next readers (instance variables):
79
82
 
80
83
  * `addr` (IP address)
81
84
  * `port`
82
85
  * `country` (USA or Brazil for example)
83
86
  * `response_time` (5217 for example)
84
- * `connection_time` (rank from 0 to 100, where 0 — slow, 100 high. **Note** depends on the proxy provider)
85
- * `speed` (rank from 0 to 100, where 0 — slow, 100 — high. **Note** depends on the proxy provider)
87
+ * `speed` (`:slow`, `:medium` or `:fast`. **Note:** depends on the proxy provider and can be `nil`)
86
88
  * `type` (URI schema, HTTP or HTTPS)
87
89
  * `anonimity` (Low or High +KA for example)
88
90
 
89
- Also you can call next instance method for every Proxy object:
91
+ Also you can call next instance methods for every Proxy object:
90
92
 
91
93
  * `connectable?` (whether proxy server is available)
92
94
  * `http?` (whether proxy server has a HTTP protocol)
@@ -123,7 +125,7 @@ manager.cleanup!
123
125
 
124
126
  ## Providers
125
127
 
126
- Currently ProxyFetcher can deal with next proxy providers:
128
+ Currently ProxyFetcher can deal with next proxy providers (services):
127
129
 
128
130
  * Hide My Name (default one)
129
131
  * Free Proxy List
@@ -131,7 +133,6 @@ Currently ProxyFetcher can deal with next proxy providers:
131
133
 
132
134
  If you wanna use one of them just setup required in the config:
133
135
 
134
-
135
136
  ```ruby
136
137
  ProxyFetcher.config.provider = :free_proxy_list
137
138
 
@@ -152,7 +153,9 @@ provider HTML page with proxy list. Take a look at the samples in the `proxy_fet
152
153
 
153
154
  ## TODO
154
155
 
155
- * Proxy filters
156
+ * Add proxy filters
157
+ * Code refactoring
158
+ * Rewrite specs
156
159
 
157
160
  ## Contributing
158
161
 
@@ -22,8 +22,6 @@ module ProxyFetcher
22
22
  when 4
23
23
  set!(:response_time, parse_response_time(td))
24
24
  set!(:speed, parse_indicator_value(td))
25
- when 5
26
- set!(:connection_time, parse_indicator_value(td))
27
25
  when 6 then
28
26
  set!(:type, td.content.strip)
29
27
  when 7
@@ -1,7 +1,7 @@
1
1
  module ProxyFetcher
2
2
  module Providers
3
3
  class HideMyName < Base
4
- PROVIDER_URL = 'https://hidemy.name/en/proxy-list/?type=hs#list'.freeze
4
+ PROVIDER_URL = 'https://hidemy.name/en/proxy-list/?type=hs'.freeze
5
5
 
6
6
  class << self
7
7
  def load_proxy_list
@@ -20,7 +20,10 @@ module ProxyFetcher
20
20
  when 2 then
21
21
  set!(:country, td.at_xpath('*//span[1]/following-sibling::text()[1]').content.strip)
22
22
  when 3
23
- set!(:response_time, Integer(td.at('p').content.strip[/\d+/]))
23
+ response_time = Integer(td.at('p').content.strip[/\d+/])
24
+
25
+ set!(:response_time, response_time)
26
+ set!(:speed, speed_from_response_time(response_time))
24
27
  when 4
25
28
  set!(:type, parse_type(td))
26
29
  when 5
@@ -42,6 +45,16 @@ module ProxyFetcher
42
45
  'HTTP'
43
46
  end
44
47
  end
48
+
49
+ def speed_from_response_time(response_time)
50
+ if response_time < 1500
51
+ :fast
52
+ elsif response_time < 3000
53
+ :medium
54
+ else
55
+ :slow
56
+ end
57
+ end
45
58
  end
46
59
  end
47
60
  end
@@ -1,7 +1,6 @@
1
1
  module ProxyFetcher
2
2
  class Proxy
3
- attr_reader :addr, :port, :country, :response_time,
4
- :connection_time, :speed, :type, :anonymity
3
+ attr_reader :addr, :port, :country, :response_time, :speed, :type, :anonymity
5
4
 
6
5
  def initialize(html_row)
7
6
  ProxyFetcher.config.provider.parse_entry(html_row, self)
@@ -24,6 +23,12 @@ module ProxyFetcher
24
23
 
25
24
  alias valid? connectable?
26
25
 
26
+ %i[slow medium fast].each do |method|
27
+ define_method "#{method}?" do
28
+ speed == method
29
+ end
30
+ end
31
+
27
32
  def http?
28
33
  type.casecmp('http').zero?
29
34
  end
@@ -32,18 +37,6 @@ module ProxyFetcher
32
37
  type.casecmp('https').zero?
33
38
  end
34
39
 
35
- def fast?
36
- speed >= 66
37
- end
38
-
39
- def medium?
40
- speed >= 33 && speed < 66
41
- end
42
-
43
- def slow?
44
- speed < 33
45
- end
46
-
47
40
  def uri
48
41
  URI::Generic.build(host: addr, port: port, scheme: type)
49
42
  end
@@ -9,7 +9,7 @@ module ProxyFetcher
9
9
  # Minor version number
10
10
  MINOR = 2
11
11
  # Smallest version number
12
- TINY = 0
12
+ TINY = 1
13
13
 
14
14
  # Full version number
15
15
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
@@ -5,10 +5,10 @@ require 'proxy_fetcher/version'
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'proxy_fetcher'
7
7
  gem.version = ProxyFetcher.gem_version
8
- gem.date = '2017-07-17'
8
+ gem.date = '2017-07-19'
9
9
  gem.summary = 'Ruby gem for dealing with proxy lists '
10
10
  gem.description = 'This gem can help your Ruby application to make HTTP(S) requests ' \
11
- 'from proxy server, fetching and validating proxy lists from the different services.'
11
+ 'from proxy server by fetching and validating proxy lists from the different providers.'
12
12
  gem.authors = ['Nikita Bulai']
13
13
  gem.email = 'bulajnikita@gmail.com'
14
14
  gem.require_paths = ['lib']
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ProxyFetcher::Manager do
3
+ describe ProxyFetcher::Providers::FreeProxyList do
4
4
  before :all do
5
5
  ProxyFetcher.config.provider = :free_proxy_list
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ProxyFetcher::Manager do
3
+ describe ProxyFetcher::Providers::HideMyAss do
4
4
  before :all do
5
5
  ProxyFetcher.config.provider = :hide_my_ass
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ProxyFetcher::Manager do
3
+ describe ProxyFetcher::Providers::HideMyName do
4
4
  before :all do
5
5
  ProxyFetcher.config.provider = :hide_my_name
6
6
  end
@@ -43,30 +43,14 @@ describe ProxyFetcher::Proxy do
43
43
  expect(proxy.url).to be_a(String)
44
44
  end
45
45
 
46
- it 'must be slow if speed < 33' do
47
- proxy.instance_variable_set(:@speed, 32)
48
- expect(proxy.slow?).to be_truthy
49
-
50
- proxy.instance_variable_set(:@speed, 33)
51
- expect(proxy.slow?).to be_falsey
52
- end
53
-
54
- it 'must be medium if speed >= 33 and < 66' do
55
- proxy.instance_variable_set(:@speed, 32)
56
- expect(proxy.medium?).to be_falsey
46
+ it 'checks speed' do
47
+ proxy.instance_variable_set(:@speed, :fast)
48
+ expect(proxy.fast?).to be_truthy
57
49
 
58
- proxy.instance_variable_set(:@speed, 33)
59
- expect(proxy.medium?).to be_truthy
50
+ proxy.instance_variable_set(:@speed, :slow)
51
+ expect(proxy.slow?).to be_truthy
60
52
 
61
- proxy.instance_variable_set(:@speed, 65)
53
+ proxy.instance_variable_set(:@speed, :medium)
62
54
  expect(proxy.medium?).to be_truthy
63
55
  end
64
-
65
- it 'must be fast if speed >= 66' do
66
- proxy.instance_variable_set(:@speed, 65)
67
- expect(proxy.fast?).to be_falsey
68
-
69
- proxy.instance_variable_set(:@speed, 66)
70
- expect(proxy.fast?).to be_truthy
71
- end
72
56
  end
@@ -1,39 +1,39 @@
1
1
  RSpec.shared_examples 'a manager' do
2
2
  it 'loads proxy list on initialization by default' do
3
- manager = described_class.new
3
+ manager = ProxyFetcher::Manager.new
4
4
  expect(manager.proxies).not_to be_empty
5
5
  end
6
6
 
7
7
  it "doesn't load proxy list on initialization if `refresh` argument was set to false" do
8
- manager = described_class.new(refresh: false)
8
+ manager = ProxyFetcher::Manager.new(refresh: false)
9
9
  expect(manager.proxies).to be_empty
10
10
  end
11
11
 
12
12
  it 'can returns Proxy objects' do
13
- manager = described_class.new
13
+ manager = ProxyFetcher::Manager.new
14
14
  expect(manager.proxies).to all(be_a(ProxyFetcher::Proxy))
15
15
  end
16
16
 
17
17
  it 'can returns raw proxies' do
18
- manager = described_class.new
18
+ manager = ProxyFetcher::Manager.new
19
19
  expect(manager.raw_proxies).to all(be_a(String))
20
20
  end
21
21
 
22
22
  it 'cleanup proxy list from dead servers' do
23
23
  allow_any_instance_of(ProxyFetcher::Proxy).to receive(:connectable?).and_return(false)
24
24
 
25
- manager = described_class.new
25
+ manager = ProxyFetcher::Manager.new
26
26
 
27
27
  expect { manager.cleanup! }.to change { manager.proxies }.to([])
28
28
  end
29
29
 
30
30
  it "doesn't pollute the output with array of proxies" do
31
- manager = described_class.new(refresh: false)
31
+ manager = ProxyFetcher::Manager.new(refresh: false)
32
32
  expect(manager.inspect).to eq(manager.to_s)
33
33
  end
34
34
 
35
35
  it 'returns first proxy' do
36
- manager = described_class.new
36
+ manager = ProxyFetcher::Manager.new
37
37
 
38
38
  first_proxy = manager.proxies.first
39
39
 
@@ -42,9 +42,9 @@ RSpec.shared_examples 'a manager' do
42
42
  end
43
43
 
44
44
  it 'returns first valid proxy' do
45
- manager = described_class.new(refresh: false)
45
+ manager = ProxyFetcher::Manager.new(refresh: false)
46
46
 
47
- proxies = 5.times.collect { instance_double('ProxyFetcher::Proxy', connectable?: false) }
47
+ proxies = Array.new(5) { instance_double('ProxyFetcher::Proxy', connectable?: false) }
48
48
  manager.instance_variable_set(:@proxies, proxies)
49
49
 
50
50
  connectable_proxy = instance_double('ProxyFetcher::Proxy')
@@ -61,14 +61,14 @@ RSpec.shared_examples 'a manager' do
61
61
  end
62
62
 
63
63
  it 'returns nothing if proxy list is empty' do
64
- manager = described_class.new(refresh: false)
64
+ manager = ProxyFetcher::Manager.new(refresh: false)
65
65
 
66
66
  expect(manager.get).to be_nil
67
67
  expect(manager.get!).to be_nil
68
68
  end
69
69
 
70
70
  it 'returns random proxy' do
71
- manager = described_class.new
71
+ manager = ProxyFetcher::Manager.new
72
72
  expect(manager.random).to be_an_instance_of(ProxyFetcher::Proxy)
73
73
  end
74
- end
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_fetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Bulai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-17 00:00:00.000000000 Z
11
+ date: 2017-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -45,7 +45,7 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.5'
47
47
  description: This gem can help your Ruby application to make HTTP(S) requests from
48
- proxy server, fetching and validating proxy lists from the different services.
48
+ proxy server by fetching and validating proxy lists from the different providers.
49
49
  email: bulajnikita@gmail.com
50
50
  executables: []
51
51
  extensions: []