14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/lita/handlers/time.rb', line 14
def fetch(response)
location = response.matches[0][0]
apikey = Lita.config.handlers.time.apikey
http_response = http.get(
URL,
q: location,
key: apikey,
format: 'json'
)
begin
data = MultiJson.load(http_response.body)["data"]
type = data['request'][0]['type']
query = data['request'][0]['query']
time = data['time_zone'][0]['localtime'].split(/ /)[1]
response.reply t("response.success", :type => type, :query => query, :time => time)
rescue MultiJson::ParseError
response.reply t("response.json_failure", :location => location)
rescue
response.reply t("response.failure", :location => location)
end
end
|