http-proxy 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: e5c7d1be3906f26aa0d62a50d61176512bbbbb8d4d1e4c512bb0874be37d5170
4
- data.tar.gz: 40f7e2a15b63525efbd73913e447e077e96b900e3ae1a5d2872530b35a1176c0
3
+ metadata.gz: eaeb307b91714f53a84e1b24e5a0160e345f1d7e37dd5b232962b7a5d42d50a2
4
+ data.tar.gz: 26e0aff91af5bbb357bf92d82c2f259c26fbd380ce927be303bb46d5bfb75b47
5
5
  SHA512:
6
- metadata.gz: ad059653188784784656180aa3ef03c376c3da08c4f70c8ac4bf36994a5af70fcfdb42a20e76784b6d3a10ea57efb3346f36de4ad29695947fb844b5619f0488
7
- data.tar.gz: a0f51b76a48898461c9e8049ecee19b2a4b190c203838f72dfa57f8fee33ae6a55023f5e1f29e57712306f393e72d07492a704a908951257a1aebbbfb7e6b00a
6
+ metadata.gz: c7e954eaa1f88f26bc1247771ad6f8cc02160f09d284ca7515956dc81391e81495165f64405ad2892de43f69a4affd010b048c808c8578d1d07bbeebb328f12d
7
+ data.tar.gz: f53b8d3430ce567b57ddce1a9466a85be309ec190731d24bf3c8db420821b3e0f4549d16d5856f27cb1e3b0b4db2bc16504933c6960c4edd5c9b5868c8b6420b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- http-proxy (0.2.0)
4
+ http-proxy (0.3.0)
5
5
  http (~> 4.4, >= 4.4.1)
6
6
  proxy_pool (~> 0.2.2)
7
7
 
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # HTTP::Proxy
2
+ [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fzt2%2Fhttp-proxy.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fzt2%2Fhttp-proxy?ref=badge_shield)
3
+
2
4
 
3
5
  HTTP::Proxy allows you sending HTTP request via proxy automatically. This library extends gem HTTP by patching HTTP::Chainable to make proxy http request possible.
4
6
 
@@ -33,6 +35,12 @@ HTTP.proxy.get 'https://httpbin.org/ip'
33
35
  # => {"origin"=>"36.83.40.184, 36.83.40.184"}
34
36
  ```
35
37
 
38
+ With any condition in block (see more in [ProxyPool](https://github.com/zt2/ProxyPool))
39
+
40
+ ```ruby
41
+ HTTP.proxy { |proxy| proxy['country'] == 'US' && proxy['response_time'] < 2 }.get
42
+ ```
43
+
36
44
  ## Development
37
45
 
38
46
  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.
@@ -41,7 +49,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
41
49
 
42
50
  ## Contributing
43
51
 
44
- Bug reports and pull requests are welcome on GitHub at https://github.com/hi_ztz/http-proxy.
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zt2/http-proxy.
45
53
 
46
54
  ## License
47
55
 
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'http-proxy'
6
- spec.version = '0.2.0'
6
+ spec.version = '0.3.0'
7
7
  spec.authors = ['hi_ztz']
8
8
  spec.email = ['hi_ztz@protonmail.com']
9
9
 
@@ -6,17 +6,16 @@ module HTTP
6
6
  # Choose a proxy to send HTTP request
7
7
  #
8
8
  # @param anonymous [Boolean] Using anonymous proxy or not
9
- def proxy(anonymous = true)
9
+ def proxy(anonymous = true, &block)
10
10
  if anonymous
11
11
  p = ProxyPool.get_high_anonymous_proxy
12
+ elsif block_given?
13
+ p = ProxyPool.get(&block)
12
14
  else
13
15
  p = ProxyPool.get
14
16
  end
15
17
 
16
18
  via(p['host'], p['port'])
17
- rescue HTTP::ConnectionError
18
- ProxyPool.remove(p)
19
- retry
20
19
  end
21
20
  end
22
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hi_ztz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-20 00:00:00.000000000 Z
11
+ date: 2020-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler