Class: Feed::TransmitEmail

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

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TransmitEmail

Returns a new instance of TransmitEmail.



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

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.



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

def logger
  @logger
end

Instance Method Details

#process(upload) ⇒ Object



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

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 => exc
    msg = "Failed to transmit. #{@options.inspect} - #{exc.message}"
    result_hsh[:message] = msg
    ErrorReporting.error(exc, msg)
  end
  Result.new(**result_hsh)
end