Class: Birdy::Base

Inherits:
Object
  • Object
show all
Includes:
Authentication, ImageDownload
Defined in:
lib/birdy/base.rb

Constant Summary

Constants included from ImageDownload

ImageDownload::IMAGES, ImageDownload::ONE_DAY

Instance Method Summary collapse

Methods included from ImageDownload

#download

Methods included from Authentication

#authenticate

Constructor Details

#initializeBase

Returns a new instance of Base.



11
12
13
14
# File 'lib/birdy/base.rb', line 11

def initialize
  @twitter = authenticate
  poll
end

Instance Method Details

#pollObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/birdy/base.rb', line 16

def poll
  @alert = LinuxNotifier.new

  while true
    tweets.reverse.each do |tweet|
      image_path = download(tweet.user.profile_image_url)
      @alert.show(image_path, tweet.user.name, tweet.text) 
    end

    sleep 60
  end
end

#tweetsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/birdy/base.rb', line 29

def tweets
  options = {}
  if @last_tweet_id
    options[:since_id] = @last_tweet_id
  else
    options[:count] = 1
  end

  begin
    timeline = @twitter.timeline_for(:friends, options) 
  rescue Twitter::RESTError => e
    puts "Twitter is not responding." + e
    timeline = []
  end

  if timeline.length > 0
    @last_tweet_id = timeline.first.id 
  end

  timeline
end