module Autoluv
Constants
- LOG_DIR
- PONY_OPTIONS
- VERSION
Public Class Methods
email(subject, body, to, bcc = nil)
click to toggle source
# File lib/autoluv.rb, line 56 def self.email(subject, body, to, bcc = nil) # only send an email if we have all the environmental variables set 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)
click to toggle source
# 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 = {})
click to toggle source
# 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