| Class | W3CValidators::Validator |
| In: |
lib/w3c_validators/validator.rb
|
| Parent: | Object |
Base class for MarkupValidator and FeedValidator.
| VERSION | = | '0.9.3' |
| USER_AGENT | = | "Ruby W3C Validators/#{Validator::VERSION} (http://code.dunae.ca/w3c_validators/)" |
| HEAD_STATUS_HEADER | = | 'X-W3C-Validator-Status' |
| HEAD_ERROR_COUNT_HEADER | = | 'X-W3C-Validator-Errors' |
| SOAP_OUTPUT_PARAM | = | 'soap12' |
| results | [R] | |
| validator_uri | [R] |
Perform a validation request.
request_mode must be either :get, :head or :post.
Returns Net::HTTPResponse.
# File lib/w3c_validators/validator.rb, line 33
33: def send_request(options, request_mode = :get)
34: response = nil
35: results = nil
36:
37: Net::HTTP.start(@validator_uri.host, @validator_uri.port) do |http|
38: case request_mode
39: when :head
40: # perform a HEAD request
41: raise ArgumentError, "a URI must be provided for HEAD requests." unless options[:uri]
42: query = create_query_string_data(options)
43: response = http.request_head(@validator_uri.path + '?' + query)
44: when :get
45: # send a GET request
46: query = create_query_string_data(options)
47: response = http.get(@validator_uri.path + '?' + query)
48: when :post
49: # send a multipart form request
50: query, boundary = create_multipart_data(options)
51: response = http.post2(@validator_uri.path, query, "Content-type" => "multipart/form-data; boundary=" + boundary)
52: else
53: raise ArgumentError, "request_mode must be either :get, :head or :post"
54: end
55: end
56:
57: response.value
58: return response
59:
60: rescue Exception => e
61: handle_exception e
62: end