derobo-imdb_og 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ .loadpath
7
+ .project
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jon Maddox
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,53 @@
1
+ = derobo-imdb_og
2
+
3
+ This is a fork of Jon Maddox's gem imdb_og (http://github.com/maddox/imdb)
4
+
5
+ == DESCRIPTION:
6
+
7
+ A simple ruby library to scrape IMDB.
8
+ * http://github.com/derobo/imdb
9
+
10
+ == FEATURES :
11
+
12
+ * Searching imdb for movies based on title
13
+ * Getting a Movie object based on it's imdb id
14
+ * Most information on imdb gets scraped, like title, poster, rating, alternative titles etc
15
+
16
+ == SYNOPSIS:
17
+
18
+ You should use following code to include this gem into your project. This prevents namespace issus.
19
+
20
+ require 'rubygems'
21
+ begin
22
+ gem "derobo-imdb_og"
23
+ require "imdb"
24
+ rescue Gem::LoadError
25
+ # handle the error somehow
26
+ end
27
+
28
+ To search for a movie(including alternative titles):
29
+
30
+ m = Imdb.search_movies_by_title("Ein Fisch namens Wanda", true)
31
+ m.first[:title]
32
+ #=> "A Fish Called Wanda"
33
+ m.first[:imdb_id]
34
+ #=> "tt0095159"
35
+
36
+ To get a movie by it's imdb-id:
37
+
38
+ m = Imdb.find_movie_by_id("tt095159")
39
+ m.title
40
+ #=> "A Fish Called Wanda"
41
+
42
+ == REQUIREMENTS:
43
+ Following gems are needed:
44
+ * Hpricot
45
+ * htmlentities
46
+
47
+ == INSTALL:
48
+ Install and activated the gemcutter gem if needed
49
+ $ gem install gemcutter
50
+ $ gem tumble
51
+
52
+ To install the gem itself run
53
+ $ gem install derobo-imdb_og
data/Rakefile ADDED
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "derobo-imdb_og"
8
+ gem.summary = %Q{Fork of Jon Maddox's simple library to look up movies on IMDB}
9
+ gem.description = %Q{Simple library to look up movies on IMDB}
10
+ gem.email = "rodarmy@gmail.com"
11
+ gem.homepage = "http://github.com/derobo/imdb"
12
+ gem.authors = ["Robert Mrasek","Jon Maddox"]
13
+ gem.add_development_dependency "shoulda"
14
+ gem.add_development_dependency "rcov"
15
+ gem.add_dependency "htmlentities"
16
+ gem.add_dependency "hpricot"
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/*_test.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/*_test.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ if File.exist?('VERSION')
50
+ version = File.read('VERSION')
51
+ else
52
+ version = ""
53
+ end
54
+
55
+ rdoc.rdoc_dir = 'rdoc'
56
+ rdoc.title = "imdb_gem #{version}"
57
+ rdoc.rdoc_files.include('README*')
58
+ rdoc.rdoc_files.include('lib/**/*.rb')
59
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.2
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{derobo-imdb_og}
8
+ s.version = "0.5.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Robert Mrasek", "Jon Maddox"]
12
+ s.date = %q{2009-12-01}
13
+ s.description = %q{Simple library to look up movies on IMDB}
14
+ s.email = %q{rodarmy@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "derobo-imdb_og.gemspec",
26
+ "lib/imdb.rb",
27
+ "lib/imdb/imdb.rb",
28
+ "lib/imdb/imdb_company.rb",
29
+ "lib/imdb/imdb_genre.rb",
30
+ "lib/imdb/imdb_movie.rb",
31
+ "lib/imdb/imdb_name.rb",
32
+ "lib/imdb/patches.rb",
33
+ "test/imdb_test.rb",
34
+ "test/test_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/derobo/imdb}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{Fork of Jon Maddox's simple library to look up movies on IMDB}
41
+ s.test_files = [
42
+ "test/imdb_test.rb",
43
+ "test/test_helper.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_development_dependency(%q<rcov>, [">= 0"])
53
+ s.add_runtime_dependency(%q<htmlentities>, [">= 0"])
54
+ s.add_runtime_dependency(%q<hpricot>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<shoulda>, [">= 0"])
57
+ s.add_dependency(%q<rcov>, [">= 0"])
58
+ s.add_dependency(%q<htmlentities>, [">= 0"])
59
+ s.add_dependency(%q<hpricot>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<rcov>, [">= 0"])
64
+ s.add_dependency(%q<htmlentities>, [">= 0"])
65
+ s.add_dependency(%q<hpricot>, [">= 0"])
66
+ end
67
+ end
68
+
data/lib/imdb.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'hpricot'
3
+ require 'open-uri'
4
+ require 'date'
5
+ require 'cgi'
6
+ require 'htmlentities'
7
+ require 'imdb/imdb'
8
+ require 'imdb/imdb_company'
9
+ require 'imdb/imdb_movie'
10
+ require 'imdb/imdb_name'
11
+ require 'imdb/imdb_genre'
12
+ require 'imdb/patches'
data/lib/imdb/imdb.rb ADDED
@@ -0,0 +1,167 @@
1
+ class Imdb
2
+
3
+ IMDB_MOVIE_BASE_URL = "http://www.imdb.com/title/"
4
+ IMDB_NAME_BASE_URL = "http://www.imdb.com/name/"
5
+ IMDB_COMPANY_BASE_URL = "http://www.imdb.com/company/"
6
+ IMDB_GENRE_BASE_URL = "http://www.imdb.com/Sections/Genres/"
7
+ IMDB_SEARCH_BASE_URL = "http://imdb.com/find?s=all&q="
8
+
9
+ # Returns an Array of Hashes of {:imdb_id => String of imdb-id, :title => String of the title}.
10
+ #
11
+ # If use_akas is set alternative titles will be included in the search.
12
+ def self.search_movies_by_title(title, use_akas = nil)
13
+ document = Hpricot(open("#{IMDB_SEARCH_BASE_URL}#{CGI::escape(title)};s=tt#{";site=aka" if use_akas}").read)
14
+ # we got search results
15
+ if document.search('title').inner_text == "IMDb Title Search"
16
+ results = document.search('a[@href^="/title/tt"]').reject do |element|
17
+ element.innerHTML.strip_tags.empty?
18
+ end.map do |element|
19
+ {:imdb_id => element['href'][/tt\d+/], :title => element.innerHTML.strip_tags.unescape_html}
20
+ end
21
+ results.uniq
22
+ else
23
+ [{: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}]
24
+ end
25
+ end
26
+
27
+ # Returns an ImdbMovie.
28
+ #
29
+ # If fetch_releasesinfos is set alternative titles and the full releases dates will be fetched.
30
+ def self.find_movie_by_id(id, fetch_releaseinfos = false)
31
+ coder = HTMLEntities.new
32
+
33
+ data = Hpricot(open(IMDB_MOVIE_BASE_URL + id))
34
+
35
+ movie = ImdbMovie.new
36
+
37
+ movie.imdb_id = id
38
+ movie.title = coder.decode(data.at("meta[@name='title']")['content'].gsub(/\((\d{4}(\/[^)]*)?|[A-Z]+)\)/,'').strip)
39
+
40
+ rating_text = (data/"div.rating/div.meta/b").inner_text
41
+ if rating_text =~ /([\d\.]+)\/10/
42
+ movie.rating = $1
43
+ end
44
+
45
+ begin
46
+ movie.poster_url = data.at("div.photo/a[@name='poster']/img")['src']
47
+ rescue
48
+ movie.poster_url = nil
49
+ end
50
+
51
+ infos = (data/"div.info")
52
+ infos.each do |info|
53
+ info_title = (info/"h5").inner_text
54
+ case info_title
55
+ when /Directors?:/
56
+ movie.directors = parse_names(info)
57
+ when /Writers?[^:]+:/
58
+ movie.writers = parse_names(info)
59
+ when /Company:/
60
+ movie.company = parse_company(info)
61
+ when "Tagline:"
62
+ movie.tagline = coder.decode(parse_info(info).strip)
63
+ when "Runtime:"
64
+ movie.runtime = parse_info(info).strip
65
+ if (movie.runtime)
66
+ movie.runtime.gsub!(/^[^:]+:\s*/, '')
67
+ movie.runtime.gsub!(/min .*/, 'min')
68
+ end
69
+ when "Plot:"
70
+ movie.plot = parse_info(info).strip
71
+ movie.plot = movie.plot.gsub(/\s*\|\s*add synopsis$/, '')
72
+ movie.plot = movie.plot.gsub(/\s*\|\s*full synopsis$/, '')
73
+ movie.plot = movie.plot.gsub(/\s*\|\s*add summary$/, '')
74
+ movie.plot = movie.plot.gsub(/full summary$/, '')
75
+ movie.plot = movie.plot.gsub(/more$/, '')
76
+ movie.plot = coder.decode(movie.plot.strip)
77
+ when "Genre:"
78
+ movie.genres = parse_genres(info)
79
+ when "Release Date:"
80
+ begin
81
+ if (parse_info(info).strip =~ /(\d{1,2}) ([a-zA-Z]+) (\d{4})/)
82
+ movie.release_date = Date.parse("#{$2} #{$1}, #{$3}")
83
+ end
84
+ rescue
85
+ movie.release_date = nil
86
+ end
87
+ when "Certification:"
88
+ begin
89
+ movie.certification = (info/"a").map { |v| v.inner_html }.select { |v| v =~ /^USA:/ && v !~ /Unrated/ }.map { |v| v[/^USA:/]=''; v.strip }.first
90
+ end
91
+ end
92
+ end
93
+
94
+ cast = (data/"table.cast"/"tr")
95
+ cast.each do |cast_member|
96
+ actor_a = (cast_member/"td.nm").inner_html
97
+ actor_a =~ /name\/([^"]+)\//
98
+ actor_id = $1
99
+ actor_name = coder.decode((cast_member/"td.nm"/"a").inner_text)
100
+ actor_role = coder.decode((cast_member/"td.char").inner_text)
101
+ movie.actors = movie.actors << ImdbName.new(actor_id, actor_name, actor_role)
102
+ end
103
+ self.parse_releaseinfo(id, movie) if fetch_releaseinfos
104
+ movie # return movie
105
+
106
+ end
107
+
108
+
109
+ protected
110
+
111
+ def self.parse_releaseinfo(id, movie)
112
+ coder = HTMLEntities.new
113
+ data = Hpricot(open(IMDB_MOVIE_BASE_URL + id + '/releaseinfo'))
114
+ infos = data/"div#tn15content/table"
115
+
116
+ dates = (infos.first/'tr').map do |e| e.inner_text.squeeze(' ').gsub("\n \n", "\n").strip.split("\n ") end.compact.reject{|a| true if a.size != 2}
117
+
118
+ titles = (infos[1]/"tr").map {|e| e.inner_text.strip.split("\n\n")}.map{|a| a[1].split(" / ").map{|c| {:country => coder.decode(c), :title => coder.decode(a[0])} }}.flatten
119
+
120
+ movie.releases = {}
121
+ dates.each do |d|
122
+ title = titles.reject{|t| t[:country] != d[0] }
123
+ begin
124
+ release_date = Date.parse("#{$2} #{$1}, #{$3}") if (d[1] =~ /(\d{1,2}) ([a-zA-Z]+) (\d{4})/)
125
+ rescue
126
+ release_date = nil
127
+ end
128
+ movie.releases[d[0]] = {:date => release_date, :title => title.size > 0 ? title.first[:title] : movie.title }
129
+ end
130
+ end
131
+
132
+ def self.parse_info(info)
133
+ value = info.inner_text.gsub(/\n/,'')
134
+ if value =~ /\:(.+)/
135
+ value = $1
136
+ end
137
+ value.gsub(/ more$/, '')
138
+ end
139
+
140
+ def self.parse_names(info)
141
+ coder = HTMLEntities.new
142
+
143
+ # <a href="/name/nm0083348/">Brad Bird</a><br/><a href="/name/nm0684342/">Jan Pinkava</a> (co-director)<br/>N
144
+ info.inner_html.scan(/<a href="\/name\/([^"]+)\/"[^>]*>([^<]+)<\/a>( \(([^)]+)\))?/).map do |match|
145
+ ImdbName.new(coder.decode(match[0]), coder.decode(match[1]), coder.decode(match[3]))
146
+ end
147
+ end
148
+
149
+ def self.parse_company(info)
150
+ coder = HTMLEntities.new
151
+ # <a href="/company/co0017902/">Pixar Animation Studios</a>
152
+ match = info.inner_html =~ /<a href="\/company\/([^"]+)\/">([^<]+)<\/a>/
153
+ ImdbCompany.new(coder.decode($1), coder.decode($2))
154
+ end
155
+
156
+ def self.parse_genres(info)
157
+ coder = HTMLEntities.new
158
+ # <a href="/Sections/Genres/Animation/">Animation</a> / <a href="/Sections/Genres/Adventure/">Adventure</a>
159
+ genre_links = (info/"a").find_all do |link|
160
+ link['href'] =~ /^\/Sections\/Genres/
161
+ end
162
+ genre_links.map do |link|
163
+ genre = link['href'] =~ /([^\/]+)\/$/
164
+ ImdbGenre.new(coder.decode($1), coder.decode($1))
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,8 @@
1
+ class ImdbCompany
2
+ attr_accessor :imdb_id, :name
3
+
4
+ def initialize(imdb_id, name)
5
+ self.imdb_id = imdb_id;
6
+ self.name = name;
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class ImdbGenre
2
+ attr_accessor :imdb_id, :name
3
+
4
+ def initialize(imdb_id, name)
5
+ self.imdb_id = imdb_id;
6
+ self.name = name;
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ class ImdbMovie
2
+ attr_accessor :imdb_id, :title, :directors, :writers, :releases, :tagline, :company, :plot, :runtime, :rating, :poster_url, :release_date, :certification, :genres, :actors
3
+
4
+ def writers
5
+ self.instance_variable_get(:@writers) || []
6
+ end
7
+
8
+ def actors
9
+ self.instance_variable_get(:@actors) || []
10
+ end
11
+
12
+ def directors
13
+ self.instance_variable_get(:@directors) || []
14
+ end
15
+
16
+ def genres
17
+ self.instance_variable_get(:@genres) || []
18
+ end
19
+
20
+ def releases
21
+ self.instance_variable_get(:@releases) || {}
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ class ImdbName
2
+ attr_accessor :imdb_id, :name, :role
3
+
4
+ def initialize(imdb_id, name, role)
5
+ self.imdb_id = imdb_id;
6
+ self.name = name;
7
+ self.role = role;
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require 'iconv'
2
+
3
+ module StringPatches
4
+ def unescape_html
5
+ Iconv.conv("UTF-8", 'ISO-8859-1', CGI::unescapeHTML(self))
6
+ end
7
+
8
+ def strip_tags
9
+ gsub(/<\/?[^>]*>/, "")
10
+ end
11
+ end
12
+
13
+ String.send :include, StringPatches
data/test/imdb_test.rb ADDED
@@ -0,0 +1,196 @@
1
+ require 'test_helper'
2
+
3
+ class ImdbTest < Test::Unit::TestCase
4
+
5
+ context "Imdb" do
6
+ should "have an imdb movie base url" do
7
+ assert_equal "http://www.imdb.com/title/", Imdb::IMDB_MOVIE_BASE_URL
8
+ end
9
+ should "have an imdb search base url" do
10
+ assert_equal "http://imdb.com/find?s=all&q=", Imdb::IMDB_SEARCH_BASE_URL
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
31
+ 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.first.class
40
+ end
41
+
42
+ should "return an the correct movie title" do
43
+ assert @result.first.has_key?(:title)
44
+ assert_equal "The September Issue", @result.first[:title]
45
+ end
46
+
47
+ should "return an the correct imdb id" do
48
+ assert @result.first.has_key?(:imdb_id)
49
+ assert_equal "tt1331025", @result.first[:imdb_id]
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ context "when searching with akas" do
56
+ setup do
57
+ @results = Imdb.search_movies_by_title('Eine Weihnachtsgeschichte', true)
58
+ end
59
+
60
+ should "return an 'A Fish Called Wanda' id " do
61
+ assert_equal "tt1067106", @results.reject {|r| r[:imdb_id] != "tt1067106" }.first[:imdb_id]
62
+ end
63
+ end
64
+
65
+ context "ImdbMovie" do
66
+ context "when first created" do
67
+ should "not have an imdb_id" do
68
+ movie = ImdbMovie.new
69
+ assert_nil movie.imdb_id
70
+ end
71
+ end
72
+
73
+ context "after an Imdb.find_by_id returns it" do
74
+ setup do
75
+ @movie = Imdb.find_movie_by_id('tt0382932')
76
+ end
77
+
78
+ should "have an imdb_id" do
79
+ assert_equal 'tt0382932', @movie.imdb_id
80
+ end
81
+
82
+ should "have a title" do
83
+ assert_equal 'Ratatouille', @movie.title
84
+ end
85
+
86
+ should "have a release date" do
87
+ # Fails for my, because imdb.com serves my the german release date (my ip should be the reason)
88
+ # assert_equal Date.new(2007, 06, 29), @movie.release_date
89
+ assert_equal Date.new(2007, 10, 3), @movie.release_date
90
+ end
91
+
92
+ should "have a G certification" do
93
+ assert_equal 'G', @movie.certification
94
+ end
95
+
96
+ should "have a company" do
97
+ assert_equal 'co0017902', @movie.company.imdb_id
98
+ assert_equal 'Pixar Animation Studios', @movie.company.name
99
+ end
100
+
101
+ should "have two directors" do
102
+ assert_equal 2, @movie.directors.length
103
+ assert_equal 'nm0083348', @movie.directors[0].imdb_id
104
+ assert_equal 'Brad Bird', @movie.directors[0].name
105
+ assert_equal '', @movie.directors[0].role
106
+
107
+ assert_equal 'nm0684342', @movie.directors[1].imdb_id
108
+ assert_equal 'Jan Pinkava', @movie.directors[1].name
109
+ assert_equal 'co-director', @movie.directors[1].role
110
+ end
111
+
112
+ should "have two writers" do
113
+ assert_equal 2, @movie.writers.length
114
+ assert_equal 'nm0083348', @movie.writers[0].imdb_id
115
+ assert_equal 'Brad Bird', @movie.writers[0].name
116
+ assert_equal 'screenplay', @movie.writers[0].role
117
+
118
+ assert_equal 'nm0684342', @movie.writers[1].imdb_id
119
+ assert_equal 'Jan Pinkava', @movie.writers[1].name
120
+ assert_equal 'story', @movie.writers[1].role
121
+ end
122
+
123
+ should "have 15 actors" do
124
+ assert_equal 15, @movie.actors.length
125
+ assert_equal 'nm0652663', @movie.actors[0].imdb_id
126
+ assert_equal 'Patton Oswalt', @movie.actors[0].name
127
+ assert_equal 'Remy (voice)', @movie.actors[0].role
128
+
129
+ assert_equal 'nm0826039', @movie.actors[14].imdb_id
130
+ assert_equal 'Jake Steinfeld', @movie.actors[14].name
131
+ assert_equal 'Git (Lab Rat) (voice)', @movie.actors[14].role
132
+ end
133
+
134
+ should "have five genres" do
135
+ assert_equal 4, @movie.genres.length
136
+ assert_equal 'Animation', @movie.genres[0].name
137
+ assert_equal 'Comedy', @movie.genres[1].name
138
+ assert_equal 'Family', @movie.genres[2].name
139
+ end
140
+
141
+ should "have a tagline" do
142
+ assert_equal 'Dinner is served... Summer 2007', @movie.tagline
143
+ end
144
+
145
+ should "have a rating" do
146
+ assert_match /\d.\d/, @movie.rating
147
+ end
148
+
149
+ should "have a poster_url" do
150
+ assert_match /http:\/\/.*\.jpg/, @movie.poster_url
151
+ end
152
+
153
+ should "have a runtime" do
154
+ assert_match /\d+ min/, @movie.runtime
155
+ end
156
+
157
+ should "have a plot" do
158
+ 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
159
+ end
160
+
161
+ should "return an empty array if writers is nil" do
162
+ @movie.writers = nil
163
+ assert_equal [], @movie.writers
164
+ end
165
+
166
+ should "return an empty array if directors is nil" do
167
+ @movie.directors = nil
168
+ assert_equal [], @movie.directors
169
+ end
170
+
171
+ should "return an empty array if genres is nil" do
172
+ @movie.genres = nil
173
+ assert_equal [], @movie.genres
174
+ end
175
+ end
176
+ context "after an Imdb.find_by_id with release fetching returns it" do
177
+ setup do
178
+ @movie = Imdb.find_movie_by_id('tt0382932', true)
179
+ end
180
+
181
+ should "have releases" do
182
+ assert_equal 53, @movie.releases.size
183
+ assert_equal 'UK', @movie.releases.keys.first
184
+ assert_equal Date.new(2007, 10, 12), @movie.releases['UK'][:date]
185
+ assert_equal 'Ratatouille', @movie.releases['UK'][:title]
186
+ assert_equal 'Taiwan', @movie.releases.keys.last
187
+ assert_equal Date.new(2007, 8, 3), @movie.releases['Taiwan'][:date]
188
+ assert_equal 'Ratatouille', @movie.releases['Taiwan'][:title]
189
+ assert_equal Date.new(2007, 10, 19), @movie.releases['Poland'][:date]
190
+ assert_equal 'Ratatuj', @movie.releases['Poland'][:title]
191
+ end
192
+ end
193
+
194
+ end
195
+
196
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'imdb'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: derobo-imdb_og
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.2
5
+ platform: ruby
6
+ authors:
7
+ - Robert Mrasek
8
+ - Jon Maddox
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-12-01 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: shoulda
18
+ type: :development
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: rcov
28
+ type: :development
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ version:
36
+ - !ruby/object:Gem::Dependency
37
+ name: htmlentities
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: hpricot
48
+ type: :runtime
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ description: Simple library to look up movies on IMDB
57
+ email: rodarmy@gmail.com
58
+ executables: []
59
+
60
+ extensions: []
61
+
62
+ extra_rdoc_files:
63
+ - LICENSE
64
+ - README.rdoc
65
+ files:
66
+ - .gitignore
67
+ - LICENSE
68
+ - README.rdoc
69
+ - Rakefile
70
+ - VERSION
71
+ - derobo-imdb_og.gemspec
72
+ - lib/imdb.rb
73
+ - lib/imdb/imdb.rb
74
+ - lib/imdb/imdb_company.rb
75
+ - lib/imdb/imdb_genre.rb
76
+ - lib/imdb/imdb_movie.rb
77
+ - lib/imdb/imdb_name.rb
78
+ - lib/imdb/patches.rb
79
+ - test/imdb_test.rb
80
+ - test/test_helper.rb
81
+ has_rdoc: true
82
+ homepage: http://github.com/derobo/imdb
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options:
87
+ - --charset=UTF-8
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ version:
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.3.5
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Fork of Jon Maddox's simple library to look up movies on IMDB
109
+ test_files:
110
+ - test/imdb_test.rb
111
+ - test/test_helper.rb