Skip to content

Instantly share code, notes, and snippets.

@oivoodoo
Created July 23, 2014 19:58
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 oivoodoo/bbde1e9f7f26a8e9bc4a to your computer and use it in GitHub Desktop.
Save oivoodoo/bbde1e9f7f26a8e9bc4a to your computer and use it in GitHub Desktop.
class Api::Client::V1::Users < Grape::API
resources :users do
RegistrationSteps = [
->(user) { FollowersPopulationService.new(user).create },
->(user) { TimelinesRegistrationService.new(user).create },
]
params do
requires :auth_token, type: String, desc: "Auth token picked up on the user activity on the device"
end
post '/facebook', rabl: 'v1/users/facebook' do
begin
@user = User.find_or_create_by_facebook_auth_token(params[:auth_token])
unless @user.present?
throw :error, status: 403, message: 'Invalid facebook auth token'
end
RegistrationSteps.each do |step|
step.call(@user)
end
# @note lets try to collect information about the user as soon as
# possible.
Facebook::Feed::UserWorker.perform_async(@user.id, { months: 24 })
rescue => boom
Airbrake.notify(boom, parameters: params)
throw :error, status: 400, message: boom.message
end
end
end # auth
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment