Class: Lita::Handlers::OnewheelMoonphase

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/onewheel_moonphase.rb

Instance Method Summary collapse

Instance Method Details

#get_data(location) ⇒ Object



38
39
40
41
42
43
# File 'lib/lita/handlers/onewheel_moonphase.rb', line 38

def get_data(location)
  Lita.logger.debug "Getting Moon data for #{location}"
  uri = "https://j8jqi56gye.execute-api.us-west-2.amazonaws.com/prod/moon?loc=#{URI.encode location}"
  Lita.logger.debug uri
  JSON.parse(RestClient.get(uri))
end

#get_location(response) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/lita/handlers/onewheel_moonphase.rb', line 45

def get_location(response)
  location = response.matches[0][0]

  if location.empty?
    location = '45.5230622,-122.6764816'
  end

  location
end

#moon(response) ⇒ Object

🌑🌛



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

def moon(response)
  location = get_location(response)
  moon = get_data(location)

  # today = Time.now
  rise_time = Time.parse moon['moondata']['rise']
  set_time = Time.parse moon['moondata']['set']

  emoonjis = {
      'New Moon'        => '🌚',
      'Waning Crescent' => '🌘',
      'Last Quarter'    => '🌗',
      'Waxing Gibbous'  => '🌔',
      'Full Moon'       => '🌕',
      'Waning Gibbous'  => '🌖',
      'First Quarter'   => '🌓',
      'Waxing Crescent' => '🌒'
  }

  reply = "#{emoonjis[moon['moondata']['curphase']]} Moon phase #{moon['moondata']['fracillum']}, #{moon['moondata']['curphase']}.  "
  reply += "Rise: #{rise_time.strftime("%H:%M")}  Set: #{set_time.strftime('%H:%M')}"
  Lita.logger.debug "Replying with #{reply}"
  response.reply reply
end