ruby-tmdb3 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'deepopenstruct'
4
+ gem 'json'
5
+ gem 'addressable'
6
+
7
+ group :development do
8
+ gem 'mocha', require: false
9
+ gem 'jeweler'
10
+ gem 'webmock'
11
+ end
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.2)
5
+ crack (0.3.1)
6
+ deepopenstruct (0.1.2)
7
+ git (1.2.5)
8
+ jeweler (1.8.4)
9
+ bundler (~> 1.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rdoc
13
+ json (1.7.5)
14
+ metaclass (0.0.1)
15
+ mocha (0.13.0)
16
+ metaclass (~> 0.0.1)
17
+ rake (10.0.1)
18
+ rdoc (3.12)
19
+ json (~> 1.4)
20
+ webmock (1.9.0)
21
+ addressable (>= 2.2.7)
22
+ crack (>= 0.1.7)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ addressable
29
+ deepopenstruct
30
+ jeweler
31
+ json
32
+ mocha
33
+ webmock
@@ -1,30 +1,32 @@
1
1
  = ruby-tmdb3
2
2
 
3
+ {<img src="https://secure.travis-ci.org/Irio/ruby-tmdb.png?branch=master" alt="Build Status" />}[https://travis-ci.org/Irio/ruby-tmdb]
4
+
3
5
  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.
4
-
6
+
5
7
  === Examples
6
8
 
7
9
  require 'rubygems'
8
10
  require 'ruby-tmdb3'
9
-
11
+
10
12
  # setup your API key
11
13
  Tmdb.api_key = "t478f8de5776c799de5a"
12
-
14
+
13
15
  # setup your default language
14
16
  Tmdb.default_language = "en"
15
-
17
+
16
18
  @movie = TmdbMovie.find(:title => "Iron Man", :limit => 1)
17
19
  # => <OpenStruct>
18
-
20
+
19
21
  @movie.title
20
22
  # => "Iron Man"
21
-
23
+
22
24
  === Installation
23
25
 
24
26
  For ease of use ruby-tmdb3 is packaged as a Rubygem. Installing it is as simple as:
25
27
 
26
28
  gem install ruby-tmdb3
27
-
29
+
28
30
  === Usage
29
31
 
30
32
  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
34
36
  Find information about an individual movie, or a set of movies that share a similar title, eg:
35
37
 
36
38
  TmdbMovie.find(:title => "fight club", :limit => 10, :expand_results => true, :language => "en")
37
-
39
+
38
40
  Parameters:
39
41
 
40
42
  [: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
51
53
  Find information about an individual cast member, or a set of cast members sharing similar names, eg:
52
54
 
53
55
  TmdbCast.find( :id => 123, :name => "Brad", :limit => 1, :expand_results => true)
54
-
56
+
55
57
  [:id] Specifies an individual cast member via their TMDb id
56
58
  [:name] Specifies a query string to look for in the cast names
57
59
  [:limit] See TmdbMovie
@@ -66,34 +68,34 @@ You must supply at least one of :id or :name. All other parameters are optional.
66
68
  Find all movies whose titles match a given string:
67
69
 
68
70
  @movies = TmdbMovie.find(:title => 'Iron Man')
69
-
71
+
70
72
  Find the movie most likely to be associated with a given title:
71
73
 
72
74
  @movie = TmdbMovie.find(:title => 'Sin City', :limit => 1)
73
-
75
+
74
76
  Find a single movie by it's TMDb ID:
75
77
 
76
78
  @movie = TmdbMovie.find(:id => 187)
77
-
79
+
78
80
  Find a single movie by it's IMDB ID:
79
81
 
80
82
  @movie = TmdbMovie.find(:imdb => 'tt0401792')
81
-
83
+
82
84
  Find all cast members whose names match a given string:
83
85
 
84
86
  @actors = TmdbCast.find(:name => 'Fred')
85
-
87
+
86
88
  Find an individual cast member via their TMDb ID:
87
89
 
88
90
  @actor = TmdbCast.find(:id => 101)
89
-
91
+
90
92
  Get the info for a movie in French:
91
93
 
92
94
  @movie = TmdbMovie.find(:title => 'Sin City', :limit => 1, :language => "fr")
93
95
 
94
96
 
95
97
  === Item information
96
-
98
+
97
99
  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
98
100
 
99
101
  === Author & Credits
@@ -103,4 +105,4 @@ Contributors:: {Alex Hayes}[https://github.com/alexhayes], {Alvaro Pereyra Raban
103
105
 
104
106
  Copyright (c) 2012 {Irio Irineu Musskopf Junior}[http://irio.posterous.com/] ({irio.posterous.com}[http://irio.posterous.com/])
105
107
 
106
- Copyright (c) 2010 {Aaron Gough}[http://thingsaaronmade.com/] ({thingsaaronmade.com}[http://thingsaaronmade.com/]), released under the MIT license
108
+ Copyright (c) 2010 {Aaron Gough}[http://thingsaaronmade.com/] ({thingsaaronmade.com}[http://thingsaaronmade.com/]), released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -13,7 +13,11 @@ class TmdbMovie
13
13
  results << Tmdb.api_call("movie", {:id => options[:id].to_s}, options[:language])
14
14
  end
15
15
  unless(options[:title].nil? || options[:title].to_s.empty?)
16
- api_return = Tmdb.api_call("search/movie", {:query => options[:title].to_s}, options[:language])
16
+ data = {:query => options[:title].to_s}
17
+ unless options[:year].nil?
18
+ data[:year] = options[:year].to_s
19
+ end
20
+ api_return = Tmdb.api_call("search/movie", data, options[:language])
17
21
  results << api_return["results"] if api_return
18
22
  end
19
23
  unless(options[:imdb].nil? || options[:imdb].to_s.empty?)
@@ -42,20 +46,22 @@ class TmdbMovie
42
46
  def self.new(raw_data, expand_results = false, language = nil)
43
47
  # expand the result by calling movie unless :expand_results is false or the data is already complete
44
48
  # (as determined by checking for the posters property in the raw data)
45
- if(expand_results && (!raw_data.has_key?("posters") || !raw_data['releases'] || !raw_data['cast']))
49
+ if(expand_results && (!raw_data.has_key?("posters") || !raw_data['releases'] || !raw_data['cast'] || !raw_data['trailers']))
46
50
  begin
47
51
  movie_id = raw_data['id']
48
52
  raw_data = Tmdb.api_call 'movie', { :id => movie_id }, language
49
53
  @images_data = Tmdb.api_call("movie/images", {:id => movie_id}, language)
50
54
  @releases_data = Tmdb.api_call('movie/releases', {:id => movie_id}, language)
51
55
  @cast_data = Tmdb.api_call('movie/casts', {:id => movie_id}, language)
56
+ @trailers_data = Tmdb.api_call('movie/trailers', {:id => movie_id}, language)
52
57
  raw_data['posters'] = @images_data['posters']
53
58
  raw_data['backdrops'] = @images_data['backdrops']
54
59
  raw_data['releases'] = @releases_data['countries']
55
60
  raw_data['cast'] = @cast_data['cast']
56
61
  raw_data['crew'] = @cast_data['crew']
62
+ raw_data['trailers'] = @trailers_data['youtube']
57
63
  rescue => e
58
- raise ArgumentError, "Unable to fetch expanded infos for Movie ID: '#{movie_id}'" if @images_data.nil? || @releases_data.nil? || @cast_data.nil?
64
+ 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?
59
65
  end
60
66
  end
61
67
  return Tmdb.data_to_object(raw_data)
@@ -61,17 +61,20 @@ Gem::Specification.new do |s|
61
61
  s.add_runtime_dependency(%q<json>, [">= 0"])
62
62
  s.add_runtime_dependency(%q<addressable>, [">= 0"])
63
63
  s.add_development_dependency(%q<webmock>, [">= 0"])
64
+ s.add_development_dependency(%q<mocha>, [">= 0.13.0"])
64
65
  else
65
66
  s.add_dependency(%q<deepopenstruct>, [">= 0.1.2"])
66
67
  s.add_dependency(%q<json>, [">= 0"])
67
68
  s.add_dependency(%q<addressable>, [">= 0"])
68
69
  s.add_dependency(%q<webmock>, [">= 0"])
70
+ s.add_dependency(%q<mocha>, [">= 0.13.0"])
69
71
  end
70
72
  else
71
73
  s.add_dependency(%q<deepopenstruct>, [">= 0.1.2"])
72
74
  s.add_dependency(%q<json>, [">= 0"])
73
75
  s.add_dependency(%q<addressable>, [">= 0"])
74
76
  s.add_dependency(%q<webmock>, [">= 0"])
77
+ s.add_dependency(%q<mocha>, [">= 0.13.0"])
75
78
  end
76
79
  end
77
80
 
@@ -0,0 +1,12 @@
1
+ HTTP/1.1 200 OK
2
+ Access-Control-Allow-Origin: *
3
+ Age: 0
4
+ Cache-Control: public, max-age=0
5
+ Content-Type: text/json;charset=utf-8
6
+ Date: Sat, 01 Sep 2012 09:37:47 GMT
7
+ Server: nginx
8
+ Status: 200 OK
9
+ Via: 1.1 varnish
10
+ X-Varnish: 609086378
11
+
12
+ {"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 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Mon, 23 Aug 2010 16:45:21 GMT
4
+ Content-Type: text/json; charset=utf-8
5
+ Transfer-Encoding: chunked
6
+ Connection: keep-alive
7
+ Keep-Alive: timeout=20
8
+ Status: 200 OK
9
+ Cache-Control: public, max-age=21600
10
+ X-Varnish: 2542127928 2542059531
11
+ Age: 1000
12
+ Via: 1.1 varnish
13
+ X-Cache: HIT
14
+
15
+ {"id": 550,"quicktime": [],"youtube": [{"name": "Trailer 1","size": "HD","source": "SUXWAEX2jlg"}]}
@@ -1,9 +1,13 @@
1
1
  def register_api_url_stubs
2
2
  unless(TEST_LIVE_API)
3
-
3
+
4
4
  File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_search.txt")) do |file|
5
5
  stub_request(:get, Regexp.new(Tmdb.base_api_url + "/search/movie" + ".*")).to_return(file)
6
6
  end
7
+
8
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_search_year.txt")) do |file|
9
+ stub_request(:get, Regexp.new(Tmdb.base_api_url + "/search/movie" + ".*year=.*")).to_return(file)
10
+ end
7
11
 
8
12
  File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_get_info.txt")) do |file|
9
13
  stub_request(:get, Regexp.new(Tmdb.base_api_url + "/movie/" + ".*")).to_return(file)
@@ -20,6 +24,10 @@ def register_api_url_stubs
20
24
  File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_casts.txt")) do |file|
21
25
  stub_request(:get, Regexp.new(Tmdb.base_api_url + '/movie/\d+/casts')).to_return(file)
22
26
  end
27
+
28
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_trailers.txt")) do |file|
29
+ stub_request(:get, Regexp.new(Tmdb.base_api_url + '/movie/\d+/trailers')).to_return(file)
30
+ end
23
31
 
24
32
  File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_imdb_lookup.txt")) do |file|
25
33
  stub_request(:get, Regexp.new(Tmdb.base_api_url + "/movie/tt" + ".*")).to_return(file)
@@ -2,7 +2,7 @@ TEST_LIVE_API = false
2
2
 
3
3
  require 'rubygems'
4
4
  require 'test/unit'
5
- require 'mocha'
5
+ require 'mocha/setup'
6
6
 
7
7
  unless(TEST_LIVE_API)
8
8
  require 'webmock/test_unit'
@@ -18,4 +18,4 @@ require_files.each do |file|
18
18
  end
19
19
 
20
20
  #load(File.join('unit', 'test_direct_require.rb'), true)
21
- system('ruby ' + File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'test_direct_require.rb')))
21
+ system('ruby ' + File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'test_direct_require.rb')))
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
2
+
3
+ class FetchTrailersWithExpansionEnabled < Test::Unit::TestCase
4
+ def setup
5
+ register_api_url_stubs
6
+ end
7
+
8
+ test "find with expansion enabled should return trailers" do
9
+ movie = TmdbMovie.find(:id => 187)
10
+ assert_not_nil movie.trailers
11
+ assert_equal movie.trailers[0].source, 'SUXWAEX2jlg'
12
+ end
13
+
14
+ test "find without expansion enabled should not return trailers" do
15
+ movie = TmdbMovie.find :id => 187, expand_results: false
16
+ assert_nil movie.trailers
17
+ end
18
+ end
@@ -60,6 +60,11 @@ class TmdbMovieTest < Test::Unit::TestCase
60
60
  assert_kind_of OpenStruct, movie
61
61
  end
62
62
  end
63
+
64
+ test "find by title with year should return movies from only that year" do
65
+ movie = TmdbMovie.find(:title => "Iron Man", :year => "2010", :expand_results => false)
66
+ assert_equal movie.id, 10138
67
+ end
63
68
 
64
69
  test "find by title with limit=1 should return a single movie" do
65
70
  assert_kind_of OpenStruct, TmdbMovie.find(:title => "Iron Man", :limit => 1)
@@ -109,6 +114,7 @@ class TmdbMovieTest < Test::Unit::TestCase
109
114
  Tmdb.expects(:api_call).with("movie/images", {:id => 999999999999}, nil).returns(nil)
110
115
  Tmdb.expects(:api_call).with("movie/releases", {:id => 999999999999}, nil).returns(nil)
111
116
  Tmdb.expects(:api_call).with("movie/casts", {:id => 999999999999}, nil).returns(nil)
117
+ Tmdb.expects(:api_call).with("movie/trailers", {:id => 999999999999}, nil).returns(nil)
112
118
  assert_raise ArgumentError do
113
119
  TmdbMovie.new({"id" => 999999999999}, true)
114
120
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-tmdb3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,104 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-15 00:00:00.000000000 Z
13
+ date: 2012-11-24 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: deepopenstruct
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: json
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: addressable
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: mocha
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: jeweler
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: webmock
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
15
111
  - !ruby/object:Gem::Dependency
16
112
  name: deepopenstruct
17
113
  requirement: !ruby/object:Gem::Requirement
@@ -84,6 +180,8 @@ extra_rdoc_files:
84
180
  - MIT-LICENSE
85
181
  - README.rdoc
86
182
  files:
183
+ - Gemfile
184
+ - Gemfile.lock
87
185
  - MIT-LICENSE
88
186
  - README.rdoc
89
187
  - Rakefile
@@ -103,12 +201,15 @@ files:
103
201
  - test/fixtures/movie_posters.txt
104
202
  - test/fixtures/movie_releases.txt
105
203
  - test/fixtures/movie_search.txt
204
+ - test/fixtures/movie_search_year.txt
205
+ - test/fixtures/movie_trailers.txt
106
206
  - test/fixtures/person_get_info.txt
107
207
  - test/fixtures/person_search.txt
108
208
  - test/setup/setup_api_key.rb
109
209
  - test/setup/test_unit_extensions.rb
110
210
  - test/setup/url_mocks.rb
111
211
  - test/test_helper.rb
212
+ - test/unit/fetch_trailers_with_expansion_enabled_test.rb
112
213
  - test/unit/test_direct_require.rb
113
214
  - test/unit/tmdb_cast_test.rb
114
215
  - test/unit/tmdb_movie_test.rb