socialforge/app/api/mobile/apis/users.rb

39 lines
898 B
Ruby
Raw Normal View History

2014-11-27 19:43:04 +08:00
module Mobile
module Apis
2014-11-27 19:43:04 +08:00
class Users < Grape::API
resource :users do
desc "get all users"
get do
['hello']
end
2014-12-04 10:11:55 +08:00
2014-11-27 19:43:04 +08:00
desc "add a user"
params do
requires :login, type: String, desc: 'username'
2014-12-07 10:48:05 +08:00
requires :mail, type: String, desc: 'mail'
2014-11-27 19:43:04 +08:00
requires :password, type: String, desc: 'password'
end
post do
2014-12-07 10:48:05 +08:00
us = UsersService.new
2014-12-04 10:11:55 +08:00
begin
2014-12-07 10:48:05 +08:00
user = us.register params.merge(:password_confirmation => params[:password],
:should_confirmation_password => true)
2014-12-08 15:27:18 +08:00
raise "register failed #{user.errors.full_messages}" if user.new_record?
2014-12-04 10:11:55 +08:00
{status: 0, data: user}
2014-12-07 10:48:05 +08:00
rescue => e
2014-12-04 10:11:55 +08:00
{status: 1, message: e.message}
2014-11-27 19:43:04 +08:00
end
end
desc "test upload"
post "upload" do
puts "haha11"
end
2014-11-27 19:43:04 +08:00
end
end
end
2014-11-27 19:43:04 +08:00
end