class Twitter2Jabber::CLI

Public Class Methods

defaults() click to toggle source
Calls superclass method
   # File lib/twitter2jabber/cli.rb
36 def defaults
37   super.merge(
38     config:   'config.yaml',
39     since_id: nil,
40     verbose:  false,
41     debug:    false
42   )
43 end
extract_since_id(log) click to toggle source
   # File lib/twitter2jabber/cli.rb
45 def extract_since_id(log)
46   return unless File.readable?(log)
47 
48   id, re = nil, /\bTWITTER\s+(\d+)\Z/
49 
50   File.foreach(log) { |line|
51     id = $1 if line =~ re
52   }
53 
54   id.to_i if id
55 end

Public Instance Methods

run(arguments) click to toggle source
   # File lib/twitter2jabber/cli.rb
59 def run(arguments)
60   if log = options[:log]
61     options[:log] = File.open(log, 'a')
62     options[:since_id] ||= self.class.extract_since_id(log)
63   end
64 
65   Twitter2Jabber.run(options, options.delete(:since_id))
66 end

Private Instance Methods

debug_message() click to toggle source
   # File lib/twitter2jabber/cli.rb
94 def debug_message
95   "don't send any messages"
96 end
opts(opts) click to toggle source
   # File lib/twitter2jabber/cli.rb
86 def opts(opts)
87   opts.option(:since_id__ID, Integer, 'Return tweets with status IDs greater than ID')
88 
89   opts.separator
90 
91   opts.option(:log__FILE, 'Path to log file [Default: STDERR]')
92 end
parse_options(arguments) click to toggle source
Calls superclass method
   # File lib/twitter2jabber/cli.rb
70 def parse_options(arguments)
71   super
72 
73   options[:log] &&= File.expand_path(options[:log])
74 
75   t = options[:twitter] ||= {}
76   t[:consumer_token]  ||= ask('Twitter consumer token: ')
77   t[:consumer_secret] ||= askpass("Consumer secret for Twitter application #{t[:consumer_token]}: ")
78   t[:access_token]    ||= ask('Twitter access token: ')
79   t[:access_secret]   ||= askpass("Access secret for Twitter user #{t[:access_token]}: ")
80 
81   j = options[:jabber] ||= {}
82   j[:username] ||= ask('Jabber ID: ')
83   j[:password] ||= askpass("Password for Jabber ID #{j[:username]}: ")
84 end