Class: Lita::Handlers::Catfacts

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

Instance Method Summary collapse

Instance Method Details

#catfacts(response) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lita/handlers/catfacts.rb', line 8

def catfacts(response)
  resp = http.get('http://catfacts-api.appspot.com/api/facts?number=1')

  raise 'RequestFail' unless resp.status == 200
  
  obj = MultiJson.load(resp.body)

  raise 'ApiError' unless obj['success'] == "true"


  response.reply obj['facts'][0]

rescue
  response.reply "Sorry, I was unable to find any cool facts about cats."
end