Class: RackJwtAegis::ResponseBuilder
- Inherits:
-
Object
- Object
- RackJwtAegis::ResponseBuilder
- Defined in:
- lib/rack_jwt_aegis/response_builder.rb
Overview
Instance Method Summary collapse
- #error_response(message, status_code) ⇒ Object
- #forbidden_response(message = nil) ⇒ Object
-
#initialize(config) ⇒ ResponseBuilder
constructor
A new instance of ResponseBuilder.
- #unauthorized_response(message = nil) ⇒ Object
Constructor Details
#initialize(config) ⇒ ResponseBuilder
Returns a new instance of ResponseBuilder.
7 8 9 |
# File 'lib/rack_jwt_aegis/response_builder.rb', line 7 def initialize(config) @config = config end |
Instance Method Details
#error_response(message, status_code) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rack_jwt_aegis/response_builder.rb', line 25 def error_response(, status_code) response_body = build_error_body(, status_code) [ status_code, { 'Content-Type' => 'application/json', 'Content-Length' => response_body.bytesize.to_s, 'Cache-Control' => 'no-cache, no-store, must-revalidate', 'Pragma' => 'no-cache', 'Expires' => '0', }, [response_body], ] end |
#forbidden_response(message = nil) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/rack_jwt_aegis/response_builder.rb', line 18 def forbidden_response( = nil) error_response( || @config.forbidden_response[:error] || 'Access denied', 403, ) end |
#unauthorized_response(message = nil) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/rack_jwt_aegis/response_builder.rb', line 11 def ( = nil) error_response( || @config.[:error] || 'Authentication required', 401, ) end |