Module: LibTAD::Client::HolidaysService

Included in:
LibTAD::Client
Defined in:
lib/services/holidays.rb

Overview

Holidays API.

Instance Method Summary collapse

Instance Method Details

#get_holidays(country:, year: nil, lang: nil, types: nil, timezone: nil) ⇒ Array<::LibTAD::Holidays::Holiday>

The Holidays service can be used to retrieve the list of holidays for a country.

Parameters:

  • country (String)

    Specify the ISO3166-1-alpha-2 Country Code for which you would like to retrieve the list of holidays.

  • year (Integer) (defaults to: nil)

    The year for which the holidays should be retrieved. Defaults to current year.

  • lang (String or Array<String>) (defaults to: nil)

    Specify the ISO639 Language Code or a list of codes for the texts.

  • types (Symbol or Array<Symbol>) (defaults to: nil)

    Specify a holiday type or a list of holiday types to filter by.

  • timezone (Boolean) (defaults to: nil)

    Adds time zone information under the time object.

Returns:

See Also:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/services/holidays.rb', line 16

def get_holidays(country:, year: nil, lang: nil, types: nil, timezone: nil)
  args = {
    country: country,
    lang: lang,
    types: (types unless ![*types].all? { |e| ::LibTAD::Holidays::HOLIDAY_TYPE.include?(e) }),
    year: if year.nil? then ::Time.now.year else year end,
    tz: timezone
  }.compact

  response = get('holidays', args)
  holidays = response.fetch('holidays', [])

  holidays.collect do |e|
    ::LibTAD::Holidays::Holiday.new(e)
  end
end