ruby-tmdb 0.1.4 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/README.rdoc +51 -28
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/ruby-tmdb/tmdb.rb +33 -3
- data/lib/ruby-tmdb/tmdb_cast.rb +9 -5
- data/lib/ruby-tmdb/tmdb_movie.rb +34 -6
- data/ruby-tmdb.gemspec +6 -2
- data/test/fixtures/movie_browse.txt +15 -0
- data/test/setup/url_mocks.rb +4 -1
- data/test/test_helper.rb +1 -0
- data/test/unit/tmdb_cast_test.rb +19 -0
- data/test/unit/tmdb_movie_test.rb +40 -0
- data/test/unit/tmdb_test.rb +38 -6
- metadata +19 -5
data/.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
*.gem
|
1
|
+
*.gem
|
2
|
+
test/setup/tmdb_api_key.txt
|
data/README.rdoc
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
= ruby-tmdb
|
2
2
|
|
3
|
-
ruby-tmdb is an ActiveRecord-style API wrapper for {TheMovieDB.org (TMDb)}[http://www.themoviedb.org/]. ruby-tmdb is designed to
|
4
|
-
|
5
|
-
=== Installation
|
6
|
-
|
7
|
-
gem install ruby-tmdb
|
3
|
+
ruby-tmdb is an ActiveRecord-style API wrapper for {TheMovieDB.org (TMDb)}[http://www.themoviedb.org/]. ruby-tmdb is designed to streamline common tasks associated with finding information about movies and cast members.
|
8
4
|
|
9
|
-
===
|
5
|
+
=== Examples
|
10
6
|
|
11
7
|
require 'rubygems'
|
12
8
|
require 'ruby-tmdb'
|
@@ -14,6 +10,9 @@ ruby-tmdb is an ActiveRecord-style API wrapper for {TheMovieDB.org (TMDb)}[http:
|
|
14
10
|
# setup your API key
|
15
11
|
Tmdb.api_key = "t478f8de5776c799de5a"
|
16
12
|
|
13
|
+
# setup your default language
|
14
|
+
Tmdb.default_language = "en"
|
15
|
+
|
17
16
|
@movie = TmdbMovie.find(:title => "Iron Man", :limit => 1)
|
18
17
|
# => <OpenStruct>
|
19
18
|
|
@@ -26,39 +25,58 @@ ruby-tmdb is an ActiveRecord-style API wrapper for {TheMovieDB.org (TMDb)}[http:
|
|
26
25
|
@movie.posters.first.data
|
27
26
|
# => [binary blob representing JPEG]
|
28
27
|
|
29
|
-
|
30
|
-
@actor = TmdbCast.find(:name => "Brad Pitt", :limit => 1)
|
31
|
-
# => <TmdbCast>
|
32
|
-
=======
|
33
|
-
=== Usage
|
28
|
+
=== Installation
|
34
29
|
|
35
|
-
ruby-tmdb
|
36
|
-
|
37
|
-
|
38
|
-
TmdbCast
|
30
|
+
For ease of use ruby-tmdb is packaged as a Rubygem. Installing it is as simple as:
|
31
|
+
|
32
|
+
gem install ruby-tmdb
|
39
33
|
|
40
|
-
|
34
|
+
=== Usage
|
41
35
|
|
42
|
-
|
36
|
+
There are 3 main methods you can use to get information about movies and cast members:
|
43
37
|
|
44
|
-
|
38
|
+
==== TmdbMovie.find([:id, :imdb, :title, :limit, :expand_results, :language])
|
45
39
|
|
40
|
+
Find information about an individual movie, or a set of movies that share a similar title, eg:
|
46
41
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
42
|
+
TmdbMovie.find(:title => "fight club", :limit => 10, :expand_results => true, :language => "en")
|
43
|
+
|
44
|
+
Parameters:
|
45
|
+
|
46
|
+
[:id] Specifies an individual movie via it's TMDb id
|
47
|
+
[:title] Specifies a query string to look for in the movie titles
|
48
|
+
[:imdb] Specifies an individual movie via it's IMDB id
|
49
|
+
[:limit] Specifies the maximum number of results to be returned
|
51
50
|
[:expand_results] The TMDb API by default returns only partial info for any API method that can return multiple results. When :expand_results is set to true ruby-tmdb automatically makes extra API calls to fetch the full information for each item. This can result in *very* slow requests though. If you only need basic information for a search listing then set this to false. Defaults to 'true'.
|
51
|
+
[:language] Allows you to override the default API language on a per-query basis.
|
52
|
+
|
53
|
+
You must supply at least one of :id, :title, or :imdb. All other parameters are optional.
|
54
|
+
|
55
|
+
==== TmdbMovie.browse([query_options],[:language, :expand_results])
|
56
|
+
|
57
|
+
Find information about a set of movies grouped by one or more defined criteria, eg:
|
58
|
+
|
59
|
+
TmdbMovie.browse(:order_by => "rating", :order => "desc", :genres => 18, :min_votes => 5, :page => 1, :per_page => 10, :language => "en", :expand_results => true)
|
52
60
|
|
61
|
+
Parameters:
|
53
62
|
|
54
|
-
|
63
|
+
[query_options] These are defined by the TMDB.org API, for more info on which options are available please have a look at the {'browse' API documentation}[http://api.themoviedb.org/2.1/methods/Movie.browse]
|
64
|
+
[:expand_results] See TmdbMovie
|
65
|
+
[:language] See TmdbMovie
|
55
66
|
|
56
|
-
|
67
|
+
==== TmdbCast.find([:id, :name, :limit, :expand_results, :language])
|
68
|
+
|
69
|
+
Find information about an individual cast member, or a set of cast members sharing similar names, eg:
|
70
|
+
|
71
|
+
TmdbCast.find( :id => 123, :name => "Brad", :limit => 1, :expand_results => true, :language => "fr")
|
57
72
|
|
58
|
-
[:id]
|
59
|
-
[:name]
|
60
|
-
[:limit]
|
61
|
-
[:expand_results]
|
73
|
+
[:id] Specifies an individual cast member via their TMDb id
|
74
|
+
[:name] Specifies a query string to look for in the cast names
|
75
|
+
[:limit] See TmdbMovie
|
76
|
+
[:expand_results] See TmdbMovie
|
77
|
+
[:language] See TmdbMovie
|
78
|
+
|
79
|
+
You must supply at least one of :id or :name. All other parameters are optional.
|
62
80
|
|
63
81
|
|
64
82
|
=== Usage Examples
|
@@ -86,6 +104,10 @@ Find all cast members whose names match a given string:
|
|
86
104
|
Find an individual cast member via their TMDb ID:
|
87
105
|
|
88
106
|
@actor = TmdbCast.find(:id => 101)
|
107
|
+
|
108
|
+
Get the info for a movie in French:
|
109
|
+
|
110
|
+
@movie = TmdbMovie.find(:title => 'Sin City', :limit => 1, :language => "fr")
|
89
111
|
|
90
112
|
|
91
113
|
=== Item information
|
@@ -95,5 +117,6 @@ To find out more about the information each object offers on retrieved items hav
|
|
95
117
|
=== Author & Credits
|
96
118
|
|
97
119
|
Author:: {Aaron Gough}[mailto:aaron@aarongough.com]
|
120
|
+
Contributors:: {Alex Hayes}[https://github.com/alexhayes], {Alvaro Pereyra Rabanal}[https://github.com/xenda], {Linus Oleander}[https://github.com/oleander], {aristides}[https://github.com/aristides], {Robin Boutros}[https://github.com/niuage]
|
98
121
|
|
99
122
|
Copyright (c) 2010 {Aaron Gough}[http://thingsaaronmade.com/] ({thingsaaronmade.com}[http://thingsaaronmade.com/]), released under the MIT license
|
data/Rakefile
CHANGED
@@ -18,6 +18,7 @@ begin
|
|
18
18
|
gemspec.extra_rdoc_files = ['README.rdoc', 'MIT-LICENSE']
|
19
19
|
gemspec.add_dependency( "deepopenstruct", ">= 0.1.2")
|
20
20
|
gemspec.add_dependency( "json")
|
21
|
+
gemspec.add_dependency "addressable"
|
21
22
|
gemspec.add_development_dependency "webmock"
|
22
23
|
end
|
23
24
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1
|
1
|
+
0.2.1
|
data/lib/ruby-tmdb/tmdb.rb
CHANGED
@@ -5,8 +5,10 @@ class Tmdb
|
|
5
5
|
require 'cgi'
|
6
6
|
require 'json'
|
7
7
|
require 'deepopenstruct'
|
8
|
+
require "addressable/uri"
|
8
9
|
|
9
10
|
@@api_key = ""
|
11
|
+
@@default_language = "en"
|
10
12
|
@@api_response = {}
|
11
13
|
|
12
14
|
def self.api_key
|
@@ -17,16 +19,44 @@ class Tmdb
|
|
17
19
|
@@api_key = key
|
18
20
|
end
|
19
21
|
|
22
|
+
def self.default_language
|
23
|
+
@@default_language
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.default_language=(language)
|
27
|
+
@@default_language = language
|
28
|
+
end
|
29
|
+
|
20
30
|
def self.base_api_url
|
21
31
|
"http://api.themoviedb.org/2.1/"
|
22
32
|
end
|
23
33
|
|
24
|
-
def self.api_call(method, data, language =
|
34
|
+
def self.api_call(method, data = nil, language = nil)
|
25
35
|
raise ArgumentError, "Tmdb.api_key must be set before using the API" if(Tmdb.api_key.nil? || Tmdb.api_key.empty?)
|
26
|
-
|
36
|
+
|
37
|
+
language = language || @@default_language
|
38
|
+
if data.class == Hash
|
39
|
+
# Addressable can only handle hashes whose values respond to to_str, so lets be nice and convert things.
|
40
|
+
query_values = {}
|
41
|
+
data.each do |key,value|
|
42
|
+
if not value.respond_to?(:to_str) and value.respond_to?(:to_s)
|
43
|
+
query_values[key] = value.to_s
|
44
|
+
else
|
45
|
+
query_values[key] = value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
uri = Addressable::URI.new
|
49
|
+
uri.query_values = query_values
|
50
|
+
params = '?' + uri.query
|
51
|
+
elsif not data.nil?
|
52
|
+
params = '/' + CGI::escape(data.to_s)
|
53
|
+
else
|
54
|
+
params = ''
|
55
|
+
end
|
56
|
+
url = Tmdb.base_api_url + method + '/' + language + '/json/' + Tmdb.api_key + params
|
27
57
|
response = Tmdb.get_url(url)
|
28
58
|
if(response.code.to_i != 200)
|
29
|
-
|
59
|
+
raise RuntimeError, "Tmdb API returned status code '#{response.code}' for URL: '#{url}'"
|
30
60
|
end
|
31
61
|
body = JSON(response.body)
|
32
62
|
if( body.first.include?("Nothing found"))
|
data/lib/ruby-tmdb/tmdb_cast.rb
CHANGED
@@ -9,10 +9,10 @@ class TmdbCast
|
|
9
9
|
|
10
10
|
results = []
|
11
11
|
unless(options[:id].nil? || options[:id].to_s.empty?)
|
12
|
-
results << Tmdb.api_call('Person.getInfo', options[:id])
|
12
|
+
results << Tmdb.api_call('Person.getInfo', options[:id], options[:language])
|
13
13
|
end
|
14
14
|
unless(options[:name].nil? || options[:name].to_s.empty?)
|
15
|
-
results << Tmdb.api_call('Person.search', options[:name])
|
15
|
+
results << Tmdb.api_call('Person.search', options[:name], options[:language])
|
16
16
|
end
|
17
17
|
|
18
18
|
results.flatten!
|
@@ -23,7 +23,7 @@ class TmdbCast
|
|
23
23
|
results = results.slice(0, options[:limit])
|
24
24
|
end
|
25
25
|
|
26
|
-
results.map!{|c| TmdbCast.new(c, options[:expand_results]) }
|
26
|
+
results.map!{|c| TmdbCast.new(c, options[:expand_results], options[:language]) }
|
27
27
|
|
28
28
|
if(results.length == 1)
|
29
29
|
return results[0]
|
@@ -32,10 +32,14 @@ class TmdbCast
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def self.new(raw_data, expand_results = false)
|
35
|
+
def self.new(raw_data, expand_results = false, language = nil)
|
36
36
|
# expand the result by calling Person.getInfo unless :expand_results is set to false or the data is already complete
|
37
37
|
# (as determined by checking for the 'known_movies' property)
|
38
|
-
|
38
|
+
if(expand_results && !raw_data.has_key?("known_movies"))
|
39
|
+
expanded_data = Tmdb.api_call('Person.getInfo', raw_data["id"], language)
|
40
|
+
raise ArgumentError, "Unable to fetch expanded info for Cast ID: '#{raw_data["id"]}'" if expanded_data.nil?
|
41
|
+
raw_data = expanded_data.first
|
42
|
+
end
|
39
43
|
return Tmdb.data_to_object(raw_data)
|
40
44
|
end
|
41
45
|
|
data/lib/ruby-tmdb/tmdb_movie.rb
CHANGED
@@ -9,14 +9,14 @@ class TmdbMovie
|
|
9
9
|
|
10
10
|
results = []
|
11
11
|
unless(options[:id].nil? || options[:id].to_s.empty?)
|
12
|
-
results << Tmdb.api_call("Movie.getInfo", options[:id])
|
12
|
+
results << Tmdb.api_call("Movie.getInfo", options[:id], options[:language])
|
13
13
|
end
|
14
14
|
unless(options[:imdb].nil? || options[:imdb].to_s.empty?)
|
15
|
-
results << Tmdb.api_call("Movie.imdbLookup", options[:imdb])
|
15
|
+
results << Tmdb.api_call("Movie.imdbLookup", options[:imdb], options[:language])
|
16
16
|
options[:expand_results] = true
|
17
17
|
end
|
18
18
|
unless(options[:title].nil? || options[:title].to_s.empty?)
|
19
|
-
results << Tmdb.api_call("Movie.search", options[:title])
|
19
|
+
results << Tmdb.api_call("Movie.search", options[:title], options[:language])
|
20
20
|
end
|
21
21
|
|
22
22
|
results.flatten!
|
@@ -27,7 +27,7 @@ class TmdbMovie
|
|
27
27
|
results = results.slice(0, options[:limit])
|
28
28
|
end
|
29
29
|
|
30
|
-
results.map!{|m| TmdbMovie.new(m, options[:expand_results]) }
|
30
|
+
results.map!{|m| TmdbMovie.new(m, options[:expand_results], options[:language]) }
|
31
31
|
|
32
32
|
if(results.length == 1)
|
33
33
|
return results[0]
|
@@ -36,10 +36,38 @@ class TmdbMovie
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def self.
|
39
|
+
def self.browse(options)
|
40
|
+
options = {
|
41
|
+
:expand_results => false
|
42
|
+
}.merge(options)
|
43
|
+
|
44
|
+
expand_results = options.delete(:expand_results)
|
45
|
+
language = options.delete(:language)
|
46
|
+
|
47
|
+
results = []
|
48
|
+
results << Tmdb.api_call("Movie.browse", options, language)
|
49
|
+
|
50
|
+
results.flatten!
|
51
|
+
results.compact!
|
52
|
+
|
53
|
+
results.map!{|m| TmdbMovie.new(m, expand_results, language) }
|
54
|
+
|
55
|
+
if(results.length == 1)
|
56
|
+
return results[0]
|
57
|
+
else
|
58
|
+
return results
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.new(raw_data, expand_results = false, language = nil)
|
40
64
|
# expand the result by calling Movie.getInfo unless :expand_results is false or the data is already complete
|
41
65
|
# (as determined by checking for the trailer property in the raw data)
|
42
|
-
|
66
|
+
if(expand_results && !raw_data.has_key?("trailer"))
|
67
|
+
expanded_data = Tmdb.api_call('Movie.getInfo', raw_data["id"], language)
|
68
|
+
raise ArgumentError, "Unable to fetch expanded info for Movie ID: '#{raw_data["id"]}'" if expanded_data.nil?
|
69
|
+
raw_data = expanded_data.first
|
70
|
+
end
|
43
71
|
return Tmdb.data_to_object(raw_data)
|
44
72
|
end
|
45
73
|
|
data/ruby-tmdb.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ruby-tmdb}
|
8
|
-
s.version = "0.1
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aaron Gough"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-04-13}
|
13
13
|
s.description = %q{An ActiveRecord-style API wrapper for TheMovieDB.org}
|
14
14
|
s.email = %q{aaron@aarongough.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"test/fixtures/example_com.txt",
|
32
32
|
"test/fixtures/image.jpg",
|
33
33
|
"test/fixtures/incorrect_api_url.txt",
|
34
|
+
"test/fixtures/movie_browse.txt",
|
34
35
|
"test/fixtures/movie_get_info.txt",
|
35
36
|
"test/fixtures/movie_imdb_lookup.txt",
|
36
37
|
"test/fixtures/movie_search.txt",
|
@@ -69,15 +70,18 @@ Gem::Specification.new do |s|
|
|
69
70
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
70
71
|
s.add_runtime_dependency(%q<deepopenstruct>, [">= 0.1.2"])
|
71
72
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
73
|
+
s.add_runtime_dependency(%q<addressable>, [">= 0"])
|
72
74
|
s.add_development_dependency(%q<webmock>, [">= 0"])
|
73
75
|
else
|
74
76
|
s.add_dependency(%q<deepopenstruct>, [">= 0.1.2"])
|
75
77
|
s.add_dependency(%q<json>, [">= 0"])
|
78
|
+
s.add_dependency(%q<addressable>, [">= 0"])
|
76
79
|
s.add_dependency(%q<webmock>, [">= 0"])
|
77
80
|
end
|
78
81
|
else
|
79
82
|
s.add_dependency(%q<deepopenstruct>, [">= 0.1.2"])
|
80
83
|
s.add_dependency(%q<json>, [">= 0"])
|
84
|
+
s.add_dependency(%q<addressable>, [">= 0"])
|
81
85
|
s.add_dependency(%q<webmock>, [">= 0"])
|
82
86
|
end
|
83
87
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: nginx
|
3
|
+
Date: Mon, 23 Aug 2010 16:42:39 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: 2542116501
|
11
|
+
Age: 0
|
12
|
+
Via: 1.1 varnish
|
13
|
+
X-Cache: MISS
|
14
|
+
|
15
|
+
[{"score":null,"popularity":3,"translated":true,"adult":false,"language":"en","original_name":"When The Sun Goes Down","name":"When The Sun Goes Down","alternative_name":null,"movie_type":"movie","id":29734,"imdb_id":"tt1525907","url":"http://www.themoviedb.org/movie/29734","votes":5,"rating":9.8,"certification":"","overview":"No overview found.","released":"2005-01-05","posters":[{"image":{"type":"poster","size":"original","height":1500,"width":1000,"url":"http://hwcdn.themoviedb.org/posters/01e/4bc97392017a3c57fe03501e/when-the-sun-goes-down-original.jpg","id":"4bc97392017a3c57fe03501e"}},{"image":{"type":"poster","size":"mid","height":750,"width":500,"url":"http://hwcdn.themoviedb.org/posters/01e/4bc97392017a3c57fe03501e/when-the-sun-goes-down-mid.jpg","id":"4bc97392017a3c57fe03501e"}},{"image":{"type":"poster","size":"cover","height":278,"width":185,"url":"http://hwcdn.themoviedb.org/posters/01e/4bc97392017a3c57fe03501e/when-the-sun-goes-down-cover.jpg","id":"4bc97392017a3c57fe03501e"}},{"image":{"type":"poster","size":"thumb","height":138,"width":92,"url":"http://hwcdn.themoviedb.org/posters/01e/4bc97392017a3c57fe03501e/when-the-sun-goes-down-thumb.jpg","id":"4bc97392017a3c57fe03501e"}}],"backdrops":[{"image":{"type":"backdrop","size":"original","height":720,"width":1280,"url":"http://hwcdn.themoviedb.org/backdrops/01a/4bc97392017a3c57fe03501a/when-the-sun-goes-down-original.jpg","id":"4bc97392017a3c57fe03501a"}},{"image":{"type":"backdrop","size":"poster","height":439,"width":780,"url":"http://hwcdn.themoviedb.org/backdrops/01a/4bc97392017a3c57fe03501a/when-the-sun-goes-down-poster.jpg","id":"4bc97392017a3c57fe03501a"}},{"image":{"type":"backdrop","size":"thumb","height":169,"width":300,"url":"http://hwcdn.themoviedb.org/backdrops/01a/4bc97392017a3c57fe03501a/when-the-sun-goes-down-thumb.jpg","id":"4bc97392017a3c57fe03501a"}}],"version":9,"last_modified_at":"2010-08-27 08:59:58"},{"score":null,"popularity":3,"translated":true,"adult":false,"language":"en","original_name":"Frankie and Johnny","name":"Frankie and Johnny","alternative_name":"Paura d'amare","movie_type":"movie","id":3784,"imdb_id":"tt0101912","url":"http://www.themoviedb.org/movie/3784","votes":5,"rating":9.6,"certification":"","overview":"Garry Marshall (Pretty Woman) directs the screen adaptation of Terence McNally's play Frankie and Johnny at the Clair de Lune, the story of a short-order cook (Al Pacino) who drives a waitress (Michelle Pfeiffer) crazy with his adamant courtship and mixed messages. The film is okay and not much more than that, the major stumbling block being Marshall's failure to scrub away enough star veneer on Pacino and Pfeiffer to accept them as minimum-wage drones with nowhere to go but toward each other. Fortunately, Marshall's feel for the texture offered by supporting players--Hector Elizondo as a caf\u00e9 owner, Nathan Lane as Pfeiffer's inevitably gay neighbour-buddy, Kate Nelligan as another lonely waitress--keeps things interesting enough.","released":"1991-10-18","posters":[{"image":{"type":"poster","size":"original","height":1450,"width":1021,"url":"http://hwcdn.themoviedb.org/posters/051/4c614eaa5e73d63c86000051/frankie-and-johnny-original.jpg","id":"4c614eaa5e73d63c86000051"}},{"image":{"type":"poster","size":"mid","height":710,"width":500,"url":"http://hwcdn.themoviedb.org/posters/051/4c614eaa5e73d63c86000051/frankie-and-johnny-mid.jpg","id":"4c614eaa5e73d63c86000051"}},{"image":{"type":"poster","size":"cover","height":263,"width":185,"url":"http://hwcdn.themoviedb.org/posters/051/4c614eaa5e73d63c86000051/frankie-and-johnny-cover.jpg","id":"4c614eaa5e73d63c86000051"}},{"image":{"type":"poster","size":"thumb","height":131,"width":92,"url":"http://hwcdn.themoviedb.org/posters/051/4c614eaa5e73d63c86000051/frankie-and-johnny-thumb.jpg","id":"4c614eaa5e73d63c86000051"}}],"backdrops":[{"image":{"type":"backdrop","size":"original","height":720,"width":1280,"url":"http://hwcdn.themoviedb.org/backdrops/c9e/4bc9197b017a3c57fe009c9e/frankie-and-johnny-original.jpg","id":"4bc9197b017a3c57fe009c9e"}},{"image":{"type":"backdrop","size":"poster","height":439,"width":780,"url":"http://hwcdn.themoviedb.org/backdrops/c9e/4bc9197b017a3c57fe009c9e/frankie-and-johnny-poster.jpg","id":"4bc9197b017a3c57fe009c9e"}},{"image":{"type":"backdrop","size":"thumb","height":169,"width":300,"url":"http://hwcdn.themoviedb.org/backdrops/c9e/4bc9197b017a3c57fe009c9e/frankie-and-johnny-thumb.jpg","id":"4bc9197b017a3c57fe009c9e"}}],"version":36,"last_modified_at":"2010-08-18 22:47:39"},{"score":null,"popularity":3,"translated":true,"adult":false,"language":"en","original_name":"The Kite Runner","name":"The Kite Runner","alternative_name":"Les Cerfs-volants de Kaboul","movie_type":"movie","id":7979,"imdb_id":"tt0419887","url":"http://www.themoviedb.org/movie/7979","votes":5,"rating":9.6,"certification":"","overview":"The Kite Runner is the story of strained family relationships between a father and a son, and between two brothers, how they deal with guilt and forgiveness, and how they weather the political and social transformations of Afghanistan from the 1970s to 2001. ","released":"2007-10-14","posters":[{"image":{"type":"poster","size":"original","height":1500,"width":1013,"url":"http://hwcdn.themoviedb.org/posters/f30/4bffc4a2017a3c7031000f30/the-kite-runner-original.jpg","id":"4bffc4a2017a3c7031000f30"}},{"image":{"type":"poster","size":"mid","height":740,"width":500,"url":"http://hwcdn.themoviedb.org/posters/f30/4bffc4a2017a3c7031000f30/the-kite-runner-mid.jpg","id":"4bffc4a2017a3c7031000f30"}},{"image":{"type":"poster","size":"cover","height":274,"width":185,"url":"http://hwcdn.themoviedb.org/posters/f30/4bffc4a2017a3c7031000f30/the-kite-runner-cover.jpg","id":"4bffc4a2017a3c7031000f30"}},{"image":{"type":"poster","size":"thumb","height":136,"width":92,"url":"http://hwcdn.themoviedb.org/posters/f30/4bffc4a2017a3c7031000f30/the-kite-runner-thumb.jpg","id":"4bffc4a2017a3c7031000f30"}}],"backdrops":[{"image":{"type":"backdrop","size":"original","height":1080,"width":1920,"url":"http://hwcdn.themoviedb.org/backdrops/9a3/4bc91fd7017a3c57fe00c9a3/the-kite-runner-original.jpg","id":"4bc91fd7017a3c57fe00c9a3"}},{"image":{"type":"backdrop","size":"poster","height":439,"width":780,"url":"http://hwcdn.themoviedb.org/backdrops/9a3/4bc91fd7017a3c57fe00c9a3/the-kite-runner-poster.jpg","id":"4bc91fd7017a3c57fe00c9a3"}},{"image":{"type":"backdrop","size":"thumb","height":169,"width":300,"url":"http://hwcdn.themoviedb.org/backdrops/9a3/4bc91fd7017a3c57fe00c9a3/the-kite-runner-thumb.jpg","id":"4bc91fd7017a3c57fe00c9a3"}}],"version":21,"last_modified_at":"2010-08-18 22:41:46"},{"score":null,"popularity":3,"translated":true,"adult":false,"language":"en","original_name":"The Last Emperor","name":"The Last Emperor","alternative_name":"L'Ultimo Imperatore","movie_type":"movie","id":746,"imdb_id":"tt0093389","url":"http://www.themoviedb.org/movie/746","votes":5,"rating":9.4,"certification":"","overview":"The Last Emeror is a monumental film about the life of the last emperor of the Chinese Quinn dynasty. Director Bertolucci illustrates the life of Pu-Yi who was crowned emperor at the age of two only to loose it at the age of five. The film won a total of nine Oscars in 1987.","released":"1987-10-29","posters":[{"image":{"type":"poster","size":"original","height":1500,"width":1000,"url":"http://hwcdn.themoviedb.org/posters/21c/4bc90bc1017a3c57fe00421c/the-last-emperor-original.jpg","id":"4bc90bc1017a3c57fe00421c"}},{"image":{"type":"poster","size":"mid","height":750,"width":500,"url":"http://hwcdn.themoviedb.org/posters/21c/4bc90bc1017a3c57fe00421c/the-last-emperor-mid.jpg","id":"4bc90bc1017a3c57fe00421c"}},{"image":{"type":"poster","size":"cover","height":278,"width":185,"url":"http://hwcdn.themoviedb.org/posters/21c/4bc90bc1017a3c57fe00421c/the-last-emperor-cover.jpg","id":"4bc90bc1017a3c57fe00421c"}},{"image":{"type":"poster","size":"thumb","height":138,"width":92,"url":"http://hwcdn.themoviedb.org/posters/21c/4bc90bc1017a3c57fe00421c/the-last-emperor-thumb.jpg","id":"4bc90bc1017a3c57fe00421c"}}],"backdrops":[{"image":{"type":"backdrop","size":"original","height":720,"width":1280,"url":"http://hwcdn.themoviedb.org/backdrops/213/4bc90bc0017a3c57fe004213/the-last-emperor-original.jpg","id":"4bc90bc0017a3c57fe004213"}},{"image":{"type":"backdrop","size":"poster","height":439,"width":780,"url":"http://hwcdn.themoviedb.org/backdrops/213/4bc90bc0017a3c57fe004213/the-last-emperor-poster.jpg","id":"4bc90bc0017a3c57fe004213"}},{"image":{"type":"backdrop","size":"thumb","height":169,"width":300,"url":"http://hwcdn.themoviedb.org/backdrops/213/4bc90bc0017a3c57fe004213/the-last-emperor-thumb.jpg","id":"4bc90bc0017a3c57fe004213"}}],"version":37,"last_modified_at":"2010-10-27 02:02:52"},{"score":null,"popularity":3,"translated":true,"adult":false,"language":"en","original_name":"Das Verlangen","name":"Das Verlangen","alternative_name":null,"movie_type":"movie","id":6179,"imdb_id":"tt0328727","url":"http://www.themoviedb.org/movie/6179","votes":5,"rating":9.2,"certification":"","overview":"No overview found.","released":"2002-08-08","posters":[],"backdrops":[],"version":19,"last_modified_at":"2010-08-18 22:50:41"},{"score":null,"popularity":3,"translated":true,"adult":false,"language":"en","original_name":"Elephant","name":"Elephant","alternative_name":null,"movie_type":"movie","id":1807,"imdb_id":"tt0363589","url":"http://www.themoviedb.org/movie/1807","votes":5,"rating":9.2,"certification":"","overview":"Elephant is a Gus Van Sant film depicting the story of a high school just before and after a massive shooting. The film is shot in a way that makes the viewer seem like they are there, in the high school, slowly walking around witnessing ever characters story unfold. The film won the Palme d\u2019Or and Best Director at the 2003 Cannes Film Festival.","released":"2003-05-18","posters":[{"image":{"type":"poster","size":"original","height":1500,"width":1000,"url":"http://hwcdn.themoviedb.org/posters/015/4c1f544a7b9aa13123000015/elephant-original.jpg","id":"4c1f544a7b9aa13123000015"}},{"image":{"type":"poster","size":"mid","height":750,"width":500,"url":"http://hwcdn.themoviedb.org/posters/015/4c1f544a7b9aa13123000015/elephant-mid.jpg","id":"4c1f544a7b9aa13123000015"}},{"image":{"type":"poster","size":"cover","height":278,"width":185,"url":"http://hwcdn.themoviedb.org/posters/015/4c1f544a7b9aa13123000015/elephant-cover.jpg","id":"4c1f544a7b9aa13123000015"}},{"image":{"type":"poster","size":"thumb","height":138,"width":92,"url":"http://hwcdn.themoviedb.org/posters/015/4c1f544a7b9aa13123000015/elephant-thumb.jpg","id":"4c1f544a7b9aa13123000015"}}],"backdrops":[{"image":{"type":"backdrop","size":"original","height":720,"width":1280,"url":"http://hwcdn.themoviedb.org/backdrops/0e0/4bc912ef017a3c57fe0070e0/elephant-original.jpg","id":"4bc912ef017a3c57fe0070e0"}},{"image":{"type":"backdrop","size":"poster","height":439,"width":780,"url":"http://hwcdn.themoviedb.org/backdrops/0e0/4bc912ef017a3c57fe0070e0/elephant-poster.jpg","id":"4bc912ef017a3c57fe0070e0"}},{"image":{"type":"backdrop","size":"thumb","height":169,"width":300,"url":"http://hwcdn.themoviedb.org/backdrops/0e0/4bc912ef017a3c57fe0070e0/elephant-thumb.jpg","id":"4bc912ef017a3c57fe0070e0"}}],"version":29,"last_modified_at":"2010-08-18 22:51:06"},{"score":null,"popularity":3,"translated":true,"adult":false,"language":"en","original_name":"Infernal Affairs","name":"Infernal Affairs","alternative_name":"Wu Jian Dao","movie_type":"movie","id":10775,"imdb_id":"tt0338564","url":"http://www.themoviedb.org/movie/10775","votes":5,"rating":9.2,"certification":"","overview":"Chan Wing Yan, a young police officer, has been sent undercover as a mole in the local mafia. Lau Kin Ming, a young mafia member, infiltrates the police force. Years later, their older counterparts, Chen Wing Yan and Inspector Lau Kin Ming, respectively, race against time to expose the mole within their midst. ","released":"2002-12-12","posters":[{"image":{"type":"poster","size":"original","height":1290,"width":900,"url":"http://hwcdn.themoviedb.org/posters/31c/4bf4736a017a3c6d9200031c/10775-original.jpg","id":"4bf4736a017a3c6d9200031c"}},{"image":{"type":"poster","size":"mid","height":717,"width":500,"url":"http://hwcdn.themoviedb.org/posters/31c/4bf4736a017a3c6d9200031c/10775-mid.jpg","id":"4bf4736a017a3c6d9200031c"}},{"image":{"type":"poster","size":"cover","height":265,"width":185,"url":"http://hwcdn.themoviedb.org/posters/31c/4bf4736a017a3c6d9200031c/10775-cover.jpg","id":"4bf4736a017a3c6d9200031c"}},{"image":{"type":"poster","size":"thumb","height":132,"width":92,"url":"http://hwcdn.themoviedb.org/posters/31c/4bf4736a017a3c6d9200031c/10775-thumb.jpg","id":"4bf4736a017a3c6d9200031c"}}],"backdrops":[{"image":{"type":"backdrop","size":"original","height":720,"width":1280,"url":"http://hwcdn.themoviedb.org/backdrops/438/4cc966d75e73d65024000438/infernal-affairs-original.jpg","id":"4cc966d75e73d65024000438"}},{"image":{"type":"backdrop","size":"poster","height":439,"width":780,"url":"http://hwcdn.themoviedb.org/backdrops/438/4cc966d75e73d65024000438/infernal-affairs-poster.jpg","id":"4cc966d75e73d65024000438"}},{"image":{"type":"backdrop","size":"thumb","height":169,"width":300,"url":"http://hwcdn.themoviedb.org/backdrops/438/4cc966d75e73d65024000438/infernal-affairs-thumb.jpg","id":"4cc966d75e73d65024000438"}}],"version":38,"last_modified_at":"2010-10-29 14:17:00"},{"score":null,"popularity":3,"translated":true,"adult":false,"language":"en","original_name":"Bride of Frankenstein","name":"Bride of Frankenstein","alternative_name":"Frankensteins R\u00fcckkehr","movie_type":"movie","id":229,"imdb_id":"tt0026138","url":"http://www.themoviedb.org/movie/229","votes":6,"rating":9.2,"certification":"PG","overview":"Bride of Frankenstein begins where James Whale's Frankenstein from 1931 ended. Dr. Frankenstein has not been killed as previously portrayed and now he wants to get away from the mad experiments. Yet when his wife is kidnapped by his creation, Frankenstein agrees to help him create a new monster, this time a woman.","released":"1935-04-22","posters":[{"image":{"type":"poster","size":"original","height":1785,"width":1200,"url":"http://hwcdn.themoviedb.org/posters/9be/4bc9056b017a3c57fe0019be/bride-of-frankenstein-original.jpg","id":"4bc9056b017a3c57fe0019be"}},{"image":{"type":"poster","size":"mid","height":744,"width":500,"url":"http://hwcdn.themoviedb.org/posters/9be/4bc9056b017a3c57fe0019be/bride-of-frankenstein-mid.jpg","id":"4bc9056b017a3c57fe0019be"}},{"image":{"type":"poster","size":"cover","height":275,"width":185,"url":"http://hwcdn.themoviedb.org/posters/9be/4bc9056b017a3c57fe0019be/bride-of-frankenstein-cover.jpg","id":"4bc9056b017a3c57fe0019be"}},{"image":{"type":"poster","size":"thumb","height":137,"width":92,"url":"http://hwcdn.themoviedb.org/posters/9be/4bc9056b017a3c57fe0019be/bride-of-frankenstein-thumb.jpg","id":"4bc9056b017a3c57fe0019be"}}],"backdrops":[{"image":{"type":"backdrop","size":"original","height":1080,"width":1920,"url":"http://hwcdn.themoviedb.org/backdrops/9ba/4bc9056a017a3c57fe0019ba/bride-of-frankenstein-original.jpg","id":"4bc9056a017a3c57fe0019ba"}},{"image":{"type":"backdrop","size":"poster","height":439,"width":780,"url":"http://hwcdn.themoviedb.org/backdrops/9ba/4bc9056a017a3c57fe0019ba/bride-of-frankenstein-poster.jpg","id":"4bc9056a017a3c57fe0019ba"}},{"image":{"type":"backdrop","size":"thumb","height":169,"width":300,"url":"http://hwcdn.themoviedb.org/backdrops/9ba/4bc9056a017a3c57fe0019ba/bride-of-frankenstein-thumb.jpg","id":"4bc9056a017a3c57fe0019ba"}}],"version":45,"last_modified_at":"2010-11-06 00:31:08"},{"score":null,"popularity":3,"translated":true,"adult":false,"language":"en","original_name":"Mean Streets","name":"Mean Streets","alternative_name":null,"movie_type":"movie","id":203,"imdb_id":"tt0070379","url":"http://www.themoviedb.org/movie/203","votes":6,"rating":9.0,"certification":"","overview":"Mean Streets is the pioneering artistic film from director Martin Scorseses. With it\u2019s experimental ease this gangster film documented the rules and rights structure and laws of the Italian-American small time criminal ambiance from 1960\u2019s New York.","released":"1973-10-02","posters":[{"image":{"type":"poster","size":"original","height":2793,"width":1920,"url":"http://hwcdn.themoviedb.org/posters/5bf/4be1a272017a3c35bf0005bf/mean-streets-original.jpg","id":"4be1a272017a3c35bf0005bf"}},{"image":{"type":"poster","size":"mid","height":727,"width":500,"url":"http://hwcdn.themoviedb.org/posters/5bf/4be1a272017a3c35bf0005bf/mean-streets-mid.jpg","id":"4be1a272017a3c35bf0005bf"}},{"image":{"type":"poster","size":"cover","height":269,"width":185,"url":"http://hwcdn.themoviedb.org/posters/5bf/4be1a272017a3c35bf0005bf/mean-streets-cover.jpg","id":"4be1a272017a3c35bf0005bf"}},{"image":{"type":"poster","size":"thumb","height":134,"width":92,"url":"http://hwcdn.themoviedb.org/posters/5bf/4be1a272017a3c35bf0005bf/mean-streets-thumb.jpg","id":"4be1a272017a3c35bf0005bf"}}],"backdrops":[{"image":{"type":"backdrop","size":"original","height":1080,"width":1920,"url":"http://hwcdn.themoviedb.org/backdrops/7e6/4bc90525017a3c57fe0017e6/mean-streets-original.jpg","id":"4bc90525017a3c57fe0017e6"}},{"image":{"type":"backdrop","size":"poster","height":439,"width":780,"url":"http://hwcdn.themoviedb.org/backdrops/7e6/4bc90525017a3c57fe0017e6/mean-streets-poster.jpg","id":"4bc90525017a3c57fe0017e6"}},{"image":{"type":"backdrop","size":"thumb","height":169,"width":300,"url":"http://hwcdn.themoviedb.org/backdrops/7e6/4bc90525017a3c57fe0017e6/mean-streets-thumb.jpg","id":"4bc90525017a3c57fe0017e6"}}],"version":32,"last_modified_at":"2010-11-07 10:17:19"},{"score":null,"popularity":3,"translated":true,"adult":false,"language":"en","original_name":"Gegen\u00fcber","name":"Gegen\u00fcber","alternative_name":null,"movie_type":"movie","id":4213,"imdb_id":"tt1031932","url":"http://www.themoviedb.org/movie/4213","votes":5,"rating":9.0,"certification":"","overview":"No overview found.","released":"2007-05-20","posters":[],"backdrops":[],"version":21,"last_modified_at":"2010-08-18 22:49:49"}]
|
data/test/setup/url_mocks.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
def register_api_url_stubs
|
2
2
|
unless(TEST_LIVE_API)
|
3
|
-
|
4
3
|
|
5
4
|
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_search.txt")) do |file|
|
6
5
|
stub_request(:get, Regexp.new(Tmdb.base_api_url + "Movie.search/" + ".*")).to_return(file)
|
@@ -14,6 +13,10 @@ def register_api_url_stubs
|
|
14
13
|
stub_request(:get, Regexp.new(Tmdb.base_api_url + "Movie.imdbLookup/" + ".*")).to_return(file)
|
15
14
|
end
|
16
15
|
|
16
|
+
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_browse.txt")) do |file|
|
17
|
+
stub_request(:get, Regexp.new(Tmdb.base_api_url + "Movie.browse/" + ".*")).to_return(file)
|
18
|
+
end
|
19
|
+
|
17
20
|
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "person_get_info.txt")) do |file|
|
18
21
|
stub_request(:get, Regexp.new(Tmdb.base_api_url + "Person.getInfo/" + ".*")).to_return(file)
|
19
22
|
end
|
data/test/test_helper.rb
CHANGED
data/test/unit/tmdb_cast_test.rb
CHANGED
@@ -84,6 +84,25 @@ class TmdbCastTest < Test::Unit::TestCase
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
test "should not pass language to Tmdb.api_call if language is not supplied" do
|
88
|
+
Tmdb.expects(:api_call).with("Person.getInfo", 1, nil).returns([])
|
89
|
+
Tmdb.expects(:api_call).with("Person.search", 1, nil).returns([])
|
90
|
+
TmdbCast.find(:id => 1, :name => 1)
|
91
|
+
end
|
92
|
+
|
93
|
+
test "should pass through language to Tmdb.api_call when language is supplied" do
|
94
|
+
Tmdb.expects(:api_call).with("Person.getInfo", 1, "foo").returns([])
|
95
|
+
Tmdb.expects(:api_call).with("Person.search", 1, "foo").returns([])
|
96
|
+
TmdbCast.find(:id => 1, :name => 1, :language => "foo")
|
97
|
+
end
|
98
|
+
|
99
|
+
test "TmdbCast.new should raise error if supplied with raw data for cast member that doesn't exist" do
|
100
|
+
Tmdb.expects(:api_call).with('Person.getInfo', "1").returns(nil)
|
101
|
+
assert_raise ArgumentError do
|
102
|
+
TmdbCast.new({"id" => "1"}, true)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
87
106
|
private
|
88
107
|
|
89
108
|
def assert_cast_methodized(actor, cast_id)
|
@@ -91,6 +91,46 @@ class TmdbMovieTest < Test::Unit::TestCase
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
|
+
|
95
|
+
test "find should not pass language to Tmdb.api_call if language is not supplied" do
|
96
|
+
Tmdb.expects(:api_call).with("Movie.getInfo", 1, nil).returns([])
|
97
|
+
Tmdb.expects(:api_call).with("Movie.imdbLookup", 1, nil).returns([])
|
98
|
+
Tmdb.expects(:api_call).with("Movie.search", 1, nil).returns([])
|
99
|
+
TmdbMovie.find(:id => 1, :imdb => 1, :title => 1)
|
100
|
+
end
|
101
|
+
|
102
|
+
test "find should pass through language to Tmdb.api_call when language is supplied" do
|
103
|
+
Tmdb.expects(:api_call).with("Movie.getInfo", 1, "foo").returns([])
|
104
|
+
Tmdb.expects(:api_call).with("Movie.imdbLookup", 1, "foo").returns([])
|
105
|
+
Tmdb.expects(:api_call).with("Movie.search", 1, "foo").returns([])
|
106
|
+
TmdbMovie.find(:id => 1, :imdb => 1, :title => 1, :language => "foo")
|
107
|
+
end
|
108
|
+
|
109
|
+
test "TmdbMovie.new should raise error if supplied with raw data for movie that doesn't exist" do
|
110
|
+
Tmdb.expects(:api_call).with('Movie.getInfo', "1").returns(nil)
|
111
|
+
assert_raise ArgumentError do
|
112
|
+
TmdbMovie.new({"id" => "1"}, true)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
test "browse should return results" do
|
117
|
+
movies = TmdbMovie.browse(:order_by => "rating", :order => "desc", :genres => 18, :min_votes => 5, :page => 1, :per_page => 10)
|
118
|
+
assert_kind_of Array, movies
|
119
|
+
assert_equal 10, movies.length
|
120
|
+
movies.each do |movie|
|
121
|
+
assert_kind_of OpenStruct, movie
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
test "browse should not pass language to Tmdb.api_call if language is not supplied" do
|
126
|
+
Tmdb.expects(:api_call).with("Movie.browse", {:option => 1}, nil).returns([])
|
127
|
+
TmdbMovie.browse(:option => 1)
|
128
|
+
end
|
129
|
+
|
130
|
+
test "browse should pass through language to Tmdb.api_call when language is supplied" do
|
131
|
+
Tmdb.expects(:api_call).with("Movie.browse", {:option => 1}, "foo").returns([])
|
132
|
+
TmdbMovie.browse(:option => 1, :language => "foo")
|
133
|
+
end
|
94
134
|
|
95
135
|
private
|
96
136
|
|
data/test/unit/tmdb_test.rb
CHANGED
@@ -6,7 +6,7 @@ class TmdbTest < Test::Unit::TestCase
|
|
6
6
|
register_api_url_stubs
|
7
7
|
end
|
8
8
|
|
9
|
-
test "
|
9
|
+
test "should allow setting and getting of api_key" do
|
10
10
|
old_api_key = Tmdb.api_key
|
11
11
|
api_key = "test1234567890"
|
12
12
|
Tmdb.api_key = api_key
|
@@ -14,6 +14,18 @@ class TmdbTest < Test::Unit::TestCase
|
|
14
14
|
Tmdb.api_key = old_api_key
|
15
15
|
end
|
16
16
|
|
17
|
+
test "language should default to 'en'" do
|
18
|
+
assert_equal "en", Tmdb.default_language
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should allow setting and getting of language" do
|
22
|
+
old_language = Tmdb.default_language
|
23
|
+
new_language = "blah"
|
24
|
+
Tmdb.default_language = new_language
|
25
|
+
assert_equal new_language, Tmdb.default_language
|
26
|
+
Tmdb.default_language = old_language
|
27
|
+
end
|
28
|
+
|
17
29
|
test "should return base API url" do
|
18
30
|
assert_equal "http://api.themoviedb.org/2.1/", Tmdb.base_api_url
|
19
31
|
end
|
@@ -28,6 +40,27 @@ class TmdbTest < Test::Unit::TestCase
|
|
28
40
|
assert_equal 404, test_response.code.to_i
|
29
41
|
end
|
30
42
|
|
43
|
+
test "API call without explicit language setting should use default language" do
|
44
|
+
method = "Movie.getInfo"
|
45
|
+
data = "hello"
|
46
|
+
Tmdb.default_language = "es"
|
47
|
+
url = Tmdb.base_api_url + method + '/' + Tmdb.default_language + '/json/' + Tmdb.api_key + '/' + CGI::escape(data.to_s)
|
48
|
+
mock_response = stub(:code => "200", :body => '[""]')
|
49
|
+
Tmdb.expects(:get_url).with(url).returns(mock_response)
|
50
|
+
Tmdb.api_call(method, data)
|
51
|
+
Tmdb.default_language = "en"
|
52
|
+
end
|
53
|
+
|
54
|
+
test "API call with explicit language setting should override default language" do
|
55
|
+
method = "Movie.getInfo"
|
56
|
+
data = "hello"
|
57
|
+
language = "blah"
|
58
|
+
url = Tmdb.base_api_url + method + '/' + language + '/json/' + Tmdb.api_key + '/' + CGI::escape(data.to_s)
|
59
|
+
mock_response = stub(:code => "200", :body => '[""]')
|
60
|
+
Tmdb.expects(:get_url).with(url).returns(mock_response)
|
61
|
+
Tmdb.api_call(method, data, language)
|
62
|
+
end
|
63
|
+
|
31
64
|
test "api_call should raise exception if api_key is not set" do
|
32
65
|
old_api_key = Tmdb.api_key
|
33
66
|
Tmdb.api_key = ""
|
@@ -97,15 +130,14 @@ class TmdbTest < Test::Unit::TestCase
|
|
97
130
|
end
|
98
131
|
end
|
99
132
|
|
100
|
-
test "
|
101
|
-
|
102
|
-
|
103
|
-
|
133
|
+
test "API call that returns 404 should raise exception" do
|
134
|
+
assert_raise RuntimeError do
|
135
|
+
movies = Tmdb.api_call('Movie.blarg', 'Transformers')
|
136
|
+
end
|
104
137
|
end
|
105
138
|
|
106
139
|
test "API call that finds no results should return nil" do
|
107
140
|
movies = Tmdb.api_call('Search.empty', 'Transformers')
|
108
|
-
assert_kind_of NilClass, movies
|
109
141
|
assert_nil movies
|
110
142
|
end
|
111
143
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 2
|
7
8
|
- 1
|
8
|
-
|
9
|
-
version: 0.1.4
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Aaron Gough
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-04-13 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
49
|
+
name: addressable
|
50
50
|
prerelease: false
|
51
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
@@ -56,8 +56,21 @@ dependencies:
|
|
56
56
|
segments:
|
57
57
|
- 0
|
58
58
|
version: "0"
|
59
|
-
type: :
|
59
|
+
type: :runtime
|
60
60
|
version_requirements: *id003
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: webmock
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
type: :development
|
73
|
+
version_requirements: *id004
|
61
74
|
description: An ActiveRecord-style API wrapper for TheMovieDB.org
|
62
75
|
email: aaron@aarongough.com
|
63
76
|
executables: []
|
@@ -82,6 +95,7 @@ files:
|
|
82
95
|
- test/fixtures/example_com.txt
|
83
96
|
- test/fixtures/image.jpg
|
84
97
|
- test/fixtures/incorrect_api_url.txt
|
98
|
+
- test/fixtures/movie_browse.txt
|
85
99
|
- test/fixtures/movie_get_info.txt
|
86
100
|
- test/fixtures/movie_imdb_lookup.txt
|
87
101
|
- test/fixtures/movie_search.txt
|