I want to get my tweets using user_timeline()
and save them to my application database.
I'm not sure where to call that function and how to save each tweet associating with my user.
This is the way I'm saving users to the database
class SessionsController < ApplicationController
def create
auth = request.env['omniauth.auth']
session[:omniauth] = auth.except('extra')
user = User.sign_in_from_omniauth(auth)
session[:user_id] = user.id
redirect_to root_url, notice: "SIGNED IN"
end
end
Here's my model...
class User < ActiveRecord::Base
def self.sign_in_from_omniauth(auth)
find_by(provider: auth['provider'], uid: auth['uid']) || create_user_from_omniauth(auth)
end
def self.create_user_from_omniauth(auth)
create(
provider: auth['provider'],
uid: auth['uid'],
name: auth['info']['name'],
screen_name: auth['info']['nickname'],
oauth_token: auth['credentials']['token'],
oauth_secret: auth['credentials']['secret']
)
end
def twitter
Twitter::REST::Client.new do |config|
config.consumer_key = 'XXXXXXXXXXXXXXXX'
config.consumer_secret = 'XXXXXXXXXXXXXXXX'
config.access_token = oauth_token
config.access_token_secret = oauth_secret
end
end
end
Where I should call user_timeline()
and save all tweets?