class MonitorInbox include Interactor AUTHORIZED_SENDERS = [ "rodolfo.leyes@gmail.com" ] def call email = context.email || ENV["EMAIL"] password = context.password || ENV["PASSWORD"] fetch_emails_res = FetchEmails.call!( email: email, password: password, # TODO: We need the process to be intelligent and know when was it's last execution query_from: Time.now - 3.days ) context.emails_arr = fetch_emails_res.messages analyze_emails(context.emails_arr) end def analyze_emails(emails_arr) emails_arr.each do |email| puts "Analyzing email with subject: #{email.subject} From: #{email.from} On #{email.date}" if is_action_email?(email) ejecutar_accion(email) end end end def is_action_email?(email) # For now we only recognize the encender action email.subject.downcase.include?("encender") && AUTHORIZED_SENDERS.include?(email.from.downcase) end def ejecutar_accion(email) end end