class Weather_Noveo
require “weather_noveo/version”
Public Class Methods
show()
click to toggle source
# File lib/weather_noveo.rb, line 4 def self.show require 'uri' require 'net/http' require 'openssl' city = gets[0..-2] url = URI("https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/#{city}?key=8MPZ8GGY87S9TUHR6N6TQXFBH") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) response = http.request(request) body = response.read_body require "json" body = response.read_body # From the URL query code above weather = JSON.parse(body) #time = Time.new #puts time.day #puts time.month #puts time.year puts "today is #{weather["days"][0]["datetime"]}" puts weather["days"][0]["description"] puts "max weather is #{weather["days"][0]["tempmax"]} F" puts "min weather is #{weather["days"][0]["tempmin"]} F" puts "current weather is #{weather["days"][0]["temp"]} F" #puts "Forecast for date: #{weather_date}" #puts " General conditions: #{weather_desc}" #puts " The high temperature will be #{weather_tmax}" #puts " The low temperature will be #{weather_tmin}" end