Class: Bistrochat::Availabilities::Timetable
- Inherits:
-
Object
- Object
- Bistrochat::Availabilities::Timetable
- Includes:
- Bistrochat::ApiHelpers, DefaultErrorContainer, ElasticAPM::SpanHelpers
- Defined in:
- app/services/bistrochat/availabilities/timetable.rb
Overview
Timetable service for fetching Bistrochat timeslot availabilities.
Splits requested dates into blocks of up to 7 days (Bistrochat API limit), fetches each block in parallel, and aggregates results.
Error handling and logging are performed using APMErrorHandler and BUSINESS_LOGGER. Supplier validation is handled by the calling service, not in this class.
Instance Attribute Summary collapse
-
#dates ⇒ Object
readonly
Returns the value of attribute dates.
-
#fetcher_service ⇒ Object
readonly
Returns the value of attribute fetcher_service.
-
#party_size ⇒ Object
readonly
Returns the value of attribute party_size.
-
#restaurant ⇒ Object
readonly
Returns the value of attribute restaurant.
-
#restaurant_id ⇒ Object
readonly
Returns the value of attribute restaurant_id.
-
#shop_id ⇒ Object
readonly
Returns the value of attribute shop_id.
Instance Method Summary collapse
-
#fetch_timeslots_with_availability ⇒ Array<Hash>
Fetch available timeslots for all requested dates.
-
#initialize(restaurant, dates, party_size) ⇒ Timetable
constructor
Initialize Timetable service.
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Methods included from Bistrochat::ApiHelpers
#api_call, #channel, #find_bistrochat_vendor_application, #get_purpose, #headers, #parse_phone_number, #parse_user_or_guest_full_name, #parsed_vendor_name, #reservation_start_at, #send_error_availability_notification_to_staff
Constructor Details
#initialize(restaurant, dates, party_size) ⇒ Timetable
Initialize Timetable service.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/services/bistrochat/availabilities/timetable.rb', line 22 def initialize(restaurant, dates, party_size) @restaurant = restaurant @restaurant_id = restaurant.id @dates = dates @party_size = party_size @shop_id = restaurant&.bistrochat_restaurant&.shop_id.to_s @fetcher_service = VendorsService::InventorySync::InventoryFetcherService.new( restaurant: restaurant, supplier: :bistrochat, ) end |
Instance Attribute Details
#dates ⇒ Object (readonly)
Returns the value of attribute dates.
15 16 17 |
# File 'app/services/bistrochat/availabilities/timetable.rb', line 15 def dates @dates end |
#fetcher_service ⇒ Object (readonly)
Returns the value of attribute fetcher_service.
15 16 17 |
# File 'app/services/bistrochat/availabilities/timetable.rb', line 15 def fetcher_service @fetcher_service end |
#party_size ⇒ Object (readonly)
Returns the value of attribute party_size.
15 16 17 |
# File 'app/services/bistrochat/availabilities/timetable.rb', line 15 def party_size @party_size end |
#restaurant ⇒ Object (readonly)
Returns the value of attribute restaurant.
15 16 17 |
# File 'app/services/bistrochat/availabilities/timetable.rb', line 15 def restaurant @restaurant end |
#restaurant_id ⇒ Object (readonly)
Returns the value of attribute restaurant_id.
15 16 17 |
# File 'app/services/bistrochat/availabilities/timetable.rb', line 15 def restaurant_id @restaurant_id end |
#shop_id ⇒ Object (readonly)
Returns the value of attribute shop_id.
15 16 17 |
# File 'app/services/bistrochat/availabilities/timetable.rb', line 15 def shop_id @shop_id end |
Instance Method Details
#fetch_timeslots_with_availability ⇒ Array<Hash>
Fetch available timeslots for all requested dates. Uses the shared fetcher service for common HTTP handling logic.
38 39 40 41 42 43 44 45 46 47 |
# File 'app/services/bistrochat/availabilities/timetable.rb', line 38 def fetch_timeslots_with_availability raise ArgumentError, "shop_id is blank for restaurant_id=#{restaurant_id}" if shop_id.blank? raise ArgumentError, 'party_size must be present and > 0' if @party_size.nil? || @party_size <= 0 BUSINESS_LOGGER.set_business_context({ restaurant_id: restaurant_id }) fetcher_service.execute_parallel_requests(dates) do |block, hydra, | queue_request(block, hydra, ) end end |