- You must complete and submit all of these assignments.
- It is due the Saturday before the start of the inning at 5pm
- Submit your work here: Survey Link
- Prepping for Mod 3
require 'faraday' require 'json' require 'pp' response = Faraday.get('https://api.nytimes.com/svc/topstories/v2/arts.json?api-key=*************************') data = JSON.parse(response.body, object_class: OpenStruct) result = data.results.find { |story| story.section == ARGV[0] } puts "Title: " + result.title puts "Author(s): " + result.byline puts "Date Published: " + result.published_date puts "Abstract: " + result.abstract puts "Website: " + result.url
ruby top_stories.rb arts # RETURNED: Title: New York’s Arts Shutdown: The Economic Crisis in One Lost Weekend Author(s): By Dina Litovsky, Victor Llorente, Daniel Arnold, Michael Paulson, Elizabeth A. Harris and Graham Bowley Date Published: 2020-09-24T05:00:02-04:00 Abstract: We zero in on one moment in New York City’s cultural calendar that’s been wiped clean — what it means, what it looks like, what it cost and what’s ahead. Website: https://www.nytimes.com/interactive/2020/09/24/arts/new-york-fall-arts-economy.html
- Sort Bookmarks from Mod 2
- Prep Bookmark manager for Mod 3
- Update your journal
- Do this
- Update your journal with prompts for Mod 3
- Confirm or Update your Ruby/Rails versions
- Follow this guide to make sure your versions are correct.
- Everything we build in Mod 3 will focus on building and consuming APIs.
- Work through this tutorial to get a brief intro to APIs.
require 'faraday' require 'json' require 'date' response = Faraday.get 'https://api.github.com/users/priyapower' body = response.body result = JSON.parse(body) date = Date.parse(result["created_at"]).strftime("%F").to_s puts "Github User: " + result["login"] puts "Number of Followers: " + result["followers"].to_s puts "Date Joined Github: " + date
- When consuming APIs, the data is often returned in deeply nested collections, so you will need to tap into your Mod 1 skills to practice digging through them to retrieve the data you need.
- Fork and clone Here Be Dragons. Get the tests to pass.
- My completed Repo
- In Mod 3, we will focus not only on getting code to work but also writing high quality code. This will involve topics covered in mod 1 such as creating classes and methods, adhering to SRP, and general refactoring principles.
- Review these topics by forking and cloning the refactoring workshop.
- Work through the activity in the README.
- This was designed as a partnered activity. You may choose to pair with a classmate or work solo.
- My completed Repo
-
If working alone, write answers to the questions in your notebook instead of discussing.
- Review these topics by forking and cloning the refactoring workshop.
- On one piece of paper, write out all of the parts of an example HTTP GET request
- (Diagram the DNS look-up as well as how a Rails Application would handle the request via MVC)
- On a separate piece of paper, write out an example 200 response to that request with all of the parts
- Bonus write your explanation as a metaphor
- Bring this to class day 1.
NOTE: This is not because one way is better, but it’s extremely important to understand what every line of your routes file is doing. Rails Engine demands a solid understanding of Rails routing.
-
Module 3 requires you to know URLs, paths and HTTP verbs inside and out. Rewrite the routes file for your Monster Shop to use only methods that map directly to HTTP verbs: get, post, put, patch and delete. You will probably need to add to: and as: parameters to make sure your apps continue to work, and tests continue to pass.
- Rewrite your Monster Shop routes.rb:
- If you wrote your routes that way already, replace them using resources.
- My Completed Repo
-
If you do not own the repo for your project, fork it, and rewrite the routes file individually.
- If you wrote your routes that way already, replace them using resources.
#BEFORE Rails.application.routes.draw do get "/", to: 'welcome#index', as: :root resources :merchants do resources :items, only: [:index] end resources :items, only: [:index, :show] do resources :reviews, only: [:new, :create] end resources :reviews, only: [:edit, :update, :destroy] get '/cart', to: 'cart#show' post '/cart/:item_id', to: 'cart#add_item' delete '/cart', to: 'cart#empty' patch '/cart/:change/:item_id', to: 'cart#update_quantity' delete '/cart/:item_id', to: 'cart#remove_item' get '/registration', to: 'users#new', as: :registration resources :users, only: [:create, :update] patch '/user/:id', to: 'users#update' get '/profile', to: 'users#show' get '/profile/edit', to: 'users#edit' get '/profile/edit_password', to: 'users#edit_password' post '/orders', to: 'user/orders#create' get '/profile/orders', to: 'user/orders#index' get '/profile/orders/:id', to: 'user/orders#show' delete '/profile/orders/:id', to: 'user/orders#cancel' get '/login', to: 'sessions#new' post '/login', to: 'sessions#login' get '/logout', to: 'sessions#logout' namespace :merchant do get '/', to: 'dashboard#index', as: :dashboard resources :orders, only: :show resources :items, only: [:index, :new, :create, :edit, :update, :destroy] put '/items/:id/change_status', to: 'items#change_status' get '/orders/:id/fulfill/:order_item_id', to: 'orders#fulfill' resources :discounts, only: [:index, :show, :new, :create, :edit, :destroy, :update] # patch '/discounts/:id', to: 'discounts#update', as: :discount_update patch '/discounts/:status/:id', to: 'discounts#update_status' end namespace :admin do get '/', to: 'dashboard#index', as: :dashboard resources :merchants, only: [:show, :update] resources :users, only: [:index, :show] patch '/orders/:id/ship', to: 'orders#ship' end end
#AFTER Rails.application.routes.draw do resources :welcome, :path => "/", only: :index resources :merchants do resources :items, only: [:index] end resources :items, only: [:index, :show] do resources :reviews, only: [:new, :create] end resources :reviews, only: [:edit, :update, :destroy] resource :cart, only: [:show], controller: "cart" do post ':item_id', :action => 'add_item' delete '', :action => 'empty' patch ':change/:item_id', :action => 'update_quantity' delete ':item_id', :action => 'remove_item' end scope controller: :users do get 'registration' => :new, as: :registration patch '/user/:id' => :update get '/profile' => :show get '/profile/edit' => :edit get '/profile/edit_password' => :edit_password end resources :users, only: [:create, :update] scope controller: :orders, module: 'user' do post '/orders' => :create get '/profile/orders' => :index get '/profile/orders/:id' => :show delete '/profile/orders/:id' => :cancel end scope controller: :sessions do get '/login' => :new post '/login' => :login get '/logout' => :logout end namespace :merchant do resources :dashboard, :path => "/", only: :index resources :orders, only: :show resources :items, only: [:index, :new, :create, :edit, :update, :destroy] resource :items do put ':id/change_status', action: :change_status end resource :orders do get '/:id/fulfill/:order_item_id' => :fulfill end resources :discounts, only: [:index, :show, :new, :create, :edit, :destroy, :update] resource :discounts do patch '/:status/:id' => :update_status end end namespace :admin do resources :dashboard, :path => "/", only: :index resources :merchants, only: [:show, :update] resources :users, only: [:index, :show] resource :orders do patch '/:id/ship' => :ship end end end
- Rewrite your Monster Shop routes.rb:
- Entering Module 3 with a solid understanding of ActiveRecord and SQL is key to getting the module off to a good start. Make sure you are able to write and understand queries that involve multiple JOIN statements and that combine math functions.
- Complete and understand the Intermediate SQL I challenges.
#What's the total revenue for all items? SELECT sum(revenue) FROM items; #What's the average revenue for all items? SELECT avg(revenue) FROM items; #What's the minimum revenue for all items? SELECT min(revenue) FROM items; #What's the maximum revenue for all items? SELECT max(revenue) FROM items; #What the count for items with a name? SELECT count(name) FROM items; #What else can you pass to count and still get 5 as your result? SELECT COUNT(*) FROM items; #Return all main courses. Hint: What ActiveRecord method would you use to get this? SELECT * FROM items WHERE items.course='main'; #Return only the names of the main courses. SELECT name FROM items WHERE items.course='main'; #Return the min and max value for the main courses. SELECT max(revenue) FROM items WHERE items.course='main'; SELECT min(revenue) FROM items WHERE items.course='main'; #What's the total revenue for all main courses? SELECT sum(revenue) FROM items WHERE items.course='main'; #Can you get it to display only the name for the item and the name for the season? SELECT items.name, seasons.name FROM items INNER JOIN seasons ON items.season_id = seasons.id; #Having two columns with the same name is confusing. Can you customize each heading using AS? SELECT items.name AS item, seasons.name AS season FROM items INNER JOIN seasons ON items.season_id = seasons.id; #Write a query that pulls all the category names for arugula salad. Hint: Use multiple INNER JOINs and a WHERE clause. SELECT items.name, categories.name FROM items INNER JOIN item_categories ON items.id = item_categories.item_id INNER JOIN categories ON item_categories.category_id = categories.id WHERE items.name='arugula salad'; #Can you change the column headings? SELECT items.name AS item, categories.name AS category FROM items INNER JOIN item_categories ON items.id = item_categories.item_id INNER JOIN categories ON item_categories.category_id = categories.id WHERE items.name='arugula salad'; #What do you think a RIGHT OUTER JOIN will do? puts "It will return all records from the right table (seasons) and return matching records from the left table (items)" #Write a query to test your guess. SELECT * FROM items i RIGHT OUTER JOIN seasons s ON i.season_id = s.id; #Insert data into the right table that will not get returned on an INNER JOIN. INSERT INTO seasons (name) VALUES ('rainy'); SELECT * FROM items i INNER JOIN seasons s ON i.season_id = s.id; #Let's say I want to return all items with above average revenue. SELECT * FROM items WHERE revenue > (SELECT avg(revenue) FROM items); #Without looking at the previous solution, write a WHERE clause that returns the items that have a revenue less than the average revenue. SELECT * FROM items WHERE revenue < (SELECT avg(revenue) FROM items); #Write a query that returns the sum of all items that have a category of dinner. # IF SUM MEANS COUNT SELECT count(items.name) AS count_for_dinner FROM items INNER JOIN item_categories ON items.id = item_categories.item_id INNER JOIN categories ON item_categories.category_id = categories.id WHERE categories.name='dinner'; # IF SUM MEANS SUM OF REVENUE SELECT sum(items.revenue) AS sum_for_dinner FROM items INNER JOIN item_categories ON items.id = item_categories.item_id INNER JOIN categories ON item_categories.category_id = categories.id WHERE categories.name='dinner'; #Write a query that returns the sum of all items for each category. The end result should look like this: SELECT categories.name, sum(items.revenue) AS sum_for_category FROM items INNER JOIN item_categories ON items.id = item_categories.item_id INNER JOIN categories ON item_categories.category_id = categories.id GROUP BY categories.name;
- Complete and understand the Intermediate SQL II challenges.
#List all the students and their classes SELECT students.name, classes.name FROM students INNER JOIN enrollments ON students.id = enrollments.student_id INNER JOIN classes ON enrollments.class_id = classes.id; #List all the students and their classes and rename the columns to "student" and "class" SELECT students.name AS students, classes.name AS class FROM students INNER JOIN enrollments ON students.id = enrollments.student_id INNER JOIN classes ON enrollments.class_id = classes.id; #List all the students and their average grade SELECT students.name, avg(enrollments.grade) FROM students LEFT JOIN enrollments ON students.id = enrollments.student_id GROUP BY students.name; #List all the students and a count of how many classes they are currently enrolled in SELECT students.name, count(enrollments.id) FROM students LEFT JOIN enrollments ON students.id = enrollments.student_id GROUP BY students.name; #List all the students and their class count IF they are in more than 2 classes # Research hint: https://www.w3schools.com/sql/sql_having.asp SELECT students.name, count(enrollments.grade) FROM students LEFT JOIN enrollments ON students.id = enrollments.student_id GROUP BY students.name HAVING count(enrollments.grade) >= 2; #List all the teachers for each student SELECT students.name, teachers.name FROM students JOIN enrollments ON students.id = enrollments.student_id JOIN classes ON enrollments.class_id = classes.id JOIN teachers ON classes.teacher_id = teachers.id; #List all the teachers for each student grouped by each student SELECT students.name, teachers.name FROM students JOIN enrollments ON students.id = enrollments.student_id JOIN classes ON enrollments.class_id = classes.id JOIN teachers ON classes.teacher_id = teachers.id ORDER BY students.name; #Find the average grade for a each class SELECT classes.name, avg(enrollments.grade) FROM classes JOIN enrollments ON classes.id = enrollments.class_id GROUP BY classes.name; #List students' name and their grade IF their grade is lower than the average. SELECT students.name, enrollments.grade FROM students JOIN enrollments ON students.id = enrollments.student_id WHERE grade < (SELECT avg(grade) FROM enrollments);
- We will discuss the following on the first day of the inning:
- Thinking Fast and Slow
- My notes: This article made me both sad and amazed. This references the public education system in America (or college system in America), specifically the content of mathematics, which is what I taught before coming to Turing. It goes on to describe the socratic method (and why it is effective) and the Kornell primate experiments on Hints. It continues to showcase study after study and learning concept after concept that just hones in on best practices for learning and why the "struggle" is a more effective use of your learning than by just receiving answers. This chapter highlights why I loved math and chemistry and statistics and all the stem contents I threw myself into. I wasn't learning how to churn out answers to problems, I was learning problem-solving, critical thinking, abstract puzzling and logical sequencing and so much more. Learning math, teaching math, and loving math has been a support and foundation as I feel successful at Turing. My habits for learning/recalling concepts AND my habits for guiding students through upper level math concepts without revealing answers or processes, really helped shape how I understand coding languages/frameworks/etc, but more importantly, how I research and continue learning.
-If you have time, here are some activities that will be valuable not only in Mod 3, but in Mod 4 and the job hunt as well._
- We are going to be covering various data structures to prepare you for the job hunt and technical interviews.
- Complete this former M1 project, Jungle Beats
-
JavaScript is the scripting language of web browsers.
-
During Module 3 we’ll start getting our first introductions to JS and we’d like you to work through some basic materials as a preparation.
- Eloquent JavaScript
- You are to complete Chapters 1-5 of Eloquent Javascript.
- Eloquent JavaScript
-
We are mainly looking for you to get experience with the syntax, and at a minimumum you should understand the JS Data Types, Conditionals, and Looping.
-
JQuery is a popular javascript library for manipulating the content of web pages. Dip your toes in with this introductory Jquery class.
- Redo the ActiveRecord Obstacle Course
- Pick 1 BE Mod 1 Project - Other Projects to complete
- Pick 2 BE Mod 1 Project - EXTENSION Projects to complete
- Pick 1 BE Mod 2 Archived Projects to complete
- Work through Week 1 of Front End Mod 1 (as best you can)