Permalink
Browse files

Merge branch 'master' into collections

  • Loading branch information...
2 parents 673c70c + e4f850e commit b840942a4e1cc6972674f1832b48f8e9c0990137 @maddox maddox committed Dec 20, 2012
View
@@ -1,5 +1,4 @@
*.gem
-test/setup/tmdb_api_key.txt
.rvmrc
.rbenv-version
-.DS_Store
+.DS_Store
View
@@ -0,0 +1,11 @@
+source "http://rubygems.org"
+
+gem 'deepopenstruct'
+gem 'json'
+gem 'addressable'
+
+group :development do
+ gem 'mocha', require: false
+ gem 'jeweler'
+ gem 'webmock'
+end
View
@@ -0,0 +1,33 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ addressable (2.3.2)
+ crack (0.3.1)
+ deepopenstruct (0.1.2)
+ git (1.2.5)
+ jeweler (1.8.4)
+ bundler (~> 1.0)
+ git (>= 1.2.5)
+ rake
+ rdoc
+ json (1.7.5)
+ metaclass (0.0.1)
+ mocha (0.13.0)
+ metaclass (~> 0.0.1)
+ rake (10.0.1)
+ rdoc (3.12)
+ json (~> 1.4)
+ webmock (1.9.0)
+ addressable (>= 2.2.7)
+ crack (>= 0.1.7)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ addressable
+ deepopenstruct
+ jeweler
+ json
+ mocha
+ webmock
View
@@ -1,30 +1,32 @@
= ruby-tmdb3
+{<img src="https://secure.travis-ci.org/Irio/ruby-tmdb.png?branch=master" alt="Build Status" />}[https://travis-ci.org/Irio/ruby-tmdb]
+
ruby-tmdb3 is an ActiveRecord-style API wrapper for {TheMovieDB.org (TMDb)}[http://www.themoviedb.org/]. ruby-tmdb3 uses tmdb's API v3 and is designed to streamline common tasks associated with finding information about movies and cast members.
-
+
=== Examples
require 'rubygems'
require 'ruby-tmdb3'
-
+
# setup your API key
Tmdb.api_key = "t478f8de5776c799de5a"
-
+
# setup your default language
Tmdb.default_language = "en"
-
+
@movie = TmdbMovie.find(:title => "Iron Man", :limit => 1)
# => <OpenStruct>
-
+
@movie.title
# => "Iron Man"
-
+
=== Installation
For ease of use ruby-tmdb3 is packaged as a Rubygem. Installing it is as simple as:
gem install ruby-tmdb3
-
+
=== Usage
There are 3 main methods you can use to get information about movies and cast members:
@@ -34,7 +36,7 @@ There are 3 main methods you can use to get information about movies and cast me
Find information about an individual movie, or a set of movies that share a similar title, eg:
TmdbMovie.find(:title => "fight club", :limit => 10, :expand_results => true, :language => "en")
-
+
Parameters:
[:id] Specifies an individual movie via it's TMDb id
@@ -51,7 +53,7 @@ You must supply at least one of :id, :title, or :imdb. All other parameters are
Find information about an individual cast member, or a set of cast members sharing similar names, eg:
TmdbCast.find( :id => 123, :name => "Brad", :limit => 1, :expand_results => true)
-
+
[:id] Specifies an individual cast member via their TMDb id
[:name] Specifies a query string to look for in the cast names
[:limit] See TmdbMovie
@@ -66,34 +68,34 @@ You must supply at least one of :id or :name. All other parameters are optional.
Find all movies whose titles match a given string:
@movies = TmdbMovie.find(:title => 'Iron Man')
-
+
Find the movie most likely to be associated with a given title:
@movie = TmdbMovie.find(:title => 'Sin City', :limit => 1)
-
+
Find a single movie by it's TMDb ID:
@movie = TmdbMovie.find(:id => 187)
-
+
Find a single movie by it's IMDB ID:
@movie = TmdbMovie.find(:imdb => 'tt0401792')
-
+
Find all cast members whose names match a given string:
@actors = TmdbCast.find(:name => 'Fred')
-
+
Find an individual cast member via their TMDb ID:
@actor = TmdbCast.find(:id => 101)
-
+
Get the info for a movie in French:
@movie = TmdbMovie.find(:title => 'Sin City', :limit => 1, :language => "fr")
=== Item information
-
+
To find out more about the information each object offers on retrieved items have a look at the {TMDb API Docs}[http://help.themoviedb.org/kb/api/about-3]. For the most accurate information about the information available have a look at the data directly through ruby-tmdb3 by calling @item.raw_data.inspect
=== Author & Credits
@@ -103,4 +105,4 @@ Contributors:: {Alex Hayes}[https://github.com/alexhayes], {Alvaro Pereyra Raban
Copyright (c) 2012 {Irio Irineu Musskopf Junior}[http://irio.posterous.com/] ({irio.posterous.com}[http://irio.posterous.com/])
-Copyright (c) 2010 {Aaron Gough}[http://thingsaaronmade.com/] ({thingsaaronmade.com}[http://thingsaaronmade.com/]), released under the MIT license
+Copyright (c) 2010 {Aaron Gough}[http://thingsaaronmade.com/] ({thingsaaronmade.com}[http://thingsaaronmade.com/]), released under the MIT license
View
@@ -1 +1 @@
-0.3.2
+0.3.4
@@ -13,7 +13,11 @@ def self.find(options)
results << Tmdb.api_call("movie", {:id => options[:id].to_s}, options[:language])
end
unless(options[:title].nil? || options[:title].to_s.empty?)
- api_return = Tmdb.api_call("search/movie", {:query => options[:title].to_s}, options[:language])
+ data = {:query => options[:title].to_s}
+ unless options[:year].nil?
+ data[:year] = options[:year].to_s
+ end
+ api_return = Tmdb.api_call("search/movie", data, options[:language])
results << api_return["results"] if api_return
end
unless(options[:imdb].nil? || options[:imdb].to_s.empty?)
@@ -42,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)
View
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = "ruby-tmdb3"
- s.version = "0.3.2"
+ s.version = "0.3.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Irio Irineu Musskopf Junior", "Aaron Gough"]
- s.date = "2012-08-20"
+ s.date = "2012-09-15"
s.description = "An ActiveRecord-style API wrapper for TheMovieDB.org"
s.email = "iirineu@gmail.com"
s.extra_rdoc_files = [
@@ -61,17 +61,20 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<json>, [">= 0"])
s.add_runtime_dependency(%q<addressable>, [">= 0"])
s.add_development_dependency(%q<webmock>, [">= 0"])
+ s.add_development_dependency(%q<mocha>, [">= 0.13.0"])
else
s.add_dependency(%q<deepopenstruct>, [">= 0.1.2"])
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<addressable>, [">= 0"])
s.add_dependency(%q<webmock>, [">= 0"])
+ s.add_dependency(%q<mocha>, [">= 0.13.0"])
end
else
s.add_dependency(%q<deepopenstruct>, [">= 0.1.2"])
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<addressable>, [">= 0"])
s.add_dependency(%q<webmock>, [">= 0"])
+ s.add_dependency(%q<mocha>, [">= 0.13.0"])
end
end
@@ -0,0 +1,12 @@
+HTTP/1.1 200 OK
+Access-Control-Allow-Origin: *
+Age: 0
+Cache-Control: public, max-age=0
+Content-Type: text/json;charset=utf-8
+Date: Sat, 01 Sep 2012 09:37:47 GMT
+Server: nginx
+Status: 200 OK
+Via: 1.1 varnish
+X-Varnish: 609086378
+
+{"page":1,"results":[{"adult":false,"backdrop_path":"/jxdSxqAFrdioKgXwgTs5Qfbazjq.jpg","id":10138,"original_title":"Iron Man 2","release_date":"2010-05-07","poster_path":"/zzwA2qnooGmrUyrcyTcPbd5WXqZ.jpg","popularity":175147.12,"title":"Iron Man 2","vote_average":7.6,"vote_count":163}],"total_pages":1,"total_results":1}
@@ -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"}]}
@@ -0,0 +1 @@
+PUT_YOUR_KEY_IN_TMDB_API_KEY_TXT_FILE
@@ -1,9 +1,13 @@
def register_api_url_stubs
unless(TEST_LIVE_API)
-
+
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_search.txt")) do |file|
stub_request(:get, Regexp.new(Tmdb.base_api_url + "/search/movie" + ".*")).to_return(file)
end
+
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_search_year.txt")) do |file|
+ stub_request(:get, Regexp.new(Tmdb.base_api_url + "/search/movie" + ".*year=.*")).to_return(file)
+ end
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_get_info.txt")) do |file|
stub_request(:get, Regexp.new(Tmdb.base_api_url + "/movie/" + ".*")).to_return(file)
@@ -20,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)
View
@@ -2,7 +2,7 @@
require 'rubygems'
require 'test/unit'
-require 'mocha'
+require 'mocha/setup'
unless(TEST_LIVE_API)
require 'webmock/test_unit'
@@ -11,11 +11,11 @@
require_files = []
require_files << File.join(File.dirname(__FILE__), '..', 'lib', 'ruby-tmdb3.rb')
-require_files.concat Dir[File.join(File.dirname(__FILE__), 'setup', '*.rb')]
+require_files.concat(Dir[File.join(File.dirname(__FILE__), 'setup', '*.rb')])
require_files.each do |file|
require File.expand_path(file)
end
#load(File.join('unit', 'test_direct_require.rb'), true)
-system('ruby ' + File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'test_direct_require.rb')))
+system('ruby ' + File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'test_direct_require.rb')))
@@ -0,0 +1,18 @@
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
+
+class FetchTrailersWithExpansionEnabled < Test::Unit::TestCase
+ def setup
+ register_api_url_stubs
+ end
+
+ test "find with expansion enabled should return trailers" do
+ movie = TmdbMovie.find(:id => 187)
+ assert_not_nil movie.trailers
+ assert_equal movie.trailers[0].source, 'SUXWAEX2jlg'
+ end
+
+ test "find without expansion enabled should not return trailers" do
+ movie = TmdbMovie.find :id => 187, expand_results: false
+ assert_nil movie.trailers
+ end
+end
@@ -1,4 +1,5 @@
-require "test/unit"
+require 'test/unit'
+require 'mocha/setup'
require_files = []
require_files << File.join(File.dirname(__FILE__), "..", "..", "lib", "ruby-tmdb3.rb")
@@ -9,17 +10,19 @@
end
class DirectRequireTest < Test::Unit::TestCase
-
+
test "TmdbMovie should not raise exception when directly required without using rubygems" do
+ Tmdb.stubs(:api_call).returns([])
assert_nothing_raised do
TmdbMovie.find(:id => 187)
end
end
-
+
test "TmdbCast should not raise exception when directly required without using rubygems" do
+ Tmdb.stubs(:api_call).returns([])
assert_nothing_raised do
TmdbCast.find(:id => 287)
end
end
-
-end
+
+end
Oops, something went wrong. Retry.

0 comments on commit b840942

Please sign in to comment.