Class: FacebookAccountsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/facebook_accounts_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::APP_DOMAIN

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #canonical_url, #check_domain, #ensure_domain, #get_notice

Instance Method Details

#callbackObject


8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/facebook_accounts_controller.rb', line 8

def callback
  if params[:error_reason] && !params[:error_reason].empty?    # We have a problem!

    redirect_to(:root, :notice => "Unable to activate facebook: #{params[:error_reason]}")
  elsif params[:code] && !params[:code].empty?    # This is the callback, we have an id and an access code

     = FacebookAccount.find(params[:id])
    .validate_oauth_token(params[:code], facebook_callback_url(:id => .id))
    redirect_to("#{root_url}admin/users/#{current_user.id}", :notice => 'Facebook account activated! You will need to resend the last post.')
  end
end

#destroyObject


32
33
34
35
36
37
38
39
40
# File 'app/controllers/facebook_accounts_controller.rb', line 32

def destroy
  @account = FacebookAccount.find(params[:id])
  @account.destroy

  respond_to do |format|
    format.html {redirect_to("#{root_url}admin/users/#{current_user.id}", :notice => 'Facebook Account destroyed!')}
    format.xml  { head :ok }
  end
end

#newObject


3
4
5
6
# File 'app/controllers/facebook_accounts_controller.rb', line 3

def new
   = FacebookAccount.create(:user => current_user)
  redirect_to(.authorize_url(facebook_callback_url(:id => .id)))
end

#send_wall_postObject


20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/facebook_accounts_controller.rb', line 20

def send_wall_post
   = FacebookAccount.find_by_user_id(current_user.id)
  if .blank?
     = FacebookAccount.create(:user_id => current_user.id)
    redirect_to(.authorize_url(facebook_callback_url(:id => .id)))
  else
    link = ShortLink.shorten_link("#{root_url}animals/#{params[:animal_uuid]}")
    FacebookAccount.post("#{params[:animal_name]} is ready for adoption at #{link} via @hospitium_app.", current_user.id)
    redirect_to("#{root_url}admin/animals/#{params[:animal_id]}-#{params[:animal_uuid]}", :notice => 'Facebook Post Sent')
  end
end