Class: Retjilp::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/retjilp/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Returns a new instance of Runner.


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/retjilp/runner.rb', line 12

def initialize(argv)
	# Parse command-line options
	OptionParser.new do |opts|
		opts.banner = "Usage: retjilp [ --help ] [ --verbose | --debug ]"
		opts.on("--verbose", "Run with verbose output") { Retjilp::log.level = Logger::INFO }
		opts.on("--debug", "Run with debug output") { Retjilp::log.level = Logger::DEBUG }
		opts.on_tail("-h", "--help", "Show this help") { puts opts ; exit }
		begin
			opts.parse!(argv)
		rescue => e
			fatal_error("Invalid option(s): #{e.message}\n" + opts.to_s)
		end
	end

	# Parse config file
	config_filename = File.join(DATA_DIR, "config")
	begin
		@options = File.open(config_filename) { |f| JSON.load(f) }
	rescue => e
		fatal_error("Error parsing configuration file #{config_filename}: #{e.message}")
	end

	# Convert keys to symbols
	@options = @options.inject({}){|m,(k,v)| m[k.to_sym] = v; m}
end

Instance Method Details

#runObject


38
39
40
41
42
43
# File 'lib/retjilp/runner.rb', line 38

def run
	consumer_key = (@options[:consumer_key] or fatal_error("Consumer key missing"))
	consumer_secret = (@options[:consumer_secret] or fatal_error("Consumer secret missing"))
	twitter = Twitter.new(@options[:consumer_key], @options[:consumer_secret])
	Retweeter.new(twitter, @options).run
end