Class: Sincerely::Services::ProcessDeliveryEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/sincerely/services/process_delivery_event.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event:) ⇒ ProcessDeliveryEvent

Returns a new instance of ProcessDeliveryEvent.



15
16
17
# File 'lib/sincerely/services/process_delivery_event.rb', line 15

def initialize(event:)
  @event = event
end

Class Method Details

.call(event:) ⇒ Object



10
11
12
# File 'lib/sincerely/services/process_delivery_event.rb', line 10

def call(event:)
  new(event:).call
end

Instance Method Details

#call ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sincerely/services/process_delivery_event.rb', line 19

def call
  return if notification.blank?

  case event_type.to_sym
  when :bounce
    notification.set_bounced! if notification.may_set_bounced?
    create_event
  when :complaint
    notification.set_complained! if notification.may_set_complained?
    create_event
  when :delivery
    notification.set_delivered! if notification.may_set_delivered?
    create_event
  when :send
    notification.set_accepted! if notification.may_set_accepted?
  when :reject
    if notification.may_set_rejected?
      notification.set_rejected!
      notification.update(error_message: event.rejection_reason)
    end
  when :open
    notification.set_opened! if notification.may_set_opened?
    create_event
  when :click
    notification.set_clicked! if notification.may_set_clicked?
    create_event
  end
end