diff --git a/Gemfile.lock b/Gemfile.lock index 4dd902c..58697bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -59,7 +59,7 @@ GEM addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) arel (7.1.4) - autoprefixer-rails (7.1.2.1) + autoprefixer-rails (7.1.2.2) execjs awesome_print (1.8.0) better_errors (2.1.1) diff --git a/app/controllers/forecast_controller.rb b/app/controllers/forecast_controller.rb index 9893ecd..3b6f030 100644 --- a/app/controllers/forecast_controller.rb +++ b/app/controllers/forecast_controller.rb @@ -16,17 +16,19 @@ def coords_to_weather # The longitude the user input is in the string @lng. # ========================================================================== + url = "https://api.darksky.net/forecast/a52814fad0486c985720046e82a2e4fa/" + @lat + "," + @lng + parsed_data = JSON.parse(open(url).read) - @current_temperature = "Replace this string with your answer." + @current_temperature = parsed_data["currently"]["temperature"].round(2) - @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("forecast/coords_to_weather.html.erb") end diff --git a/app/controllers/geocoding_controller.rb b/app/controllers/geocoding_controller.rb index 077d802..b651c2f 100644 --- a/app/controllers/geocoding_controller.rb +++ b/app/controllers/geocoding_controller.rb @@ -15,11 +15,13 @@ def street_to_coords # The street address that the user typed is in the variable @street_address. # ========================================================================== + url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + @street_address.gsub(" ", "+") + parsed_data = JSON.parse(open(url).read) - @latitude = "Replace this string with your answer." + @latitude = parsed_data["results"][0]["geometry"]["location"]["lat"] - @longitude = "Replace this string with your answer." + @longitude = parsed_data["results"][0]["geometry"]["location"]["lng"] render("geocoding/street_to_coords.html.erb") end diff --git a/app/controllers/meteorologist_controller.rb b/app/controllers/meteorologist_controller.rb index 38a8d5d..895c471 100644 --- a/app/controllers/meteorologist_controller.rb +++ b/app/controllers/meteorologist_controller.rb @@ -14,19 +14,37 @@ def street_to_weather # # The street address that the user typed is in the variable @street_address. # ========================================================================== + + # Get coordinates from Google maps + # + google_maps_url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + @street_address.gsub(" ", "+") + + maps_results = JSON.parse(open(google_maps_url).read) + + @lat = maps_results["results"][0]["geometry"]["location"]["lat"].to_s + + @lng = maps_results["results"][0]["geometry"]["location"]["lng"].to_s + + # Get coordinates from dark sky + # + dark_sky_url = "https://api.darksky.net/forecast/a52814fad0486c985720046e82a2e4fa/" + @lat + "," + @lng + + dark_sky_results = JSON.parse(open(dark_sky_url).read) + + # Return data for the page + # + @current_temperature = dark_sky_results["currently"]["temperature"].round(2) + @current_summary = dark_sky_results["currently"]["summary"] + @summary_of_next_sixty_minutes = dark_sky_results["minutely"]["summary"] - @current_temperature = "Replace this string with your answer." - - @current_summary = "Replace this string with your answer." - - @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_hours = dark_sky_results["hourly"]["summary"] - @summary_of_next_several_days = "Replace this string with your answer." + @summary_of_next_several_days = dark_sky_results["daily"]["summary"] + # Render the page + # render("meteorologist/street_to_weather.html.erb") end end