validator.nu 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -1,5 +1,9 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
+ require 'yajl/http_stream'
4
+ require 'yajl/gzip'
5
+ require 'yajl/deflate'
6
+
3
7
  require 'net/http'
4
8
  require 'cgi'
5
9
  require 'uri'
@@ -44,12 +48,13 @@ module Validator
44
48
  HOST = "validator.nu"
45
49
  GZIP = false
46
50
  PORT = 80
51
+ LAX_CONTENT_TYPE = false
47
52
 
48
53
  def nu(uri_or_document, options={})
49
54
  if uri_or_document.kind_of?(URI::HTTP)
50
- get(uri_or_document, options)
55
+ get(uri_or_document, options)
51
56
  else
52
- post(uri_or_document, options)
57
+ post(uri_or_document, options)
53
58
  end
54
59
  end
55
60
 
@@ -63,20 +68,28 @@ module Validator
63
68
  begin
64
69
  host = options[:host] || HOST
65
70
  port = options[:port] || PORT
66
- http = Net::HTTP.new(host, port)
67
- uri = "/?&doc=#{CGI::escape(url.to_s)}&out=json"
68
-
69
- response = http.start do |http|
70
- http.get(uri)
71
- end
71
+ laxtype = options[:lax_content_type] || LAX_CONTENT_TYPE
72
+
73
+ # http = Net::HTTP.new(host, port)
74
+ uri = "http://#{host}/?&doc=#{CGI::escape(url.to_s)}&out=json"
75
+ uri += "&laxtype=yes" if laxtype
76
+ url = URI.parse uri
77
+ #STDERR.puts url
78
+ #url.port = port
72
79
 
73
- if response.kind_of? Net::HTTPSuccess
74
- return response.body
75
- else
76
- STDERR.puts response.body.inspect
77
- raise RemoteException.new("#{response.code}: #{response.message}")
78
- end
79
-
80
+ return Yajl::HttpStream.get(url)
81
+
82
+ # response = http.start do |http|
83
+ # http.get(url.path)
84
+ # end
85
+ #
86
+ # if response.kind_of? Net::HTTPSuccess
87
+ # return response.body
88
+ # else
89
+ # STDERR.puts response.body.inspect
90
+ # raise RemoteException.new("#{response.code}: #{response.message}")
91
+ # end
92
+ #
80
93
  rescue Exception => e
81
94
  STDERR.puts "Error contacting validator.nu: #{e}"
82
95
  STDERR.puts e.backtrace.join("\n"), 'debug'
@@ -91,6 +104,7 @@ module Validator
91
104
  content_type = options[:content_type] || CONTENT_TYPE
92
105
  content_encoding = options[:content_encoding] || CONTENT_ENCODING
93
106
  gzip = options[:gzip] || GZIP
107
+ laxtype = options[:lax_content_type] || LAX_CONTENT_TYPE
94
108
 
95
109
  if gzip
96
110
  content_encoding = 'gzip'
@@ -103,6 +117,7 @@ module Validator
103
117
 
104
118
  http = Net::HTTP.new(host, port)
105
119
  uri = "/?out=json"
120
+ uri += "&laxtype=yes" if laxtype
106
121
  headers = { 'Content-Type' => content_type, 'Content-Encoding' => content_encoding }
107
122
 
108
123
  response = http.start do |http|
@@ -1 +1 @@
1
- {"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}]}
1
+ {"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 & error</p>\n</b","hiliteStart":15,"hiliteLength":1}]}
@@ -1 +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}]}
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 & error</p>\n</b","hiliteStart":15,"hiliteLength":1}]}
@@ -1 +1 @@
1
- {"messages":[{"type":"info","message":"The Content-Type was “text/html”. Using the HTML parser."},{"type":"info","message":"Using the schema for HTML5+ARIA (experimental)."}]}
1
+ {"messages":[{"type":"info","message":"The Content-Type was “text/html”. Using the HTML parser."},{"type":"info","message":"Using the schema for HTML5+ARIA, SVG 1.1 plus MathML 2.0 (experimental)."}]}
@@ -1 +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)."}]}
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, SVG 1.1 plus MathML 2.0 (experimental)."}]}
@@ -1 +1 @@
1
- {"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}]}
1
+ {"messages":[{"type":"info","message":"The Content-Type was “text/html”. Using the HTML parser."},{"type":"info","message":"Using the schema for HTML5+ARIA, SVG 1.1 plus MathML 2.0 (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>\n</body>\n","hiliteStart":15,"hiliteLength":1}]}
@@ -1 +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}]}
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, SVG 1.1 plus MathML 2.0 (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>\n</body>\n","hiliteStart":15,"hiliteLength":1}]}
@@ -1 +1 @@
1
- {"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}]}
1
+ {"messages":[{"type":"info","message":"The Content-Type was “text/html”. Using the HTML parser."},{"type":"info","message":"Using the schema for HTML5+ARIA, SVG 1.1 plus MathML 2.0 (experimental)."},{"type":"error","lastLine":7,"lastColumn":13,"firstColumn":10,"message":"End tag “p” seen, but there were open elements.","extract":"\n<p><span></p>\n</bod","hiliteStart":10,"hiliteLength":4},{"type":"error","lastLine":7,"lastColumn":9,"firstColumn":4,"message":"Unclosed element “span”.","extract":"<body>\n<p><span></p>\n<","hiliteStart":10,"hiliteLength":6}]}
@@ -1 +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}]}
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, SVG 1.1 plus MathML 2.0 (experimental)."},{"type":"error","lastLine":7,"lastColumn":13,"firstColumn":10,"message":"End tag “p” seen, but there were open elements.","extract":"\n<p><span></p>\n</bod","hiliteStart":10,"hiliteLength":4},{"type":"error","lastLine":7,"lastColumn":9,"firstColumn":4,"message":"Unclosed element “span”.","extract":"<body>\n<p><span></p>\n<","hiliteStart":10,"hiliteLength":6}]}
@@ -1 +1 @@
1
- {"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}]}
1
+ {"messages":[{"type":"info","message":"The Content-Type was “text/html”. Using the HTML parser."},{"type":"info","message":"Using the schema for HTML5+ARIA, SVG 1.1 plus MathML 2.0 (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></p>\n</bod","hiliteStart":15,"hiliteLength":1}]}
@@ -1 +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}]}
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, SVG 1.1 plus MathML 2.0 (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></p>\n</bod","hiliteStart":15,"hiliteLength":1}]}
@@ -1,2 +1,4 @@
1
1
  require 'rubygems'
2
2
  require File.dirname(__FILE__) + '/../lib/validator.nu.rb'
3
+
4
+ require 'yajl'
@@ -58,7 +58,11 @@ describe Validator do
58
58
  end
59
59
 
60
60
  it "should receive a fatal error result" do
61
- fixture = File.open("#{File.dirname(__FILE__)}/fixtures/fatal-error.json").read
61
+ # fixture = File.open("#{File.dirname(__FILE__)}/fixtures/fatal-error.json").read
62
+ file = File.new("#{File.dirname(__FILE__)}/fixtures/fatal-error.json", 'r')
63
+ parser = Yajl::Parser.new
64
+ fixture = parser.parse(file)
65
+
62
66
  Validator.nu(
63
67
  URI.parse("http://hsivonen.iki.fi/test/moz/messages-types/fatal.xhtml")
64
68
  ).should == fixture
@@ -1,72 +1,63 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{validator.nu}
8
- s.version = "0.0.4"
7
+ s.name = "validator.nu"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Rice"]
12
- s.date = %q{2010-04-16}
13
- s.description = %q{ruby client library for the validator.nu HTML5 validation API}
14
- s.email = %q{me@davidjrice.co.uk}
12
+ s.date = "2011-10-12"
13
+ s.description = "ruby client library for the validator.nu HTML5 validation API"
14
+ s.email = "me@davidjrice.co.uk"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/validator.nu.rb",
27
- "spec/fixtures/fatal-error-post.json",
28
- "spec/fixtures/fatal-error.html",
29
- "spec/fixtures/fatal-error.json",
30
- "spec/fixtures/info-post.json",
31
- "spec/fixtures/info.json",
32
- "spec/fixtures/info.svg",
33
- "spec/fixtures/no-message-post.json",
34
- "spec/fixtures/no-message.html",
35
- "spec/fixtures/no-message.json",
36
- "spec/fixtures/non-document-error-post.json",
37
- "spec/fixtures/non-document-error.json",
38
- "spec/fixtures/precise-error-post.json",
39
- "spec/fixtures/precise-error.html",
40
- "spec/fixtures/precise-error.json",
41
- "spec/fixtures/range-error-post.json",
42
- "spec/fixtures/range-error.html",
43
- "spec/fixtures/range-error.json",
44
- "spec/fixtures/warning-post.json",
45
- "spec/fixtures/warning.html",
46
- "spec/fixtures/warning.json",
47
- "spec/spec_helper.rb",
48
- "spec/validator_spec.rb",
49
- "test/helper.rb",
50
- "test/test_validator.nu.rb",
51
- "validator.nu.gemspec"
52
- ]
53
- s.homepage = %q{http://github.com/davidjrice/validator.nu}
54
- s.rdoc_options = ["--charset=UTF-8"]
55
- s.require_paths = ["lib"]
56
- s.rubygems_version = %q{1.3.6}
57
- s.summary = %q{ruby client library for the validator.nu HTML5 validation API}
58
- s.test_files = [
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/validator.nu.rb",
26
+ "spec/fixtures/fatal-error-post.json",
27
+ "spec/fixtures/fatal-error.html",
28
+ "spec/fixtures/fatal-error.json",
29
+ "spec/fixtures/info-post.json",
30
+ "spec/fixtures/info.json",
31
+ "spec/fixtures/info.svg",
32
+ "spec/fixtures/no-message-post.json",
33
+ "spec/fixtures/no-message.html",
34
+ "spec/fixtures/no-message.json",
35
+ "spec/fixtures/non-document-error-post.json",
36
+ "spec/fixtures/non-document-error.json",
37
+ "spec/fixtures/precise-error-post.json",
38
+ "spec/fixtures/precise-error.html",
39
+ "spec/fixtures/precise-error.json",
40
+ "spec/fixtures/range-error-post.json",
41
+ "spec/fixtures/range-error.html",
42
+ "spec/fixtures/range-error.json",
43
+ "spec/fixtures/warning-post.json",
44
+ "spec/fixtures/warning.html",
45
+ "spec/fixtures/warning.json",
59
46
  "spec/spec_helper.rb",
60
- "spec/validator_spec.rb",
61
- "test/helper.rb",
62
- "test/test_validator.nu.rb"
47
+ "spec/validator_spec.rb",
48
+ "test/helper.rb",
49
+ "test/test_validator.nu.rb",
50
+ "validator.nu.gemspec"
63
51
  ]
52
+ s.homepage = "http://github.com/davidjrice/validator.nu"
53
+ s.require_paths = ["lib"]
54
+ s.rubygems_version = "1.8.10"
55
+ s.summary = "ruby client library for the validator.nu HTML5 validation API"
64
56
 
65
57
  if s.respond_to? :specification_version then
66
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
67
58
  s.specification_version = 3
68
59
 
69
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
60
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
70
61
  else
71
62
  end
72
63
  else
metadata CHANGED
@@ -1,35 +1,25 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: validator.nu
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 4
9
- version: 0.0.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - David Rice
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-04-16 00:00:00 +01:00
18
- default_executable:
12
+ date: 2011-10-12 00:00:00.000000000Z
19
13
  dependencies: []
20
-
21
14
  description: ruby client library for the validator.nu HTML5 validation API
22
15
  email: me@davidjrice.co.uk
23
16
  executables: []
24
-
25
17
  extensions: []
26
-
27
- extra_rdoc_files:
18
+ extra_rdoc_files:
28
19
  - LICENSE
29
20
  - README.rdoc
30
- files:
21
+ files:
31
22
  - .document
32
- - .gitignore
33
23
  - LICENSE
34
24
  - README.rdoc
35
25
  - Rakefile
@@ -60,38 +50,28 @@ files:
60
50
  - test/helper.rb
61
51
  - test/test_validator.nu.rb
62
52
  - validator.nu.gemspec
63
- has_rdoc: true
64
53
  homepage: http://github.com/davidjrice/validator.nu
65
54
  licenses: []
66
-
67
55
  post_install_message:
68
- rdoc_options:
69
- - --charset=UTF-8
70
- require_paths:
56
+ rdoc_options: []
57
+ require_paths:
71
58
  - lib
72
- required_ruby_version: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- segments:
77
- - 0
78
- version: "0"
79
- required_rubygems_version: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- segments:
84
- - 0
85
- version: "0"
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
86
71
  requirements: []
87
-
88
72
  rubyforge_project:
89
- rubygems_version: 1.3.6
73
+ rubygems_version: 1.8.10
90
74
  signing_key:
91
75
  specification_version: 3
92
76
  summary: ruby client library for the validator.nu HTML5 validation API
93
- test_files:
94
- - spec/spec_helper.rb
95
- - spec/validator_spec.rb
96
- - test/helper.rb
97
- - test/test_validator.nu.rb
77
+ test_files: []
data/.gitignore DELETED
@@ -1,21 +0,0 @@
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