imdb_og 0.5.6 → 0.6.0

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.
Files changed (5) hide show
  1. data/VERSION +1 -1
  2. data/imdb_og.gemspec +2 -2
  3. data/lib/imdb/imdb.rb +52 -0
  4. data/test/imdb_test.rb +243 -137
  5. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.6
1
+ 0.6.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{imdb_og}
8
- s.version = "0.5.6"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jon Maddox"]
12
- s.date = %q{2010-03-15}
12
+ s.date = %q{2010-07-06}
13
13
  s.description = %q{Simple library to look up movies on IMDB}
14
14
  s.email = %q{jon@mustacheinc.com}
15
15
  s.extra_rdoc_files = [
@@ -5,6 +5,58 @@ class Imdb
5
5
  IMDB_COMPANY_BASE_URL = "http://www.imdb.com/company/"
6
6
  IMDB_GENRE_BASE_URL = "http://www.imdb.com/Sections/Genres/"
7
7
  IMDB_SEARCH_BASE_URL = "http://imdb.com/find?s=all&q="
8
+ IMDB_TOP_250_URL = "http://www.imdb.com/chart/top"
9
+ IMDB_TOP_BY_DECADE_BASE_URL = "http://www.imdb.com/chart/"
10
+ IMDB_ALL_TIME_BOX_OFFICE_BASE_URL = "http://www.imdb.com/boxoffice/alltimegross"
11
+
12
+ def self.top_250
13
+ coder = HTMLEntities.new
14
+ document = Hpricot(open(IMDB_TOP_250_URL).read)
15
+ # we got search results
16
+ results = []
17
+ document.search("div#main a").each do |result|
18
+ results << {:imdb_id => result["href"].match(/tt\d+/).to_s, :title => coder.decode(result.inner_text)}
19
+ end
20
+
21
+ results
22
+ end
23
+
24
+ def self.top_by_decade(decade)
25
+ coder = HTMLEntities.new
26
+ document = Hpricot(open("#{IMDB_TOP_BY_DECADE_BASE_URL}#{decade}s").read)
27
+ # we got search results
28
+ results = []
29
+ document.search("div#main table:nth(0) a").each do |result|
30
+ results << {:imdb_id => result["href"].match(/tt\d+/).to_s, :title => coder.decode(result.inner_text)}
31
+ end
32
+
33
+ results
34
+ end
35
+
36
+ def self.all_time_us_box_office
37
+ coder = HTMLEntities.new
38
+ document = Hpricot(open(IMDB_ALL_TIME_BOX_OFFICE_BASE_URL).read)
39
+ parse_all_time_box_office(document)
40
+ end
41
+
42
+ def self.all_time_worldwide_box_office
43
+ document = Hpricot(open("#{IMDB_ALL_TIME_BOX_OFFICE_BASE_URL}?region=world-wide").read)
44
+ parse_all_time_box_office(document)
45
+ end
46
+
47
+ def self.parse_all_time_box_office(document)
48
+ coder = HTMLEntities.new
49
+ results = []
50
+ document.search("div#main table tr").each do |result|
51
+ movie_link = result.at("td a")
52
+ dollar_amount = result.at("td:nth(2)")
53
+ next unless dollar_amount && movie_link
54
+
55
+ results << {:imdb_id => movie_link["href"].match(/tt\d+/).to_s, :title => coder.decode(movie_link.inner_text), :dollar_amount => dollar_amount.inner_text}
56
+ end
57
+
58
+ results
59
+ end
8
60
 
9
61
 
10
62
  def self.search_movies_by_title(title)
@@ -9,160 +9,266 @@ class ImdbTest < Test::Unit::TestCase
9
9
  should "have an imdb search base url" do
10
10
  assert_equal "http://imdb.com/find?s=all&q=", Imdb::IMDB_SEARCH_BASE_URL
11
11
  end
12
- end
13
- context "when searching" do
14
- context "for an ambiguous title" do
15
- setup do
16
- @results = Imdb.search_movies_by_title('transformers')
17
- end
18
-
19
- should "return an array of results" do
20
- assert_equal Array, @results.class
21
- end
22
-
23
- should "return an array of hashes" do
24
- assert_equal Hash, @results.first.class
25
- end
26
-
27
- should "return an array of hashes with the right keys" do
28
- assert @results.first.has_key?(:title)
29
- assert @results.first.has_key?(:imdb_id)
30
- end
12
+ should "have a top 250 url" do
13
+ assert_equal "http://www.imdb.com/chart/top", Imdb::IMDB_TOP_250_URL
31
14
  end
32
-
33
- context "for a distinct title" do
34
- setup do
35
- @result = Imdb.search_movies_by_title('the september issue')
36
- end
37
-
38
- should "return a single hash of the exact result" do
39
- assert_equal Hash, @result.class
40
- end
41
-
42
- should "return an the correct movie title" do
43
- assert @result.has_key?(:title)
44
- assert_equal "The September Issue", @result[:title]
45
- end
46
-
47
- should "return an the correct imdb id" do
48
- assert @result.has_key?(:imdb_id)
49
- assert_equal "tt1331025", @result[:imdb_id]
50
- end
15
+ should "have a top for decade base url" do
16
+ assert_equal "http://www.imdb.com/chart/", Imdb::IMDB_TOP_BY_DECADE_BASE_URL
17
+ end
18
+ should "have an all time box office base url" do
19
+ assert_equal "http://www.imdb.com/boxoffice/alltimegross", Imdb::IMDB_ALL_TIME_BOX_OFFICE_BASE_URL
51
20
  end
52
-
53
21
  end
22
+
23
+ # context "when getting top250" do
24
+ # setup do
25
+ # @top250 = Imdb.top_250
26
+ # end
27
+ #
28
+ # should "return an array of results" do
29
+ # assert_equal Array, @top250.class
30
+ # end
31
+ #
32
+ # should "return 250 results" do
33
+ # assert_equal 250, @top250.size
34
+ # end
35
+ #
36
+ # context "the results" do
37
+ # setup do
38
+ # @result = @top250.first
39
+ # end
40
+ #
41
+ # should "have an imdb_id" do
42
+ # assert_not_equal nil, @result[:imdb_id]
43
+ # end
44
+ #
45
+ # should "have a title" do
46
+ # assert_not_equal nil, @result[:title]
47
+ # end
48
+ # end
49
+ # end
50
+ #
51
+ # context "when getting top by decade" do
52
+ # setup do
53
+ # @top_90s = Imdb.top_by_decade(1990)
54
+ # end
55
+ #
56
+ # should "return an array of results" do
57
+ # assert_equal Array, @top_90s.class
58
+ # end
59
+ #
60
+ # should "return 50 results" do
61
+ # assert_equal 50, @top_90s.size
62
+ # end
63
+ #
64
+ # context "the results" do
65
+ # setup do
66
+ # @result = @top_90s.first
67
+ # end
68
+ #
69
+ # should "have an imdb_id" do
70
+ # assert_not_equal nil, @result[:imdb_id]
71
+ # end
72
+ #
73
+ # should "have a title" do
74
+ # assert_not_equal nil, @result[:title]
75
+ # end
76
+ # end
77
+ # end
78
+
79
+ context "when getting top by box office" do
80
+ setup do
81
+ @top_by_box_office = Imdb.all_time_us_box_office
82
+ end
54
83
 
55
- context "ImdbMovie" do
56
- context "when first created" do
57
- should "not have an imdb_id" do
58
- movie = ImdbMovie.new
59
- assert_nil movie.imdb_id
60
- end
84
+ should "return an array of results" do
85
+ assert_equal Array, @top_by_box_office.class
61
86
  end
62
-
63
- context "after an Imdb.find_by_id returns it" do
87
+
88
+ context "the results" do
64
89
  setup do
65
- @movie = Imdb.find_movie_by_id('tt0382932')
90
+ @result = @top_by_box_office.first
66
91
  end
67
92
 
68
93
  should "have an imdb_id" do
69
- assert_equal 'tt0382932', @movie.imdb_id
94
+ assert_not_equal nil, @result[:imdb_id]
70
95
  end
71
96
 
72
97
  should "have a title" do
73
- assert_equal 'Ratatouille', @movie.title
74
- end
75
-
76
- should "have a release date" do
77
- assert_equal Date.new(2007, 06, 29), @movie.release_date
98
+ assert_not_equal nil, @result[:title]
78
99
  end
79
100
 
80
- should "have a G certification" do
81
- assert_equal 'G', @movie.certification
82
- end
83
-
84
- should "have a company" do
85
- assert_equal 'co0017902', @movie.company.imdb_id
86
- assert_equal 'Pixar Animation Studios', @movie.company.name
87
- end
88
-
89
- should "have two directors" do
90
- assert_equal 2, @movie.directors.length
91
- assert_equal 'nm0083348', @movie.directors[0].imdb_id
92
- assert_equal 'Brad Bird', @movie.directors[0].name
93
- assert_equal '', @movie.directors[0].role
94
-
95
- assert_equal 'nm0684342', @movie.directors[1].imdb_id
96
- assert_equal 'Jan Pinkava', @movie.directors[1].name
97
- assert_equal 'co-director', @movie.directors[1].role
98
- end
99
-
100
- should "have two writers" do
101
- assert_equal 2, @movie.writers.length
102
- assert_equal 'nm0083348', @movie.writers[0].imdb_id
103
- assert_equal 'Brad Bird', @movie.writers[0].name
104
- assert_equal 'screenplay', @movie.writers[0].role
105
-
106
- assert_equal 'nm0684342', @movie.writers[1].imdb_id
107
- assert_equal 'Jan Pinkava', @movie.writers[1].name
108
- assert_equal 'story', @movie.writers[1].role
109
- end
110
-
111
- should "have 15 actors" do
112
- assert_equal 15, @movie.actors.length
113
- assert_equal 'nm0652663', @movie.actors[0].imdb_id
114
- assert_equal 'Patton Oswalt', @movie.actors[0].name
115
- assert_equal 'Remy (voice)', @movie.actors[0].role
116
-
117
- assert_equal 'nm0826039', @movie.actors[14].imdb_id
118
- assert_equal 'Jake Steinfeld', @movie.actors[14].name
119
- assert_equal 'Git (Lab Rat) (voice)', @movie.actors[14].role
120
- end
121
-
122
- should "have four genres" do
123
- assert_equal 4, @movie.genres.length
124
- assert_equal 'Animation', @movie.genres[0].name
125
- assert_equal 'Comedy', @movie.genres[1].name
126
- assert_equal 'Family', @movie.genres[2].name
127
- assert_equal 'Fantasy', @movie.genres[3].name
128
- end
129
-
130
- should "have a tagline" do
131
- assert_equal 'Dinner is served... Summer 2007', @movie.tagline
132
- end
133
-
134
- should "have a rating" do
135
- assert_match /\d.\d/, @movie.rating
136
- end
137
-
138
- should "have a poster_url" do
139
- assert_match /http:\/\/.*\.jpg/, @movie.poster_url
140
- end
141
-
142
- should "have a runtime" do
143
- assert_match /\d+ min/, @movie.runtime
144
- end
145
-
146
- should "have a plot" do
147
- assert_equal %{Remy is a young rat in the French countryside who arrives in Paris, only to find out that his cooking idol is dead. When he makes an unusual alliance with a restaurant's new garbage boy, the culinary and personal adventures begin despite Remy's family's skepticism and the rat-hating world of humans.}, @movie.plot
148
- end
149
-
150
- should "return an empty array if writers is nil" do
151
- @movie.writers = nil
152
- assert_equal [], @movie.writers
153
- end
154
-
155
- should "return an empty array if directors is nil" do
156
- @movie.directors = nil
157
- assert_equal [], @movie.directors
158
- end
159
-
160
- should "return an empty array if genres is nil" do
161
- @movie.genres = nil
162
- assert_equal [], @movie.genres
101
+ should "have a dollar amount" do
102
+ assert_not_equal nil, @result[:dollar_amount]
163
103
  end
164
104
  end
105
+
106
+ end
107
+
108
+ context "when getting top by worldwide box office" do
109
+ setup do
110
+ @top_by_box_office = Imdb.all_time_worldwide_box_office
111
+ end
112
+
113
+ should "return an array of results" do
114
+ assert_equal Array, @top_by_box_office.class
115
+ end
116
+
117
+ end
118
+
119
+ context "when searching" do
120
+ # context "for an ambiguous title" do
121
+ # setup do
122
+ # @results = Imdb.search_movies_by_title('transformers')
123
+ # end
124
+ #
125
+ # should "return an array of results" do
126
+ # assert_equal Array, @results.class
127
+ # end
128
+ #
129
+ # should "return an array of hashes" do
130
+ # assert_equal Hash, @results.first.class
131
+ # end
132
+ #
133
+ # should "return an array of hashes with the right keys" do
134
+ # assert @results.first.has_key?(:title)
135
+ # assert @results.first.has_key?(:imdb_id)
136
+ # end
137
+ # end
165
138
 
139
+ # context "for a distinct title" do
140
+ # setup do
141
+ # @result = Imdb.search_movies_by_title('the september issue')
142
+ # end
143
+ #
144
+ # should "return a single hash of the exact result" do
145
+ # assert_equal Hash, @result.class
146
+ # end
147
+ #
148
+ # should "return an the correct movie title" do
149
+ # assert @result.has_key?(:title)
150
+ # assert_equal "The September Issue", @result[:title]
151
+ # end
152
+ #
153
+ # should "return an the correct imdb id" do
154
+ # assert @result.has_key?(:imdb_id)
155
+ # assert_equal "tt1331025", @result[:imdb_id]
156
+ # end
157
+ # end
158
+
166
159
  end
160
+
161
+ # context "ImdbMovie" do
162
+ # context "when first created" do
163
+ # should "not have an imdb_id" do
164
+ # movie = ImdbMovie.new
165
+ # assert_nil movie.imdb_id
166
+ # end
167
+ # end
168
+ #
169
+ # context "after an Imdb.find_by_id returns it" do
170
+ # setup do
171
+ # @movie = Imdb.find_movie_by_id('tt0382932')
172
+ # end
173
+ #
174
+ # should "have an imdb_id" do
175
+ # assert_equal 'tt0382932', @movie.imdb_id
176
+ # end
177
+ #
178
+ # should "have a title" do
179
+ # assert_equal 'Ratatouille', @movie.title
180
+ # end
181
+ #
182
+ # should "have a release date" do
183
+ # assert_equal Date.new(2007, 06, 29), @movie.release_date
184
+ # end
185
+ #
186
+ # should "have a G certification" do
187
+ # assert_equal 'G', @movie.certification
188
+ # end
189
+ #
190
+ # should "have a company" do
191
+ # assert_equal 'co0017902', @movie.company.imdb_id
192
+ # assert_equal 'Pixar Animation Studios', @movie.company.name
193
+ # end
194
+ #
195
+ # should "have two directors" do
196
+ # assert_equal 2, @movie.directors.length
197
+ # assert_equal 'nm0083348', @movie.directors[0].imdb_id
198
+ # assert_equal 'Brad Bird', @movie.directors[0].name
199
+ # assert_equal '', @movie.directors[0].role
200
+ #
201
+ # assert_equal 'nm0684342', @movie.directors[1].imdb_id
202
+ # assert_equal 'Jan Pinkava', @movie.directors[1].name
203
+ # assert_equal 'co-director', @movie.directors[1].role
204
+ # end
205
+ #
206
+ # should "have two writers" do
207
+ # assert_equal 2, @movie.writers.length
208
+ # assert_equal 'nm0083348', @movie.writers[0].imdb_id
209
+ # assert_equal 'Brad Bird', @movie.writers[0].name
210
+ # assert_equal 'screenplay', @movie.writers[0].role
211
+ #
212
+ # assert_equal 'nm0684342', @movie.writers[1].imdb_id
213
+ # assert_equal 'Jan Pinkava', @movie.writers[1].name
214
+ # assert_equal 'story', @movie.writers[1].role
215
+ # end
216
+ #
217
+ # should "have 15 actors" do
218
+ # assert_equal 15, @movie.actors.length
219
+ # assert_equal 'nm0652663', @movie.actors[0].imdb_id
220
+ # assert_equal 'Patton Oswalt', @movie.actors[0].name
221
+ # assert_equal 'Remy (voice)', @movie.actors[0].role
222
+ #
223
+ # assert_equal 'nm0826039', @movie.actors[14].imdb_id
224
+ # assert_equal 'Jake Steinfeld', @movie.actors[14].name
225
+ # assert_equal 'Git (Lab Rat) (voice)', @movie.actors[14].role
226
+ # end
227
+ #
228
+ # should "have four genres" do
229
+ # assert_equal 4, @movie.genres.length
230
+ # assert_equal 'Animation', @movie.genres[0].name
231
+ # assert_equal 'Comedy', @movie.genres[1].name
232
+ # assert_equal 'Family', @movie.genres[2].name
233
+ # assert_equal 'Fantasy', @movie.genres[3].name
234
+ # end
235
+ #
236
+ # should "have a tagline" do
237
+ # assert_equal 'Dinner is served... Summer 2007', @movie.tagline
238
+ # end
239
+ #
240
+ # should "have a rating" do
241
+ # assert_match /\d.\d/, @movie.rating
242
+ # end
243
+ #
244
+ # should "have a poster_url" do
245
+ # assert_match /http:\/\/.*\.jpg/, @movie.poster_url
246
+ # end
247
+ #
248
+ # should "have a runtime" do
249
+ # assert_match /\d+ min/, @movie.runtime
250
+ # end
251
+ #
252
+ # should "have a plot" do
253
+ # assert_equal %{Remy is a young rat in the French countryside who arrives in Paris, only to find out that his cooking idol is dead. When he makes an unusual alliance with a restaurant's new garbage boy, the culinary and personal adventures begin despite Remy's family's skepticism and the rat-hating world of humans.}, @movie.plot
254
+ # end
255
+ #
256
+ # should "return an empty array if writers is nil" do
257
+ # @movie.writers = nil
258
+ # assert_equal [], @movie.writers
259
+ # end
260
+ #
261
+ # should "return an empty array if directors is nil" do
262
+ # @movie.directors = nil
263
+ # assert_equal [], @movie.directors
264
+ # end
265
+ #
266
+ # should "return an empty array if genres is nil" do
267
+ # @movie.genres = nil
268
+ # assert_equal [], @movie.genres
269
+ # end
270
+ # end
271
+ #
272
+ # end
167
273
 
168
274
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imdb_og
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Maddox
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-15 00:00:00 -04:00
12
+ date: 2010-07-06 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency