Class: HolidaysFromGoogleCalendar::Client
- Inherits:
-
Object
- Object
- HolidaysFromGoogleCalendar::Client
- Defined in:
- lib/holidays_from_google_calendar/client.rb
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Client
constructor
A new instance of Client.
- #retrieve(date_min: nil, date_max: nil) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Client
Returns a new instance of Client.
3 4 5 6 7 8 9 10 11 |
# File 'lib/holidays_from_google_calendar/client.rb', line 3 def initialize(configuration) @nation = configuration.calendar[:nation] @language = configuration.calendar[:language] @api_key = configuration.credential[:api_key] @cache = Cache.new(**configuration.cache) return unless configuration.preload[:enable] preload(configuration.preload[:date_range]) end |
Instance Method Details
#retrieve(date_min: nil, date_max: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/holidays_from_google_calendar/client.rb', line 13 def retrieve(date_min: nil, date_max: nil) date_min = Date.parse(date_min.iso8601) date_max = Date.parse(date_max.iso8601) if @cache.enabled? cached_holidays = @cache.retrieve(date_min, date_max) return cached_holidays if cached_holidays end retrieve_from_google_calendar(date_min, date_max).tap do |holidays| @cache.cache(holidays, date_min, date_max) if @cache.enabled? end end |