Class: CuckooTwitterer

Inherits:
Object
  • Object
show all
Includes:
CuckooEnvironment
Defined in:
lib/cuckoo_twitterer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CuckooEnvironment

#set_testing, #testing?

Constructor Details

#initializeCuckooTwitterer

Returns a new instance of CuckooTwitterer.



14
15
16
17
# File 'lib/cuckoo_twitterer.rb', line 14

def initialize
  @time_to_sleep = "1d"
  super
end

Instance Attribute Details

#time_to_sleepObject

the idea is to include a module with a well-defined API with three methods:

  • load_tweets

  • next

  • store(tweet)



12
13
14
# File 'lib/cuckoo_twitterer.rb', line 12

def time_to_sleep
  @time_to_sleep
end

Instance Method Details

#get_config_values_from_fileObject



32
33
34
35
36
37
38
# File 'lib/cuckoo_twitterer.rb', line 32

def get_config_values_from_file
  config_values = {}
  open('config/cuckoo.yml', 'r') do |f|
    config_values = YAML.load(f.read)
  end
  config_values
end

#quitObject



61
62
63
# File 'lib/cuckoo_twitterer.rb', line 61

def quit
  exit
end

#relaxObject



46
47
48
49
# File 'lib/cuckoo_twitterer.rb', line 46

def relax
  seconds_to_sleep = DurationString.to_seconds(time_to_sleep)
  sleep(seconds_to_sleep)
end

#runObject



51
52
53
54
55
56
57
58
59
# File 'lib/cuckoo_twitterer.rb', line 51

def run
  setup
  load_tweets
  loop do
    tweeted = tweet
    quit if tweeted.nil?
    relax
  end
end

#setupObject



40
41
42
43
44
# File 'lib/cuckoo_twitterer.rb', line 40

def setup
  get_config_values_from_file.each_pair do |attr, value|
    self.send("#{attr}=".to_sym, value)
  end
end

#tweetObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cuckoo_twitterer.rb', line 19

def tweet
  next_tweet = self.next
  unless next_tweet.nil?
    store(next_tweet)
    if testing?
      puts "(test) Tweeting #{next_tweet}"
    else
      twitter.status(:post, next_tweet)
    end
  end
  next_tweet
end