Class: Twitorious::API::Twitter
- Inherits:
-
Object
- Object
- Twitorious::API::Twitter
- Defined in:
- lib/twitorious/api/twitter.rb
Instance Method Summary collapse
- #fetch_mentions ⇒ Object
- #fetch_timeline ⇒ Object
-
#initialize(config, site) ⇒ Twitter
constructor
A new instance of Twitter.
- #update(status) ⇒ Object
Constructor Details
#initialize(config, site) ⇒ Twitter
Returns a new instance of Twitter.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/twitorious/api/twitter.rb', line 9 def initialize(config, site) @config = config @site = site @notifier = Twitorious::Notifier.new @auth = @site[:oauth_enabled] ? Twitorious::Auth::OAuth.new : Twitorious::Auth::Basic.new(@site[:user], @site[:pass]) if(@site[:oauth_enabled] && !@site[:oauth_authorized]) rt = @auth.get_request_token puts "You need to authorize first" %x{open #{@auth.}} puts "Press enter when done" gets at = rt.get_access_token @site[:oauth_authorized] = true @site[:oauth_token] = at.token @site[:oauth_secret] = at.secret end if @site[:oauth_enabled] && @site[:oauth_authorized] @auth.set_token(@site[:oauth_token], @site[:oauth_secret]) end end |
Instance Method Details
#fetch_mentions ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/twitorious/api/twitter.rb', line 57 def fetch_mentions puts "Fetching mentions from #{@site[:name]}" path = @site[:url].path + "/statuses/mentions.json" path = @site[:url].path + "/statuses/replies.json" if @site[:name] == "Identi.ca" path += "?since_id=#{@site[:mentions_since_id]}" if @site[:mentions_since_id] body = @auth.get(@site[:url], path) updates = JSON.parse(body) puts " No new mentions" if updates.empty? return if updates.empty? puts " Got #{updates.size} new mentions" if updates.size > 1 puts " Got one new mention" if updates.size == 1 show_notifications(updates.reverse) # Returning the last ID we saw, so we can update since_id for the mentions return updates[0]["id"] end |
#fetch_timeline ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/twitorious/api/twitter.rb', line 39 def fetch_timeline puts "Fetching timeline from #{@site[:name]}" path = @site[:url].path + "/statuses/friends_timeline.json" path += "?count=200&since_id=#{@site[:timeline_since_id]}" if @site[:timeline_since_id] body = @auth.get(@site[:url], path) updates = JSON.parse(body) puts " No updates" if updates.empty? return if updates.empty? puts " Got #{updates.size} update#{"s" if updates.size > 1}" show_notifications(updates.reverse) # Returning the last ID we saw, so we can update since_id for the site return updates[0]["id"] end |
#update(status) ⇒ Object
34 35 36 37 |
# File 'lib/twitorious/api/twitter.rb', line 34 def update(status) puts "Updating #{@site[:name]}" res = @auth.post(@site[:url], @site[:url].path + "/statuses/update.json", {"status" => status}) end |