Module: Autoluv
- Defined in:
- lib/autoluv.rb,
lib/autoluv/version.rb,
lib/autoluv/southwestclient.rb
Defined Under Namespace
Classes: Error, SouthwestClient
Constant Summary
collapse
- PONY_OPTIONS =
{
from: "#{ENV["LUV_FROM_EMAIL"]}",
via: :smtp,
via_options: {
address: "#{ENV["LUV_SMTP_SERVER"]}",
port: "#{ENV["LUV_PORT"]}",
user_name: "#{ENV["LUV_USER_NAME"]}",
password: "#{ENV["LUV_PASSWORD"]}",
authentication: :login,
},
}
- LOG_DIR =
File.expand_path("../logs/", __dir__)
- VERSION =
"0.3.2"
Class Method Summary
collapse
-
.email(subject, body, to, bcc = nil) ⇒ Object
-
.log(confirmation_number, first_name, last_name, message, exception) ⇒ Object
-
.notify_user(success, confirmation_number, first_name, last_name, data = {}) ⇒ Object
Class Method Details
.email(subject, body, to, bcc = nil) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/autoluv.rb', line 56
def self.email(subject, body, to, bcc = nil)
return if PONY_OPTIONS.values.any? &:empty?
begin
Pony.mail(PONY_OPTIONS.merge({
to: to,
bcc: bcc,
subject: subject,
body: body,
}))
rescue => e
puts e.message
end
end
|
.log(confirmation_number, first_name, last_name, message, exception) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/autoluv.rb', line 27
def self.log(confirmation_number, first_name, last_name, message, exception)
log_path = "#{LOG_DIR}/#{first_name} #{last_name}"
FileUtils.mkdir_p(log_path) unless Dir.exist?(log_path)
logger = Logger.new("#{log_path}/#{confirmation_number}.log")
logger.error(message + "\n" + exception.backtrace.join("\n"))
end
|
.notify_user(success, confirmation_number, first_name, last_name, data = {}) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/autoluv.rb', line 36
def self.notify_user(success, confirmation_number, first_name, last_name, data = {})
subject = "#{first_name} #{last_name} (#{confirmation_number}): "
body = ""
if success
subject << "Succeeded at #{data[:metadata][:end_time]}. #{data[:metadata][:attempts]} attempt(s) in #{data[:metadata][:elapsed_time]} sec."
body = data[:boarding_positions]
else
subject << "Unsuccessful check-in."
body = data[:exception_message]
Autoluv::log(confirmation_number, first_name, last_name, body, data[:exception])
end
if data[:to].nil?
puts body
else
Autoluv::email(subject, body, data[:to], data[:bcc])
end
end
|