2015-04-07 13:47:39 +08:00
|
|
|
module Mobile
|
|
|
|
require_relative 'middleware/error_handler'
|
|
|
|
require_relative 'apis/auth'
|
|
|
|
require_relative 'apis/users'
|
|
|
|
require_relative 'apis/courses'
|
|
|
|
require_relative 'apis/watches'
|
|
|
|
require_relative 'apis/upgrade'
|
|
|
|
require_relative 'apis/homeworks'
|
|
|
|
require_relative 'apis/comments'
|
2016-03-21 18:17:39 +08:00
|
|
|
require_relative 'apis/issues'
|
2016-03-30 10:32:45 +08:00
|
|
|
require_relative 'apis/activities'
|
|
|
|
require_relative 'apis/whomeworks'
|
2016-03-30 15:51:27 +08:00
|
|
|
require_relative 'apis/newss'
|
|
|
|
require_relative 'apis/journal_for_messages'
|
|
|
|
require_relative 'apis/messages'
|
|
|
|
require_relative 'apis/blog_comments'
|
2016-03-21 18:17:39 +08:00
|
|
|
|
2015-04-07 13:47:39 +08:00
|
|
|
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
|
|
|
|
mount Apis::Comments
|
2016-03-21 18:17:39 +08:00
|
|
|
mount Apis::Issues
|
2016-03-30 10:32:45 +08:00
|
|
|
mount Apis::Activities
|
|
|
|
mount Apis::Whomeworks
|
2016-03-30 15:51:27 +08:00
|
|
|
mount Apis::Newss
|
|
|
|
mount Apis::JournalForMessages
|
|
|
|
mount Apis::Messages
|
|
|
|
mount Apis::BlogComments
|
2015-04-07 13:47:39 +08:00
|
|
|
|
|
|
|
#add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'})
|
|
|
|
#add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|