ruby-tmdb 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,232 @@
1
+ HTTP/1.1 200 OK
2
+ Status: 200 OK
3
+ Content-Type: text/x-yaml; charset=utf-8
4
+ Transfer-Encoding: chunked
5
+ Date: Sun, 16 May 2010 17:55:18 GMT
6
+ X-Varnish: 4020117426
7
+ Age: 0
8
+ Via: 1.1 varnish
9
+ Connection: keep-alive
10
+ X-Cache: MISS
11
+
12
+ ---
13
+ - score: 25
14
+ popularity: 3
15
+ name: Vince Locke
16
+ id: 4484
17
+ biography: ""
18
+ url: http://www.themoviedb.org/person/4484
19
+ profile: []
20
+
21
+ - score: 24
22
+ popularity: 3
23
+ name: Vince Deadrick Jr.
24
+ id: 12879
25
+ biography: ""
26
+ url: http://www.themoviedb.org/person/12879
27
+ profile: []
28
+
29
+ - score: 23
30
+ popularity: 3
31
+ name: Vince Trankina
32
+ id: 91412
33
+ biography: ""
34
+ url: http://www.themoviedb.org/person/91412
35
+ profile: []
36
+
37
+ - score: 22
38
+ popularity: 3
39
+ name: Pruitt Taylor Vince
40
+ id: 3201
41
+ biography: ""
42
+ url: http://www.themoviedb.org/person/3201
43
+ profile: []
44
+
45
+ - score: 21
46
+ popularity: 3
47
+ name: Vince Edwards
48
+ id: 3337
49
+ biography: ""
50
+ url: http://www.themoviedb.org/person/3337
51
+ profile: []
52
+
53
+ - score: 20
54
+ popularity: 3
55
+ name: Vince Vaughn
56
+ id: 4937
57
+ biography: ""
58
+ url: http://www.themoviedb.org/person/4937
59
+ profile:
60
+ - image:
61
+ type: profile
62
+ size: original
63
+ height: 1087
64
+ width: 800
65
+ url: http://i2.themoviedb.org/profiles/029/4bc9fe2c017a3c0e8b000029/vince-vaughn-original.jpg
66
+ id: 4bc9fe2c017a3c0e8b000029
67
+ - image:
68
+ type: profile
69
+ size: profile
70
+ height: 251
71
+ width: 185
72
+ url: http://i2.themoviedb.org/profiles/029/4bc9fe2c017a3c0e8b000029/vince-vaughn-profile.jpg
73
+ id: 4bc9fe2c017a3c0e8b000029
74
+ - image:
75
+ type: profile
76
+ size: thumb
77
+ height: 61
78
+ width: 45
79
+ url: http://i1.themoviedb.org/profiles/029/4bc9fe2c017a3c0e8b000029/vince-vaughn-thumb.jpg
80
+ id: 4bc9fe2c017a3c0e8b000029
81
+ - score: 19
82
+ popularity: 3
83
+ name: William Vince
84
+ id: 5358
85
+ biography: ""
86
+ url: http://www.themoviedb.org/person/5358
87
+ profile: []
88
+
89
+ - score: 18
90
+ popularity: 3
91
+ name: Vince Oddone
92
+ id: 9467
93
+ biography: ""
94
+ url: http://www.themoviedb.org/person/9467
95
+ profile: []
96
+
97
+ - score: 17
98
+ popularity: 3
99
+ name: Vince Barnett
100
+ id: 13357
101
+ biography: ""
102
+ url: http://www.themoviedb.org/person/13357
103
+ profile: []
104
+
105
+ - score: 16
106
+ popularity: 3
107
+ name: Vince DiCola
108
+ id: 16637
109
+ biography: ""
110
+ url: http://www.themoviedb.org/person/16637
111
+ profile: []
112
+
113
+ - score: 15
114
+ popularity: 3
115
+ name: Vince Palmieri
116
+ id: 19446
117
+ biography: ""
118
+ url: http://www.themoviedb.org/person/19446
119
+ profile: []
120
+
121
+ - score: 14
122
+ popularity: 3
123
+ name: Alexander Vince
124
+ id: 20058
125
+ biography: ""
126
+ url: http://www.themoviedb.org/person/20058
127
+ profile: []
128
+
129
+ - score: 13
130
+ popularity: 3
131
+ name: Barrie Vince
132
+ id: 22154
133
+ biography: ""
134
+ url: http://www.themoviedb.org/person/22154
135
+ profile: []
136
+
137
+ - score: 12
138
+ popularity: 3
139
+ name: Robert Vince
140
+ id: 25010
141
+ biography: ""
142
+ url: http://www.themoviedb.org/person/25010
143
+ profile: []
144
+
145
+ - score: 11
146
+ popularity: 3
147
+ name: Vince Desiderio
148
+ id: 27591
149
+ biography: ""
150
+ url: http://www.themoviedb.org/person/27591
151
+ profile: []
152
+
153
+ - score: 10
154
+ popularity: 3
155
+ name: Vince Giordano
156
+ id: 28009
157
+ biography: ""
158
+ url: http://www.themoviedb.org/person/28009
159
+ profile: []
160
+
161
+ - score: 9
162
+ popularity: 3
163
+ name: Pruitt Taylor Vince
164
+ id: 28411
165
+ biography: ""
166
+ url: http://www.themoviedb.org/person/28411
167
+ profile: []
168
+
169
+ - score: 8
170
+ popularity: 3
171
+ name: Vince Di Meglio
172
+ id: 29012
173
+ biography: ""
174
+ url: http://www.themoviedb.org/person/29012
175
+ profile: []
176
+
177
+ - score: 7
178
+ popularity: 3
179
+ name: Vince Murdocco
180
+ id: 33585
181
+ biography: ""
182
+ url: http://www.themoviedb.org/person/33585
183
+ profile: []
184
+
185
+ - score: 6
186
+ popularity: 3
187
+ name: Vince Martin
188
+ id: 45215
189
+ biography: ""
190
+ url: http://www.themoviedb.org/person/45215
191
+ profile: []
192
+
193
+ - score: 5
194
+ popularity: 3
195
+ name: Vince Gerardis
196
+ id: 54268
197
+ biography: ""
198
+ url: http://www.themoviedb.org/person/54268
199
+ profile: []
200
+
201
+ - score: 4
202
+ popularity: 3
203
+ name: Vince Gilligan
204
+ id: 66633
205
+ biography: ""
206
+ url: http://www.themoviedb.org/person/66633
207
+ profile: []
208
+
209
+ - score: 3
210
+ popularity: 3
211
+ name: Nicholas Vince
212
+ id: 56559
213
+ biography: ""
214
+ url: http://www.themoviedb.org/person/56559
215
+ profile: []
216
+
217
+ - score: 2
218
+ popularity: 3
219
+ name: Vince McMahon
220
+ id: 57342
221
+ biography: ""
222
+ url: http://www.themoviedb.org/person/57342
223
+ profile: []
224
+
225
+ - score: 1
226
+ popularity: 3
227
+ name: Vince Vieluf
228
+ id: 58381
229
+ biography: ""
230
+ url: http://www.themoviedb.org/person/58381
231
+ profile: []
232
+
@@ -0,0 +1 @@
1
+ tmdb_api_key.txt
@@ -0,0 +1,21 @@
1
+ module Test::Unit
2
+ # Used to fix a minor minitest/unit incompatibility in flexmock
3
+ AssertionFailedError = Class.new(StandardError)
4
+
5
+ class TestCase
6
+
7
+ def self.test(name, &block)
8
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
9
+ defined = instance_method(test_name) rescue false
10
+ raise "#{test_name} is already defined in #{self}" if defined
11
+ if block_given?
12
+ define_method(test_name, &block)
13
+ else
14
+ define_method(test_name) do
15
+ flunk "No implementation provided for #{name}"
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,37 @@
1
+ def register_api_url_stubs
2
+ unless(TEST_LIVE_API)
3
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_search.txt")) do |file|
4
+ stub_request(:get, Regexp.new(Tmdb.base_api_url + "Movie.search/" + ".*")).to_return(file)
5
+ end
6
+
7
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_get_info.txt")) do |file|
8
+ stub_request(:get, Regexp.new(Tmdb.base_api_url + "Movie.getInfo/" + ".*")).to_return(file)
9
+ end
10
+
11
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "movie_imdb_lookup.txt")) do |file|
12
+ stub_request(:get, Regexp.new(Tmdb.base_api_url + "Movie.imdbLookup/" + ".*")).to_return(file)
13
+ end
14
+
15
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "person_get_info.txt")) do |file|
16
+ stub_request(:get, Regexp.new(Tmdb.base_api_url + "Person.getInfo/" + ".*")).to_return(file)
17
+ end
18
+
19
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "person_search.txt")) do |file|
20
+ stub_request(:get, Regexp.new(Tmdb.base_api_url + "Person.search/" + ".*")).to_return(file)
21
+ end
22
+
23
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "incorrect_api_url.txt")) do |file|
24
+ stub_request(:get, Regexp.new(Tmdb.base_api_url + "Movie.blarg/" + ".*")).to_return(file)
25
+ end
26
+
27
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "example_com.txt")) do |file|
28
+ stub_request(:get, Regexp.new("http://example.com.*")).to_return(file)
29
+ end
30
+
31
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "image.jpg")) do |file|
32
+ stub_request(:get, Regexp.new('http://i[0-9].themoviedb.org/[backdrops|posters|profiles].*')).to_return(file)
33
+ end
34
+
35
+ stub_request(:get, 'http://thisisaurlthatdoesntexist.co.nz').to_return(:body => "", :status => 404, :headers => {'content-length' => 0})
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ TEST_LIVE_API = false
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'yaml'
6
+ require 'net/http'
7
+
8
+ unless(TEST_LIVE_API)
9
+ require 'webmock/test_unit'
10
+ include WebMock
11
+ end
12
+
13
+ require_files = []
14
+ require_files << File.join(File.dirname(__FILE__), '..', 'lib', 'ruby-tmdb.rb')
15
+ require_files.concat Dir[File.join(File.dirname(__FILE__), 'setup', '*.rb')]
16
+
17
+ require_files.each do |file|
18
+ require File.expand_path(file)
19
+ end
20
+
21
+ File.open(File.join(File.dirname(__FILE__), 'setup', 'tmdb_api_key.txt')) do |file|
22
+ Tmdb.api_key = file.read
23
+ end
@@ -0,0 +1,107 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
2
+
3
+ class TmdbCastTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ register_api_url_stubs
7
+ end
8
+
9
+ test "find by id should return full cast data" do
10
+ cast = TmdbCast.find(:id => 287)
11
+ assert_cast_methodized(cast, 287)
12
+ end
13
+
14
+ test "two cast objects with same data should be equal" do
15
+ cast1 = TmdbCast.find(:id => 287, :limit => 1)
16
+ cast2 = TmdbCast.find(:id => 287, :limit => 1)
17
+ assert_equal cast1, cast2
18
+ end
19
+
20
+ test "find by name should return full cast data" do
21
+ cast = TmdbCast.find(:name => "Brad Pitt").first
22
+ assert_cast_methodized(cast, 287)
23
+ end
24
+
25
+ test "should raise exception if no arguments supplied to find" do
26
+ assert_raise ArgumentError do
27
+ TmdbCast.find()
28
+ end
29
+ end
30
+
31
+ test "find by id should return a single cast member" do
32
+ assert_kind_of TmdbCast, TmdbCast.find(:id => 287)
33
+ end
34
+
35
+ test "find by name should return an array of cast members" do
36
+ cast_members = TmdbCast.find(:name => "vince")
37
+ assert_kind_of Array, cast_members
38
+ cast_members.each do |actor|
39
+ assert_kind_of TmdbCast, actor
40
+ end
41
+ end
42
+
43
+ test "should raise error if limit is smaller than 1" do
44
+ [0, -1, -100].each do |limit|
45
+ assert_raise ArgumentError do
46
+ TmdbCast.find(:name => "vince", :limit => limit)
47
+ end
48
+ end
49
+ end
50
+
51
+ test "should raise error if limit is not an integer" do
52
+ [1.001, "1.2", "hello", [1,2,3], {:test => "1"}].each do |limit|
53
+ assert_raise ArgumentError do
54
+ TmdbCast.find(:name => "vince", :limit => limit)
55
+ end
56
+ end
57
+ end
58
+
59
+ test "should only return a single item if limit=1" do
60
+ actor = TmdbCast.find(:name => "Vince", :limit => 1)
61
+ assert_kind_of TmdbCast, actor
62
+ end
63
+
64
+ test "should return X items if limit=X" do
65
+ (2..5).each do |x|
66
+ actors = TmdbCast.find(:name => "Vince", :limit => x)
67
+ assert_kind_of Array, actors
68
+ assert_equal x, actors.length
69
+ actors.each do |actor|
70
+ assert_kind_of TmdbCast, actor
71
+ end
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ def assert_cast_methodized(actor, cast_id)
78
+ @cast_data = Tmdb.api_call('Person.getInfo', cast_id)[0]
79
+ assert_equal @cast_data["popularity"], actor.popularity
80
+ assert_equal @cast_data["name"], actor.name
81
+ assert_equal @cast_data["known_as"], actor.known_as
82
+ assert_equal @cast_data["id"], actor.id
83
+ assert_equal @cast_data["biography"], actor.biography
84
+ assert_equal @cast_data["known_movies"], actor.known_movies
85
+ assert_equal @cast_data["birthday"], actor.birthday
86
+ assert_equal @cast_data["birthplace"], actor.birthplace
87
+ assert_equal @cast_data["url"], actor.url
88
+ @cast_data["filmography"].each_index do |x|
89
+ assert_equal @cast_data["filmography"][x]["name"], actor.filmography[x].name
90
+ assert_equal @cast_data["filmography"][x]["id"], actor.filmography[x].id
91
+ assert_equal @cast_data["filmography"][x]["job"], actor.filmography[x].job
92
+ assert_equal @cast_data["filmography"][x]["department"], actor.filmography[x].department
93
+ assert_equal @cast_data["filmography"][x]["character"], actor.filmography[x].character
94
+ assert_equal @cast_data["filmography"][x]["url"], actor.filmography[x].url
95
+ end
96
+ @cast_data["profile"].each_index do |x|
97
+ assert_equal @cast_data["profile"][x]["image"]["type"], actor.profiles[x].type
98
+ assert_equal @cast_data["profile"][x]["image"]["size"], actor.profiles[x].size
99
+ assert_equal @cast_data["profile"][x]["image"]["height"], actor.profiles[x].height
100
+ assert_equal @cast_data["profile"][x]["image"]["width"], actor.profiles[x].width
101
+ assert_equal @cast_data["profile"][x]["image"]["url"], actor.profiles[x].url
102
+ assert_equal @cast_data["profile"][x]["image"]["id"], actor.profiles[x].id
103
+ assert_equal Tmdb.get_url(@cast_data["profile"][x]["image"]["url"]).body, actor.profiles[x].data
104
+ end
105
+ end
106
+
107
+ end
@@ -0,0 +1,151 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
2
+
3
+ class TmdbMovieTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ register_api_url_stubs
7
+ end
8
+
9
+ test "find by id should return the full movie data" do
10
+ movie = TmdbMovie.find(:id => 187)
11
+ assert_movie_methodized(movie, 187)
12
+ end
13
+
14
+ test "movies with same data should be seen as equal" do
15
+ movie1 = TmdbMovie.find(:id => 187, :limit => 1)
16
+ movie2 = TmdbMovie.find(:id => 187, :limit => 1)
17
+ assert_equal movie1, movie2
18
+ end
19
+
20
+ test "find by imdb should return the full movie data" do
21
+ movie = TmdbMovie.find(:imdb => "tt0401792")
22
+ assert_movie_methodized(movie, 187)
23
+ end
24
+
25
+ test "find by title should return the full movie data" do
26
+ movie = TmdbMovie.find(:title => "Sin City", :limit => 1)
27
+ assert_movie_methodized(movie, 187)
28
+ end
29
+
30
+ test "should raise exception if no arguments supplied to find" do
31
+ assert_raise ArgumentError do
32
+ TmdbMovie.find()
33
+ end
34
+ end
35
+
36
+ test "find by id should return a single movie" do
37
+ assert_kind_of TmdbMovie, TmdbMovie.find(:id => 187)
38
+ end
39
+
40
+ test "find by imdb should return a single movie" do
41
+ assert_kind_of TmdbMovie, TmdbMovie.find(:imdb => "tt0401792")
42
+ end
43
+
44
+ test "find by title should return an array of movies" do
45
+ movies = TmdbMovie.find(:title => "Iron Man")
46
+ assert_kind_of Array, movies
47
+ movies.each do |movie|
48
+ assert_kind_of TmdbMovie, movie
49
+ end
50
+ end
51
+
52
+ test "find by title with limit=1 should return a single movie" do
53
+ assert_kind_of TmdbMovie, TmdbMovie.find(:title => "Iron Man", :limit => 1)
54
+ end
55
+
56
+ test "find by title with limit=X should return an array of X movies" do
57
+ (2..5).each do |x|
58
+ movies = TmdbMovie.find(:title => "Iron Man", :limit => x)
59
+ assert_kind_of Array, movies
60
+ assert_equal x, movies.length
61
+ movies.each do |movie|
62
+ assert_kind_of TmdbMovie, movie
63
+ end
64
+ end
65
+ end
66
+
67
+ test "should raise error if limit is smaller than 1" do
68
+ [0, -1, -100].each do |limit|
69
+ assert_raise ArgumentError do
70
+ TmdbMovie.find(:title => "Iron Man", :limit => limit)
71
+ end
72
+ end
73
+ end
74
+
75
+ test "should raise error if limit is not an integer" do
76
+ [1.001, "1.2", "hello", [1,2,3], {:test => "1"}].each do |limit|
77
+ assert_raise ArgumentError do
78
+ TmdbMovie.find(:title => "Iron Man", :limit => limit)
79
+ end
80
+ end
81
+ end
82
+
83
+ private
84
+
85
+ def assert_movie_methodized(movie, movie_id)
86
+ @movie_data = Tmdb.api_call('Movie.getInfo', movie_id)[0]
87
+ assert_equal @movie_data["popularity"], movie.popularity
88
+ assert_equal @movie_data["translated"], movie.translated
89
+ assert_equal @movie_data["language"], movie.language
90
+ assert_equal @movie_data["name"], movie.name
91
+ assert_equal @movie_data["alternative_name"], movie.alternative_name
92
+ assert_equal @movie_data["movie_type"], movie.movie_type
93
+ assert_equal @movie_data["id"], movie.id
94
+ assert_equal @movie_data["imdb_id"], movie.imdb_id
95
+ assert_equal @movie_data["url"], movie.url
96
+ assert_equal @movie_data["rating"], movie.rating
97
+ assert_equal @movie_data["tagline"], movie.tagline
98
+ assert_equal @movie_data["certification"], movie.certification
99
+ assert_equal @movie_data["overview"], movie.overview
100
+ assert_equal @movie_data["released"], movie.released
101
+ assert_equal @movie_data["runtime"], movie.runtime
102
+ assert_equal @movie_data["budget"], movie.budget
103
+ assert_equal @movie_data["revenue"], movie.revenue
104
+ assert_equal @movie_data["homepage"], movie.homepage
105
+ assert_equal @movie_data["trailer"], movie.trailer
106
+ assert_equal @movie_data["last_modified_at"], movie.last_modified_at
107
+ @movie_data["genres"].each_index do |x|
108
+ assert_equal @movie_data["genres"][x]["type"], movie.genres[x].type
109
+ assert_equal @movie_data["genres"][x]["url"], movie.genres[x].url
110
+ assert_equal @movie_data["genres"][x]["name"], movie.genres[x].name
111
+ end
112
+ @movie_data["studios"].each_index do |x|
113
+ assert_equal @movie_data["studios"][x]["url"], movie.studios[x].url
114
+ assert_equal @movie_data["studios"][x]["name"], movie.studios[x].name
115
+ end
116
+ @movie_data["countries"].each_index do |x|
117
+ assert_equal @movie_data["countries"][x]["code"], movie.countries[x].code
118
+ assert_equal @movie_data["countries"][x]["url"], movie.countries[x].url
119
+ assert_equal @movie_data["countries"][x]["name"], movie.countries[x].name
120
+ end
121
+ @movie_data["posters"].each_index do |x|
122
+ assert_equal @movie_data["posters"][x]["image"]["type"], movie.posters[x].type
123
+ assert_equal @movie_data["posters"][x]["image"]["size"], movie.posters[x].size
124
+ assert_equal @movie_data["posters"][x]["image"]["height"], movie.posters[x].height
125
+ assert_equal @movie_data["posters"][x]["image"]["width"], movie.posters[x].width
126
+ assert_equal @movie_data["posters"][x]["image"]["url"], movie.posters[x].url
127
+ assert_equal @movie_data["posters"][x]["image"]["id"], movie.posters[x].id
128
+ assert_equal Tmdb.get_url(@movie_data["posters"][x]["image"]["url"]).body, movie.posters[x].data
129
+ end
130
+ @movie_data["backdrops"].each_index do |x|
131
+ assert_equal @movie_data["backdrops"][x]["image"]["type"], movie.backdrops[x].type
132
+ assert_equal @movie_data["backdrops"][x]["image"]["size"], movie.backdrops[x].size
133
+ assert_equal @movie_data["backdrops"][x]["image"]["height"], movie.backdrops[x].height
134
+ assert_equal @movie_data["backdrops"][x]["image"]["width"], movie.backdrops[x].width
135
+ assert_equal @movie_data["backdrops"][x]["image"]["url"], movie.backdrops[x].url
136
+ assert_equal @movie_data["backdrops"][x]["image"]["id"], movie.backdrops[x].id
137
+ assert_equal Tmdb.get_url(@movie_data["backdrops"][x]["image"]["url"]).body, movie.backdrops[x].data
138
+ end
139
+ @movie_data["cast"].each_index do |x|
140
+ assert_equal @movie_data["cast"][x]["name"], movie.cast[x].name
141
+ assert_equal @movie_data["cast"][x]["job"], movie.cast[x].job
142
+ assert_equal @movie_data["cast"][x]["department"], movie.cast[x].department
143
+ assert_equal @movie_data["cast"][x]["character"], movie.cast[x].character
144
+ assert_equal @movie_data["cast"][x]["id"], movie.cast[x].id
145
+ assert_equal @movie_data["cast"][x]["url"], movie.cast[x].url
146
+ assert_equal @movie_data["cast"][x]["profile"], movie.cast[x].profile
147
+ assert_equal TmdbCast.find(:id => @movie_data["cast"][x]["id"], :limit => 1), movie.cast[x].bio
148
+ end
149
+ end
150
+
151
+ end
@@ -0,0 +1,105 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
2
+
3
+ class TmdbTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ register_api_url_stubs
7
+ end
8
+
9
+ test "allows setting of api_key" do
10
+ old_api_key = Tmdb.api_key
11
+ api_key = "test1234567890"
12
+ Tmdb.api_key = api_key
13
+ assert_equal Tmdb.api_key, api_key
14
+ Tmdb.api_key = old_api_key
15
+ end
16
+
17
+ test "should return base API url" do
18
+ assert_equal "http://api.themoviedb.org/2.1/", Tmdb.base_api_url
19
+ end
20
+
21
+ test "get url returns a response object" do
22
+ test_response = Tmdb.get_url("http://example.com/")
23
+ assert_equal 200, test_response.code.to_i
24
+ end
25
+
26
+ test "getting nonexistent URL returns response object" do
27
+ test_response = Tmdb.get_url('http://thisisaurlthatdoesntexist.co.nz')
28
+ assert_equal 404, test_response.code.to_i
29
+ end
30
+
31
+ test "should perform Movie.search API call and return array of results" do
32
+ movies = Tmdb.api_call('Movie.search', 'Transformers')
33
+ assert_kind_of Array, movies
34
+ assert movies.length > 1
35
+ movies.each do |movie|
36
+ assert_kind_of Hash, movie
37
+ ["url", "id", "name"].each do |item|
38
+ assert movie[item]
39
+ end
40
+ end
41
+ end
42
+
43
+ test "should perform Movie.getInfo API call and return array of results" do
44
+ movies = Tmdb.api_call('Movie.getInfo', 187)
45
+ assert_kind_of Array, movies
46
+ assert movies.length == 1
47
+ movies.each do |movie|
48
+ assert_kind_of Hash, movie
49
+ ["url", "id", "name"].each do |item|
50
+ assert movie[item]
51
+ end
52
+ end
53
+ end
54
+
55
+ test "should perform Movie.imdbLookup API call and return array of results" do
56
+ movies = Tmdb.api_call('Movie.imdbLookup', "tt0401792")
57
+ assert_kind_of Array, movies
58
+ assert movies.length == 1
59
+ movies.each do |movie|
60
+ assert_kind_of Hash, movie
61
+ ["url", "id", "name"].each do |item|
62
+ assert movie[item]
63
+ end
64
+ end
65
+ end
66
+
67
+ test "should perform Person.getInfo API call and return array of results" do
68
+ people = Tmdb.api_call('Person.getInfo', 287)
69
+ assert_kind_of Array, people
70
+ assert people.length == 1
71
+ people.each do |person|
72
+ assert_kind_of Hash, person
73
+ ["url", "id", "name"].each do |item|
74
+ assert person[item]
75
+ end
76
+ end
77
+ end
78
+
79
+ test "should perform Person.search API call and return array of results" do
80
+ people = Tmdb.api_call('Person.search', "vince")
81
+ assert_kind_of Array, people
82
+ assert people.length > 1
83
+ people.each do |person|
84
+ assert_kind_of Hash, person
85
+ ["url", "id", "name"].each do |item|
86
+ assert person[item]
87
+ end
88
+ end
89
+ end
90
+
91
+ test "failed API call should return empty array" do
92
+ movies = Tmdb.api_call('Movie.blarg', 'Transformers')
93
+ assert_kind_of Array, movies
94
+ assert movies.empty?
95
+ end
96
+
97
+ test "API call cache should not be changed when data altered in the receiving method" do
98
+ person = Tmdb.api_call('Person.getInfo', 287)[0]
99
+ assert_not_nil person[person.keys[0]]
100
+ person[person.keys[0]] = nil
101
+ person = Tmdb.api_call('Person.getInfo', 287)[0]
102
+ assert_not_nil person[person.keys[0]]
103
+ end
104
+
105
+ end