Class: TwitterAccountsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/twitter_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
19
20
21
# File 'app/controllers/twitter_accounts_controller.rb', line 8

def callback
  if params[:denied] && !params[:denied].empty?
    redirect_to(deals_url, :alert => 'Unable to connect with twitter: #{parms[:denied]}')
  else
     = TwitterAccount.find_by_oauth_token(params[:oauth_token])
    .validate_oauth_token(params[:oauth_verifier], twitter_callback_url)
    .save
    if .active?
      redirect_to("#{root_url}admin/users/#{current_user.id}", :notice => 'Twitter account activated! You will need to resend the last tweet.')
    else
      redirect_to("#{root_url}admin/users/#{current_user.id}", :notice => "Unable to activate twitter account.")
    end
  end
end

#destroyObject


38
39
40
41
42
43
44
45
46
# File 'app/controllers/twitter_accounts_controller.rb', line 38

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

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

#newObject


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

def new
   = TwitterAccount.create(:user => current_user)
  redirect_to(.authorize_url(twitter_callback_url))
end

#send_tweetObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/twitter_accounts_controller.rb', line 23

def send_tweet
   = Rails.cache.fetch("twitter_account_user_#{current_user.id}", :expires_in => 35.minutes) do
     TwitterAccount.find_by_user_id(current_user.id)
  end
  #account = TwitterAccount.find_by_user_id(current_user.id)
  if .blank?
     = TwitterAccount.create(:user_id => current_user.id)
    redirect_to(.authorize_url(twitter_callback_url))
  else
    link = ShortLink.shorten_link("https://hospitium.co/animals/#{params[:animal_uuid]}")
    TwitterAccount.twitter_post("#{params[:animal_name]} is ready for adoption at #{link} via [email protected]_app", current_user.id)
    redirect_to("#{root_url}admin/animals/#{params[:animal_id]}-#{params[:animal_uuid]}", :notice => 'Tweet Sent')
  end
end