Browse Source
Implemented the MonitorInbox interactor that should detect and execute the actions A new rake task monitor:run has been implemented for execution from the consolemaster
7 changed files with 69 additions and 27 deletions
@ -0,0 +1,39 @@ |
|||
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 |
|||
@ -0,0 +1,6 @@ |
|||
namespace :monitor do |
|||
desc "executes the monitoring logic" |
|||
task :run => :environment do |
|||
MonitorInbox.call! |
|||
end |
|||
end |
|||
@ -0,0 +1,7 @@ |
|||
require 'spec_helper' |
|||
|
|||
RSpec.describe MonitorInbox, type: :interactor do |
|||
describe '.call' do |
|||
pending "add some examples to (or delete) #{__FILE__}" |
|||
end |
|||
end |
|||
Loading…
Reference in new issue