Skip to content

Instantly share code, notes, and snippets.

@rainerborene
Created January 20, 2014 22:16
Show Gist options
  • Select an option

  • Save rainerborene/8530365 to your computer and use it in GitHub Desktop.

Select an option

Save rainerborene/8530365 to your computer and use it in GitHub Desktop.
class SocialProxy < SimpleDelegator
attr_reader :auth
def initialize(auth)
@auth = auth
@provider = auth.provider.to_sym
case @provider
when :facebook then require 'koala'
when :twitter then require 'twitter'
end
super send(@provider) if respond_to?(@provider, true)
end
def exchange_facebook_token
oauth = Koala::Facebook::OAuth.new ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET']
oauth.exchange_access_token(auth.token)
end
private
def facebook
Koala::Facebook::API.new auth.token
end
def twitter
Twitter::REST::Client.new do |config|
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
config.access_token = auth.token
config.access_token_secret = auth.secret
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment