If you realize you've made an error on any of the following steps, just type incd ~/workspace
and hit enter. That should get you back to the starting point.
cd ~
and hit enter. This command should take you to the home folder of your workspace.touch .bash_profile
and hit enter. This command creates a hidden file called .bash_profile
in your home folder.ls -a
and hit enter. You'll see a list of all the files in your current directory, including hidden files (the ones whose names start with a .
)..bash_profile
and click it. The file should open up in your editor.=
sign=
.cd ~/workspace
to go back to your main folder, or just close that tab.If you ever need to reopen your bash profile, typecd ~
, hit enter, then typels -a
, hit enter and click on the file to open it.
export
in the .bash_profile
file become key-value pairs in a special Hash that we can access anywhere in our Rails environment called ENV
. For example, to access this sensitive info, in a NEW Terminal tab (it won't work in old tabs) we can open a rails console
and type in:YOUR_API_KEY
with the one provided to you. Paste that URL into a Chrome tab; you should see something like this:address_components
section to make the value of the geometry
key stand out, since that is where our target information lives:lat
and lng
keys within the location
hash. Notice that JSON uses curly braces for Hashes and square brackets for Arrays just like Ruby does.?address=
with the address we want geocoded:+
s. If you tried typing the address with spaces in it, you'll have noticed that Google encodes spaces automatically with %20%
.)bin/setup
,rails console
. This launches an interactive Ruby sandbox for us to experiment in.open()
method to read Google's page. The open()
method takes one String
argument, which should contain the URL of the page you want to open. I'm going to copy-paste the URL within " "
and store it in a variable url
to make it easier to work with:open
that URL and read
the body of the page:Note: To scroll through long output inrails console
, you can use return to scroll one line at a time, Space to scroll one page at a time, or Q to just get back to the prompt to enter a new Ruby expression.
open
ed the page at the location in url
, and the return value was the HTTP response. The HTTP response is actually a complicated object, with headers and status codes and other things we haven't talked about yet..read
method to pull that out. However, we just dropped that string on the ground; let's instead store the result in a variable called raw_data
:raw_data
for "lat"
, perhaps. But then what? We could probably figure it out, but there's a much better way.JSON
, similar to the CSV
class, which makes parsing a string that has data in JSON format a snap:geometry
key. We can remind ourselves what keys are in the hash:Note: As you explore, don't forget that you can use your UP ARROW to scroll through your command line history. You don't always have to re-type the same thing over and over!
f
that has a key called "geometry"
, which, as we learned from our initial research above, is what contains our target. Let's keep going:dig
that can help us drill down into nested Hash/Array structures like this a bit more concisely:latitude
and longitude
that I need.bin/server
and navigate to the homepage in a Chrome tab.app/controllers/geocoding_controller.rb
app/controllers/forecast_controller.rb
app/controllers/meteorologist_controller.rb
app/controllers/geocoding_controller.rb
. Your job is to write some code in the street_to_coords
method, where indicated, and put the correct value in the @latitude
and @longitude
variables.5807 S Woodlawn Ave
at the Street → Coords form, I should see something likeStreet Address5807 S Woodlawn AveLatitude41.7896234Longitude-87.5964137
app/controllers/forecast_controller.rb
, you will do something similar; but instead of using Google's Geocoding API, you will use The Forecast API. We will exchange a latitude/longitude pair for weather information. Forecast is an amazing API that gives you minute-by-minute meteorological information.street_to_coords
and try it out.coords_to_weather
method, where indicated, and put the correct value in the instance variables at the end.41.78
and -87.59
at the Coords → Weather form, I should see something likeLatitude41.78Longitude-87.59Current Temperature73.35Current SummaryClearOutlook for next sixty minutesClear for the hour.Outlook for next several hoursPartly cloudy tomorrow morning.Outlook for next several daysNo precipitation throughout the week, with temperatures falling to 62°F on Tuesday.
nil
s. If you run into issues, using dig
might be helpful, since it doesn't throw an error if a key is missing along the way:app/controllers/meteorologist_controller.rb
. Use both the Google Geocoding API and the Forecast API so that if I type in 5807 S Woodlawn Ave
at the Street → Weather form, I should see something likeHere's the outlook for 5807 S Woodlawn Ave:Current Temperature73.35Current SummaryClearOutlook for next sixty minutesClear for the hour.Outlook for next several hoursPartly cloudy tomorrow morning.Outlook for next several daysNo precipitation throughout the week, with temperatures falling to 62°F on Tuesday.
rails grade:all
at a Terminal prompt when you're ready for feedback and your score. You can run it as many times as you want.<link>
to Bootstrap or a Bootswatch in the <head>
of your pages (located in app/views/layouts/application.html.erb
), and make things look prettier.