Class: EMN
- Inherits:
-
Object
show all
- Defined in:
- lib/emn.rb,
lib/emn/config.rb,
lib/emn/eve_api.rb,
lib/emn/version.rb,
lib/emn/monitor/pi.rb,
lib/emn/monitor/mail.rb,
lib/emn/notifier/pushover.rb
Defined Under Namespace
Classes: Config, EveAPI, Monitor, Notifier
Constant Summary
collapse
- OPTIONS =
{
:verbose => false,
:debug => false,
:config => File.expand_path("~/.emn"),
:seen => File.expand_path("~/.emn_seen"),
:checkers => []
}
- VERSION =
"0.0.5"
Instance Method Summary
collapse
Instance Method Details
#eve_api ⇒ Object
75
76
77
|
# File 'lib/emn.rb', line 75
def eve_api
@eve_api ||= EveAPI.new(config)
end
|
#logger ⇒ Object
63
64
65
|
# File 'lib/emn.rb', line 63
def logger
config.logger
end
|
#parse_options ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/emn.rb', line 23
def parse_options
opt = OptionParser.new
opt.banner = "New mail notifications for Eve Online"
opt.separator ""
opt.on("--debug", "Enable debug mode") do
OPTIONS[:debug] = true
end
opt.on("--verbose", "Verbose logging") do
OPTIONS[:verbose] = true
end
opt.on("--config [CONFIG]", "Config file location (%s)" % OPTIONS[:config]) do |v|
OPTIONS[:config] = File.expand_path(v)
end
opt.on("--seen [SEEN_FILE]", "Seen file location (%s)" % OPTIONS[:seen]) do |v|
OPTIONS[:seen] = File.expand_path(v)
end
opt.on("--pi", "Check PI extractor cycles") do
OPTIONS[:checkers] << EMN::Monitor::Pi
end
opt.on("--mail", "Check for new emails") do
OPTIONS[:checkers] << EMN::Monitor::Mail
end
opt.separator ""
opt.separator "http://github.com/ripienaar/emn"
opt.parse!
if OPTIONS[:checkers].empty?
abort("Please specify either --mail, --pi or both")
end
end
|
#process! ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/emn.rb', line 79
def process!
OPTIONS[:checkers].each do |klass|
checker = klass.new(config)
logger.debug("Processing %s" % checker.class)
notifications = checker.notifications
if !notifications[:data].empty?
template_file = File.expand_path(File.join(File.dirname(__FILE__), "..", notifications[:template]))
logger.debug("Sending notifications using template %s" % template_file)
template = Tilt::ERBTemplate.new(template_file)
output = template.render(:data => notifications[:data], :config => config)
if pushover.publish(output, notifications[:subject])
config.save_seen!(config.seen.merge(notifications[:seen]))
end
else
config.save_seen!(config.seen.merge(notifications[:seen]))
end
end
rescue EAAL::Exception::EveAPIException
STDERR.puts("Failed to communicate with the EVE API: %s: %s: %s" % [$!.class, caller.first, $!.to_s])
exit 1
end
|