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



65
66
67
68
69
70
# File 'lib/lita/handlers/onewheel_moonphase.rb', line 65

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



72
73
74
75
76
77
78
79
80
# File 'lib/lita/handlers/onewheel_moonphase.rb', line 72

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

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

  location
end

#mars(response) ⇒ Object

🌑🌛



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lita/handlers/onewheel_moonphase.rb', line 18

def mars(response)
  api_resp = RestClient.get 'https://api.maas2.apollorion.com'
  data = JSON.parse(api_resp)
  # {
  #   "status": 200,
  #   "id": 198,
  #   "sol": 2108,
  #   "season": "Month 7",
  #   "min_temp": -65,
  #   "max_temp": -24,
  #   "atmo_opacity": "Sunny",
  #   "sunrise": "05:19",
  #   "sunset": "17:27",
  #   "min_gts_temp": -58,
  #   "max_gts_temp": -15,
  #   "unitOfMeasure": "Celsius",
  #   "TZ_Data": "America/Port_of_Spain"
  # }

  resp = "Sol #{data['sol']}, #{data['season']}, A #{data['atmo_opacity']} day with a min temp of #{data['min_temp']} and a high of #{data['max_temp']} #{data['unitOfMeasure']}.  Sunrise is at #{data['sunrise']} and sunset occurs at #{data['sunset']}."
  response.reply resp
end

#moon(response) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/lita/handlers/onewheel_moonphase.rb', line 40

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'        => '🌚',
    'Waxing Crescent' => '🌒',
    'First Quarter'   => '🌓',
    'Waxing Gibbous'  => '🌔',
    'Full Moon'       => '🌕',
    'Waning Gibbous'  => '🌖',
    'Last Quarter'    => '🌗',
    'Waning 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