Sha256: 1592d30962d2f04bb84e3027d72ba4e38d6550e22c28d55bc9519c9f1326863e
Contents?: true
Size: 862 Bytes
Versions: 7
Compression:
Stored size: 862 Bytes
Contents
module ApiHelpers def current_user params[:api_key].present? && @user = User.find_by_authentication_token(params[:api_key]) end def authenticate! unauthenticated! unless login_request? || current_user end def login_request? self.method_name.start_with?('POST') && self.namespace == '/sessions' end # returns an 'unauthenticated' response def unauthenticated!(error_type = nil) respond_error!('unauthenticated', 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
7 entries across 7 versions & 1 rubygems