Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment #2 #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Api
def self.search_by_title(title)
url = "http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=#{APIKEY}&q=#{URI.encode(title)}&page_limit=1"
struct = OpenStruct.new(get_url_as_json(url).fetch("movies").first)

return "Not Found" if struct.id.nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you're returning a string that has a semantic meaning of "nothing was found". So this method could either return:

  • string with "Not Found"
  • Movie object with information

I think either raising an exception, or a specific NilMovie would be more expressive of what happened.


Movie.new(id: struct.id.to_i,
title: struct.title,
year: struct.year,
Expand Down
8 changes: 7 additions & 1 deletion movie_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ def find_movie
puts "OH HAI. Search?"
movie_title = gets
movie = Api.search_by_title(movie_title)
puts "Found: #{movie.title}. Score: #{movie.score}"

if movie == "Not Found"
puts "Not Found"
else
puts "Found: #{movie.title}. Score: #{movie.score}"
end

end

find_movie
Expand Down
4 changes: 4 additions & 0 deletions spec/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
it "should return the year" do
movie.year.should eq(1994)
end

it "should not blow up" do
expect { Api.search_by_title("NOTHINGFOUNDHERE") }.to_not raise_error
end
end