Sha256: 9a718f4bc33c12cb123a119fed3ecc44cfce5ffaca150cccdbef4d50cf14530c
Contents?: true
Size: 822 Bytes
Versions: 2
Compression:
Stored size: 822 Bytes
Contents
module ApiHelpers include IntrospectiveGrape::CamelSnake def warden env['warden'] end def current_user warden.user || params[:api_key].present? && @user = User.find_by_authentication_token(params[:api_key]) end def authorize! unauthorized! unless current_user end # returns an 'unauthorized' response def unauthorized!(error_type = nil) respond_error!('unauthorized', error_type, 401) end # returns a error response with given type, message_key and status def respond_error!(type, message_key, status = 500, other = {}) e = { type: type, status: status } e['message_key'] = message_key if message_key e.merge!(other) error!({ error: e }, status) end private def safe_params(params) ActionController::Parameters.new(params) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
introspective_grape-0.0.4 | spec/dummy/app/api/api_helpers.rb |
introspective_grape-0.0.3 | spec/dummy/app/api/api_helpers.rb |