Class: LivingValidator::Validator
- Inherits:
-
Object
- Object
- LivingValidator::Validator
- Defined in:
- lib/living-validator.rb
Overview
Validator class. Should be accesses statically
Class Method Summary collapse
-
.check(url, options = {}) ⇒ LivingValidator::Result, boolean
Perform the validation on a given URL against the validator endpoint.
Class Method Details
.check(url, options = {}) ⇒ LivingValidator::Result, boolean
Perform the validation on a given URL against the validator endpoint. Has two options ‘:endpoint` and `:lax_type`. The endpoint option configures where the validator instance is running. It defaults to validator.nu. The lax type option allows for lax type checking. The default for this is false. Make sure to test the result of this method for a false falue as this is the failure output.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/living-validator.rb', line 34 def self.check(url, = {}) # Determine the endpoint url endpoint = [:endpoint] || ENDPOINT # Determine if you should use the lax content type lax_type = [:lax_type] || LAX_TYPE # Build the URL to query the validator req_url = 'http://' + endpoint + '/?out=json' + ((lax_type)? '&laxtype=yes':'') + '&doc=' + CGI::escape(url.to_s) # Query the validator response = false begin req_uri = URI.parse(req_url) response = HTTParty.get(req_url) response = JSON.parse(response.body) rescue response = false end # Build a results object if the query succeeded unless response == false result = Result.new(url.to_s, response['messages']) response = result end # Return the results object response end |