proxi_clean 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
  SHA1:
3
- metadata.gz: 30f5030f18725abe227258fb52fd86acb87076d3
4
- data.tar.gz: 5dc61fcee5b3c27e9b3a2c9db1b4041fa677ae8f
3
+ metadata.gz: 37b2808d78d23e3acb73baae1109f2856577cb65
4
+ data.tar.gz: 34cd41a3b0bdd3245661231bcc3465860292db64
5
5
  SHA512:
6
- metadata.gz: 42ef3886baf40113f2827b1a615aae78d6d791229078b1c19b112eb8bfb0302543392e6f0aacea1c2791e622064af8be1d740499f6c1225c270d4ea0c04e8f32
7
- data.tar.gz: 778804f73bd1f35832b23d26baaba5572208e330711cbfb003efbf784ee15fe275167910087ca5fc209313f7a864a4fe16382a94618f0ecebe0b587f58d4631e
6
+ metadata.gz: f00387a4977f012ef6649223596752cd92158ace51bfbb4b38c4dd966930c35d9b19ea4b835d3e86b0b3f4fe938f6366e221ea93cd5a890fa0b82a1ea044b227
7
+ data.tar.gz: f4ecc1d355b6feb8ef7ea26588c6acdd40d9d3f060ef4e4a6189919ff545328c13595a7195fb9c2d918db9972777a0e07234e1550c04eb8236c105968939fbc2
@@ -1,17 +1,21 @@
1
- require 'rest_client'
1
+ require 'faraday'
2
+ require 'json'
2
3
 
3
4
  module ProxiClean
4
5
  class Client
5
- attr_reader :public_ip
6
+ attr_reader :public_ip, :debug
6
7
 
7
- def initialize
8
+ def initialize(debug=false)
9
+ @debug = debug
8
10
  public_ip
9
11
  end
10
12
 
11
13
  def works?(proxy_uri)
12
14
  begin
15
+ puts 'Checking: ' + proxy_uri if @debug
13
16
  proxied_ip = proxied_ip(proxy_uri)
14
17
  rescue StandardError => e
18
+ puts 'ERROR: ' + e.message if @debug
15
19
  # If anything goes wrong, assuming the proxy is no good
16
20
  return false
17
21
  end
@@ -20,25 +24,25 @@ module ProxiClean
20
24
  end
21
25
 
22
26
  def public_ip
23
- RestClient.proxy = nil
24
27
  # Try to not hit realip more than we really need
25
- @public_ip ||= result_from_real_ip_api
28
+ @public_ip ||= real_ip(proxy_uri: nil)
26
29
  end
27
30
 
28
- private
29
-
30
31
  def proxied_ip(proxy_uri)
31
- RestClient.proxy = proxy_uri
32
- result_from_real_ip_api
32
+ real_ip(proxy_uri: proxy_uri)
33
33
  end
34
34
 
35
- def result_from_real_ip_api
36
- real_up_url = 'http://www.realip.info/api/p/realip.php'
37
- response = RestClient::Request.execute(method: :get,
38
- url: real_up_url,
39
- read_timeout: 10,
40
- open_timeout: 10)
41
- JSON.parse(response)['IP']
35
+ private
36
+
37
+ def real_ip(proxy_uri: nil)
38
+ conn = Faraday.new(proxy: proxy_uri)
39
+ conn.headers[:user_agent] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36'
40
+ response = conn.get do |req|
41
+ req.url 'http://www.realip.info/api/p/realip.php'
42
+ req.options.timeout = 5
43
+ req.options.open_timeout = 2
44
+ end
45
+ JSON.parse(response.body)['IP']
42
46
  end
43
47
  end
44
48
  end
@@ -1,3 +1,3 @@
1
1
  module ProxiClean
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/proxi_clean.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_runtime_dependency 'rest-client', '~> 1.8', '>= 1.8.0'
22
+ spec.add_runtime_dependency 'faraday', '~> 0.9.1'
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 1.8'
25
25
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxi_clean
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
  - Mario Zigliotto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-04 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rest-client
14
+ name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.8.0
19
+ version: 0.9.1
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '1.8'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 1.8.0
26
+ version: 0.9.1
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement