Skip to content

Commit

Permalink
Added trailer informations to api extended results
Browse files Browse the repository at this point in the history
  • Loading branch information
romaind committed Nov 7, 2012
1 parent ef6b811 commit 89d0d3f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,5 @@
test/setup/tmdb_api_key.txt
.rvmrc
.rbenv-version
.DS_Store
.DS_Store
Gemfile*
6 changes: 4 additions & 2 deletions lib/ruby-tmdb3/tmdb_movie.rb
Expand Up @@ -46,20 +46,22 @@ def self.find(options)
def self.new(raw_data, expand_results = false, language = nil)
# expand the result by calling movie unless :expand_results is false or the data is already complete
# (as determined by checking for the posters property in the raw data)
if(expand_results && (!raw_data.has_key?("posters") || !raw_data['releases'] || !raw_data['cast']))
if(expand_results && (!raw_data.has_key?("posters") || !raw_data['releases'] || !raw_data['cast'] || !raw_data['trailers']))
begin
movie_id = raw_data['id']
raw_data = Tmdb.api_call 'movie', { :id => movie_id }, language
@images_data = Tmdb.api_call("movie/images", {:id => movie_id}, language)
@releases_data = Tmdb.api_call('movie/releases', {:id => movie_id}, language)
@cast_data = Tmdb.api_call('movie/casts', {:id => movie_id}, language)
@trailers_data = Tmdb.api_call('movie/trailers', {:id => movie_id}, language)
raw_data['posters'] = @images_data['posters']
raw_data['backdrops'] = @images_data['backdrops']
raw_data['releases'] = @releases_data['countries']
raw_data['cast'] = @cast_data['cast']
raw_data['crew'] = @cast_data['crew']
raw_data['trailers'] = @trailers_data['youtube']
rescue => e
raise ArgumentError, "Unable to fetch expanded infos for Movie ID: '#{movie_id}'" if @images_data.nil? || @releases_data.nil? || @cast_data.nil?
raise ArgumentError, "Unable to fetch expanded infos for Movie ID: '#{movie_id}'" if @images_data.nil? || @releases_data.nil? || @cast_data.nil? || @trailers_data.nil?
end
end
return Tmdb.data_to_object(raw_data)
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/movie_trailers.txt
@@ -0,0 +1,15 @@
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 23 Aug 2010 16:45:21 GMT
Content-Type: text/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=20
Status: 200 OK
Cache-Control: public, max-age=21600
X-Varnish: 2542127928 2542059531
Age: 1000
Via: 1.1 varnish
X-Cache: HIT

{"id": 550,"quicktime": [],"youtube": [{"name": "Trailer 1","size": "HD","source": "SUXWAEX2jlg"}]}
4 changes: 4 additions & 0 deletions test/setup/url_mocks.rb
Expand Up @@ -24,6 +24,10 @@ def register_api_url_stubs
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_casts.txt")) do |file|
stub_request(:get, Regexp.new(Tmdb.base_api_url + '/movie/\d+/casts')).to_return(file)
end

File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_trailers.txt")) do |file|
stub_request(:get, Regexp.new(Tmdb.base_api_url + '/movie/\d+/trailers')).to_return(file)
end

File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_imdb_lookup.txt")) do |file|
stub_request(:get, Regexp.new(Tmdb.base_api_url + "/movie/tt" + ".*")).to_return(file)
Expand Down
1 change: 1 addition & 0 deletions test/unit/tmdb_movie_test.rb
Expand Up @@ -114,6 +114,7 @@ def setup
Tmdb.expects(:api_call).with("movie/images", {:id => 999999999999}, nil).returns(nil)
Tmdb.expects(:api_call).with("movie/releases", {:id => 999999999999}, nil).returns(nil)
Tmdb.expects(:api_call).with("movie/casts", {:id => 999999999999}, nil).returns(nil)
Tmdb.expects(:api_call).with("movie/trailers", {:id => 999999999999}, nil).returns(nil)
assert_raise ArgumentError do
TmdbMovie.new({"id" => 999999999999}, true)
end
Expand Down

0 comments on commit 89d0d3f

Please sign in to comment.