lib/nunchaku/checker.rb in nunchaku-0.1.1 vs lib/nunchaku/checker.rb in nunchaku-0.2.0

- old
+ new

@@ -1,21 +1,22 @@ require 'httparty' require 'json' module Nunchaku class Checker - attr_reader :url, :checker_uri + attr_reader :url, :checker_uri, :user_agent def initialize(url, options = {}) options = defaults.merge(options) @url = url @checker_uri = options[:checker_uri] + @user_agent = options[:user_agent] end def raw - @raw ||= JSON.parse HTTParty.get("#{checker_uri}?out=json&doc=#{@url}").body + @raw ||= JSON.parse vnu_request end def messages @messages ||= raw['messages'].map { |message| Nunchaku::Message.new(message) } end @@ -27,9 +28,19 @@ def warnings messages.select { |message| message.subtype == 'warning' } end private + + def vnu_request + HTTParty.get(vnu_request_querystring).body + end + + def vnu_request_querystring + s = "#{checker_uri}?out=json&doc=#{@url}" + s += "&useragent=#{@user_agent}" if @user_agent + s + end def defaults { checker_uri: 'http://validator.w3.org/nu/' } end end