Class: AlphaApi::BaseController
- Inherits:
-
ActionController::API
- Object
- ActionController::API
- AlphaApi::BaseController
- Defined in:
- lib/alpha_api/base_controller.rb
Instance Attribute Summary collapse
-
#current_auth_token ⇒ Object
readonly
Returns the value of attribute current_auth_token.
-
#current_auth_token_payload ⇒ Object
readonly
Returns the value of attribute current_auth_token_payload.
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
Instance Method Summary collapse
- #error_generator(title, detail, source = nil) ⇒ Object
- #method_not_allowed ⇒ Object (also: #create, #destroy, #index, #update)
- #not_found ⇒ Object (also: #show)
- #unsupported_media_type ⇒ Object
- #version ⇒ Object
Instance Attribute Details
#current_auth_token ⇒ Object (readonly)
Returns the value of attribute current_auth_token.
55 56 57 |
# File 'lib/alpha_api/base_controller.rb', line 55 def current_auth_token @current_auth_token end |
#current_auth_token_payload ⇒ Object (readonly)
Returns the value of attribute current_auth_token_payload.
55 56 57 |
# File 'lib/alpha_api/base_controller.rb', line 55 def current_auth_token_payload @current_auth_token_payload end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
55 56 57 |
# File 'lib/alpha_api/base_controller.rb', line 55 def current_user @current_user end |
Instance Method Details
#error_generator(title, detail, source = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/alpha_api/base_controller.rb', line 57 def error_generator(title, detail, source = nil) error = { title: title, detail: detail } if source key_mapper = { organisation: 'organisation_id', splash: 'splash_id', box_hardware: 'box_hardware_id' } error[:source] = { pointer: "/data/attributes/#{key_mapper[source] || source}" } end error end |
#method_not_allowed ⇒ Object Also known as: create, destroy, index, update
82 83 84 85 86 87 88 |
# File 'lib/alpha_api/base_controller.rb', line 82 def method_not_allowed error = error_generator( 'Method Not Allowed', "Method #{request.method} is not allowed on #{request.path}" ) render json: { errors: [error] }, status: :method_not_allowed end |
#not_found ⇒ Object Also known as: show
74 75 76 77 78 79 80 |
# File 'lib/alpha_api/base_controller.rb', line 74 def not_found error = error_generator( 'Not Found', "Resource #{request.path} is not found" ) render json: { errors: [error] }, status: :not_found end |
#unsupported_media_type ⇒ Object
70 71 72 |
# File 'lib/alpha_api/base_controller.rb', line 70 def unsupported_media_type head :unsupported_media_type end |
#version ⇒ Object
96 97 98 |
# File 'lib/alpha_api/base_controller.rb', line 96 def version render json: Constants::VERSION end |