imdb_og 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/{imdb.gemspec → imdb_og.gemspec} +5 -3
- data/lib/imdb/imdb.rb +12 -0
- data/lib/imdb/patches.rb +13 -0
- data/lib/imdb.rb +2 -0
- data/test/imdb_test.rb +19 -0
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
@@ -4,12 +4,12 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{
|
8
|
-
s.version = "0.5.
|
7
|
+
s.name = %q{imdb_og}
|
8
|
+
s.version = "0.5.1"
|
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-
|
12
|
+
s.date = %q{2009-11-03}
|
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 = [
|
@@ -22,12 +22,14 @@ Gem::Specification.new do |s|
|
|
22
22
|
"README.textile",
|
23
23
|
"Rakefile",
|
24
24
|
"VERSION",
|
25
|
+
"imdb_og.gemspec",
|
25
26
|
"lib/imdb.rb",
|
26
27
|
"lib/imdb/imdb.rb",
|
27
28
|
"lib/imdb/imdb_company.rb",
|
28
29
|
"lib/imdb/imdb_genre.rb",
|
29
30
|
"lib/imdb/imdb_movie.rb",
|
30
31
|
"lib/imdb/imdb_name.rb",
|
32
|
+
"lib/imdb/patches.rb",
|
31
33
|
"test/imdb_test.rb",
|
32
34
|
"test/test_helper.rb"
|
33
35
|
]
|
data/lib/imdb/imdb.rb
CHANGED
@@ -6,6 +6,18 @@ class Imdb
|
|
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
8
|
|
9
|
+
|
10
|
+
def self.search_movies_by_title(title)
|
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}
|
17
|
+
end
|
18
|
+
results.uniq
|
19
|
+
end
|
20
|
+
|
9
21
|
def self.find_movie_by_id(id)
|
10
22
|
coder = HTMLEntities.new
|
11
23
|
|
data/lib/imdb/patches.rb
ADDED
data/lib/imdb.rb
CHANGED
@@ -2,9 +2,11 @@ require 'rubygems'
|
|
2
2
|
require 'hpricot'
|
3
3
|
require 'open-uri'
|
4
4
|
require 'date'
|
5
|
+
require 'cgi'
|
5
6
|
require 'htmlentities'
|
6
7
|
require 'imdb/imdb'
|
7
8
|
require 'imdb/imdb_company'
|
8
9
|
require 'imdb/imdb_movie'
|
9
10
|
require 'imdb/imdb_name'
|
10
11
|
require 'imdb/imdb_genre'
|
12
|
+
require 'imdb/patches'
|
data/test/imdb_test.rb
CHANGED
@@ -10,6 +10,25 @@ class ImdbTest < Test::Unit::TestCase
|
|
10
10
|
assert_equal "http://imdb.com/find?s=all&q=", Imdb::IMDB_SEARCH_BASE_URL
|
11
11
|
end
|
12
12
|
end
|
13
|
+
context "when searching" do
|
14
|
+
setup do
|
15
|
+
@results = Imdb.search_movies_by_title('transformers')
|
16
|
+
end
|
17
|
+
|
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
|
24
|
+
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)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
13
32
|
|
14
33
|
context "ImdbMovie" do
|
15
34
|
context "when first created" do
|
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.
|
4
|
+
version: 0.5.1
|
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-
|
12
|
+
date: 2009-11-03 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -57,13 +57,14 @@ files:
|
|
57
57
|
- README.textile
|
58
58
|
- Rakefile
|
59
59
|
- VERSION
|
60
|
-
-
|
60
|
+
- imdb_og.gemspec
|
61
61
|
- lib/imdb.rb
|
62
62
|
- lib/imdb/imdb.rb
|
63
63
|
- lib/imdb/imdb_company.rb
|
64
64
|
- lib/imdb/imdb_genre.rb
|
65
65
|
- lib/imdb/imdb_movie.rb
|
66
66
|
- lib/imdb/imdb_name.rb
|
67
|
+
- lib/imdb/patches.rb
|
67
68
|
- test/imdb_test.rb
|
68
69
|
- test/test_helper.rb
|
69
70
|
has_rdoc: true
|