Slide 17
Slide 17 text
Crystal way
require "http/client"
require "json"
class WeatherResponse
json_mapping({
weather: Array(Weather),
})
class Weather
json_mapping({
id: Int32,
main: String,
description: String,
icon: String,
})
end
end
place = ARGV[0]
url = "http://api.openweathermap.org/data/2.5/weather?q=#{place}"
resp = HTTP::Client.get(url)
puts "-" * 80
weather_resp = WeatherResponse.from_json(resp.body)
pp weather_resp
pp weather_resp.weather[0].main