Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
Created April 9, 2014 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhjguxin/10229720 to your computer and use it in GitHub Desktop.
Save jhjguxin/10229720 to your computer and use it in GitHub Desktop.
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