2014-11-27 19:43:04 +08:00
|
|
|
module Mobile
|
|
|
|
|
|
|
|
class API < Grape::API
|
|
|
|
version 'v1', using: :path
|
|
|
|
format :json
|
2014-12-03 17:28:19 +08:00
|
|
|
content_type :json, "application/json;charset=UTF-8"
|
2014-11-27 19:43:04 +08:00
|
|
|
|
|
|
|
helpers do
|
|
|
|
def logger
|
|
|
|
API.logger
|
|
|
|
end
|
|
|
|
|
|
|
|
def authticate!
|
|
|
|
error!('Unauthorized. Invalid or expired token.', 401) unless current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_user
|
|
|
|
token = ApiKey.where(access_token: params[:token]).first
|
|
|
|
if token && !token.expired?
|
|
|
|
@current_user = User.find(token.user_id)
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-12-09 15:16:47 +08:00
|
|
|
mount Apis::Auth
|
|
|
|
mount Apis::Users
|
|
|
|
mount Apis::Courses
|
2014-11-27 19:43:04 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|