doublecheck 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/doublecheck CHANGED
@@ -6,8 +6,13 @@ if ARGV[0].nil?
6
6
  puts "USAGE: doublecheck http://example.com/sitemap.xml"
7
7
  else
8
8
  sitemap = DoubleCheck::Sitemap.new(ARGV[0])
9
- sitemap.urls.each do |url|
10
- test_url = DoubleCheck::TestUrl.new(url)
11
- test_url.test
9
+ sitemap.process
10
+ data = sitemap.data
11
+ data.each do |code, urls|
12
+ puts "Status Code: #{code}"
13
+ puts "#{urls.size} urls"
14
+ urls.each do |url|
15
+ puts "\t#{url}"
16
+ end
12
17
  end
13
18
  end
data/lib/check_url.rb ADDED
@@ -0,0 +1,10 @@
1
+ class DoubleCheck::CheckUrl
2
+ require 'uri'
3
+
4
+ def self.get_response(url)
5
+ uri = URI.parse(url)
6
+ response = Net::HTTP.start(uri.host, uri.port) do |http|
7
+ http.get(uri.path)
8
+ end
9
+ end
10
+ end
data/lib/doublecheck.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module DoubleCheck
2
2
  require 'rubygems'
3
3
  require 'sitemap'
4
- require 'test_url'
4
+ require 'check_url'
5
5
  end
data/lib/sitemap.rb CHANGED
@@ -3,16 +3,28 @@ class DoubleCheck::Sitemap
3
3
  require 'nokogiri'
4
4
 
5
5
  def initialize(url)
6
- @url = url
6
+ @sitemap_url = url
7
+ @data = {}
7
8
  end
8
9
 
9
- def urls
10
- doc = Nokogiri::XML(open(@url))
11
- urls = []
10
+ def process
11
+ doc = Nokogiri::XML(open(@sitemap_url))
12
12
  doc.css('loc').each do |url|
13
- urls.push(url.content)
13
+ response = DoubleCheck::CheckUrl.get_response(url.content)
14
+ record_result(url.content, response)
14
15
  end
15
- return urls
16
+ end
17
+
18
+ def record_result(url, response)
19
+ if @data[response.code].nil?
20
+ @data[response.code] = [url]
21
+ else
22
+ @data[response.code].push(url)
23
+ end
24
+ end
25
+
26
+ def data
27
+ return @data
16
28
  end
17
29
 
18
30
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doublecheck
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- version: "0.1"
8
+ - 2
9
+ version: "0.2"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nathan Humbert
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-11 00:00:00 -08:00
17
+ date: 2011-03-24 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -48,6 +48,20 @@ dependencies:
48
48
  version: "0"
49
49
  type: :development
50
50
  version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: mocha
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
51
65
  description: Check URLs in a sitemap to make sure you have not introduced any issues.
52
66
  email:
53
67
  - nathan.humbert@gmail.com
@@ -61,7 +75,7 @@ files:
61
75
  - README.markdown
62
76
  - MIT_LICENSE
63
77
  - bin/doublecheck
64
- - lib/test_url.rb
78
+ - lib/check_url.rb
65
79
  - lib/doublecheck.rb
66
80
  - lib/sitemap.rb
67
81
  has_rdoc: true
data/lib/test_url.rb DELETED
@@ -1,17 +0,0 @@
1
- class DoubleCheck::TestUrl
2
- require 'uri'
3
- def initialize(url)
4
- @url = URI.parse(url)
5
- end
6
-
7
- def test
8
- response = make_request
9
- puts 'HTTP code: ' + response.code + ' for ' + @url.host + @url.path
10
- end
11
-
12
- def make_request
13
- response = Net::HTTP.start(@url.host, @url.port) do |http|
14
- http.get(@url.path)
15
- end
16
- end
17
- end