validator.nu 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 David Rice
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = validator.nu
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 David Rice. See LICENSE for details.
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "validator.nu"
8
+ gem.summary = %Q{ruby client library for the validator.nu HTML5 validation API}
9
+ gem.description = %Q{ruby client library for the validator.nu HTML5 validation API}
10
+ gem.email = "me@davidjrice.co.uk"
11
+ gem.homepage = "http://github.com/davidjrice/validator.nu"
12
+ gem.authors = ["David Rice"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/test_*.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "validator.nu #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,78 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'net/http'
4
+ require 'cgi'
5
+
6
+ module Validator
7
+
8
+ # http://about.validator.nu/#api
9
+ # http://wiki.whatwg.org/wiki/Validator.nu_Web_Service_Interface
10
+
11
+ # INPUT
12
+ #
13
+ # Document URL as a GET parameter; the service retrieves the document by URL over HTTP or HTTPS.
14
+ # Document POSTed as the HTTP entity body; parameters in query string as with GET.
15
+ # Document POSTed as a textarea value.
16
+ # Document POSTed as a form-based file upload.
17
+
18
+ # OUTPUT
19
+ #
20
+ # HTML with microformat-style class annotations (default output; should not be assumed to be forward-compatibly stable).
21
+ # XHTML with microformat-style class annotations (append &out=xhtml to URL; should not be assumed to be forward-compatibly stable).
22
+ # XML (append &out=xml to URL).
23
+ # JSON (append &out=json to URL).
24
+ # GNU error format (append &out=gnu to URL).
25
+ # Human-readably plain text (append &out=text to URL; should not be assumed to be forward-compatibly stable for machine parsing—use the GNU format for that).
26
+
27
+ # COMPRESSION
28
+
29
+ # Request Compression
30
+ # Validator.nu supports HTTP request compression. To use it, compress the request entity body using gzip and specify Content-Encoding: gzip as a request header.
31
+ #
32
+ # Response Compression
33
+ # Validator.nu supports HTTP response compression. Please use it. Response compression is orthogonal to the input methods and output formats.
34
+ # The standard HTTP gzip mechanism is used. To indicated that you prepared to handle gzipped responses, include the Accept-Encoding: gzip request header. When the header is present, Validator.nu will gzip compress the response. You should also be prepared to receive an uncompressed, though, since in the future it may make sense to turn off compression under heavy CPU load.
35
+
36
+
37
+ class << self
38
+ class RemoteException < StandardError; end;
39
+
40
+ HOST = "validator.nu"
41
+ PORT = 80
42
+
43
+ def nu(url_or_document)
44
+ get(url_or_document)
45
+ end
46
+
47
+
48
+ def get(url)
49
+ begin
50
+ http = Net::HTTP.new(HOST, PORT)
51
+ # http.set_debug_output STDERR
52
+ # http.use_ssl = true if SSL
53
+ uri = "/?&doc=#{CGI::escape(url)}&out=json"
54
+ # headers = method.to_s == 'errors' ? { 'Content-Type' => 'application/x-gzip', 'Accept' => 'application/x-gzip' } : {}
55
+
56
+ # compressed_data = CGI::escape(Zlib::Deflate.deflate(data, Zlib::BEST_SPEED))
57
+ # STDERR.puts uri
58
+ response = http.start do |http|
59
+ http.get(uri)
60
+ end
61
+
62
+ if response.kind_of? Net::HTTPSuccess
63
+ return response.body
64
+ else
65
+ STDERR.puts response.body.inspect
66
+ raise RemoteException.new("#{response.code}: #{response.message}")
67
+ end
68
+
69
+ rescue Exception => e
70
+ STDERR.puts "Error contacting validator.nu: #{e}"
71
+ STDERR.puts e.backtrace.join("\n"), 'debug'
72
+ raise e
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ end
@@ -0,0 +1 @@
1
+ {"url":"http://hsivonen.iki.fi/test/moz/messages-types/fatal.xhtml","messages":[{"type":"info","message":"The Content-Type was “application/xhtml+xml”. Using the XML parser (not resolving external entities)."},{"type":"info","message":"Using the preset for XHTML5+ARIA, SVG 1.1 plus MathML 2.0 (experimental) based on the root namespace."},{"type":"error","lastLine":6,"lastColumn":10,"subType":"fatal","message":"name expected","extract":"body>\n<p>Fatal & erro","hiliteStart":15,"hiliteLength":1}]}
@@ -0,0 +1 @@
1
+ {"url":"http://hsivonen.iki.fi/test/moz/messages-types/info.svg","messages":[{"type":"info","message":"The Content-Type was “image/svg+xml”. Using the XML parser (not resolving external entities)."},{"type":"info","message":"Using the preset for SVG 1.1+IRI, XHTML5+ARIA plus MathML 2.0 (experimental) based on the root namespace."}]}
@@ -0,0 +1 @@
1
+ {"url":"http://hsivonen.iki.fi/test/moz/messages-types/no-message.html","messages":[{"type":"info","message":"The Content-Type was “text/html”. Using the HTML parser."},{"type":"info","message":"Using the schema for HTML5+ARIA (experimental)."}]}
@@ -0,0 +1 @@
1
+ {"url":"http://hsivonen.iki.fi/test/moz/messages-types/404.html","messages":[{"type":"non-document-error","subType":"io","message":"HTTP resource not retrievable. The HTTP status from the remote server was: 404."}]}
@@ -0,0 +1 @@
1
+ {"url":"http://hsivonen.iki.fi/test/moz/messages-types/precise-error.html","messages":[{"type":"info","message":"The Content-Type was “text/html”. Using the HTML parser."},{"type":"info","message":"Using the schema for HTML5+ARIA (experimental)."},{"type":"error","lastLine":7,"lastColumn":4,"message":"“&” did not start a character reference. (“&” probably should have been escaped as “&amp;”.)","extract":"ead>\n<body>\n<p>&a</p>","hiliteStart":15,"hiliteLength":1}]}
@@ -0,0 +1 @@
1
+ {"url":"http://hsivonen.iki.fi/test/moz/messages-types/range-error.html","messages":[{"type":"info","message":"The Content-Type was “text/html”. Using the HTML parser."},{"type":"info","message":"Using the schema for HTML5+ARIA (experimental)."},{"type":"error","lastLine":7,"lastColumn":13,"firstColumn":10,"message":"End tag for “p” seen, but there were unclosed elements.","extract":"\n<p><span></p>\n</bod","hiliteStart":10,"hiliteLength":4}]}
@@ -0,0 +1 @@
1
+ {"url":"http://hsivonen.iki.fi/test/moz/messages-types/warning.html","messages":[{"type":"info","message":"The Content-Type was “text/html”. Using the HTML parser."},{"type":"info","message":"Using the schema for HTML5+ARIA (experimental)."},{"type":"error","lastLine":7,"lastColumn":13,"message":"“<” in an unquoted attribute value. Probable cause: Missing “>” immediately before.","extract":"y>\n<p class=foo<bar><","hiliteStart":15,"hiliteLength":1}]}
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require File.dirname(__FILE__) + '/../lib/validator.nu.rb'
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+
4
+ describe Validator do
5
+
6
+
7
+ describe "Validator.nu" do
8
+
9
+ it "should receive a no message result" do
10
+ fixture = File.open("#{File.dirname(__FILE__)}/fixtures/no-message.json").read
11
+
12
+ Validator.nu(
13
+ "http://hsivonen.iki.fi/test/moz/messages-types/no-message.html"
14
+ ).should == fixture
15
+ end
16
+
17
+ # http://hsivonen.iki.fi/test/moz/messages-types/info.svg
18
+ it "should receive an info result" do
19
+ fixture = File.open("#{File.dirname(__FILE__)}/fixtures/info.json").read
20
+
21
+
22
+ Validator.nu(
23
+ "http://hsivonen.iki.fi/test/moz/messages-types/info.svg"
24
+ ).should == fixture
25
+ end
26
+
27
+ it "should receive a warning result" do
28
+ fixture = File.open("#{File.dirname(__FILE__)}/fixtures/warning.json").read
29
+
30
+
31
+ Validator.nu(
32
+ "http://hsivonen.iki.fi/test/moz/messages-types/warning.html"
33
+ ).should == fixture
34
+ end
35
+
36
+ it "should receive a non-document result" do
37
+ fixture = File.open("#{File.dirname(__FILE__)}/fixtures/non-document-error.json").read
38
+
39
+
40
+ Validator.nu(
41
+ "http://hsivonen.iki.fi/test/moz/messages-types/404.html"
42
+ ).should == fixture
43
+ end
44
+
45
+ it "should receive a precise error result" do
46
+ fixture = File.open("#{File.dirname(__FILE__)}/fixtures/precise-error.json").read
47
+
48
+ Validator.nu(
49
+ "http://hsivonen.iki.fi/test/moz/messages-types/precise-error.html"
50
+ ).should == fixture
51
+ end
52
+
53
+ it "should receive a range error result" do
54
+ fixture = File.open("#{File.dirname(__FILE__)}/fixtures/range-error.json").read
55
+ Validator.nu(
56
+ "http://hsivonen.iki.fi/test/moz/messages-types/range-error.html"
57
+ ).should == fixture
58
+ end
59
+
60
+ it "should receive a fatal error result" do
61
+ fixture = File.open("#{File.dirname(__FILE__)}/fixtures/fatal-error.json").read
62
+ Validator.nu(
63
+ "http://hsivonen.iki.fi/test/moz/messages-types/fatal.xhtml"
64
+ ).should == fixture
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'validator.nu'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestValidator.nu < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{validator.nu}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David Rice"]
12
+ s.date = %q{2010-04-06}
13
+ s.description = %q{ruby client library for the validator.nu HTML5 validation API}
14
+ s.email = %q{me@davidjrice.co.uk}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/validator.nu.rb",
27
+ "spec/fixtures/fatal-error.json",
28
+ "spec/fixtures/info.json",
29
+ "spec/fixtures/no-message.json",
30
+ "spec/fixtures/non-document-error.json",
31
+ "spec/fixtures/precise-error.json",
32
+ "spec/fixtures/range-error.json",
33
+ "spec/fixtures/warning.json",
34
+ "spec/spec_helper.rb",
35
+ "spec/validator_spec.rb",
36
+ "test/helper.rb",
37
+ "test/test_validator.nu.rb",
38
+ "validator.nu.gemspec"
39
+ ]
40
+ s.homepage = %q{http://github.com/davidjrice/validator.nu}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.6}
44
+ s.summary = %q{ruby client library for the validator.nu HTML5 validation API}
45
+ s.test_files = [
46
+ "spec/spec_helper.rb",
47
+ "spec/validator_spec.rb",
48
+ "test/helper.rb",
49
+ "test/test_validator.nu.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ else
58
+ end
59
+ else
60
+ end
61
+ end
62
+
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: validator.nu
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - David Rice
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-06 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: ruby client library for the validator.nu HTML5 validation API
22
+ email: me@davidjrice.co.uk
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.rdoc
30
+ files:
31
+ - .document
32
+ - .gitignore
33
+ - LICENSE
34
+ - README.rdoc
35
+ - Rakefile
36
+ - VERSION
37
+ - lib/validator.nu.rb
38
+ - spec/fixtures/fatal-error.json
39
+ - spec/fixtures/info.json
40
+ - spec/fixtures/no-message.json
41
+ - spec/fixtures/non-document-error.json
42
+ - spec/fixtures/precise-error.json
43
+ - spec/fixtures/range-error.json
44
+ - spec/fixtures/warning.json
45
+ - spec/spec_helper.rb
46
+ - spec/validator_spec.rb
47
+ - test/helper.rb
48
+ - test/test_validator.nu.rb
49
+ - validator.nu.gemspec
50
+ has_rdoc: true
51
+ homepage: http://github.com/davidjrice/validator.nu
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: ruby client library for the validator.nu HTML5 validation API
80
+ test_files:
81
+ - spec/spec_helper.rb
82
+ - spec/validator_spec.rb
83
+ - test/helper.rb
84
+ - test/test_validator.nu.rb