Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
vcooline wshop api
# app/grape/api.rb
###
# http://intridea.github.io/grape/docs/index.html
# http://blog.brunoscopelliti.com/authentication-to-a-restful-web-service-in-an-angularjs-web-app
# http://stackoverflow.com/questions/21255203/angularjs-clientside-routing-and-token-authentication-with-webapi
###
class API < Grape::API
  # prefix "api"
  # version 'v1'
  format :json

  rescue_from :all do |e|
    Rack::Response.new([ e.message ], 500, { "Content-type" => "text/error" }).finish
  end

  helpers do
    def session
      env[Rack::Session::Abstract::ENV_SESSION_KEY]
    end
  end
  helpers ApiAuthorization

  desc "test interface"
  get :hello do
    {hello: "world"}
  end

  # curl -H 'Wx-Mp-User-Id:mp_uid_filler' -H 'Wx-User-Id:uid_filler' localhost:3000/api/oauth_test
  get :oauth_test do
    authenticate!
    {authorization: "success"}
  end

end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment