- Project Work Time and Check-Ins
- Additional Concepts in Ruby
- Defining and calling methods
- Passing parameters
- Introduction to APIs
- API Work Time
- Gradual release of responsibility
- Teaching to fish (use your resources, ask a peer, ask an instructor)
- Emotional intelligence: managing the discomfort of not knowing
- Technical strategy and communication
When you're not doing your check-in, continue to work on your project and fill out the self-reflection questions (below). Challenges from last week are described here.
- What have been the most difficult parts of your challenge? How did/are you moving through them?
- What have your "wins" been?
- What's the next thing you're gonna tackle?
One way to bring some order to a simple application is to organize your code into methods you define and call.
def my_method
prints "Hello World"
end
my_method
What happens if you remove the second my_method here? Why?
We can also write methods that take parameter that change the output of a method.
def my_method(greeting)
prints greeting
end
my_method("Hello, friend!")
Passing arguments to methods is a very powerful tool that allows us to simply our code and create code that is dynamic and flexible (sometimes a very good thing!).
Let's take a look at this cultivated list of APIs. These APIs are special because they are "open" and can be accessed without us needing a secret key to gain access to them.
When you hit one of the described endpoints, what do you see in your browser?
JSON is the standard format with which APIs return data to the requester. Create a file with the following JSON content, and we'll experiment with working with JSON to extract meaningful data.
// weather_data.json
{
"query":{
"count":1,
"created":"2018-06-15T00:58:27Z",
"lang":"en-US",
"results":{
"channel":{
"item":{
"condition":{
"text":"Mostly Sunny"
}
}
}
}
}
}
# json_playground.rb
require 'json'
json = File.read('weather_data.json')
obj = JSON.parse(json)
puts obj["query"]["results"]["channel"]["item"]["condition"]["text"]
What does line puts obj["query"]["results"]["channel"]["item"]["condition"]["text"]
do for us?
Make a new json file with the JSON response from this Yahoo Weather endpoint and make changes to json_playground.rb to read from that new file and puts
the high for the coming Saturday in Nome, AK.
Pick another open API from toddmotto's list of openapis, save the response in a new JSON file, and write a program that will puts a meaningful sentence containing 3 independent pieces of information from the response. For example, using the AK weather conditions, you could prepare the sentence, The forecast for this Fri is a high of 51, a low of 44, and it will be partially cloudy.