Class: TwitterRSS
- Inherits:
-
Object
- Object
- TwitterRSS
- Defined in:
- lib/twitter_rss.rb,
lib/twitter_rss/version.rb
Overview
Twitter RSS
Constant Summary collapse
- VERSION =
"0.2.1"
Instance Method Summary collapse
-
#favorites_list(params, info) ⇒ String
Returns a RSS feed of the most recent Tweets liked by the authenticating or specified user.
-
#initialize(credentials) ⇒ TwitterRSS
constructor
Initializes a TwitterRSS object.
- #make_rss(info, tweets) ⇒ Object
-
#search_tweets(params, info) ⇒ String
Returns a RSS feed of a collection of relevant Tweets matching a specified query.
-
#statuses_user_timeline(params, info) ⇒ String
Returns a RSS feed of the most recent Tweets posted by the user indicated by the screen_name or user_id parameters.
Constructor Details
#initialize(credentials) ⇒ TwitterRSS
Initializes a TwitterRSS object.
14 15 16 |
# File 'lib/twitter_rss.rb', line 14 def initialize(credentials) @t = TwitterAPI::Client.new(credentials) end |
Instance Method Details
#favorites_list(params, info) ⇒ String
Returns a RSS feed of the most recent Tweets liked by the authenticating or specified user.
34 35 36 37 38 |
# File 'lib/twitter_rss.rb', line 34 def favorites_list(params, info) json = @t.favorites_list(params).body tweets = JSON.parse(json) make_rss(info, tweets) end |
#make_rss(info, tweets) ⇒ Object
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 80 81 82 83 84 85 86 87 88 |
# File 'lib/twitter_rss.rb', line 52 def make_rss(info, tweets) rss = RSS::Maker.make('2.0') do |maker| maker.channel.title = info['channel']['title'] maker.channel.description = info['channel']['description'] maker.channel.link = info['channel']['link'] # Sort in new order maker.items.do_sort = true tweets.each do |f| # Use full_text for more than 140 characters. # # ref. Tweet updates — Twitter Developers # https://developer.twitter.com/en/docs/tweets/tweet-updates.html if f['retweeted_status'] text = f['retweeted_status']['full_text'] ? f['retweeted_status']['full_text'] : f['retweeted_status']['text'] screen_name = f['retweeted_status']['user']['screen_name'] text = "RT @#{screen_name}: #{text}" else text = f['full_text'] ? f['full_text'] : f['text'] end maker.items.new_item do |item| url = "https://twitter.com/#{f['user']['screen_name']}/status/#{f['id_str']}" item.link = url item.title = "@#{f['user']['screen_name']}: \"#{text}\" / Twitter" item.description = "#{text}" item.pubDate = f['created_at'] end end end rss.to_s end |
#search_tweets(params, info) ⇒ String
Returns a RSS feed of a collection of relevant Tweets matching a specified query.
45 46 47 48 49 50 |
# File 'lib/twitter_rss.rb', line 45 def search_tweets(params, info) json = @t.search_tweets(params).body searched = JSON.parse(json) tweets = searched['statuses'] make_rss(info, tweets) end |
#statuses_user_timeline(params, info) ⇒ String
Returns a RSS feed of the most recent Tweets posted by the user indicated by the screen_name or user_id parameters.
23 24 25 26 27 |
# File 'lib/twitter_rss.rb', line 23 def statuses_user_timeline(params, info) json = @t.statuses_user_timeline(params).body tweets = JSON.parse(json) make_rss(info, tweets) end |