Skip to content

Commit

Permalink
Merge pull request #15 from elizakeating/api_user_stories
Browse files Browse the repository at this point in the history
Api user stories
  • Loading branch information
Antoine-Aube authored Oct 11, 2023
2 parents 9d5118b + ba4d38d commit a7de63d
Show file tree
Hide file tree
Showing 21 changed files with 837 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ gem "bootsnap", require: false
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

gem "faraday"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "pry"
Expand All @@ -71,4 +73,7 @@ group :test do
gem "launchy"
gem "simplecov"
gem "shoulda-matchers"
gem "webmock"
gem "vcr"
gem "orderly"
end
26 changes: 26 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ GEM
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
base64 (0.1.1)
bindex (0.8.1)
bootsnap (1.16.0)
msgpack (~> 1.2)
Expand All @@ -84,13 +85,21 @@ GEM
xpath (~> 3.2)
coderay (1.1.3)
concurrent-ruby (1.2.2)
crack (0.4.5)
rexml
crass (1.0.6)
date (3.3.3)
diff-lcs (1.5.0)
docile (1.4.0)
erubi (1.12.0)
faraday (2.7.11)
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
globalid (1.1.0)
activesupport (>= 5.0)
hashdiff (1.0.1)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
importmap-rails (1.2.1)
Expand Down Expand Up @@ -131,6 +140,9 @@ GEM
racc (~> 1.4)
nokogiri (1.15.2-x86_64-darwin)
racc (~> 1.4)
orderly (0.1.1)
capybara (>= 1.1)
rspec (>= 2.14)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
Expand Down Expand Up @@ -178,6 +190,10 @@ GEM
rake (13.0.6)
regexp_parser (2.8.1)
rexml (3.2.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
Expand Down Expand Up @@ -213,6 +229,7 @@ GEM
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
shoulda-matchers (5.3.0)
activesupport (>= 5.2.0)
simplecov (0.22.0)
Expand All @@ -239,11 +256,16 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
vcr (6.2.0)
web-console (4.2.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webmock (3.19.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -259,9 +281,11 @@ PLATFORMS
DEPENDENCIES
bootsnap
capybara
faraday
importmap-rails
jbuilder
launchy
orderly
pg (~> 1.1)
pry
puma (~> 5.0)
Expand All @@ -274,7 +298,9 @@ DEPENDENCIES
stimulus-rails
turbo-rails
tzinfo-data
vcr
web-console
webmock

RUBY VERSION
ruby 3.2.2p53
Expand Down
36 changes: 35 additions & 1 deletion app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
class MoviesController < ApplicationController
def index

end

def search
conn = Faraday.new(url: "https://api.themoviedb.org") do |faraday|
faraday.params["api_key"] = Rails.application.credentials.tmdb[:key]
end

if params[:q] == "top20rated"
response = conn.get("/3/movie/top_rated")

json = JSON.parse(response.body, symbolize_names: true)
@movies = json[:results][0..19]
else
response = conn.get("3/search/movie?query=#{params[:q]}")

json = JSON.parse(response.body, symbolize_names: true)
@movies = json[:results][0..19]
end
end

def show
conn = Faraday.new(url: "https://api.themoviedb.org") do |faraday|
faraday.params["api_key"] = Rails.application.credentials.tmdb[:key]
end

response = conn.get("3/movie/#{params[:movie_id]}")
@movie = JSON.parse(response.body, symbolize_names: true)

response = conn.get("3/movie/#{params[:movie_id]}/credits")
json = JSON.parse(response.body, symbolize_names: true)
@movie_cast = json[:cast][0..9]

response = conn.get("3/movie/#{params[:movie_id]}/reviews")
json = JSON.parse(response.body, symbolize_names: true)
@movie_reviews = json[:results]
end
end
4 changes: 4 additions & 0 deletions app/controllers/viewing_parties_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ViewingPartiesController < ApplicationController
def new
end
end
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<%= javascript_importmap_tags %>
</head>

<center><h1>Viewing Party</h1></center>
<body>
<table>
<tbody>
Expand Down
8 changes: 8 additions & 0 deletions app/views/movies/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>Discover Movies</h1>

<%= button_to "Find Top Rated Movies", "/users/#{params[:id]}/movies", params: { q: "top20rated" }, method: :get %>

<%= form_with url: "/users/#{params[:id]}/movies", method: :get, data: { turbo: false } do |form| %>
<%= form.text_field :q, placeholder: "search" %>
<%= form.submit "Find Movies" %>
<% end %>
14 changes: 14 additions & 0 deletions app/views/movies/search.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= button_to "Discover Page", "/users/#{params[:id]}/discover", method: :get %><br>

<% if params[:q] != "top20rated" %>
<h3>Movie results for: <%= params[:q] %></h3>
<% end %>

<% if @movies %>
<% @movies.each do |movie| %>
<section id=<%= movie[:id] %>>
<%= link_to "#{movie[:title]}", "/users/#{params[:id]}/movies/#{movie[:id]}" %>
<p>Vote Average: <%= movie[:vote_average] %></p>
</section>
<% end %>
<% end %>
44 changes: 44 additions & 0 deletions app/views/movies/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<h3><%= @movie[:original_title] %></h3>

<%= button_to "Discover Page", "/users/#{params[:id]}/discover", method: :get %>

<%= button_to "Create Viewing Party for #{@movie[:original_title]}", "/users/#{params[:id]}/movies/#{@movie[:id]}/viewing_party/new", method: :get %>

<p>Vote: <%= @movie[:vote_average] %></p>
<p>Runtime: <% if @movie[:runtime] > 60 %>
<%= "#{@movie[:runtime]/60}h #{@movie[:runtime]-60}min" %>
<% else %>
<%= "#{@movie[:runtime]}min" %>
<% end %>
</p>
<p>Genre: <% @movie[:genres].each do |genre| %>
<% if genre != @movie[:genres].last %>
<%= "#{genre[:name]}, " %>
<% else %>
<%= genre[:name] %>
<% end %>
<% end %>
</p>

<section id="summary">
<p>Summary</p>
<p><%= @movie[:overview] %></p>
</section>

<section id="cast">
<p>Cast</p>
<p>
<% @movie_cast.each do |member| %>
<p><%= member[:name] %> - <%= member[:character] %></p>
<% end %>
</p>
</section>

<p id="review-count"><%= @movie_reviews.count %> Reviews</p>
<section id="reviews">
<p>
<% @movie_reviews.each do |review| %>
<p><%= review[:author] %> - <%= review[:content] %></p>
<% end %>
</p>
</section>
Empty file.
2 changes: 1 addition & 1 deletion app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<center><%= button_to "Create New User", "/register/new", method: :get%>

<% @users.each do |user| %>
<p><%= link_to user.name %></p>
<p><%= link_to user.name, "/users/#{user.id}" %></p>
<%end %>
</ul>
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
IdUl8TW1RuV/hrFBOw2ofbe8+xWVzpTQtF36N+5vBKyWgaq4Juryc86xLP3lLDmJ8pVNpg/g8TYSAWeu+JUTlE4iCq31IZTknkB4BPLpz4ULj3UpYkEFRSB9ZdDufx9ccU4l+4GGtdv5KRqc105s0v09MDWYT+X6NHHUrFlSGepCEXzG7JuQziJCcYxDZccsb0qlsdcUnpWspc6GBBo451lm0YviUcWx3kNsSNqApQqtQENrruynV3UoKipateylgTlrUlOMbYyHIkY1daxdV4EcxSIF1mUy6UwciNIC9xa0WnAGb+oaki6mPvs+FpWz+o548lWRrz91opxNIBv8Zrh+ZwfnQVxByuI2Uqj4fYbETjhbRfu2IbjTk1sQGqZlgougYXtMmCTxe8PNP29bmaxa2s7r4i2dAb9P--jqBTwrKsjHULkBor--z3IhADU0xjCYptFz4QGfyw==
+owmBR3rF4P0621XqrD/iFBz2sK+7l5bXHgBGAyYnDT46sUGU0LilI52AXhgQOh5vqfPItyNuq53hXXnWfIY9CVYu+3brUU0PJY3dCXuDF8YoWR8dMyXEjCk9ZMb5i0u/C9IB0WW8gNFUHDFz/k2yjVdcJ7PpdUcNOCrNUxGCOCJ2mrBcUZ2WmR0/SpYoDcdSnrZlK9uzLF6kfmHJ+L5qFhOOVdUx+2mCU/xnG+jDRX9tnExayneabKaUCLe4MaSIW92yI7+jZGKzEX7OtuclGitoAexLvva7pPlhUznPTwr4qo/0UB7/Ro4BThgJ/qOY20Xxz26Wu4WbXoRsXMu6etrSoOziYQv55ISthQdWl0jsViiH5W+TaTIRQZdb6w9oFb1dNOHlyO9fBgxoxRN1enBwJqdB2/uUCsH1tZyjLzzl+zlAaE74JY46tFzR4CTXTOnVtfEAnLbBCeIuFb8MgDxLNs=--Px4DqD+ikPBVl58Y--xFezR2XEGw59Uj9boaEZXw==
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

resources :users, only: [:show]
get "/users/:id/discover", to: "movies#index"
get "/users/:id/movies", to: "movies#search"
get "/users/:id/movies/:movie_id", to: "movies#show"

root "welcome#index"
get "/register/new", to: "users#new"
post "/register", to: "users#create"

get "/users/:id/movies/:movie_id/viewing_party/new", to: "viewing_parties#new"
end
77 changes: 77 additions & 0 deletions spec/features/movies/show_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
require "rails_helper"

RSpec.describe "Movie Details Page", type: :feature do
before(:each) do
@user = User.create(name: "Brad", email: "bradsmith@gmail.com")
end

describe "when I visit a movie's detail page '/users/:id/movies/:movie_id'" do
it "I should see a button to create a viewing party that takes me to '/users/:id/movies/:movie_id/viewing_party/new'" do
VCR.use_cassette("barbie_details") do
visit "/users/#{@user.id}/movies/346698"

expect(page).to have_button("Create Viewing Party for Barbie")

click_button "Create Viewing Party for Barbie"

expect(current_path).to eq("/users/#{@user.id}/movies/346698/viewing_party/new")
end
end

it "I should see a button to return to the discover page" do
VCR.use_cassette("barbie_details") do
visit "/users/#{@user.id}/movies/346698"

expect(page).to have_button("Discover Page")

click_button "Discover Page"

expect(current_path).to eq("/users/#{@user.id}/discover")
end
end

it "should have the move information including the title, vote average, runtime in hours and minutes, genre(s) associated to the movie, and a summary description" do
VCR.use_cassette("barbie_details") do
visit "/users/#{@user.id}/movies/346698"

expect(page).to have_content("Barbie")
expect(page).to have_content("Vote: 7.254")
expect(page).to have_content("Runtime: 1h 54min")
expect(page).to have_content("Genre: Comedy, Adventure, Fantasy")

within("#summary") do
expect(page).to have_content("Summary")
expect(page).to have_content("Barbie and Ken are having the time of their lives in the colorful and seemingly perfect world of Barbie Land. However, when they get a chance to go to the real world, they soon discover the joys and perils of living among humans.")
end
end
end

it "should have a list of the first 10 cast members (characters&actress/actors)" do
VCR.use_cassette("barbie_details") do
visit "/users/#{@user.id}/movies/346698"
within("#cast") do
expect(page).to have_content("Cast")
expect(page).to have_content("Margot Robbie - Barbie")
expect(page).to have_content("Ryan Gosling - Ken")
expect(page).to have_content("Issa Rae - Barbie")
end
end
end

it "should have a count of total reviews, and each review's author and information" do
VCR.use_cassette("barbie_details") do
visit "/users/#{@user.id}/movies/346698"

within("#review-count") do
expect(page).to have_content("11 Reviews")
end

within("#reviews") do
expect(page).to have_content("Chris Sawin - _Barbie_ reels you in with its silly humor and fantastical ideas. The war of Kens during the last half hour of the film is an all-timer because a battle full of handsome maneuvers, like showing off their naked chest and manly noogies, turns into a full on dance off between Ryan Gosling and Simu Liu.\r \r But the second half of the film leaves a thought-provoking message in your brain regarding both men and women. The Kens gaining respect little by little mirrors how women eventually earned their rights to be respected individuals — after being considered as only being useful in the kitchen or for making babies — except with the gender roles reversed and nude blobs instead of genitalia.\r \r **Full review:** https://bit.ly/beachoff\n")

expect(page).to have_content("Thulan Perera - Barbie presents a captivating cinematic journey, deftly utilizing an iconic doll to explore intricate gender dynamics. Guided by Greta Gerwig’s direction, Margot Robbie and Ryan Gosling offer standout performances, complemented by memorable songs and stunning set designs, creating an immersive and humorous experience. This thought-provoking film seamlessly weaves a commentary on equality into its dazzling visuals and catchy tunes, harmoniously blending humour and insight. The result is an unforgettable viewing adventure that engages, entertains, and resonates long after the credits roll.")
end
end
end
end
end
34 changes: 34 additions & 0 deletions spec/features/users/discover_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require "rails_helper"

RSpec.describe "Discover Movies Page" do
before(:each) do
@user = User.create(name: "Brad", email: "bradsmith@gmail.com")
visit "/users/#{@user.id}/discover"
end

describe "when I visit '/users/:id/discover'" do
it "should see a button to discover top rated movies that routes to `/users.:id/movies?q=top%20rated" do
VCR.use_cassette("top_20_rated_movies") do
expect(page).to have_content("Discover Movies")

expect(page).to have_button "Find Top Rated Movies"

click_button "Find Top Rated Movies"
expect(current_path).to eq("/users/#{@user.id}/movies")
end
end

it "should see a text field to enter keyword(s) to search by movie title and a button to submit that takes you to '/users/:user_id/movies?q=keyword" do
VCR.use_cassette("barbie_movie_search") do
expect(page).to have_field "search"

expect(page).to have_button "Find Movies"

fill_in "search", with: "barbie"
click_button "Find Movies"

expect(current_path).to eq("/users/#{@user.id}/movies")
end
end
end
end
Loading

0 comments on commit a7de63d

Please sign in to comment.