class Twitter2Jabber::CLI

Public Class Methods

defaults() click to toggle source
Calls superclass method
# File lib/twitter2jabber/cli.rb, line 36
def defaults
  super.merge(
    config:   'config.yaml',
    since_id: nil,
    verbose:  false,
    debug:    false
  )
end
extract_since_id(log) click to toggle source
# File lib/twitter2jabber/cli.rb, line 45
def extract_since_id(log)
  return unless File.readable?(log)

  id, re = nil, /\bTWITTER\s+(\d+)\Z/

  File.foreach(log) { |line|
    id = $1 if line =~ re
  }

  id.to_i if id
end

Public Instance Methods

run(arguments) click to toggle source
# File lib/twitter2jabber/cli.rb, line 59
def run(arguments)
  if log = options[:log]
    options[:log] = File.open(log, 'a')
    options[:since_id] ||= self.class.extract_since_id(log)
  end

  Twitter2Jabber.run(options, options.delete(:since_id))
end

Private Instance Methods

debug_message() click to toggle source
# File lib/twitter2jabber/cli.rb, line 94
def debug_message
  "don't send any messages"
end
opts(opts) click to toggle source
# File lib/twitter2jabber/cli.rb, line 86
def opts(opts)
  opts.option(:since_id__ID, Integer, 'Return tweets with status IDs greater than ID')

  opts.separator

  opts.option(:log__FILE, 'Path to log file [Default: STDERR]')
end
parse_options(arguments) click to toggle source
Calls superclass method
# File lib/twitter2jabber/cli.rb, line 70
def parse_options(arguments)
  super

  options[:log] &&= File.expand_path(options[:log])

  t = options[:twitter] ||= {}
  t[:consumer_token]  ||= ask('Twitter consumer token: ')
  t[:consumer_secret] ||= askpass("Consumer secret for Twitter application #{t[:consumer_token]}: ")
  t[:access_token]    ||= ask('Twitter access token: ')
  t[:access_secret]   ||= askpass("Access secret for Twitter user #{t[:access_token]}: ")

  j = options[:jabber] ||= {}
  j[:username] ||= ask('Jabber ID: ')
  j[:password] ||= askpass("Password for Jabber ID #{j[:username]}: ")
end