imdb_og 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.5.2
data/imdb_og.gemspec CHANGED
@@ -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.1"
8
+ s.version = "0.5.2"
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{2009-11-03}
12
+ s.date = %q{2009-11-28}
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 = [
data/lib/imdb/imdb.rb CHANGED
@@ -9,13 +9,17 @@ class Imdb
9
9
 
10
10
  def self.search_movies_by_title(title)
11
11
  document = Hpricot(open("#{IMDB_SEARCH_BASE_URL}#{CGI::escape(title)};s=tt").read)
12
-
13
- results = document.search('a[@href^="/title/tt"]').reject do |element|
14
- element.innerHTML.strip_tags.empty?
15
- end.map do |element|
16
- {:imdb_id => element['href'][/tt\d+/], :title => element.innerHTML.strip_tags.unescape_html}
12
+ # we got search results
13
+ if document.search('title').inner_text == "IMDb Title Search"
14
+ results = document.search('a[@href^="/title/tt"]').reject do |element|
15
+ element.innerHTML.strip_tags.empty?
16
+ end.map do |element|
17
+ {:imdb_id => element['href'][/tt\d+/], :title => element.innerHTML.strip_tags.unescape_html}
18
+ end
19
+ results.uniq
20
+ else
21
+ {:imdb_id => document.search('link[@href^="http://www.imdb.com/title/tt"]').first['href'].match(/tt\d+/).to_s, :title => document.search('meta[@name="title"]').first["content"].gsub(/\(\d\d\d\d\)$/, '').strip}
17
22
  end
18
- results.uniq
19
23
  end
20
24
 
21
25
  def self.find_movie_by_id(id)
data/test/imdb_test.rb CHANGED
@@ -11,21 +11,43 @@ class ImdbTest < Test::Unit::TestCase
11
11
  end
12
12
  end
13
13
  context "when searching" do
14
- setup do
15
- @results = Imdb.search_movies_by_title('transformers')
16
- end
14
+ context "for an ambiguous title" do
15
+ setup do
16
+ @results = Imdb.search_movies_by_title('transformers')
17
+ end
17
18
 
18
- should "return an array of results" do
19
- assert_equal Array, @results.class
20
- end
21
-
22
- should "return an array of hashes" do
23
- assert_equal Hash, @results.first.class
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
24
31
  end
25
-
26
- should "return an array of hashes with the right keys" do
27
- assert @results.first.has_key?(:title)
28
- assert @results.first.has_key?(:imdb_id)
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
29
51
  end
30
52
 
31
53
  end
@@ -80,7 +102,7 @@ class ImdbTest < Test::Unit::TestCase
80
102
  assert_equal 'nm0083348', @movie.writers[0].imdb_id
81
103
  assert_equal 'Brad Bird', @movie.writers[0].name
82
104
  assert_equal 'screenplay', @movie.writers[0].role
83
-
105
+
84
106
  assert_equal 'nm0684342', @movie.writers[1].imdb_id
85
107
  assert_equal 'Jan Pinkava', @movie.writers[1].name
86
108
  assert_equal 'story', @movie.writers[1].role
@@ -91,7 +113,7 @@ class ImdbTest < Test::Unit::TestCase
91
113
  assert_equal 'nm0652663', @movie.actors[0].imdb_id
92
114
  assert_equal 'Patton Oswalt', @movie.actors[0].name
93
115
  assert_equal 'Remy (voice)', @movie.actors[0].role
94
-
116
+
95
117
  assert_equal 'nm0826039', @movie.actors[14].imdb_id
96
118
  assert_equal 'Jake Steinfeld', @movie.actors[14].name
97
119
  assert_equal 'Git (Lab Rat) (voice)', @movie.actors[14].role
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.1
4
+ version: 0.5.2
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: 2009-11-03 00:00:00 -05:00
12
+ date: 2009-11-28 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency