Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created June 15, 2012 15:25
Show Gist options
  • Save mahemoff/2937018 to your computer and use it in GitHub Desktop.
Save mahemoff/2937018 to your computer and use it in GitHub Desktop.
Authetnicated Twitter calls using Devise
module Twitvise
def search
return unless twitter_client = client
twitter_client.search 'groo'
end
private
def client
consumer = Devise.omniauth_configs[:twitter].strategy
tokens = self.user_tokens.where(provider: 'twitter')
return unless consumer and tokens.length > 0
TwitterOAuth::Client.new ({
consumer_key: consumer.consumer_key,
consumer_secret: consumer.consumer_secret,
token: token.token,
secret: token.secret
})
end
end
@mahemoff
Copy link
Author

Then you can say

def User
include Twitvise
...
end

User.find('joe').search 'weather today'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment