Class: MyPusher::ReservationDriver

Inherits:
Object
  • Object
show all
Defined in:
app/my_lib/my_pusher/reservation_driver.rb

Overview

typed: ignore

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.broadcast_reservation(reservation, action) ⇒ Object

Broadcasts a reservation update to the Pusher channel. We use this method to notify the admin dashboard about reservation for delivery updates

Parameters:

  • reservation (Reservation)
  • action (Symbol)

    if `:action` or `:update`, then table row on admin deliveries page will be updated if `:destroy`, then table row on admin deliveries page will be deleted



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/my_lib/my_pusher/reservation_driver.rb', line 29

def self.broadcast_reservation(reservation, action)
  return if !reservation.delivery? && reservation.reached_goal? && reservation.pending_payment_non_cc?

  pusher = ::MyPusher::ReservationDriver.new

  case action.to_sym
  when :create
    pusher.notify_create(reservation)
  when :update
    pusher.notify_update(reservation)
  when :destroy
    pusher.notify_cancel(reservation)
  when :alert
    pusher.notify_alert(reservation)
  else
    APMErrorHandler.report('NotImplementedError', reservation_id: reservation.id, action: action)
    raise NotImplementedError
  end
rescue Pusher::Error => e
  HH_LOGGER.error e unless e.message.include? 'quota exceeded'
rescue StandardError => e
  HH_LOGGER.error e
end

Instance Method Details

#notify_alert(reservation) ⇒ Object

Parameters:



14
15
16
# File 'app/my_lib/my_pusher/reservation_driver.rb', line 14

def notify_alert(reservation)
  trigger('alert', { html: reservation_to_html(reservation), id: reservation.id })
end

#notify_cancel(reservation) ⇒ Object

Parameters:



19
20
21
# File 'app/my_lib/my_pusher/reservation_driver.rb', line 19

def notify_cancel(reservation)
  trigger('alert', { html: reservation_to_html(reservation), id: reservation.id })
end

#notify_create(reservation) ⇒ Object

Parameters:



9
10
11
# File 'app/my_lib/my_pusher/reservation_driver.rb', line 9

def notify_create(reservation)
  trigger('created', { html: reservation_to_html(reservation), id: reservation.id })
end

#notify_update(reservation) ⇒ Object

Parameters:



4
5
6
# File 'app/my_lib/my_pusher/reservation_driver.rb', line 4

def notify_update(reservation)
  trigger('updated', { html: reservation_to_html(reservation), id: reservation.id })
end