class Twitter2Jabber

Constants

VERSION

Attributes

debug[R]
jabber[R]
twitter[R]

Public Class Methods

client(client) click to toggle source
# File lib/twitter2jabber.rb, line 35
def client(client)
  const_get("#{client.to_s.capitalize}Client")
end
new(options) click to toggle source
# File lib/twitter2jabber.rb, line 41
def initialize(options)
  @twitter = initialize_client(:twitter, options)
  @jabber  = initialize_client(:jabber,  options)

  if @debug = options[:debug] or options[:verbose]
    @spec = "#{twitter.spec} -> #{jabber.spec}"

    @log = options[:log] || $stderr
    @log.sync = true

    require 'time'
  else
    define_singleton_method(:log) { |_| }
  end
end
run(options, since_id = nil) click to toggle source
# File lib/twitter2jabber.rb, line 31
def run(options, since_id = nil)
  new(options).connect.deliver_tweets(since_id).disconnect
end

Public Instance Methods

connect() click to toggle source
# File lib/twitter2jabber.rb, line 59
def connect
  log 'Connecting...'

  twitter.connect
  jabber.connect

  self
end
deliver_tweets(since_id = nil) click to toggle source
# File lib/twitter2jabber.rb, line 77
def deliver_tweets(since_id = nil)
  twitter.tweets(since_id) { |tweet| jabber.deliver(tweet) }
  self
end
disconnect() click to toggle source
# File lib/twitter2jabber.rb, line 68
def disconnect
  log 'Disconnecting...'

  twitter.disconnect
  jabber.disconnect

  self
end
log(msg) click to toggle source
# File lib/twitter2jabber.rb, line 82
def log(msg)
  @log.puts "#{Time.now.xmlschema} [#{@spec}] #{msg}"
end

Private Instance Methods

initialize_client(client, options) click to toggle source
# File lib/twitter2jabber.rb, line 88
def initialize_client(client, options)
  (config = options[client]).is_a?(Hash) ?
    self.class.client(client).new(self, config) :
    raise(ArgumentError, "#{client} config missing")
end