http_status_checker 0.0.5 → 0.0.6

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: 3a39372c3765ae03312978566c678ba0f8e0358e
4
- data.tar.gz: c7ecabc3effcd2cfefee29d7f0295e0ec84433a0
3
+ metadata.gz: 884c48b9bc2833265b0f97dac47f77017ea45a52
4
+ data.tar.gz: ef49ec1bf965d4b44749ac6011080405eb2ae197
5
5
  SHA512:
6
- metadata.gz: 72a2303bf664b690b52de1a8cf85711f3f0bc123afc7e7de60d0fdd8b67bd46001afb2512615d84c77cb53cf9c826921a14fa20cf12e3f98d224c146de55c3e0
7
- data.tar.gz: 8cf114f84f961c40cd9b7e9a768080c0af1a00ad2a114778800f0d8a4cb48f84710babe29e809d8a126ae4261a34d3f0fa75761fc761333504906da5f5e55775
6
+ metadata.gz: be1ef7e4b381ac1191e6f44a99be459120fe05b79475e1fdefcc0cb075b73d1a06efde356e5d71a14a3fc6c3cd4e0e6544fdeab011adc88a241338a83baa49ab
7
+ data.tar.gz: 4a050c9820dc02996038373e516b671ec072f6c742392b9e7d5fdf7fb237e70e9df9b3eb19b9b820a06d1ed52c63af77720d4b468498fb0f19d743e9d3ec7c53
@@ -22,6 +22,13 @@ module HttpStatusChecker
22
22
 
23
23
  def get_response(url, redirect_url = nil, redirect_count = 0, retry_count = 0)
24
24
  result = HttpStatusChecker::Connection.get_header(redirect_url || url)
25
+ parse_response(redirect_count, redirect_url, result, url)
26
+ rescue => e
27
+ get_response(url, nil, redirect_count + 1, retry_count + 1) if retry_count < RETRY_MAX
28
+ { url => { code: result ? result.code : nil, is_alive: false, error: e.message } }
29
+ end
30
+
31
+ def parse_response(redirect_count, redirect_url, result, url)
25
32
  location_url = result['location']
26
33
  if !location_url.nil? && (redirect_url || url) != location_url
27
34
  raise InvalidRedirectError if redirect_count > REDIRECT_MAX
@@ -31,13 +38,6 @@ module HttpStatusChecker
31
38
  else
32
39
  raise InvalidResponseError, "Unknown class #{result.class} : #{result.to_s}"
33
40
  end
34
- rescue => e
35
- if retry_count < RETRY_MAX
36
- retry_count += 1
37
- retry
38
- end
39
- code = result ? result.code : nil
40
- { url => { code: code, is_alive: false, error: e.message } }
41
41
  end
42
42
 
43
43
  def to_host_hash(urls)
@@ -1,3 +1,3 @@
1
1
  module HttpStatusChecker
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -78,6 +78,7 @@ describe HttpStatusChecker::Connection do
78
78
  let!(:morizyun_404) { 'http://morizyun.github.io/404/' }
79
79
  it 'returns is_alive = false, redirect = nil, error present' do
80
80
  response = HttpStatusChecker.check(morizyun_404)
81
+ expect(response.first[morizyun_404][:code]).to eq('404')
81
82
  expect(response.first[morizyun_404][:is_alive]).to eq(false)
82
83
  expect(response.first[morizyun_404][:redirect_url]).to be_nil
83
84
  expect(response.first[morizyun_404][:error]).not_to be_nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_status_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - morizyun