Module: Twix

Defined in:
lib/twix.rb

Class Method Summary collapse

Class Method Details

.display_tweet(tweet, index) ⇒ Object



42
43
44
# File 'lib/twix.rb', line 42

def self.display_tweet(tweet, index)
  puts "\t#{index} - #{tweet.text}"
end

.handle_switchesObject



23
24
25
# File 'lib/twix.rb', line 23

def self.handle_switches
  true
end

.initObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/twix.rb', line 5

def self.init
  config_file = File.expand_path("~") + "/.twixrc"
  twix_config = YAML.load_file(config_file)
  Twitter.configure do |config|
     config.consumer_key = twix_config['twitter']['consumer_key']
     config.consumer_secret = twix_config['twitter']['consumer_secret']
     config.oauth_token = twix_config['twitter']['oauth_token']
     config.oauth_token_secret = twix_config['twitter']['oauth_token_secret']
  end
end

.run(args) ⇒ Object



16
17
18
19
20
21
# File 'lib/twix.rb', line 16

def self.run(args)
  handle_switches
  usernames = args.select {|arg| arg.match(/\A@/)}
  user = usernames.first
  show_user_tweets(user) if user
end

.show_user_tweets(user) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/twix.rb', line 27

def self.show_user_tweets(user)
  timeline = Twitter.user_timeline(user.gsub(/\A@/, ''))
  puts "Tweets for #{user}:"
  timeline.each_with_index do |tweet, index|
    display_tweet(tweet, index)
  end
  print "\nWhich Tweet do you want to execute? "
  tweet_index = $stdin.gets.chomp
  if tweet_index.match(/\A(1|)[0-9]\Z/).nil?
    puts "\n\nYour input must be between 0 and 19"
    show_user_tweets(user)
  end
  eval timeline[tweet_index.to_i].text
end