Class: Feed::TransmitEmail

Inherits:
Object
  • Object
show all
Defined in:
app/services/feed/transmit_email.rb

Overview

Service object: transmit email.

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TransmitEmail

Returns a new instance of TransmitEmail.



12
13
14
15
16
17
18
19
# File 'app/services/feed/transmit_email.rb', line 12

def initialize(options = {})
  @logger = options.delete(:logger)
  @recipient_contact_points = options[:recipient_contact_points]
  @sender_email = options[:sender_email]
  @cc_email = options[:cc_email]
  @extra_emails = options[:extra_emails]
  @options = options
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'app/services/feed/transmit_email.rb', line 4

def logger
  @logger
end

Instance Method Details

#process(upload) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/services/feed/transmit_email.rb', line 21

def process(upload)
  result_hsh = {}
  begin
    result_hsh[:transmitted] = false # Default
    result_hsh[:status] = :error # Default
    communication = CommunicationBuilder.new(
      emails: @extra_emails.map(&:presence).presence,
      sender: @sender_email,
      cc: @cc_email,
      recipient_contact_points: @recipient_contact_points,
      template_system_code: 'INVENTORY_FEED',
      uploads: [upload]
    ).create
    result_hsh[:transmitted] = true
    result_hsh[:status] = :ok
    result_hsh[:upload] = upload
    result_hsh[:communication] = communication
  rescue StandardError => e
    msg = "Failed to transmit. #{@options.inspect} - #{e.message}"
    result_hsh[:message] = msg
    ErrorReporting.error(e, msg)
  end
  Result.new(**result_hsh)
end