diff --git a/Gemfile.lock b/Gemfile.lock index 5fdee76..58697bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://github.com/firstdraft/grade_runner.git - revision: 881cce30367bc9a5f15a3e4ac4cb48599dbecec2 + revision: 83db5d2b90086055aa3204afe38a18394aecea16 specs: grade_runner (0.0.1) @@ -59,7 +59,7 @@ GEM addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) arel (7.1.4) - autoprefixer-rails (7.1.1.3) + autoprefixer-rails (7.1.2.2) execjs awesome_print (1.8.0) better_errors (2.1.1) @@ -102,7 +102,7 @@ GEM globalid (0.4.0) activesupport (>= 4.2.0) hashdiff (0.3.4) - i18n (0.8.4) + i18n (0.8.6) jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) @@ -183,7 +183,7 @@ GEM rspec-support (~> 3.6.0) rspec-support (3.6.0) safe_yaml (1.0.4) - sass (3.4.24) + sass (3.4.25) sass-rails (5.0.6) railties (>= 4.0.0, < 6) sass (~> 3.1) diff --git a/app/controllers/forecast_controller.rb b/app/controllers/forecast_controller.rb index 9893ecd..374bba3 100644 --- a/app/controllers/forecast_controller.rb +++ b/app/controllers/forecast_controller.rb @@ -16,17 +16,18 @@ def coords_to_weather # The longitude the user input is in the string @lng. # ========================================================================== + url = "https://api.darksky.net/forecast/6842c74db30df2e42d7a490dc31acdd3/"+@lat+","+@lng #37.8267,-122.4233 + parsed_data = JSON.parse(open(url).read) + @current_temperature = parsed_data.dig("currently","temperature").to_s - @current_temperature = "Replace this string with your answer." + @current_summary = parsed_data.dig("currently","summary").to_s - @current_summary = "Replace this string with your answer." + @summary_of_next_sixty_minutes = parsed_data.dig("minutely","summary").to_s - @summary_of_next_sixty_minutes = "Replace this string with your answer." + @summary_of_next_several_hours = parsed_data.dig("hourly","summary").to_s - @summary_of_next_several_hours = "Replace this string with your answer." - - @summary_of_next_several_days = "Replace this string with your answer." + @summary_of_next_several_days = parsed_data.dig("daily","summary").to_s render("forecast/coords_to_weather.html.erb") end diff --git a/app/controllers/geocoding_controller.rb b/app/controllers/geocoding_controller.rb index 077d802..401ec0a 100644 --- a/app/controllers/geocoding_controller.rb +++ b/app/controllers/geocoding_controller.rb @@ -14,12 +14,14 @@ def street_to_coords # # The street address that the user typed is in the variable @street_address. # ========================================================================== - - - - @latitude = "Replace this string with your answer." - - @longitude = "Replace this string with your answer." + + url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + @street_address + parsed_data = JSON.parse(open(url).read) + latitude = parsed_data["results"][0]["geometry"]["location"]["lat"] + longitude = parsed_data["results"][0]["geometry"]["location"]["lng"] + @latitude = latitude + + @longitude = longitude render("geocoding/street_to_coords.html.erb") end diff --git a/app/controllers/meteorologist_controller.rb b/app/controllers/meteorologist_controller.rb index 38a8d5d..2b857fa 100644 --- a/app/controllers/meteorologist_controller.rb +++ b/app/controllers/meteorologist_controller.rb @@ -14,18 +14,23 @@ def street_to_weather # # The street address that the user typed is in the variable @street_address. # ========================================================================== + + geocodeUrl = "https://maps.googleapis.com/maps/api/geocode/json?address=" + @street_address + parsed_address = JSON.parse(open(geocodeUrl).read) + latitude = parsed_address["results"][0]["geometry"]["location"]["lat"] + longitude = parsed_address["results"][0]["geometry"]["location"]["lng"] + forecastUrl = "https://api.darksky.net/forecast/6842c74db30df2e42d7a490dc31acdd3/"+latitude.to_s+","+longitude.to_s + parsed_forecast = JSON.parse(open(forecastUrl).read) + @current_temperature = parsed_forecast.dig("currently","temperature") + @current_summary = parsed_forecast.dig("currently","summary") - @current_temperature = "Replace this string with your answer." + @summary_of_next_sixty_minutes = parsed_forecast.dig("minutely","summary") - @current_summary = "Replace this string with your answer." + @summary_of_next_several_hours = parsed_forecast.dig("hourly","summary") - @summary_of_next_sixty_minutes = "Replace this string with your answer." - - @summary_of_next_several_hours = "Replace this string with your answer." - - @summary_of_next_several_days = "Replace this string with your answer." + @summary_of_next_several_days = parsed_forecast.dig("daily","summary") render("meteorologist/street_to_weather.html.erb") end