Class: GouvCalendarCompilator::DataFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/gouv_calendar_compilator/data_fetcher.rb

Overview

This is the Data Fetcher Object for the Gouv Data Compilator gem It manages the fetching of the needed data through the different sources

Instance Method Summary collapse

Instance Method Details

#fetch_national_days_off_dataObject

Method used to fetch national days off data from governement open data sources



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gouv_calendar_compilator/data_fetcher.rb', line 16

def fetch_national_days_off_data
  ndo_data_full = []
  ::GouvCalendarCompilator::DAYS_OFF_ZONES_MATCHING.each_key do |zone_name|
    zone_data = {}
    (::GouvCalendarCompilator::YEAR_START..::GouvCalendarCompilator::YEAR_END).each do |year|
      url = ::GouvCalendarCompilator::DAYS_OFF_API_BASE_URL + "#{zone_name}/#{year}.json"
      zone_data.merge!(::JSON.parse(::URI.parse(url).read))
    end
    ndo_data_full.push({ data: zone_data, zones: ::GouvCalendarCompilator::DAYS_OFF_ZONES_MATCHING[zone_name] })
  end
  ndo_data_full
end

#fetch_school_holidays_dataObject

Method used to fetch school holidays data from governement open data sources



30
31
32
# File 'lib/gouv_calendar_compilator/data_fetcher.rb', line 30

def fetch_school_holidays_data
  ::JSON.parse(::URI.parse(::GouvCalendarCompilator::SCHOOL_HOLIDAYS_DATA_URL).read)
end