Class: Fitting::Response
- Inherits:
-
Object
- Object
- Fitting::Response
- Defined in:
- lib/fitting/response.rb
Defined Under Namespace
Classes: NotDocumented, Unsuitable
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#schemas ⇒ Object
Returns the value of attribute schemas.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(env_response, expect_request) ⇒ Response
constructor
A new instance of Response.
- #set_fully_validate ⇒ Object
- #to_hash ⇒ Object
- #valid! ⇒ Object
- #validate? ⇒ Boolean
Constructor Details
#initialize(env_response, expect_request) ⇒ Response
Returns a new instance of Response.
8 9 10 11 12 13 14 15 |
# File 'lib/fitting/response.rb', line 8 def initialize(env_response, expect_request) @status = env_response.status @body = env_response.body @schemas = expect_request.find_responses(status: @status).map{|response|response['body']} if expect_request @fully_validates = set_fully_validate if @schemas raise Response::NotDocumented unless (@schemas && @schemas.first) || Fitting.configuration.skip_not_documented self end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/fitting/response.rb', line 3 def body @body end |
#schemas ⇒ Object
Returns the value of attribute schemas.
3 4 5 |
# File 'lib/fitting/response.rb', line 3 def schemas @schemas end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/fitting/response.rb', line 3 def status @status end |
Instance Method Details
#set_fully_validate ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fitting/response.rb', line 21 def set_fully_validate @valid = false fully_validates = [] @schemas.map do |old_schema| fully_validate = JSON::Validator.fully_validate(old_schema, @body) fully_validates.push(fully_validate) @valid = true if fully_validate == [] end fully_validates end |
#to_hash ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/fitting/response.rb', line 36 def to_hash { 'status' => @status, 'body' => @body, 'schemas' => @schemas, 'fully_validates' => @fully_validates, 'valid' => @valid } end |
#valid! ⇒ Object
17 18 19 |
# File 'lib/fitting/response.rb', line 17 def valid! raise Unsuitable unless @valid end |
#validate? ⇒ Boolean
32 33 34 |
# File 'lib/fitting/response.rb', line 32 def validate? @schemas && @schemas.first && Fitting.configuration.validation_response end |