Module: LibTAD::Client::AstronomyService

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

Overview

Astronomy API.

Instance Method Summary collapse

Instance Method Details

#get_astro_events(object:, place_id:, start_date: nil, end_date: nil, types: nil, geo: nil, isotime: nil, lang: nil, radius: nil, utctime: nil) ⇒ Array<::LibTAD::Astronomy::AstronomyLocation>

The Astro Event service can be used retrieve the sunrise, sunset, moonrise, moonset, solar noon and twilight times for all locations in our database. The service also returns the azimuth of the events, the altitude, and the distance to the sun for the noon event.

Parameters:

  • object (Symbol)

    Specify an object type to retrieve information about.

  • place_id (String)

    Specify the ID or a list of IDs of the location(s) you would like to retrieve information for.

  • start_date (String) (defaults to: nil)

    Specify the ISO 8601 date for the first date you are interested in. Defaults to current date.

  • end_date (String) (defaults to: nil)

    The last date you are interested in. The service can be used to calculate data for a maximum of 31 days in a row. If the end date is omitted, only one day is retrieved.

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

    Specify an astronomical event class or a list of classes to filter by.

  • geo (Boolean) (defaults to: nil)

    Return longitude and latitude for the geo object.

  • isotime (Boolean) (defaults to: nil)

    Adds time stamps (local time) in ISO 8601 format to all events.

  • lang (String) (defaults to: nil)

    Preferred language for texts.

  • radius (Integer) (defaults to: nil)

    Search radius for translating coordinates to locations.

  • utctime (Boolean) (defaults to: nil)

    Adds UTC time stamps in ISO 8601 format to all events.

Returns:

See Also:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/services/astronomy.rb', line 24

def get_astro_events(
  object:,
  place_id:,
  start_date: nil,
  end_date: nil,
  types: nil,
  geo: nil,
  isotime: nil,
  lang: nil,
  radius: nil,
  utctime: nil
)
  args = {
    object: (object unless !::LibTAD::Astronomy::ASTRONOMY_OBJECT_TYPE.include?(object)),
    placeid: place_id,
    startdt: if start_date.nil? then ::Time.now.strftime('%Y-%m-%d') else start_date end,
    enddt: end_date,
    types: (types unless ![*types].all? { |e| ::LibTAD::Astronomy::ASTRONOMY_EVENT_CLASS.include?(e) }),
    geo: geo,
    isotime: isotime,
    lang: lang,
    radius: radius,
    utctime: utctime
  }.compact

  response = get('astronomy', args)
  astroevents = response.fetch('locations', [])

  astroevents.collect do |e|
    ::LibTAD::Astronomy::AstronomyLocation.new(e)
  end
end

#get_astro_position(object:, place_id:, interval:, localtime: nil, utctime: nil, isotime: nil, lang: nil, radius: nil) ⇒ Array<::LibTAD::Astronomy::AstronomyLocation>

The Astro Position service can be used to retrieve the altitude, azimuth and distance to the Moon and the Sun for all locations in our database. The service also returns the moon phase, the fraction of the Moon’s illuminated side as well as the midpoint angle of the Moon’s bright limb at any point in time. Unlike the Astro Event service, the Astro Position service can be queried on a specific point in time, down to the second.

Parameters:

  • object (Symbol)

    Specify an object type to retrieve information about.

  • place_id (String)

    Specify the ID of the location you would like to retrieve information for.

  • interval (String or Array<String>)

    Specify the point or a list of points in time you would like to calculate data for.

  • localtime (Boolean) (defaults to: nil)

    Specify whether or not the intervals should be considered the local time for the place(s) or UTC time.

  • utctime (Boolean) (defaults to: nil)

    Adds UTC time stamps in ISO 8601 format to all events.

  • isotime (Boolean) (defaults to: nil)

    Adds time stamps (local time) in ISO 8601 format to all events.

  • lang (String) (defaults to: nil)

    Preferred language for texts.

  • radius (Integer) (defaults to: nil)

    Search radius for translating coordinates to locations.

Returns:

See Also:



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/services/astronomy.rb', line 72

def get_astro_position(
  object:,
  place_id:,
  interval:,
  localtime: nil,
  utctime: nil,
  isotime: nil,
  lang: nil,
  radius: nil
)
  args = {
    object: (object unless !::LibTAD::Astronomy::ASTRONOMY_OBJECT_TYPE.include?(object)),
    placeid: place_id,
    interval: interval,
    localtime: localtime,
    utctime: utctime,
    isotime: isotime,
    lang: lang,
    radius: radius
  }.compact

  response = get('astrodata', args)
  astropositions = response.fetch('locations', [])

  astropositions.collect do |e|
    ::LibTAD::Astronomy::AstronomyLocation.new(e)
  end
end