module FilmBuff class IMDb attr_accessor :locale include HTTParty include HTTParty::Icebox cache :store => 'memory', :timeout => 120 base_uri 'app.imdb.com' format :json def initialize @locale = "en_US" end public def find_by_id(imdb_id) result = self.class.get('/title/maindetails', :query => { :tconst => imdb_id, :locale => @locale }).parsed_response Title.new(result["data"]) end def find_by_title(title) result = self.class.get('http://www.imdb.com/xml/find', :query => { :q => title, :json => '1', :tt => 'on' }).parsed_response %w(title_popular title_exact title_approx title_substring).each do |key| if result[key] result[key].each do |row| next unless row['id'] && row['title'] && row['description'] return self.find_by_id(row['id']) end end end end end end