Class: BookingReminder::ManualQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/booking_reminder/manual_queue.rb

Overview

Trigger sms reminder manually (by owner)

Instance Method Summary collapse

Constructor Details

#initialize(reservation_id) ⇒ ManualQueue

Returns a new instance of ManualQueue.



13
14
15
# File 'lib/booking_reminder/manual_queue.rb', line 13

def initialize(reservation_id)
  @reservation = ::Reservation.find(reservation_id)
end

Instance Method Details

#has_reminded?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/booking_reminder/manual_queue.rb', line 46

def has_reminded?
  reservation.remindered?
end

#remindObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/booking_reminder/manual_queue.rb', line 17

def remind
  return RESULT.new success: false, message: I18n.t('reservation.has_been_reminded') if has_reminded?

  if update_remindered_attr
    send_sms_reminder
    RESULT.new success: true, message: 'Reminder sent'
  else
    RESULT.new success: false, message: I18n.t('reservation.failed_to_reminder')
  end
rescue => error
  APMErrorHandler.report 'BookingReminder::ManualQueue went wrong', error: error
  message = if error&.message && error.message.include?('Validation failed')
              error.message
            else
              'Something went wrong, please contact our support'
            end
  RESULT.new success: false, message: message
end

#send_sms_reminderObject



36
37
38
# File 'lib/booking_reminder/manual_queue.rb', line 36

def send_sms_reminder
  NotificationService::Sms.new(phones: reservation.phone, reservation: reservation).send_reminder_booking_to_user
end

#update_remindered_attrObject

update :remindered attribute to prevent system to send SMS more than once :remindered attribute could be re-updated by another web hook whom responsible to Infobip notification



42
43
44
# File 'lib/booking_reminder/manual_queue.rb', line 42

def update_remindered_attr
  reservation.update_attributes! remindered: true
end