Class: MenuDataService

Inherits:
Object
  • Object
show all
Includes:
ElasticAPM::SpanHelpers
Defined in:
app/services/menu_data_service.rb

Overview

Service class to handle menu data fetching and processing from external API Handles both Ayce and PartyPack menu data formats

CHANGE (2025-09): Time limit attributes (`use_time_limit` / `time_limit_minutes`) are evaluated for all section types, but the exposed output now ONLY includes `:minutes` for UNLIMITED items (Ayce & PartyPack). Limited items (including beverages) never include `:minutes` even if a time limit exists upstream.

Constant Summary collapse

AYCE_TYPE =
'HhPackage::Package::Ayce'.freeze
SECTION_TYPE =
'section'.freeze
'menu_group_section'.freeze
BEVERAGE_SECTION =
'beverage'.freeze
FOOD_SECTION =
'food'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(menu_group_id, package_id, package_type) ⇒ MenuDataService

Returns a new instance of MenuDataService.



16
17
18
19
20
# File 'app/services/menu_data_service.rb', line 16

def initialize(menu_group_id, package_id, package_type)
  @menu_group_id = menu_group_id
  @package_id = package_id
  @package_type = package_type
end

Instance Method Details

#callHash?

Fetch and process menu data from external API

Returns:

  • (Hash, nil)

    Processed menu data or nil if not available



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/services/menu_data_service.rb', line 24

def call
  ElasticAPM.with_span('MenuDataService#call', 'ext', subtype: 'http') do
    response = fetch_menu_data_from_api
    return nil unless response_valid?(response)

    result = parse_response(response)
    return nil unless result_valid?(result)

    process_menu_data(result)
  rescue StandardError => e
    HH_LOGGER.error('Error in MenuDataService#call', {
                      error: e.message,
                      menu_group_id: @menu_group_id,
                      package_id: @package_id,
                      package_type: @package_type,
                    })
    APMErrorHandler.report(e, context: {
                             menu_group_id: @menu_group_id,
                             package_id: @package_id,
                             package_type: @package_type,
                           })
    nil
  end
end