Module: Rotten_tomatoes

Defined in:
lib/rotten-tomatoes.rb

Overview

Module to hold everything

Defined Under Namespace

Classes: Movie, Person

Constant Summary collapse

Base_url =
'http://www.rottentomatoes.com'
Movie_search_url =
Base_url + '/search/movie.php?searchby=movies&page=1&search='
Person_search_url =
Base_url + '/search/person.php?searchby=celebs&page=1&search='

Class Method Summary collapse

Class Method Details

.find_movie(movie) ⇒ Object

Search rottentomatoes.com for the movie you are looking for will return an array of movies for you to select from, each will contain the ‘info_url’ you need to us Rotten_tomatoes:get_info



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rotten-tomatoes.rb', line 32

def self.find_movie movie
  movies = []
  url = URI.parse(URI.encode(Movie_search_url + movie.to_s))
  results = Nokogiri::HTML(open(url))
  results.css('#movie_search_main tr').each do |row|
    movies.push({
                  :title => row.css('td:nth-of-type(3) p:first-of-type a').inner_text,
                  :plot => row.css('td:nth-of-type(3) p:nth-of-type(2)').inner_text.gsub(/\APlot:/, '').strip,
                  :year => row.css('.date').inner_text,
                  :director => row.css('td:nth-of-type(3) p:nth-of-type(3) a:first-of-type').inner_text,
                  :movie_url => row.css('td:nth-of-type(3) p:first-of-type a').attr('href').value
                })
  end
  return movies
end

.find_person(person) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rotten-tomatoes.rb', line 48

def self.find_person person
  people = []
  url = URI.parse(URI.encode(Person_search_url + person.to_s))
  results = Nokogiri::HTML(open(url))
  results.css('#contrib_search_main tbody a').each do |row|
    people.push({
                  :name => row.text,
                  :person_url => row.attribute('href').value
                })
  end
  return people
end

.get_movie_info(movie_path) ⇒ Object

Create a new instance of Rotten_tomatoes::Movie with the rottentomatoes.com movie path as an argument



21
22
23
# File 'lib/rotten-tomatoes.rb', line 21

def self.get_movie_info movie_path
  Movie.new movie_path
end

.get_person_info(person_path) ⇒ Object



25
26
27
# File 'lib/rotten-tomatoes.rb', line 25

def self.get_person_info person_path
  Person.new person_path
end

.lucky_get_movie_info(movie) ⇒ Object

Uses Rotten_tomatoes::get_info to fetch info for the first search result found with Rotten_tomatoes::find_movie



63
64
65
# File 'lib/rotten-tomatoes.rb', line 63

def self.lucky_get_movie_info movie
  get_movie_info find_movie(movie).first[:movie_url]
end

.lucky_get_person_info(person) ⇒ Object



67
68
69
# File 'lib/rotten-tomatoes.rb', line 67

def self.lucky_get_person_info person
  get_person_info find_person(person).first[:person_url]
end