Module: LibTAD::Client::OnThisDayService

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

Overview

On This Day API.

Instance Method Summary collapse

Instance Method Details

#get_events_on_this_day(month: nil, day: nil, lang: nil, types: nil) ⇒ Array<::LibTAD::OnThisDay::Event>, Array<::LibTAD::OnThisDay::Person>

The On This Day service can be used to retrieve events, births and deaths for a specific date.

Parameters:

  • month (Integer) (defaults to: nil)

    The month for which the events should be retrieved. Defaults to current month.

  • day (Integer) (defaults to: nil)

    The day for which the events should be retrieved. Defaults to current day.

  • 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 an event type or a list of event types to filter by.

Returns:

See Also:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/services/onthisday.rb', line 13

def get_events_on_this_day(month: nil, day: nil, lang: nil, types: nil)
  args = {
    month: month,
    day: day,
    lang: lang,
    types: (types unless ![*types].all? { |e| ::LibTAD::OnThisDay::EVENT_TYPE.include?(e) }),
  }.compact

  response = get('onthisday', args)
  events = response.fetch('events', [])
  births = response.fetch('births', [])
  deaths = response.fetch('deaths', [])

  events = events.collect do |e|
    ::LibTAD::OnThisDay::Event.new(e)
  end

  births = births.collect do |e|
    ::LibTAD::OnThisDay::Person.new(e)
  end

  deaths = deaths.collect do |e|
    ::LibTAD::OnThisDay::Person.new(e)
  end

  return events, births, deaths
end