| Class | W3C::FeedValidator |
| In: |
lib/feed_validator.rb
lib/feed_validator/assertions.rb |
| Parent: | Object |
Implements an interface to the W3C Feed Validation online service, based on its SOAP 1.2 support.
It helps to find errors in RSS or Atom feeds.
Please remember that the W3C Feed Validation service is a shared resource, so do not abuse it: you should make your scripts sleep between requests.
| VERSION | = | "0.1.1" |
| valid | -> | valid? |
| errors | [R] | Collection of errors founded by the w3c feed validation service. Every error is a hash containing: :type, :line, :column, :text, :element |
| informations | [R] | Collection of informations founded by the w3c feed validation service. Every error is a hash containing: :type, :line, :column, :text, :element |
| response | [R] | The complete response (as Net::HTTPResponse object) sent it by the w3c feed validation service. |
| valid | [R] | True if the w3c feed validation service not found errors in the feed. |
| warnings | [R] | Collection of warnings founded by the w3c feed validation service. Every error is a hash containing: :type, :line, :column, :text, :element |
Initialize the feed validator object
# File lib/feed_validator.rb, line 72
72: def initialize
73: clear
74: end
Parse a response from the w3c feed validation service. Used by assert_valid_feed
# File lib/feed_validator/assertions.rb, line 33
33: def parse(response)
34: clear
35: if response.respond_to?(:body)
36: parse_response(response.body)
37: else
38: parse_response(response)
39: end
40: end
# File lib/feed_validator.rb, line 113
113: def to_s
114: msg = "Vailidity: #{@valid}\n"
115: msg << "Errors count: #{@errors.size}\n"
116: @errors.each_with_index{ |item, i| msg << "(#{i+1}) type: #{item[:type]} | line: #{item[:line]} | column: #{item[:column]} | text: #{item[:text]},\n"}
117: msg << "Warnings count: #{@warnings.size}\n"
118: @warnings.each_with_index{ |item, i| msg << "(#{i+1}) type: #{item[:type]} | line: #{item[:line]} | column: #{item[:column]} | text: #{item[:text]},\n"}
119: msg << "Informations count: #{@informations.size}\n"
120: @informations.each_with_index{ |item, i| msg << "(#{i+1}) type: #{item[:type]} | line: #{item[:line]} | column: #{item[:column]} | text: #{item[:text]},\n"}
121: msg
122: end
Validate the data provided. Returns a true value if the validation succeeded (regardless of whether the feed contains errors).
# File lib/feed_validator.rb, line 79
79: def validate_data(rawdata)
80: clear
81: params = "rawdata=#{CGI.escape(rawdata)}&manual=1&output=soap12"
82: begin
83: headers = ::VERSION == "1.8.4" ? {'Content-Type'=>'application/x-www-form-urlencoded'} : {}
84: @response = Net::HTTP.start('validator.w3.org',80) {|http|
85: http.post('/feed/check.cgi',params,headers)
86: }
87: rescue Exception => e
88: warn "Exception: #{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")}" if $VERBOSE
89: return false
90: end
91: parse_response(@response.body)
92: return true
93: end
Validate the url provided. Returns a true value if the validation succeeded (regardless of whether the feed contains errors).
# File lib/feed_validator.rb, line 98
98: def validate_url(url)
99: clear
100: params = "url=#{CGI.escape(url)}&output=soap12"
101: begin
102: @response = Net::HTTP.get_response('validator.w3.org',"/feed/check.cgi?#{params}",80)
103: rescue Exception => e
104: warn "Exception: #{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")}" if $VERBOSE
105: return false
106: end
107: parse_response(@response.body)
108: return true
109: end