42 lines
924 B
Ruby
42 lines
924 B
Ruby
module Mobile
|
|
|
|
class API < Grape::API
|
|
version 'v1', using: :path
|
|
format :json
|
|
content_type :json, "application/json;charset=UTF-8"
|
|
use Mobile::Middleware::ErrorHandler
|
|
|
|
helpers do
|
|
def logger
|
|
API.logger
|
|
end
|
|
|
|
def authenticate!
|
|
raise('Unauthorized. Invalid or expired token.') 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
|
|
|
|
mount Apis::Auth
|
|
mount Apis::Users
|
|
mount Apis::Courses
|
|
mount Apis::Watches
|
|
mount Apis::Upgrade
|
|
mount Apis::Homeworks
|
|
|
|
#add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'})
|
|
add_swagger_documentation ({api_version: 'v1', base_path: '/api'})
|
|
|
|
end
|
|
end
|
|
|
|
|