Class: Twitter2MixiVoice::TwitterClient
- Inherits:
-
Object
- Object
- Twitter2MixiVoice::TwitterClient
- Defined in:
- lib/twitter_client.rb
Overview
This class provides twitter functions.
Instance Method Summary collapse
-
#get_tweets_from_timeline ⇒ Object
Get tweets from timeline.
-
#initialize(id, password) ⇒ TwitterClient
constructor
Create TwitterClient class instance.
Constructor Details
#initialize(id, password) ⇒ TwitterClient
Create TwitterClient class instance.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/twitter_client.rb', line 26 def initialize(id, password) # check parameter. raise TwitterException.new("Invalid 'id' parameter.") if id.nil? || id.empty? raise TwitterException.new("Invalid 'password' password.") if password.nil? || password.empty? # login to twitter. begin @client = Twitter::Client.new(:login => id, :password => password) rescue Exception => e raise TwitterException.new(e.to_s) end # check authenticate. unless @client.authenticate?(id, password) raise TwitterException.new("Not authenticate.") end end |
Instance Method Details
#get_tweets_from_timeline ⇒ Object
Get tweets from timeline.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/twitter_client.rb', line 48 def get_tweets_from_timeline # initialize tweets tweets = [] # add that get status from timeline in tweet collection. begin # insert status in tweet collection. @client.timeline_for(:me) do |status| tweet = Tweet.new tweet.id = status.id.to_i tweet.text = status.text tweet.created_at = status.created_at tweets << tweet end # sort tweet collection. unless tweets.empty? tweets = tweets.sort do |a, b| a.created_at.to_f <=> b.created_at.to_f end end rescue Exception => e raise TwitterException.new(e.to_s) end # return tweets. tweets end |