Class: SpreeCmCommissioner::Integrations::Larryta::Polling::SyncSeatLayout
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::Larryta::Polling::SyncSeatLayout
- Defined in:
- app/services/spree_cm_commissioner/integrations/larryta/polling/sync_seat_layout.rb
Overview
SyncSeatLayout handles synchronization of seat layouts from Larryta API
This service is responsible for:
-
Fetching seat layout data from Larryta API for a specific schedule
-
Creating or updating SeatLayout records for vehicle types (bus types)
-
Creating Block records representing individual seats
-
Supporting multi-layer layouts (e.g., double-decker buses)
-
Managing integration mappings for seat layouts
-
Tracking sync results and metrics
Larryta API Payload Structure:
{
"data": {
"schedule_id": 626511,
"sche_date": "2026-04-02",
"sche_time": "15:30",
"bus_template": {
"bus_type_id": 3,
"bus_name": "Minivan 15 Seats",
"seat_num": 15,
"seat_map": [
[
{"label": "DR_IMG", "class": "available", "booking": []},
{"label": "", "class": "available", "booking": []},
{"label": 1, "class": "available", "booking": []},
{"label": 2, "class": "available", "booking": []}
],
...
]
}
}
}
Usage:
sync_service = SyncSeatLayout.new(integration: integration, sync_result: sync_result)
seat_layout = sync_service.call(vehicle_type: vehicle_type, schedule: schedule, variant: variant)
Instance Method Summary collapse
-
#call(vehicle_type:, schedule:, variant: nil) ⇒ SpreeCmCommissioner::SeatLayout?
The synced seat layout or nil.
-
#initialize(integration:, sync_result: nil) ⇒ SyncSeatLayout
constructor
A new instance of SyncSeatLayout.
Constructor Details
#initialize(integration:, sync_result: nil) ⇒ SyncSeatLayout
Returns a new instance of SyncSeatLayout.
40 41 42 43 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_seat_layout.rb', line 40 def initialize(integration:, sync_result: nil) @integration = integration @sync_result = sync_result || SpreeCmCommissioner::Integrations::Base::SyncResult.new end |
Instance Method Details
#call(vehicle_type:, schedule:, variant: nil) ⇒ SpreeCmCommissioner::SeatLayout?
Returns The synced seat layout or nil.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_seat_layout.rb', line 49 def call(vehicle_type:, schedule:, variant: nil) return nil if vehicle_type.blank? || schedule.blank? external_seat_layout = fetch_external_seat_layout(schedule) return nil if external_seat_layout.blank? vehicle_seat_layout = sync_vehicle_type_template!(vehicle_type:, external_seat_layout:) sync_trip_layout_if_needed!(vehicle_seat_layout:, variant:) if variant.present? vehicle_seat_layout rescue SpreeCmCommissioner::Integrations::ExternalClientError => e @sync_result.record_error(SpreeCmCommissioner::Integrations::SyncError.new("Failed to sync seat layout: #{e.}")) nil rescue StandardError => e @sync_result.record_error(StandardError.new("[Larryta::SyncSeatLayout] #{e.}")) nil end |