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 |
# File 'lib/twitorious/api/twitter.rb', line 9 def initialize(config, site) @config = config @site = site @notifier = Twitorious::Notifier.new end |
Instance Method Details
#fetch_mentions ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/twitorious/api/twitter.rb', line 41 def fetch_mentions puts "Fetching mentions from #{@site[:name]}" path = @site[:url].path + "/statuses/mentions.json" path += "?since_id=#{@site[:mentions_since_id]}" if @site[:mentions_since_id] res = fetch_body(@site[:url].host, @site[:url].port, path, @site[:user], @site[:pass]) updates = JSON.parse(res) 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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/twitorious/api/twitter.rb', line 23 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] res = fetch_body(@site[:url].host, @site[:url].port, path, @site[:user], @site[:pass]) updates = JSON.parse(res) 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
15 16 17 18 19 20 21 |
# File 'lib/twitorious/api/twitter.rb', line 15 def update(status) puts "Updating #{@site[:name]}" req = Net::HTTP::Post.new(@site[:url].path + "/statuses/update.json", { "User-Agent" => "Twitorious/#{Twitorious::VERSION}"}) req.basic_auth @site[:user], @site[:pass] req.set_form_data({'status' => status}, ';') res = Net::HTTP.new(@site[:url].host, @site[:url].port).start { |http| http.request(req) } end |