Class: SpreeCmCommissioner::Integrations::BookMeBusV1::Polling::SyncServiceCalendars
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::BookMeBusV1::Polling::SyncServiceCalendars
- Defined in:
- app/services/spree_cm_commissioner/integrations/book_me_bus_v1/polling/sync_service_calendars.rb
Instance Method Summary collapse
- #call(product:, external_trip:) ⇒ Object
-
#initialize(integration:, sync_result: nil) ⇒ SyncServiceCalendars
constructor
A new instance of SyncServiceCalendars.
Constructor Details
#initialize(integration:, sync_result: nil) ⇒ SyncServiceCalendars
Returns a new instance of SyncServiceCalendars.
3 4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/polling/sync_service_calendars.rb', line 3 def initialize(integration:, sync_result: nil) @integration = integration @sync_result = sync_result || SpreeCmCommissioner::Integrations::Base::SyncResult.new end |
Instance Method Details
#call(product:, external_trip:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/polling/sync_service_calendars.rb', line 8 def call(product:, external_trip:) return unless product && external_trip.service_calendar.is_a?(Hash) calendar_data = external_trip.service_calendar service_calendar = product.service_calendar || product.build_service_calendar @sync_result.track(:service_calendar, service_calendar) do |tracker| service_calendar.assign_attributes( name: calendar_data['name'] || 'Default', monday: calendar_data['monday'] != false, tuesday: calendar_data['tuesday'] != false, wednesday: calendar_data['wednesday'] != false, thursday: calendar_data['thursday'] != false, friday: calendar_data['friday'] != false, saturday: calendar_data['saturday'] != false, sunday: calendar_data['sunday'] != false, start_date: parse_date(calendar_data['start_date']), end_date: parse_date(calendar_data['end_date']), exception_rules: build_exception_rules(calendar_data['service_exception_rules']) ) tracker.save_if_changed!(service_calendar) end service_calendar end |