Class: Committee::ResponseValidator
- Inherits:
-
Object
- Object
- Committee::ResponseValidator
- Defined in:
- lib/committee/response_validator.rb
Instance Method Summary collapse
- #call(headers, data) ⇒ Object
-
#initialize(link) ⇒ ResponseValidator
constructor
A new instance of ResponseValidator.
Constructor Details
#initialize(link) ⇒ ResponseValidator
Returns a new instance of ResponseValidator.
3 4 5 6 |
# File 'lib/committee/response_validator.rb', line 3 def initialize(link) @link = link @validator = JsonSchema::Validator.new(link.parent) end |
Instance Method Details
#call(headers, data) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/committee/response_validator.rb', line 8 def call(headers, data) check_content_type!(headers) if @link.rel == "instances" if !data.is_a?(Array) raise InvalidResponse, "List endpoints must return an array of objects." end # only consider the first object during the validation from here on data = data[0] end if !@validator.validate(data) errors = (@validator.errors).join("\n") raise InvalidResponse, "Invalid response.\n\n#{errors}" end end |