Chore: Twitter Integration house cleaning (#855)

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2020-05-14 22:51:07 +05:30
committed by GitHub
parent 1108446974
commit 20f39caa42
11 changed files with 159 additions and 63 deletions

View File

@@ -14,7 +14,7 @@ class Api::V1::Accounts::CallbacksController < Api::BaseController
@facebook_inbox = current_account.inboxes.create!(name: inbox_name, channel: facebook_channel)
set_avatar(@facebook_inbox, page_id)
rescue StandardError => e
Rails.logger e
Rails.logger.info e
end
end
@@ -62,7 +62,7 @@ class Api::V1::Accounts::CallbacksController < Api::BaseController
koala = Koala::Facebook::OAuth.new(ENV['FB_APP_ID'], ENV['FB_APP_SECRET'])
koala.exchange_access_token_info(omniauth_token)['access_token']
rescue StandardError => e
Rails.logger e
Rails.logger.info e
end
def mark_already_existing_facebook_pages(data)

View File

@@ -2,18 +2,18 @@ class Twitter::CallbacksController < Twitter::BaseController
def show
return redirect_to twitter_app_redirect_url if permitted_params[:denied]
@response = twitter_client.access_token(
oauth_token: permitted_params[:oauth_token],
oauth_verifier: permitted_params[:oauth_verifier]
)
if @response.status == '200'
inbox = build_inbox
@response = ensure_access_token
return redirect_to twitter_app_redirect_url if @response.status != '200'
ActiveRecord::Base.transaction do
inbox = create_inbox
::Redis::Alfred.delete(permitted_params[:oauth_token])
::Twitter::WebhookSubscribeService.new(inbox_id: inbox.id).perform
redirect_to app_twitter_inbox_agents_url(account_id: account.id, inbox_id: inbox.id)
else
redirect_to twitter_app_redirect_url
end
rescue StandardError => e
Rails.logger.info e
redirect_to twitter_app_redirect_url
end
private
@@ -34,20 +34,23 @@ class Twitter::CallbacksController < Twitter::BaseController
app_new_twitter_inbox_url(account_id: account.id)
end
def build_inbox
ActiveRecord::Base.transaction do
twitter_profile = account.twitter_profiles.create(
twitter_access_token: parsed_body['oauth_token'],
twitter_access_token_secret: parsed_body['oauth_token_secret'],
profile_id: parsed_body['user_id']
)
account.inboxes.create(
name: parsed_body['screen_name'],
channel: twitter_profile
)
rescue StandardError => e
Rails.logger e
end
def ensure_access_token
twitter_client.access_token(
oauth_token: permitted_params[:oauth_token],
oauth_verifier: permitted_params[:oauth_verifier]
)
end
def create_inbox
twitter_profile = account.twitter_profiles.create(
twitter_access_token: parsed_body['oauth_token'],
twitter_access_token_secret: parsed_body['oauth_token_secret'],
profile_id: parsed_body['user_id']
)
account.inboxes.create(
name: parsed_body['screen_name'],
channel: twitter_profile
)
end
def permitted_params