@@ -37,7 +37,7 @@ class MuleSoft::CalendarExporter < PlaceOS::Driver
3737 self [:timezone ] = @time_zone .to_s
3838
3939 subscription = system.subscribe(:Bookings_1 , :bookings ) do |_subscription , mulesoft_bookings |
40- logger.debug { " DETECTED changed in Mulesoft Bookings..." }
40+ logger.debug { " DETECTED change in Mulesoft Bookings..." }
4141 @bookings = Array (Hash (String , Int64 | String | Nil )).from_json(mulesoft_bookings)
4242 logger.debug { " #{ @bookings .size} bookings in total" }
4343 self [:total_bookings ] = @bookings .size
@@ -73,7 +73,9 @@ class MuleSoft::CalendarExporter < PlaceOS::Driver
7373 ).get.as_a
7474 end
7575
76- protected def export_booking (booking : Hash (String , Int64 | String | Nil ))
76+ protected def export_booking (mulesoft_booking : Hash (String , Int64 | String | Nil ))
77+ # The resulting Calendar Event is to be slightly different to the Mulesoft Booking, so clone here and transform
78+ booking = mulesoft_booking.clone
7779 # Add the course code to the front of the booking title/body
7880 booking[" title" ] = " #{ booking[" recurring_master_id" ] } #{ booking[" title" ] || booking[" body" ] } "
7981 logger.debug { " Checking for existing events that match: #{ booking } " }
@@ -89,17 +91,17 @@ class MuleSoft::CalendarExporter < PlaceOS::Driver
8991 attendees: [@just_this_system ],
9092 location: system.name.not_nil!,
9193 }
92- logger.debug { " >>> EXPORTING booking #{ new_event } " }
94+ logger.debug { " >>> EXPORTING booking as: #{ new_event } " }
9395 calendar.create_event(** new_event)
9496 end
9597 end
9698
97- protected def event_already_exists? (new_event : Hash (String , Int64 | String | Nil ), existing_events : Array (JSON ::Any ))
98- existing_events.any? { |existing_event | events_match?(new_event , existing_event.as_h) }
99+ protected def event_already_exists? (booking : Hash (String , Int64 | String | Nil ), existing_events : Array (JSON ::Any ))
100+ existing_events.any? { |existing_event | booking_matches_event?(booking , existing_event.as_h) }
99101 end
100102
101- protected def events_match? ( event_a : Hash (String , Int64 | String | Nil ), event_b : Hash (String , JSON ::Any ))
102- event_a .select(" event_start" , " event_end" , " title" ) == event_b .select(" event_start" , " event_end" , " title" )
103+ protected def booking_matches_event? ( booking : Hash (String , Int64 | String | Nil ), event : Hash (String , JSON ::Any ))
104+ booking .select(" event_start" , " event_end" , " title" ) == event .select(" event_start" , " event_end" , " title" )
103105 end
104106
105107 def delete_all_events (past_days : Int32 = 14 , future_days : Int32 = 14 )
0 commit comments