Class: Tweetskim::TwitterAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/tweetskim/core.rb

Constant Summary collapse

CONSUMER_KEY =
"3oUZhYLZcaqqQePajIjnBg"
CONSUMER_SECRET =
"mAYecEGPwy7BlkibFGHCACtY5x1Mm0YOvczxsll4OY"

Instance Method Summary collapse

Instance Method Details

#authenticated_clientObject

TODO call for specific user



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/tweetskim/core.rb', line 111

def authenticated_client
  settings = Tweetskim::Settings.new
  
  if settings.user_credentials_stored?
    user_token, user_secret = settings.load_credentials
  else
    user_token, user_secret = oauth_pin_dance_for_token_and_secret
    settings.save_credentials(user_token, user_secret)
  end

  Twitter.configure do |config|
    config.consumer_key = CONSUMER_KEY
    config.consumer_secret = CONSUMER_SECRET
    config.oauth_token = user_token
    config.oauth_token_secret = user_secret
  end

  client = Twitter::Client.new
  client.verify_credentials
  return client
end

#mentions(tweet_count, since_id) ⇒ Object

TODO call for each user in config implicit for the user authenticated in client. Different user = different client



97
98
99
100
# File 'lib/tweetskim/core.rb', line 97

def mentions(tweet_count, since_id)
  client = authenticated_client 
  mentions = client.mentions({:count => tweet_count.to_i, :since_id => since_id.to_i})
end

#oauth_pin_dance_for_token_and_secretObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/tweetskim/core.rb', line 133

def oauth_pin_dance_for_token_and_secret
  oauth_consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET,
                                       :site => 'http://api.twitter.com',
                                       :request_token_path => '/oauth/request_token',
                                       :access_token_path => '/oauth/access_token',
                                       :authorize_path => '/oauth/authorize')
  
  request_token = oauth_consumer.get_request_token
  rtoken  = request_token.token
  rsecret = request_token.secret
  
  puts "You have to set up Twitter authentication the first time you use tweetskim."
  puts "Please authenticate by following this URL:"
  puts request_token.authorize_url
  
  puts "What was the PIN that Twitter gave you? "
  pin = gets.chomp
 
  OAuth::RequestToken.new(oauth_consumer, rtoken, rsecret)
  access_token = request_token.get_access_token(:oauth_verifier => pin)
  
  return access_token.token, access_token.secret
end

#timeline(tweet_count, since_id) ⇒ Object



102
103
104
105
# File 'lib/tweetskim/core.rb', line 102

def timeline(tweet_count, since_id) 
  client = authenticated_client
  timeline = client.home_timeline({:count => tweet_count.to_i, :since_id => since_id.to_i})
end