http_status_checker 0.0.3 → 0.0.4
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 +4 -4
- data/lib/http_status_checker.rb +1 -1
- data/lib/http_status_checker/base.rb +7 -10
- data/lib/http_status_checker/connection.rb +1 -1
- data/lib/http_status_checker/error.rb +7 -0
- data/lib/http_status_checker/version.rb +1 -1
- data/spec/http_status_checker/base_spec.rb +11 -0
- data/spec/http_status_checker/connection_spec.rb +14 -3
- data/spec/spec_helper.rb +0 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 05033eced256b186dbc266e52867b44d9d74d053
|
|
4
|
+
data.tar.gz: c584834e0dfb5c2bb4d319b5c8ddd6c77bb45535
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b481d34c22d0540621537f7d972fa647d514381933ad87cc1bb03d4acd4097130f7d305afe3167cc68021d770e9feedbc589325a78f0305dd7ba27be25e4fbd2
|
|
7
|
+
data.tar.gz: 1e1d63f8509d18b32d698bdc172b1d14442bd9d531f0834de0095d449d6f7d37401229efe254f3aedea1d3f119ece61151de1db9b878596e4adf414c84b37f65
|
data/lib/http_status_checker.rb
CHANGED
|
@@ -3,10 +3,10 @@ require 'parallel'
|
|
|
3
3
|
|
|
4
4
|
require 'http_status_checker/version'
|
|
5
5
|
|
|
6
|
+
require 'http_status_checker/error'
|
|
6
7
|
require 'http_status_checker/connection'
|
|
7
8
|
require 'http_status_checker/base'
|
|
8
9
|
|
|
9
10
|
module HttpStatusChecker
|
|
10
|
-
extend HttpStatusChecker::Connection
|
|
11
11
|
extend HttpStatusChecker::Base
|
|
12
12
|
end
|
|
@@ -4,9 +4,6 @@ module HttpStatusChecker
|
|
|
4
4
|
REDIRECT_MAX = 5.freeze
|
|
5
5
|
RETRY_MAX = 1.freeze
|
|
6
6
|
|
|
7
|
-
class InvalidResponseError < StandardError; end
|
|
8
|
-
class InvalidRedirectError < StandardError; end
|
|
9
|
-
|
|
10
7
|
def check(urls, wait_sec = 1)
|
|
11
8
|
results = []
|
|
12
9
|
|
|
@@ -23,13 +20,13 @@ module HttpStatusChecker
|
|
|
23
20
|
|
|
24
21
|
private
|
|
25
22
|
|
|
26
|
-
def get_response(url, redirect_url = nil, redirect_count = 0, retry_count = 0
|
|
27
|
-
result = get_header(redirect_url || url)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
raise InvalidRedirectError if
|
|
31
|
-
get_response(url,
|
|
32
|
-
elsif result.
|
|
23
|
+
def get_response(url, redirect_url = nil, redirect_count = 0, retry_count = 0)
|
|
24
|
+
result = HttpStatusChecker::Connection.get_header(redirect_url || url)
|
|
25
|
+
location_url = result['location']
|
|
26
|
+
if !location_url.nil? && (redirect_url || url) != location_url
|
|
27
|
+
raise InvalidRedirectError if redirect_count > REDIRECT_MAX
|
|
28
|
+
get_response(url, location_url, redirect_count + 1, 0)
|
|
29
|
+
elsif result.code =~ /^(2|3)[0-9]{2}$/
|
|
33
30
|
{ url => { code: result.code, is_alive: true, redirect_url: redirect_url } }
|
|
34
31
|
else
|
|
35
32
|
raise InvalidResponseError, "Unknown class #{result.class} : #{result.to_s}"
|
|
@@ -14,6 +14,17 @@ describe HttpStatusChecker::Connection do
|
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
context 'when set valid url with invalid http status' do
|
|
18
|
+
let!(:atnd_http_url) { 'http://atnd.org/events/14386' }
|
|
19
|
+
let!(:atnd_https_url) { 'https://atnd.org/events/14386' }
|
|
20
|
+
it 'returns is_alive = true, redirect = nil, error = nil' do
|
|
21
|
+
response = HttpStatusChecker.check(atnd_http_url)
|
|
22
|
+
expect(response.first[atnd_http_url][:is_alive]).to eq(true)
|
|
23
|
+
expect(response.first[atnd_http_url][:redirect_url]).to eq(atnd_https_url)
|
|
24
|
+
expect(response.first[atnd_http_url][:error]).to be_nil
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
17
28
|
context 'when set 2 urls' do
|
|
18
29
|
let!(:morizyun_css) { 'http://morizyun.github.io/blog/css3-html-front-coding-book-review/' }
|
|
19
30
|
let!(:morizyun_js) { 'http://morizyun.github.io/blog/javascript-learning-tech-yourself_01/' }
|
|
@@ -4,26 +4,37 @@ describe HttpStatusChecker::Connection do
|
|
|
4
4
|
describe '.get_header' do
|
|
5
5
|
let!(:valid_url) { 'http://www.yahoo.co.jp/' }
|
|
6
6
|
let!(:redirect_url) { 'http://yahoo.co.jp/' }
|
|
7
|
+
let!(:atnd_http_url) { 'http://atnd.org/events/14386' }
|
|
8
|
+
let!(:atnd_https_url) { 'https://atnd.org/events/14386' }
|
|
7
9
|
|
|
8
10
|
context 'when get http valid url' do
|
|
9
11
|
it 'return Net::HTTPOK response' do
|
|
10
|
-
response = HttpStatusChecker.get_header(valid_url)
|
|
12
|
+
response = HttpStatusChecker::Connection.get_header(valid_url)
|
|
11
13
|
expect(response.is_a?(Net::HTTPOK)).to be == true
|
|
14
|
+
expect(response['location']).to be_nil
|
|
12
15
|
end
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
context 'when get http redirect url' do
|
|
16
19
|
it 'return Net::HTTPRedirection response' do
|
|
17
|
-
response = HttpStatusChecker.get_header(redirect_url)
|
|
20
|
+
response = HttpStatusChecker::Connection.get_header(redirect_url)
|
|
18
21
|
expect(response.is_a?(Net::HTTPRedirection)).to be == true
|
|
19
22
|
expect(response['location']).to eq(valid_url)
|
|
20
23
|
end
|
|
21
24
|
end
|
|
22
25
|
|
|
26
|
+
context 'when get invalid http status(atnd.org)' do
|
|
27
|
+
it 'return Net::HTTPRedirection response' do
|
|
28
|
+
response = HttpStatusChecker::Connection.get_header(atnd_https_url)
|
|
29
|
+
expect(response.is_a?(Net::HTTPRedirection)).to be == true
|
|
30
|
+
expect(response['location']).to eq(atnd_https_url)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
23
34
|
context 'when get http invalid url' do
|
|
24
35
|
let!(:invalid_url) { 'http://www.nothing-dummy.com/' }
|
|
25
36
|
it 'raise SocketError' do
|
|
26
|
-
expect{ HttpStatusChecker.get_header(invalid_url) }.to raise_error(SocketError)
|
|
37
|
+
expect{ HttpStatusChecker::Connection.get_header(invalid_url) }.to raise_error(SocketError)
|
|
27
38
|
end
|
|
28
39
|
end
|
|
29
40
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: http_status_checker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- morizyun
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-12-
|
|
11
|
+
date: 2014-12-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|
|
@@ -113,6 +113,7 @@ files:
|
|
|
113
113
|
- lib/http_status_checker.rb
|
|
114
114
|
- lib/http_status_checker/base.rb
|
|
115
115
|
- lib/http_status_checker/connection.rb
|
|
116
|
+
- lib/http_status_checker/error.rb
|
|
116
117
|
- lib/http_status_checker/version.rb
|
|
117
118
|
- spec/http_status_checker/base_spec.rb
|
|
118
119
|
- spec/http_status_checker/connection_spec.rb
|