diff --git a/Gemfile.lock b/Gemfile.lock index 1dc8870..11393ec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -91,6 +91,8 @@ GEM multi_json (1.11.2) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) + nokogiri (1.6.7.2-x86-mingw32) + mini_portile2 (~> 2.0.0.rc2) quiet_assets (1.1.0) railties (>= 3.1, < 5.0) rack (1.6.4) @@ -159,11 +161,14 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.11) + sqlite3 (1.3.11-x86-mingw32) thor (0.19.1) thread_safe (0.3.5) tilt (2.0.2) tzinfo (1.2.2) thread_safe (~> 0.1) + tzinfo-data (1.2016.4) + tzinfo (>= 1.0.0) uglifier (3.0.0) execjs (>= 0.3.0, < 3) webmock (1.24.5) @@ -175,6 +180,7 @@ GEM PLATFORMS ruby + x86-mingw32 DEPENDENCIES better_errors diff --git a/app/controllers/forecast_controller.rb b/app/controllers/forecast_controller.rb index 720b50c..902724a 100644 --- a/app/controllers/forecast_controller.rb +++ b/app/controllers/forecast_controller.rb @@ -16,17 +16,25 @@ def coords_to_weather # The longitude the user input is in the string @lng. # ========================================================================== + url_lat_lng = @lat+ "," + @lng + @url = "https://api.forecast.io/forecast/89941ac599de9219989802563cbd5e2a/" + url_lat_lng + @raw_data = open(@url).read + @parsed_data = JSON.parse(@raw_data) - @current_temperature = "Replace this string with your answer." + # @results = @parsed_data["results"] + # @first = @results[0] + # @geometry = @first["geometry"] - @current_summary = "Replace this string with your answer." + @current_temperature = @parsed_data["currently"]["temperature"] - @summary_of_next_sixty_minutes = "Replace this string with your answer." + @current_summary = @parsed_data["currently"]["summary"] - @summary_of_next_several_hours = "Replace this string with your answer." + @summary_of_next_sixty_minutes = @parsed_data["minutely"]["summary"] - @summary_of_next_several_days = "Replace this string with your answer." + @summary_of_next_several_hours = @parsed_data["hourly"]["summary"] + + @summary_of_next_several_days = @parsed_data["daily"]["summary"] render("coords_to_weather.html.erb") end diff --git a/app/controllers/geocoding_controller.rb b/app/controllers/geocoding_controller.rb index 542ec85..c44d156 100644 --- a/app/controllers/geocoding_controller.rb +++ b/app/controllers/geocoding_controller.rb @@ -1,4 +1,5 @@ require 'open-uri' +require 'json' class GeocodingController < ApplicationController def street_to_coords_form @@ -17,11 +18,19 @@ def street_to_coords # characters removed, is in the string url_safe_street_address. # ========================================================================== + @url = "http://maps.googleapis.com/maps/api/geocode/json?address=" + url_safe_street_address + @parsed_data = JSON.parse(open(@url).read) + # @results = @parsed_data["results"] + # @first = @results[0] + # @geometry = @first["geometry"] - @latitude = "Replace this string with your answer." + @latitude = @parsed_data["results"][0]["geometry"]["location"]["lat"] + @longitude = @parsed_data["results"][0]["geometry"]["location"]["lng"] - @longitude = "Replace this string with your answer." + # @latitude = "Replace this string with your answer." + # + # @longitude = "Replace this string with your answer." render("street_to_coords.html.erb") end diff --git a/app/controllers/meteorologist_controller.rb b/app/controllers/meteorologist_controller.rb index 8a3c4a4..8c6bf46 100644 --- a/app/controllers/meteorologist_controller.rb +++ b/app/controllers/meteorologist_controller.rb @@ -17,17 +17,26 @@ def street_to_weather # characters removed, is in the string url_safe_street_address. # ========================================================================== + @url1 = "http://maps.googleapis.com/maps/api/geocode/json?address=" + url_safe_street_address + @parsed_data1 = JSON.parse(open(@url1).read) + @latitude = @parsed_data1["results"][0]["geometry"]["location"]["lat"] + @longitude = @parsed_data1["results"][0]["geometry"]["location"]["lng"] + @lat = @latitude.to_s + @lng = @longitude.to_s + url_lat_lng = @lat + "," + @lng + @url = "https://api.forecast.io/forecast/89941ac599de9219989802563cbd5e2a/" + url_lat_lng + @parsed_data = JSON.parse(open(@url).read) - @current_temperature = "Replace this string with your answer." + @current_temperature = @parsed_data["currently"]["temperature"] - @current_summary = "Replace this string with your answer." + @current_summary = @parsed_data["currently"]["summary"] - @summary_of_next_sixty_minutes = "Replace this string with your answer." + @summary_of_next_sixty_minutes = @parsed_data["minutely"]["summary"] - @summary_of_next_several_hours = "Replace this string with your answer." + @summary_of_next_several_hours = @parsed_data["hourly"]["summary"] - @summary_of_next_several_days = "Replace this string with your answer." + @summary_of_next_several_days = @parsed_data["daily"]["summary"] render("street_to_weather.html.erb") end