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.



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.



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