Skip to content

Instantly share code, notes, and snippets.

@fltiago
Created October 8, 2012 18:10
Show Gist options
  • Save fltiago/3853980 to your computer and use it in GitHub Desktop.
Save fltiago/3853980 to your computer and use it in GitHub Desktop.
require "debugger"
class Wally < Grape::API
format :json
helpers do
def current_user
@current_user ||= Author.find_by(token: params[:token])
end
def authorize!(action)
error!('401 Unauthorized', 401) unless current_user and permit.able_to?(:read, action)
end
def permit
@permit ||= Permit::Mechanism.new(:subject_id => current_user.subject_permit, :service_name => "wally")
end
end
resource :walls do
params do
requires :token, type: String, desc: "Your api token."
end
get ':resource_id' do
authorize!(params[:resource_id])
...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment