lib/filmbuff/imdb.rb in filmbuff-0.1.5 vs lib/filmbuff/imdb.rb in filmbuff-0.1.6
- old
+ new
@@ -5,16 +5,11 @@
include HTTParty
include HTTParty::Icebox
cache :store => 'memory', :timeout => 120
base_uri 'app.imdb.com'
- default_params = {
- "api" => "v1",
- "app_id" => "iphone1_1",
- "timestamp" => Time.now.utc.to_i,
- "sig" => "app1_1"
- }
+ format :json
def initialize
@locale = "en_US"
end
@@ -25,12 +20,23 @@
}).parsed_response
Title.new(result["data"])
end
def find_by_title(title)
- results = self.class.get('/find', :query => {
- :q => title, :locale => @locale
+ result = self.class.get('http://www.imdb.com/xml/find', :query => {
+ :q => title,
+ :json => '1',
+ :tt => 'on'
}).parsed_response
- find_by_id(results["data"]["results"][0]["list"][0]["tconst"])
+
+ %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