Class: SpreeCmCommissioner::Integrations::Larryta::Polling::SyncTrips
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::Larryta::Polling::SyncTrips
- Defined in:
- app/services/spree_cm_commissioner/integrations/larryta/polling/sync_trips.rb
Overview
SyncTrips synchronizes Larryta schedule data into BookMe+ transit records.
Larryta’s API provides schedules per direction+date via ‘POST /gateway/get_schedules`. This service:
1. Resolves the Larryta direction_id from the Route's integration mapping
2. Fetches schedules for the given date from the Larryta API
3. For each schedule:
a. Syncs VehicleType (from bus_type_data)
b. Syncs Product (one per direction, shared by all schedules)
c. Syncs Variant (unique per schedule_id + date)
d. Syncs Trip record (the core transit trip entity)
e. Syncs StockItem (StockItem count_on_hand = total_available)
f. Enqueues PermanentInventoryItemsGeneratorJob for new variants
4. Archives stale trip mappings that were not returned by the API
5. Touches the route mapping's last_synced_at
Key Design Decisions
-
No ServiceCalendar: schedules are fetched per-date; no calendar model needed.
-
Direction ID: resolved from IntegrationMapping for the given Route.
-
Departure time: parsed from schedule.time string (“08:00 AM”) on schedule.date.
-
Sync identifier: “#schedule_id-#depart_date” — unique per trip/date combo.
-
SeatLayout: synced from Larryta bus template after trip creation.
Larryta API Schedule Response (abbreviated)
{
"schedule_id": 516250,
"sche_date": "2025-08-31",
"sche_time": "08:00 AM",
"direction_id": 1,
"bus_type_id": 3,
"prices": { "unit_price": "13.00", "net_price": 11.75 },
"bus_type": { "bus_name": "Minivan 15 Seats", "seat_num": 15 },
"direction": { "dire_code": "PP-SR", "arrival_time": "02:00 PM", ... },
"total_available": 15,
"total_unavailable": 0
}
Instance Attribute Summary collapse
-
#integration ⇒ Object
readonly
rubocop:disable Metrics/ClassLength.
-
#route ⇒ Object
readonly
rubocop:disable Metrics/ClassLength.
-
#sync_result ⇒ Object
readonly
rubocop:disable Metrics/ClassLength.
-
#vendor ⇒ Object
readonly
rubocop:disable Metrics/ClassLength.
Instance Method Summary collapse
- #call(on_date: nil) ⇒ Object
-
#initialize(integration:, sync_result: nil, route: nil) ⇒ SyncTrips
constructor
A new instance of SyncTrips.
Constructor Details
#initialize(integration:, sync_result: nil, route: nil) ⇒ SyncTrips
Returns a new instance of SyncTrips.
44 45 46 47 48 49 50 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_trips.rb', line 44 def initialize(integration:, sync_result: nil, route: nil) @integration = integration @sync_result = sync_result || SpreeCmCommissioner::Integrations::Base::SyncResult.new @route = route @vendor = integration.vendor @location_mappings = {} end |
Instance Attribute Details
#integration ⇒ Object (readonly)
rubocop:disable Metrics/ClassLength
42 43 44 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_trips.rb', line 42 def integration @integration end |
#route ⇒ Object (readonly)
rubocop:disable Metrics/ClassLength
42 43 44 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_trips.rb', line 42 def route @route end |
#sync_result ⇒ Object (readonly)
rubocop:disable Metrics/ClassLength
42 43 44 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_trips.rb', line 42 def sync_result @sync_result end |
#vendor ⇒ Object (readonly)
rubocop:disable Metrics/ClassLength
42 43 44 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_trips.rb', line 42 def vendor @vendor end |
Instance Method Details
#call(on_date: nil) ⇒ Object
53 54 55 56 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_trips.rb', line 53 def call(on_date: nil) preload_location_mappings! sync_items!(on_date) end |