ruby-tmdb3 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +3 -2
- data/VERSION +1 -1
- data/lib/ruby-tmdb3/tmdb.rb +30 -23
- data/lib/ruby-tmdb3/tmdb_movie.rb +15 -7
- data/ruby-tmdb3.gemspec +6 -3
- data/test/fixtures/movie_casts.txt +15 -0
- data/test/fixtures/movie_get_info.txt +1 -1
- data/test/fixtures/movie_imdb_lookup.txt +1 -1
- data/test/fixtures/movie_posters.txt +15 -0
- data/test/fixtures/movie_releases.txt +15 -0
- data/test/setup/setup_api_key.rb +2 -2
- data/test/setup/url_mocks.rb +19 -7
- data/test/unit/tmdb_movie_test.rb +7 -4
- data/test/unit/tmdb_test.rb +13 -7
- metadata +5 -2
data/README.rdoc
CHANGED
@@ -98,8 +98,9 @@ To find out more about the information each object offers on retrieved items hav
|
|
98
98
|
|
99
99
|
=== Author & Credits
|
100
100
|
|
101
|
-
|
102
|
-
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]
|
101
|
+
Authors:: {Irio Irineu Musskopf Junior}[mailto:iirineu@gmail.com], {Aaron Gough}[mailto:aaron@aarongough.com]
|
102
|
+
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], {Loïc Guitaut}[https://github.com/Flink]
|
103
103
|
|
104
104
|
Copyright (c) 2012 {Irio Irineu Musskopf Junior}[http://irio.posterous.com/] ({irio.posterous.com}[http://irio.posterous.com/])
|
105
|
+
|
105
106
|
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.
|
1
|
+
0.3.1
|
data/lib/ruby-tmdb3/tmdb.rb
CHANGED
@@ -10,6 +10,17 @@ class Tmdb
|
|
10
10
|
@@api_key = ""
|
11
11
|
@@default_language = "en"
|
12
12
|
@@api_response = {}
|
13
|
+
|
14
|
+
# TODO: Should be refreshed and cached from API
|
15
|
+
CONFIGURATION = DeepOpenStruct.load({ "images" =>
|
16
|
+
{
|
17
|
+
"base_url" => "http://cf2.imgobject.com/t/p/",
|
18
|
+
"posters_sizes" => ["w92", "w154", "w185", "w342", "w500", "original"],
|
19
|
+
"backdrops_sizes" => ["w300", "w780", "w1280", "original"],
|
20
|
+
"profiles_sizes" => ["w45", "w185", "h632", "original"],
|
21
|
+
"logos_sizes" => ["w45", "w92", "w154", "w185", "w300", "w500", "original"]
|
22
|
+
}
|
23
|
+
})
|
13
24
|
|
14
25
|
def self.api_key
|
15
26
|
@@api_key
|
@@ -28,13 +39,15 @@ class Tmdb
|
|
28
39
|
end
|
29
40
|
|
30
41
|
def self.base_api_url
|
31
|
-
"http://api.themoviedb.org/3
|
42
|
+
"http://api.themoviedb.org/3"
|
32
43
|
end
|
33
44
|
|
34
45
|
def self.api_call(method, data, language = @@default_language)
|
35
46
|
raise ArgumentError, "Tmdb.api_key must be set before using the API" if(Tmdb.api_key.nil? || Tmdb.api_key.empty?)
|
36
47
|
raise ArgumentError, "Invalid data." if(data.nil? || (data.class != Hash))
|
37
48
|
|
49
|
+
method, action = method.split '/'
|
50
|
+
|
38
51
|
data = {
|
39
52
|
api_key: Tmdb.api_key,
|
40
53
|
language: language
|
@@ -55,21 +68,17 @@ class Tmdb
|
|
55
68
|
# Construct URL for queries with id
|
56
69
|
if data.has_key?(:id)
|
57
70
|
uri.query_values = query_values
|
58
|
-
|
59
|
-
url = Tmdb.base_api_url + method + "/" + data[:id].to_s + "?" + uri.query
|
60
|
-
|
61
71
|
# Construct URL other queries
|
62
72
|
else
|
63
73
|
query_values = {
|
64
74
|
query: CGI::escape(data[:query])
|
65
75
|
}.merge(query_values)
|
66
|
-
|
67
76
|
uri.query_values = query_values
|
68
|
-
|
69
|
-
url = Tmdb.base_api_url + method + "?" + uri.query
|
70
77
|
end
|
78
|
+
url = [Tmdb.base_api_url, method, data[:id], action].compact.join '/'
|
79
|
+
url_with_query = [url, uri.query].compact.join '?'
|
71
80
|
|
72
|
-
response = Tmdb.get_url(
|
81
|
+
response = Tmdb.get_url(url_with_query)
|
73
82
|
if(response.code.to_i != 200)
|
74
83
|
raise RuntimeError, "Tmdb API returned status code '#{response.code}' for URL: '#{url}'"
|
75
84
|
end
|
@@ -100,22 +109,20 @@ class Tmdb
|
|
100
109
|
end
|
101
110
|
|
102
111
|
def self.data_to_object(data)
|
103
|
-
object
|
112
|
+
object = DeepOpenStruct.load(data)
|
104
113
|
object.raw_data = data
|
105
|
-
["posters", "backdrops"
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
114
|
+
["posters", "backdrops"].each do |image_array_name|
|
115
|
+
image_array = Array object.send(image_array_name)
|
116
|
+
single_name = image_array_name.slice 0..-2 # singularize name
|
117
|
+
single_path = object.send "#{single_name}_path" # default poster/backdrop image
|
118
|
+
image_array << object.send("#{image_array_name.slice 0..-2}=", DeepOpenStruct.load({file_path: single_path}))
|
119
|
+
# build a struct containing availables sizes with their urls
|
120
|
+
image_array.each do |image|
|
121
|
+
urls = CONFIGURATION.images.send("#{image_array_name}_sizes").inject({}) do |hash, size|
|
122
|
+
hash[size] = {'url' => [CONFIGURATION.images.base_url, size, image.file_path].join}
|
123
|
+
hash
|
115
124
|
end
|
116
|
-
|
117
|
-
if(object.profile)
|
118
|
-
object.profiles = object.profile
|
125
|
+
image.sizes = DeepOpenStruct.load urls
|
119
126
|
end
|
120
127
|
end
|
121
128
|
unless(object.cast.nil?)
|
@@ -130,4 +137,4 @@ class Tmdb
|
|
130
137
|
return object
|
131
138
|
end
|
132
139
|
|
133
|
-
end
|
140
|
+
end
|
@@ -40,14 +40,22 @@ class TmdbMovie
|
|
40
40
|
|
41
41
|
def self.new(raw_data, expand_results = false, language = nil)
|
42
42
|
# expand the result by calling movie unless :expand_results is false or the data is already complete
|
43
|
-
# (as determined by checking for the
|
44
|
-
if(expand_results && !raw_data.has_key?("
|
43
|
+
# (as determined by checking for the posters property in the raw data)
|
44
|
+
if(expand_results && (!raw_data.has_key?("posters") || !raw_data['releases'] || !raw_data['cast']))
|
45
45
|
begin
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
movie_id = raw_data['id']
|
47
|
+
raw_data = Tmdb.api_call 'movie', { id: movie_id }, language
|
48
|
+
@images_data = Tmdb.api_call("movie/images", {id: movie_id}, language)
|
49
|
+
@releases_data = Tmdb.api_call('movie/releases', {id: movie_id}, language)
|
50
|
+
@cast_data = Tmdb.api_call('movie/casts', {id: movie_id}, language)
|
51
|
+
raw_data['posters'] = @images_data['posters']
|
52
|
+
raw_data['backdrops'] = @images_data['backdrops']
|
53
|
+
raw_data['releases'] = @releases_data['countries']
|
54
|
+
raw_data['cast'] = @cast_data['cast']
|
55
|
+
raw_data['crew'] = @cast_data['crew']
|
56
|
+
rescue => e
|
57
|
+
raise ArgumentError, "Unable to fetch expanded infos for Movie ID: '#{movie_id}'" if @images_data.nil? || @releases_data.nil? || @cast_data.nil?
|
49
58
|
end
|
50
|
-
raw_data = expanded_data
|
51
59
|
end
|
52
60
|
return Tmdb.data_to_object(raw_data)
|
53
61
|
end
|
@@ -57,4 +65,4 @@ class TmdbMovie
|
|
57
65
|
return @raw_data == other.raw_data
|
58
66
|
end
|
59
67
|
|
60
|
-
end
|
68
|
+
end
|
data/ruby-tmdb3.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "ruby-tmdb3"
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Irio Irineu Musskopf Junior", "Aaron Gough"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-07-11"
|
13
13
|
s.description = "An ActiveRecord-style API wrapper for TheMovieDB.org"
|
14
14
|
s.email = "iirineu@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,8 +30,11 @@ Gem::Specification.new do |s|
|
|
30
30
|
"test/fixtures/example_com.txt",
|
31
31
|
"test/fixtures/image.jpg",
|
32
32
|
"test/fixtures/incorrect_api_url.txt",
|
33
|
+
"test/fixtures/movie_casts.txt",
|
33
34
|
"test/fixtures/movie_get_info.txt",
|
34
35
|
"test/fixtures/movie_imdb_lookup.txt",
|
36
|
+
"test/fixtures/movie_posters.txt",
|
37
|
+
"test/fixtures/movie_releases.txt",
|
35
38
|
"test/fixtures/movie_search.txt",
|
36
39
|
"test/fixtures/person_get_info.txt",
|
37
40
|
"test/fixtures/person_search.txt",
|
@@ -47,7 +50,7 @@ Gem::Specification.new do |s|
|
|
47
50
|
s.homepage = "https://github.com/Irio/ruby-tmdb"
|
48
51
|
s.rdoc_options = ["--line-numbers", "--inline-source"]
|
49
52
|
s.require_paths = ["lib"]
|
50
|
-
s.rubygems_version = "1.8.
|
53
|
+
s.rubygems_version = "1.8.24"
|
51
54
|
s.summary = "An ActiveRecord-style API wrapper for TheMovieDB.org"
|
52
55
|
|
53
56
|
if s.respond_to? :specification_version then
|
@@ -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":49517,"cast":[{"id":5472,"name":"Colin Firth","character":"Bill Haydon","order":0,"profile_path":"/gqcM1rKobitst1mZ999fRmXPjru.jpg"},{"id":2983,"name":"Mark Strong","character":"Jim Prideaux","order":1,"profile_path":"/vC1a35KBxx8f2rkMKyaik7bTOud.jpg"},{"id":2524,"name":"Tom Hardy","character":"Ricki Tarr","order":2,"profile_path":"/aYWIZ7ywOFzyK7B1HHCQj2nq8s4.jpg"},{"id":64,"name":"Gary Oldman","character":"George Smiley","order":3,"profile_path":"/kCWUeBkZ2sf8LObSpUFgRngawQb.jpg"},{"id":71580,"name":"Benedict Cumberbatch","character":"Peter Guillam","order":4,"profile_path":"/pFNkVEjlgls3e9r4PwKuN0VBLQN.jpg"},{"id":13014,"name":"Toby Jones","character":"Percy Alleline","order":5,"profile_path":"/8HDeyCbDzjeylqfDIIs8Bmv40vX.jpg"},{"id":93236,"name":"David Dencik","character":"Toby Esterhase","order":6,"profile_path":null},{"id":8785,"name":"Ciarán Hinds","character":"Roy Bland","order":7,"profile_path":"/8kOafsmtTjY5IxdDUAhFrHKALK5.jpg"},{"id":5049,"name":"John Hurt","character":"Control","order":8,"profile_path":"/zUQ7WL3xg9C532Aa8hftcJUnk9j.jpg"},{"id":42069,"name":"Zoltán Mucsi","character":"Magyar","order":9,"profile_path":"/z4S9Bg4f8gDvBtduEV3vdieHQey.jpg"},{"id":89645,"name":"Péter Kálloy Molnár","character":"Hungarian Waiter","order":10,"profile_path":null},{"id":933031,"name":"Ilona Kassai","character":"Woman in Window","order":11,"profile_path":null},{"id":82364,"name":"Imre Csuja","character":"KGB Agent","order":12,"profile_path":null},{"id":37759,"name":"Kathy Burke","character":"Connie Sachs","order":13,"profile_path":"/vqCHCywlp7HfoKBW6ZzCuQmnJx9.jpg"},{"id":1115,"name":"Stephen Graham","character":"Jerry Westerby","order":14,"profile_path":"/81VZiCA6w8nXG0UjqXCgSJare5N.jpg"},{"id":186275,"name":"Arthur Nightingale","character":"Bryant","order":15,"profile_path":null},{"id":16358,"name":"Simon McBurney","character":"Oliver Lacon","order":16,"profile_path":"/3SMFfBtmoDQncXBtICD61plB04W.jpg"},{"id":235837,"name":"Amanda Fairbank-Hynes","character":"Belinda","order":17,"profile_path":"/127xlkSaLK92NaYdStJQxWkqR1I.jpg"}],"crew":[{"id":74396,"name":"Tomas Alfredson","department":"Directing","job":"Director","profile_path":"/sRl6QzCtO7SlLspfFSvnv8u7ITi.jpg"},{"id":20422,"name":"John le Carré","department":"Writing","job":"Novel","profile_path":null},{"id":64814,"name":"Peter Straughan","department":"Writing","job":"Screenplay","profile_path":null},{"id":227094,"name":"Bridget O'Connor","department":"Writing","job":"Screenplay","profile_path":null}]}
|
@@ -12,4 +12,4 @@ Age: 1000
|
|
12
12
|
Via: 1.1 varnish
|
13
13
|
X-Cache: HIT
|
14
14
|
|
15
|
-
{"adult":false,"backdrop_path":"/
|
15
|
+
{"adult":false,"backdrop_path":"/hqLNDL7ugQzAbK79uvzjIkmfDN2.jpg","belongs_to_collection":{"id":86311,"name":"The Avengers Theatrical Movie Collection","poster_path":"/hiLkVTP34V24JtzOQ22r7Uu8eMc.jpg","backdrop_path":"/xCbb3hIID1AnEOBxPzsnBXG3n2h.jpg"},"budget":140000000,"genres":[{"id":28,"name":"Action"},{"id":12,"name":"Adventure"},{"id":878,"name":"Science Fiction"},{"id":53,"name":"Thriller"}],"homepage":"http://www.ironmanmovie.com/","id":1726,"imdb_id":"tt0371746","original_title":"Iron Man","overview":"After escaping from kidnappers using makeshift power armor, an ultrarich inventor and weapons maker turns his creation into a force for good by using it to fight crime. But his skills are stretched to the limit when he must face the evil Iron Monger.","popularity":68803.606,"poster_path":"/s2IG9qXfhJYxIttKyroYFBsHwzQ.jpg","production_companies":[{"name":"Marvel Studios","id":420}],"production_countries":[{"iso_3166_1":"US","name":"United States of America"}],"release_date":"2008-05-02","revenue":585174222,"runtime":126,"spoken_languages":[{"iso_639_1":"en","name":"English"}],"tagline":"Heroes aren't born. They're built.","title":"Iron Man","vote_average":8.4,"vote_count":103}
|
@@ -12,4 +12,4 @@ Age: 0
|
|
12
12
|
Via: 1.1 varnish
|
13
13
|
X-Cache: MISS
|
14
14
|
|
15
|
-
{"adult":false,"backdrop_path":"/
|
15
|
+
{"adult":false,"backdrop_path":"/hqLNDL7ugQzAbK79uvzjIkmfDN2.jpg","belongs_to_collection":{"id":86311,"name":"The Avengers Theatrical Movie Collection","poster_path":"/hiLkVTP34V24JtzOQ22r7Uu8eMc.jpg","backdrop_path":"/xCbb3hIID1AnEOBxPzsnBXG3n2h.jpg"},"budget":140000000,"genres":[{"id":28,"name":"Action"},{"id":12,"name":"Adventure"},{"id":878,"name":"Science Fiction"},{"id":53,"name":"Thriller"}],"homepage":"http://www.ironmanmovie.com/","id":1726,"imdb_id":"tt0371746","original_title":"Iron Man","overview":"After escaping from kidnappers using makeshift power armor, an ultrarich inventor and weapons maker turns his creation into a force for good by using it to fight crime. But his skills are stretched to the limit when he must face the evil Iron Monger.","popularity":68803.606,"poster_path":"/s2IG9qXfhJYxIttKyroYFBsHwzQ.jpg","production_companies":[{"name":"Marvel Studios","id":420}],"production_countries":[{"iso_3166_1":"US","name":"United States of America"}],"release_date":"2008-05-02","revenue":585174222,"runtime":126,"spoken_languages":[{"iso_639_1":"en","name":"English"}],"tagline":"Heroes aren't born. They're built.","title":"Iron Man","vote_average":8.4,"vote_count":103}
|
@@ -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":49517,"backdrops":[{"file_path":"/4rYvCgyPx8eOEMLSaeuDOPdyQvB.jpg","width":1280,"height":720,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":8.0,"vote_count":3},{"file_path":"/jFhMjUmxSEh9vKMgHiViEqQCmiM.jpg","width":1280,"height":720,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":7.5,"vote_count":1},{"file_path":"/lRrYvUwR2vwxR6Fs8PKWIOSVLkp.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":6.75,"vote_count":2},{"file_path":"/97ib91kLwDlyB31pbqPtVYLzr2N.jpg","width":1600,"height":900,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":6.625,"vote_count":4},{"file_path":"/5oS5Qx6yAkdQCzLMXl5BQSCFhBI.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":6.5,"vote_count":5},{"file_path":"/dk6vIA6sWY11YHqIZWVlnp3CUhK.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":6.1,"vote_count":5},{"file_path":"/9M7aadoZIM1Atz3tToDjxJ6EJGa.jpg","width":1280,"height":720,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":5.833333333333333,"vote_count":6},{"file_path":"/kP09gF5nPu3OTIrhrl2x0w2LUD8.jpg","width":1280,"height":720,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":5.5,"vote_count":1},{"file_path":"/eDidONF03foKowW6MxJz7LTrLd1.jpg","width":1280,"height":720,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":5.166666666666667,"vote_count":3},{"file_path":"/68Hkre0dyPaz1FYEHvYWV3HoVM1.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":4.5,"vote_count":2},{"file_path":"/cXrJJLDQLKS5wsMjG4wS00tJ3Dn.jpg","width":1280,"height":720,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":4.0,"vote_count":1},{"file_path":"/cbcOWRsiMcAXGMxOu6klv4B20mp.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":3.0,"vote_count":1},{"file_path":"/8enB6zxS4ZoOoQ52TveIgJNEnAa.jpg","width":1280,"height":720,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":2.5,"vote_count":1},{"file_path":"/i1Kl77Z2Gio4ZEVZOMLjxWhBHtI.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":2.0,"vote_count":1},{"file_path":"/me1lCjal7vHNN5J0OefN5wmaNpp.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":2.0,"vote_count":1},{"file_path":"/wCcvWWzFUSQw1dUshp53wd71eKk.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":2.0,"vote_count":1},{"file_path":"/7mrdovWse6N66LC1XqlvkLsE2sP.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":2.0,"vote_count":1},{"file_path":"/l7N9SraMyj7MtGacoGnuR0bTJNG.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":2.0,"vote_count":1},{"file_path":"/eEKCDuZAsnugIBsksNTsPjnvI4x.jpg","width":1280,"height":720,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":2.0,"vote_count":1},{"file_path":"/4smv3B2gorWogu5ahMJTAjG7QG1.jpg","width":1280,"height":720,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":1.0,"vote_count":1},{"file_path":"/okvKba6NLBW78K5UT0qtL0wwy4K.jpg","width":1280,"height":720,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":0.0,"vote_count":0},{"file_path":"/ugaaNPbKF2sQAqzIOhlnSpkNpRx.jpg","width":1280,"height":720,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":0.0,"vote_count":0},{"file_path":"/6y5YQMb38aTNdAi6Li9SWtXm2IG.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":0.0,"vote_count":0}],"posters":[{"file_path":"/2N3P730TYXEcNL0BO8WBuMc6yJz.jpg","width":1000,"height":1500,"iso_639_1":"en","aspect_ratio":0.67,"vote_average":7.5,"vote_count":8},{"file_path":"/xXkkNXJRGEHD0QjPjHgaTtuhbZV.jpg","width":4051,"height":6001,"iso_639_1":"en","aspect_ratio":0.68,"vote_average":7.35,"vote_count":20},{"file_path":"/ggu2lYqxSAObuK82wk1TmEyyWGr.jpg","width":1000,"height":1500,"iso_639_1":"en","aspect_ratio":0.67,"vote_average":6.809523809523809,"vote_count":21},{"file_path":"/u2HlQA0VFeeNBfHesLSPoWZodwe.jpg","width":1131,"height":1600,"iso_639_1":"en","aspect_ratio":0.71,"vote_average":6.690476190476191,"vote_count":21},{"file_path":"/imDQdA47IfWOL13BiRLyDu6Q2b1.jpg","width":800,"height":1200,"iso_639_1":"ru","aspect_ratio":0.67,"vote_average":5.25,"vote_count":4},{"file_path":"/3sjSl5uaNLeIa7fySK5Cz1fF5Fz.jpg","width":1400,"height":2240,"iso_639_1":"en","aspect_ratio":0.63,"vote_average":5.125,"vote_count":8},{"file_path":"/ypCnGGSgIS93aLx0GcL8DPUbTZX.jpg","width":740,"height":1046,"iso_639_1":"de","aspect_ratio":0.71,"vote_average":4.5,"vote_count":3},{"file_path":"/49ohCbedmB4S1IgpN09Fv08B5Bf.jpg","width":420,"height":600,"iso_639_1":"it","aspect_ratio":0.7,"vote_average":4.125,"vote_count":4},{"file_path":"/aADb4oVjxeTujuisL7S25Ge4J0z.jpg","width":1181,"height":1757,"iso_639_1":"pt","aspect_ratio":0.67,"vote_average":3.75,"vote_count":2},{"file_path":"/xSFqKRbhXWMOsbDMqljwntJekue.jpg","width":1012,"height":1500,"iso_639_1":"en","aspect_ratio":0.67,"vote_average":2.4,"vote_count":5},{"file_path":"/t2gAZJuTZGTbMP4ymXyVFVmhh7R.jpg","width":1012,"height":1500,"iso_639_1":"en","aspect_ratio":0.67,"vote_average":2.0,"vote_count":4},{"file_path":"/dVaaL1NwEgKXcmlMxIOab49iuya.jpg","width":1455,"height":2081,"iso_639_1":"hu","aspect_ratio":0.7,"vote_average":1.0,"vote_count":1},{"file_path":"/5rONpcG54LqtDFcLrRrfbeUilto.jpg","width":1013,"height":1500,"iso_639_1":"en","aspect_ratio":0.68,"vote_average":0.5,"vote_count":2},{"file_path":"/1fudfIPnLOFl7jJFsRYbOPisoV6.jpg","width":1500,"height":2000,"iso_639_1":"fr","aspect_ratio":0.75,"vote_average":0.0,"vote_count":0},{"file_path":"/ozKFQ9uCyxqGxeYfJfrwkPq93r9.jpg","width":800,"height":1200,"iso_639_1":"en","aspect_ratio":0.67,"vote_average":0.0,"vote_count":0},{"file_path":"/5msUg8U2S64eFBhaVfziLpnlc2i.jpg","width":423,"height":630,"iso_639_1":"da","aspect_ratio":0.67,"vote_average":0.0,"vote_count":0},{"file_path":"/tHvYtrRU9iORz96GYlxqk98FTSN.jpg","width":458,"height":660,"iso_639_1":"es","aspect_ratio":0.69,"vote_average":0.0,"vote_count":0},{"file_path":"/qwzs6DKqb00aD7GkNbyCEQQ1CES.jpg","width":600,"height":800,"iso_639_1":"fr","aspect_ratio":0.75,"vote_average":0.0,"vote_count":0}]}
|
@@ -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":49517,"countries":[{"iso_3166_1":"GB","certification":"15","release_date":"2011-09-16"},{"iso_3166_1":"US","certification":"R","release_date":"2011-12-09"},{"iso_3166_1":"IE","certification":"","release_date":"2011-09-16"},{"iso_3166_1":"AU","certification":"","release_date":"2011-10-27"},{"iso_3166_1":"DE","certification":"12","release_date":"2011-11-10"},{"iso_3166_1":"SE","certification":"","release_date":"2011-12-25"},{"iso_3166_1":"FR","certification":"","release_date":"2012-02-08"},{"iso_3166_1":"HU","certification":"16 éven aluliak számára nem ajánlott","release_date":"2012-01-26"},{"iso_3166_1":"CZ","certification":"","release_date":"2012-02-02"},{"iso_3166_1":"PT","certification":"M12","release_date":"2011-12-22"},{"iso_3166_1":"IT","certification":"","release_date":"2011-09-05"},{"iso_3166_1":"AT","certification":"","release_date":"2012-02-02"}]}
|
data/test/setup/setup_api_key.rb
CHANGED
@@ -2,9 +2,9 @@ begin
|
|
2
2
|
file_path = File.absolute_path('tmdb_api_key.txt', File.dirname(__FILE__))
|
3
3
|
|
4
4
|
File.open(file_path) do |file|
|
5
|
-
Tmdb.api_key = file.read
|
5
|
+
Tmdb.api_key = file.read.chomp
|
6
6
|
end
|
7
7
|
rescue Errno::ENOENT => e
|
8
8
|
$stderr.puts "You need place your api key in #{file_path}"
|
9
9
|
exit
|
10
|
-
end
|
10
|
+
end
|
data/test/setup/url_mocks.rb
CHANGED
@@ -2,27 +2,39 @@ 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
|
-
stub_request(:get, Regexp.new(Tmdb.base_api_url + "search/movie" + ".*")).to_return(file)
|
5
|
+
stub_request(:get, Regexp.new(Tmdb.base_api_url + "/search/movie" + ".*")).to_return(file)
|
6
6
|
end
|
7
7
|
|
8
8
|
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_get_info.txt")) do |file|
|
9
|
-
stub_request(:get, Regexp.new(Tmdb.base_api_url + "movie/" + ".*")).to_return(file)
|
9
|
+
stub_request(:get, Regexp.new(Tmdb.base_api_url + "/movie/" + ".*")).to_return(file)
|
10
|
+
end
|
11
|
+
|
12
|
+
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_posters.txt")) do |file|
|
13
|
+
stub_request(:get, Regexp.new(Tmdb.base_api_url + '/movie/\d+/images')).to_return(file)
|
14
|
+
end
|
15
|
+
|
16
|
+
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_releases.txt")) do |file|
|
17
|
+
stub_request(:get, Regexp.new(Tmdb.base_api_url + '/movie/\d+/releases')).to_return(file)
|
18
|
+
end
|
19
|
+
|
20
|
+
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_casts.txt")) do |file|
|
21
|
+
stub_request(:get, Regexp.new(Tmdb.base_api_url + '/movie/\d+/casts')).to_return(file)
|
10
22
|
end
|
11
23
|
|
12
24
|
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_imdb_lookup.txt")) do |file|
|
13
|
-
stub_request(:get, Regexp.new(Tmdb.base_api_url + "movie/tt" + ".*")).to_return(file)
|
25
|
+
stub_request(:get, Regexp.new(Tmdb.base_api_url + "/movie/tt" + ".*")).to_return(file)
|
14
26
|
end
|
15
27
|
|
16
28
|
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "person_get_info.txt")) do |file|
|
17
|
-
stub_request(:get, Regexp.new(Tmdb.base_api_url + "person/" + ".*")).to_return(file)
|
29
|
+
stub_request(:get, Regexp.new(Tmdb.base_api_url + "/person/" + ".*")).to_return(file)
|
18
30
|
end
|
19
31
|
|
20
32
|
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "person_search.txt")) do |file|
|
21
|
-
stub_request(:get, Regexp.new(Tmdb.base_api_url + "search/person" + ".*")).to_return(file)
|
33
|
+
stub_request(:get, Regexp.new(Tmdb.base_api_url + "/search/person" + ".*")).to_return(file)
|
22
34
|
end
|
23
35
|
|
24
36
|
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "incorrect_api_url.txt")) do |file|
|
25
|
-
stub_request(:get, Regexp.new(Tmdb.base_api_url + "Movie.blarg/" + ".*")).to_return(file)
|
37
|
+
stub_request(:get, Regexp.new(Tmdb.base_api_url + "/Movie.blarg/" + ".*")).to_return(file)
|
26
38
|
end
|
27
39
|
|
28
40
|
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "example_com.txt")) do |file|
|
@@ -43,4 +55,4 @@ def register_api_url_stubs
|
|
43
55
|
|
44
56
|
stub_request(:get, 'http://thisisaurlthatdoesntexist.co.nz').to_return(:body => "", :status => 404, :headers => {'content-length' => 0})
|
45
57
|
end
|
46
|
-
end
|
58
|
+
end
|
@@ -35,8 +35,8 @@ class TmdbMovieTest < Test::Unit::TestCase
|
|
35
35
|
end
|
36
36
|
|
37
37
|
test "find by title should return the full movie data when expand_results set to true" do
|
38
|
-
movie = TmdbMovie.find(:title => "
|
39
|
-
assert_movie_methodized(movie,
|
38
|
+
movie = TmdbMovie.find(:title => "Iron Man", :limit => 1, :expand_results => true)
|
39
|
+
assert_movie_methodized(movie, 1726)
|
40
40
|
end
|
41
41
|
|
42
42
|
test "should raise exception if no arguments supplied to find" do
|
@@ -105,7 +105,10 @@ class TmdbMovieTest < Test::Unit::TestCase
|
|
105
105
|
end
|
106
106
|
|
107
107
|
test "TmdbMovie.new should raise error if supplied with raw data for movie that doesn't exist" do
|
108
|
-
Tmdb.expects(:api_call).with("movie", {id:
|
108
|
+
Tmdb.expects(:api_call).with("movie", {id: 999999999999}, nil).returns(nil)
|
109
|
+
Tmdb.expects(:api_call).with("movie/images", {id: 999999999999}, nil).returns(nil)
|
110
|
+
Tmdb.expects(:api_call).with("movie/releases", {id: 999999999999}, nil).returns(nil)
|
111
|
+
Tmdb.expects(:api_call).with("movie/casts", {id: 999999999999}, nil).returns(nil)
|
109
112
|
assert_raise ArgumentError do
|
110
113
|
TmdbMovie.new({"id" => 999999999999}, true)
|
111
114
|
end
|
@@ -155,4 +158,4 @@ class TmdbMovieTest < Test::Unit::TestCase
|
|
155
158
|
end
|
156
159
|
end
|
157
160
|
|
158
|
-
end
|
161
|
+
end
|
data/test/unit/tmdb_test.rb
CHANGED
@@ -31,7 +31,7 @@ class TmdbTest < Test::Unit::TestCase
|
|
31
31
|
end
|
32
32
|
|
33
33
|
test "should return base API url" do
|
34
|
-
assert_equal "http://api.themoviedb.org/3
|
34
|
+
assert_equal "http://api.themoviedb.org/3", Tmdb.base_api_url
|
35
35
|
end
|
36
36
|
|
37
37
|
test "get url returns a response object" do
|
@@ -48,7 +48,7 @@ class TmdbTest < Test::Unit::TestCase
|
|
48
48
|
method = "search/movie"
|
49
49
|
data = "hello"
|
50
50
|
Tmdb.default_language = "es"
|
51
|
-
url = Tmdb.base_api_url + method + '?api_key=' + Tmdb.api_key + '&language=' + Tmdb.default_language + '&query=' + CGI::escape(data.to_s)
|
51
|
+
url = Tmdb.base_api_url + '/' + method + '?api_key=' + Tmdb.api_key + '&language=' + Tmdb.default_language + '&query=' + CGI::escape(data.to_s)
|
52
52
|
mock_response = stub(:code => "200", :body => '{"page":1,"results":[],"total_pages":0,"total_results":0}')
|
53
53
|
Tmdb.expects(:get_url).with(url).returns(mock_response)
|
54
54
|
Tmdb.api_call(method, {query: data})
|
@@ -58,7 +58,7 @@ class TmdbTest < Test::Unit::TestCase
|
|
58
58
|
method = "movie"
|
59
59
|
data = "hello"
|
60
60
|
language = "blah"
|
61
|
-
url = Tmdb.base_api_url + method + "?api_key=" + Tmdb.api_key + "&language=" + language + '&query=' + CGI::escape(data.to_s)
|
61
|
+
url = Tmdb.base_api_url + '/' + method + "?api_key=" + Tmdb.api_key + "&language=" + language + '&query=' + CGI::escape(data.to_s)
|
62
62
|
mock_response = stub(:code => "200", :body => '{"page":1,"results":[],"total_pages":0,"total_results":0}')
|
63
63
|
Tmdb.expects(:get_url).with(url).returns(mock_response)
|
64
64
|
Tmdb.api_call(method, {query: data}, language)
|
@@ -92,6 +92,14 @@ class TmdbTest < Test::Unit::TestCase
|
|
92
92
|
assert_not_nil result[item]
|
93
93
|
end
|
94
94
|
end
|
95
|
+
|
96
|
+
test "should perform movie API call with an action and return a single result" do
|
97
|
+
result = Tmdb.api_call("movie/images", {id: "187"})
|
98
|
+
assert_kind_of Hash, result
|
99
|
+
%w(posters id).each do |item|
|
100
|
+
assert_not_nil result[item]
|
101
|
+
end
|
102
|
+
end
|
95
103
|
|
96
104
|
test "should perform Movie.imdbLookup API call and return a single result" do
|
97
105
|
result = Tmdb.api_call("movie", {id: "tt0401792"})
|
@@ -165,9 +173,7 @@ class TmdbTest < Test::Unit::TestCase
|
|
165
173
|
test_data = {
|
166
174
|
"backdrops" => [
|
167
175
|
{
|
168
|
-
|
169
|
-
:test => 1
|
170
|
-
}
|
176
|
+
:test => 1
|
171
177
|
}
|
172
178
|
]
|
173
179
|
}
|
@@ -177,4 +183,4 @@ class TmdbTest < Test::Unit::TestCase
|
|
177
183
|
end
|
178
184
|
end
|
179
185
|
|
180
|
-
end
|
186
|
+
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.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-07-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: deepopenstruct
|
@@ -97,8 +97,11 @@ files:
|
|
97
97
|
- test/fixtures/example_com.txt
|
98
98
|
- test/fixtures/image.jpg
|
99
99
|
- test/fixtures/incorrect_api_url.txt
|
100
|
+
- test/fixtures/movie_casts.txt
|
100
101
|
- test/fixtures/movie_get_info.txt
|
101
102
|
- test/fixtures/movie_imdb_lookup.txt
|
103
|
+
- test/fixtures/movie_posters.txt
|
104
|
+
- test/fixtures/movie_releases.txt
|
102
105
|
- test/fixtures/movie_search.txt
|
103
106
|
- test/fixtures/person_get_info.txt
|
104
107
|
- test/fixtures/person_search.txt
|