nunchaku 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ddf5bc35da29a3edf8f2a56e1b574440bff21ff
4
- data.tar.gz: adb9b9f66db78361eb081d2b24d8cb5a91bf06c4
3
+ metadata.gz: f7a9c94be805b03ab590a70c96432eb9356cfd81
4
+ data.tar.gz: 35b618607ae4b266c48b7076337a56ec0b57c9b9
5
5
  SHA512:
6
- metadata.gz: 26884c9fb005cc9d5d705ad3b0e5048958c18ab669b18ad70d792f104b40071f390c500721325bfb7e8baa0774f1af585cd8fae7b886a9b1f2920e13dff1b0ad
7
- data.tar.gz: d7e97333fd2f5390a893d68a9f1db22ce2160ccc1cede513af58962f08ca7f6109282e0aa26caa291eb52c0476eb8758f12d05daf698a1e22a3fa600a00cfa4e
6
+ metadata.gz: 850c2993cb704bb796b92d30897324a7c85c8147dc669cf95de067039ad82f24d133d32065896327df271d0bfc258b1fba016070806b15c4b22e16478f342dc4
7
+ data.tar.gz: d424456741d35d9905a3ef3709b16f74cd5d5a68ec0556fbefc9945721e66dcaa5d2bcd629e187a248cd945ecf9f7e7c56e72ef07f52f2fd8710c4d591bb5d15
data/README.md CHANGED
@@ -71,6 +71,14 @@ By default, Nunchaku will query the Nu HTML Checker at http://validator.w3.org/n
71
71
  Nunchaku.check('http://example.com', checker_uri: 'http://yourchecker.com')
72
72
  ```
73
73
 
74
+ ## Specifying a custom User-Agent string
75
+
76
+ If you want to specify a custom User-Agent string so that the Nu HTML Checker presents itself as another agent, you can do it like this:
77
+
78
+ ```ruby
79
+ Nunchaku.check('http://example.com', user_agent: 'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0')
80
+ ```
81
+
74
82
  ## Development
75
83
 
76
84
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -3,17 +3,18 @@ require 'json'
3
3
 
4
4
  module Nunchaku
5
5
  class Checker
6
- attr_reader :url, :checker_uri
6
+ attr_reader :url, :checker_uri, :user_agent
7
7
 
8
8
  def initialize(url, options = {})
9
9
  options = defaults.merge(options)
10
10
 
11
11
  @url = url
12
12
  @checker_uri = options[:checker_uri]
13
+ @user_agent = options[:user_agent]
13
14
  end
14
15
 
15
16
  def raw
16
- @raw ||= JSON.parse HTTParty.get("#{checker_uri}?out=json&doc=#{@url}").body
17
+ @raw ||= JSON.parse vnu_request
17
18
  end
18
19
 
19
20
  def messages
@@ -30,6 +31,16 @@ module Nunchaku
30
31
 
31
32
  private
32
33
 
34
+ def vnu_request
35
+ HTTParty.get(vnu_request_querystring).body
36
+ end
37
+
38
+ def vnu_request_querystring
39
+ s = "#{checker_uri}?out=json&doc=#{@url}"
40
+ s += "&useragent=#{@user_agent}" if @user_agent
41
+ s
42
+ end
43
+
33
44
  def defaults
34
45
  { checker_uri: 'http://validator.w3.org/nu/' }
35
46
  end
@@ -1,3 +1,3 @@
1
1
  module Nunchaku
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nunchaku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime Iniesta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty