Class: Datadome::ValidationResponse
- Inherits:
-
Object
- Object
- Datadome::ValidationResponse
- Defined in:
- lib/datadome/validation_response.rb
Instance Attribute Summary collapse
-
#pass ⇒ Object
Returns the value of attribute pass.
-
#redirect ⇒ Object
Returns the value of attribute redirect.
-
#redirection_location ⇒ Object
Returns the value of attribute redirection_location.
-
#request_headers ⇒ Object
Returns the value of attribute request_headers.
-
#response_body ⇒ Object
Returns the value of attribute response_body.
-
#response_headers ⇒ Object
Returns the value of attribute response_headers.
-
#response_status ⇒ Object
Returns the value of attribute response_status.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ ValidationResponse
constructor
A new instance of ValidationResponse.
- #to_rack_response ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ ValidationResponse
Returns a new instance of ValidationResponse.
44 45 46 47 48 49 50 51 |
# File 'lib/datadome/validation_response.rb', line 44 def initialize(attrs = {}) self.request_headers = {} self.response_headers = {} attrs.each do |key, value| public_send("#{key}=", value) end end |
Instance Attribute Details
#pass ⇒ Object
Returns the value of attribute pass.
41 42 43 |
# File 'lib/datadome/validation_response.rb', line 41 def pass @pass end |
#redirect ⇒ Object
Returns the value of attribute redirect.
41 42 43 |
# File 'lib/datadome/validation_response.rb', line 41 def redirect @redirect end |
#redirection_location ⇒ Object
Returns the value of attribute redirection_location.
42 43 44 |
# File 'lib/datadome/validation_response.rb', line 42 def redirection_location @redirection_location end |
#request_headers ⇒ Object
Returns the value of attribute request_headers.
42 43 44 |
# File 'lib/datadome/validation_response.rb', line 42 def request_headers @request_headers end |
#response_body ⇒ Object
Returns the value of attribute response_body.
42 43 44 |
# File 'lib/datadome/validation_response.rb', line 42 def response_body @response_body end |
#response_headers ⇒ Object
Returns the value of attribute response_headers.
42 43 44 |
# File 'lib/datadome/validation_response.rb', line 42 def response_headers @response_headers end |
#response_status ⇒ Object
Returns the value of attribute response_status.
42 43 44 |
# File 'lib/datadome/validation_response.rb', line 42 def response_status @response_status end |
Class Method Details
.from_faraday_response(response) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/datadome/validation_response.rb', line 12 def from_faraday_response(response) validation_response = if response.status == 403 new(pass: false, redirect: false, response_status: 403, response_body: response.body) elsif response.status == 301 || response.status == 302 new(pass: false, redirect: true, response_status: response.status, redirection_location: response.headers["Location"]) else pass end parse_headers_list(response.headers["X-DataDome-request-headers"]).each do |key| validation_response.request_headers[key] = response.headers[key] end parse_headers_list(response.headers["X-DataDome-headers"]).each do |key| validation_response.response_headers[key] = response.headers[key] end validation_response end |
.parse_headers_list(list) ⇒ Object
33 34 35 36 37 |
# File 'lib/datadome/validation_response.rb', line 33 def parse_headers_list(list) return [] if list.nil? || list == "" list.split(" ") end |
.pass ⇒ Object
8 9 10 |
# File 'lib/datadome/validation_response.rb', line 8 def pass new(pass: true, redirect: false) end |
Instance Method Details
#to_rack_response ⇒ Object
53 54 55 56 57 58 |
# File 'lib/datadome/validation_response.rb', line 53 def to_rack_response response = ::Rack::Response.new(@response_body || [], @response_status, @response_headers) response.redirect(@redirection_location, @response_status) if @redirect response.finish end |