Class: Lita::Handlers::Tuc

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

Constant Summary collapse

URL =
"https://tuc.herokuapp.com/v2/"

Instance Method Summary collapse

Instance Method Details

#tuc(response) ⇒ Object



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

def tuc(response)
  query = response.matches[0][0]

  http_response = http.get(
    URL + query
  )

  data = MultiJson.load(http_response.body)

  if data['error']
    reason = data['error']['message'] || "unknown error"
    Lita.logger.warn(
      "Error: #{reason}"
    )
  else
    response.reply data['balance']
  end
rescue => e
  Lita.logger.error("Tuc#balance raised #{e.class}: #{e.message}")
  response.reply "Tuc has turned off the internetz, #{e.class} is raising '#{e.message}'"
end