feedvalidator 0.2.0 → 0.2.1
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/.travis.yml +3 -1
- data/feedvalidator.gemspec +1 -0
- data/lib/feed_validator.rb +34 -21
- data/lib/feed_validator/assertions.rb +4 -4
- data/test/unit/feed_validator_assertions_test.rb +6 -6
- data/test/unit/feed_validator_test.rb +6 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edd11b2f4b25f9248aed8ec078e86c957d7c9004
|
4
|
+
data.tar.gz: 8c8c4e13138b80d1646ee6939065939dd52e7a08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bb7389d9b2b04f6e6f16ffc632380a9c1de7d54c5e10910ccea90bf76b7cf1840325afe4f6101ebee493508808992f2b4ec9f460e632b9b3df3b922b7db643d
|
7
|
+
data.tar.gz: 566bfc63a3baf491d9c534dd2aae215872f03067e0eb4c883047d33fd08c53fb9bc873dab052591ea2b976ccc105c04f06af35dcaeaba90771ea008f9c31c824
|
data/.travis.yml
CHANGED
data/feedvalidator.gemspec
CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.authors = ["Edgar Gonzalez"]
|
15
15
|
gem.email = ["edgargonzalez@gmail.com"]
|
16
16
|
gem.description = %q{Interface to the W3C Feed Validation online service http://validator.w3.org/feed/}
|
17
|
+
gem.homepage = "http://github.com/edgar/feedvalidator"
|
17
18
|
|
18
19
|
gem.add_development_dependency 'rake'
|
19
20
|
|
data/lib/feed_validator.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2006 Edgar Gonzalez <
|
2
|
+
# Copyright (c) 2006 Edgar Gonzalez <edgargonzalez@gmail.com>
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -21,8 +21,8 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
#
|
24
|
-
# Provide an interface to the {W3C Feed Validation online service}[http://validator.w3.org/feed/],
|
25
|
-
# based on its SOAP 1.2 support.
|
24
|
+
# Provide an interface to the {W3C Feed Validation online service}[http://validator.w3.org/feed/],
|
25
|
+
# based on its SOAP 1.2 support.
|
26
26
|
#
|
27
27
|
require 'net/http'
|
28
28
|
require 'cgi'
|
@@ -31,8 +31,8 @@ require 'rexml/document'
|
|
31
31
|
|
32
32
|
module W3C
|
33
33
|
|
34
|
-
# Implements an interface to the {W3C Feed Validation online service}[http://validator.w3.org/feed/],
|
35
|
-
# based on its SOAP 1.2 support.
|
34
|
+
# Implements an interface to the {W3C Feed Validation online service}[http://validator.w3.org/feed/],
|
35
|
+
# based on its SOAP 1.2 support.
|
36
36
|
#
|
37
37
|
# It helps to find errors in RSS or Atom feeds.
|
38
38
|
# ---
|
@@ -40,52 +40,58 @@ module W3C
|
|
40
40
|
# so do not abuse it: you should make your scripts sleep between requests.
|
41
41
|
#
|
42
42
|
class FeedValidator
|
43
|
-
VERSION = "0.2.
|
43
|
+
VERSION = "0.2.1"
|
44
44
|
|
45
45
|
# True if the w3c feed validation service not found errors in the feed.
|
46
46
|
#
|
47
47
|
attr_reader :valid
|
48
|
-
|
48
|
+
|
49
49
|
# The complete response (as Net::HTTPResponse object) sent it by the w3c feed validation service.
|
50
50
|
#
|
51
51
|
attr_reader :response
|
52
|
-
|
52
|
+
|
53
53
|
# Collection of _errors_ founded by the w3c feed validation service.
|
54
|
-
# Every error is a hash containing: <tt>:type</tt>, <tt>:line</tt>,
|
54
|
+
# Every error is a hash containing: <tt>:type</tt>, <tt>:line</tt>,
|
55
55
|
# <tt>:column</tt>, <tt>:text</tt>, <tt>:element</tt>
|
56
56
|
#
|
57
57
|
attr_reader :errors
|
58
58
|
|
59
59
|
# Collection of _warnings_ founded by the w3c feed validation service.
|
60
|
-
# Every error is a hash containing: <tt>:type</tt>, <tt>:line</tt>,
|
60
|
+
# Every error is a hash containing: <tt>:type</tt>, <tt>:line</tt>,
|
61
61
|
# <tt>:column</tt>, <tt>:text</tt>, <tt>:element</tt>
|
62
62
|
#
|
63
63
|
attr_reader :warnings
|
64
64
|
|
65
65
|
# Collection of _informations_ founded by the w3c feed validation service.
|
66
|
-
# Every error is a hash containing: <tt>:type</tt>, <tt>:line</tt>,
|
66
|
+
# Every error is a hash containing: <tt>:type</tt>, <tt>:line</tt>,
|
67
67
|
# <tt>:column</tt>, <tt>:text</tt>, <tt>:element</tt>
|
68
68
|
#
|
69
69
|
attr_reader :informations
|
70
|
-
|
70
|
+
|
71
|
+
# request_type
|
72
|
+
# :manuel for direct input validation
|
73
|
+
# :url for url validation
|
74
|
+
attr_reader :request_type
|
75
|
+
|
71
76
|
# Initialize the feed validator object
|
72
77
|
#
|
73
78
|
def initialize
|
74
79
|
clear
|
75
80
|
end
|
76
|
-
|
77
|
-
# Validate the data provided.
|
81
|
+
|
82
|
+
# Validate the data provided.
|
78
83
|
# Returns a true value if the validation succeeded (regardless of whether the feed contains errors).
|
79
84
|
#
|
80
85
|
def validate_data(rawdata)
|
81
86
|
clear
|
82
87
|
params = "rawdata=#{CGI.escape(rawdata)}&manual=1&output=soap12"
|
88
|
+
@request_type = :manual
|
83
89
|
begin
|
84
90
|
# headers = VERSION == "1.8.4" ? {'Content-Type'=>'application/x-www-form-urlencoded'} : {}
|
85
91
|
headers = {'Content-Type'=>'application/x-www-form-urlencoded'}
|
86
92
|
@response = Net::HTTP.start('validator.w3.org',80) {|http|
|
87
93
|
http.post('/feed/check.cgi',params,headers)
|
88
|
-
}
|
94
|
+
}
|
89
95
|
rescue Exception => e
|
90
96
|
warn "Exception: #{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")}" if $VERBOSE
|
91
97
|
return false
|
@@ -95,12 +101,13 @@ module W3C
|
|
95
101
|
return true
|
96
102
|
end
|
97
103
|
|
98
|
-
# Validate the url provided.
|
104
|
+
# Validate the url provided.
|
99
105
|
# Returns a true value if the validation succeeded (regardless of whether the feed contains errors).
|
100
106
|
#
|
101
107
|
def validate_url(url)
|
102
108
|
clear
|
103
109
|
params = "url=#{CGI.escape(url)}&output=soap12"
|
110
|
+
@request_type = :url
|
104
111
|
begin
|
105
112
|
@response = Net::HTTP.get_response('validator.w3.org',"/feed/check.cgi?#{params}",80)
|
106
113
|
rescue Exception => e
|
@@ -116,16 +123,16 @@ module W3C
|
|
116
123
|
def to_s
|
117
124
|
msg = "Vailidity: #{@valid}\n"
|
118
125
|
msg << "Errors count: #{@errors.size}\n"
|
119
|
-
@errors.each_with_index{ |item, i| msg << "(#{i+1}) type: #{item[:type]} | line: #{item[:line]} | column: #{item[:column]} | text: #{item[:text]},\n"}
|
126
|
+
@errors.each_with_index{ |item, i| msg << "(#{i+1}) type: #{item[:type]} | line: #{item[:line]} | column: #{item[:column]} | text: #{item[:text]},\n"}
|
120
127
|
msg << "Warnings count: #{@warnings.size}\n"
|
121
|
-
@warnings.each_with_index{ |item, i| msg << "(#{i+1}) type: #{item[:type]} | line: #{item[:line]} | column: #{item[:column]} | text: #{item[:text]},\n"}
|
128
|
+
@warnings.each_with_index{ |item, i| msg << "(#{i+1}) type: #{item[:type]} | line: #{item[:line]} | column: #{item[:column]} | text: #{item[:text]},\n"}
|
122
129
|
msg << "Informations count: #{@informations.size}\n"
|
123
|
-
@informations.each_with_index{ |item, i| msg << "(#{i+1}) type: #{item[:type]} | line: #{item[:line]} | column: #{item[:column]} | text: #{item[:text]},\n"}
|
130
|
+
@informations.each_with_index{ |item, i| msg << "(#{i+1}) type: #{item[:type]} | line: #{item[:line]} | column: #{item[:column]} | text: #{item[:text]},\n"}
|
124
131
|
msg
|
125
132
|
end
|
126
133
|
|
127
134
|
private
|
128
|
-
|
135
|
+
|
129
136
|
def parse_response(response) #nodoc
|
130
137
|
xml = REXML::Document.new(response)
|
131
138
|
@valid = (/true/.match(xml.root.elements["env:Body/m:feedvalidationresponse/m:validity"].get_text.value))? true : false
|
@@ -141,6 +148,11 @@ module W3C
|
|
141
148
|
end
|
142
149
|
end
|
143
150
|
xml.elements.each("env:Envelope/env:Body/m:feedvalidationresponse/m:warnings/m:warninglist/warning") do |warning|
|
151
|
+
next if
|
152
|
+
@request_type == :manual &&
|
153
|
+
warning.elements["type"].get_text.value == "SelfDoesntMatchLocation" &&
|
154
|
+
warning.elements["text"].get_text.value == "Self reference doesn't match document location"
|
155
|
+
|
144
156
|
@warnings << {
|
145
157
|
:type => warning.elements["type"].nil? ? "" : warning.elements["type"].get_text.value,
|
146
158
|
:line => warning.elements["line"].nil? ? "" : warning.elements["line"].get_text.value,
|
@@ -162,11 +174,12 @@ module W3C
|
|
162
174
|
|
163
175
|
def clear #nodoc
|
164
176
|
@response = nil
|
177
|
+
@request_type = nil
|
165
178
|
@valid = false
|
166
179
|
@errors = []
|
167
180
|
@warnings = []
|
168
181
|
@informations = []
|
169
182
|
end
|
170
|
-
|
183
|
+
|
171
184
|
end
|
172
185
|
end
|
@@ -36,7 +36,7 @@ module W3C
|
|
36
36
|
parse_response(response.body)
|
37
37
|
else
|
38
38
|
parse_response(response)
|
39
|
-
end
|
39
|
+
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -62,7 +62,7 @@ class Test::Unit::TestCase
|
|
62
62
|
begin
|
63
63
|
response = File.open filename do |f| Marshal.load(f) end
|
64
64
|
v.parse(response)
|
65
|
-
rescue
|
65
|
+
rescue
|
66
66
|
unless v.validate_data(fragment)
|
67
67
|
warn("Sorry! could not validate the feed.")
|
68
68
|
return assert(true,'')
|
@@ -71,7 +71,7 @@ class Test::Unit::TestCase
|
|
71
71
|
end
|
72
72
|
assert(v.valid?, v.valid? ? '' : v.to_s)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
# Class-level method to quickly create validation tests for a bunch of actions at once in Rails.
|
76
76
|
# For example, if you have a FooController with three actions, just add one line to foo_controller_test.rb:
|
77
77
|
#
|
@@ -87,5 +87,5 @@ class Test::Unit::TestCase
|
|
87
87
|
EOF
|
88
88
|
end
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2006 Edgar Gonzalez <
|
2
|
+
# Copyright (c) 2006 Edgar Gonzalez <edgargonzalez@gmail.com>
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -27,7 +27,7 @@ require 'feed_validator/assertions'
|
|
27
27
|
require 'digest/md5'
|
28
28
|
|
29
29
|
class FeedValidatorAssertionsTest < Test::Unit::TestCase
|
30
|
-
|
30
|
+
|
31
31
|
def test_assert_valid_feed
|
32
32
|
# a valid feed
|
33
33
|
data = ""
|
@@ -36,14 +36,14 @@ class FeedValidatorAssertionsTest < Test::Unit::TestCase
|
|
36
36
|
}
|
37
37
|
assert_valid_feed(data)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def test_cache
|
41
41
|
# testing the cache using an invalid feed with a success response cached
|
42
|
-
fragment_feed = ">--invalid feed--<"
|
42
|
+
fragment_feed = ">--invalid feed--<"
|
43
43
|
response = File.open File.dirname(__FILE__) + "/../responses/success_with_warnings" do |f| Marshal.load(f) end
|
44
44
|
filename = File.join Dir::tmpdir, 'feed.' + Digest::MD5.hexdigest(fragment_feed).to_s
|
45
45
|
File.open filename, 'w+' do |f| Marshal.dump response, f end
|
46
|
-
assert_valid_feed(fragment_feed)
|
46
|
+
assert_valid_feed(fragment_feed)
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2006 Edgar Gonzalez <
|
2
|
+
# Copyright (c) 2006 Edgar Gonzalez <edgargonzalez@gmail.com>
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -26,7 +26,7 @@ require 'test/unit'
|
|
26
26
|
require 'feed_validator'
|
27
27
|
|
28
28
|
class FeedValidatorTest < Test::Unit::TestCase
|
29
|
-
|
29
|
+
|
30
30
|
def test_validate_url
|
31
31
|
v = W3C::FeedValidator.new()
|
32
32
|
assert v.validate_url('http://www.w3.org/QA/news.rss')
|
@@ -39,7 +39,7 @@ class FeedValidatorTest < Test::Unit::TestCase
|
|
39
39
|
|
40
40
|
def test_validate_data
|
41
41
|
v = W3C::FeedValidator.new()
|
42
|
-
|
42
|
+
|
43
43
|
data = ""
|
44
44
|
File.open(File.dirname(__FILE__) + "/../feeds/" + "weblog.rubyonrails.org_rss_2_0_articles.xml").each { |line|
|
45
45
|
data << line
|
@@ -48,7 +48,7 @@ class FeedValidatorTest < Test::Unit::TestCase
|
|
48
48
|
assert v.valid?
|
49
49
|
|
50
50
|
assert v.errors.size == 0
|
51
|
-
|
51
|
+
assert v.warnings.size == 0
|
52
52
|
assert v.informations.size == 0
|
53
53
|
|
54
54
|
data = ""
|
@@ -59,7 +59,7 @@ class FeedValidatorTest < Test::Unit::TestCase
|
|
59
59
|
assert v.valid?
|
60
60
|
assert v.errors.size == 0
|
61
61
|
assert v.warnings.size >= 1
|
62
|
-
|
62
|
+
|
63
63
|
data = ""
|
64
64
|
File.open(File.dirname(__FILE__) + "/../feeds/" + "weblog.rubyonrails.org_rss_2_0_articles_malformed.xml").each { |line|
|
65
65
|
data << line
|
@@ -70,5 +70,5 @@ class FeedValidatorTest < Test::Unit::TestCase
|
|
70
70
|
assert v.errors.first[:line] == "5"
|
71
71
|
assert v.errors.first[:column] == "4"
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feedvalidator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgar Gonzalez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -61,7 +61,7 @@ files:
|
|
61
61
|
- test/responses/success_with_warnings
|
62
62
|
- test/unit/feed_validator_assertions_test.rb
|
63
63
|
- test/unit/feed_validator_test.rb
|
64
|
-
homepage:
|
64
|
+
homepage: http://github.com/edgar/feedvalidator
|
65
65
|
licenses:
|
66
66
|
- MIT
|
67
67
|
metadata: {}
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
version: '0'
|
82
82
|
requirements: []
|
83
83
|
rubyforge_project:
|
84
|
-
rubygems_version: 2.4
|
84
|
+
rubygems_version: 2.6.4
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: Interface to the W3C Feed Validation online service http://validator.w3.org/feed/
|