impawards 0.1.0 → 0.2.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.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{impawards}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jon Maddox"]
12
+ s.date = %q{2009-10-30}
13
+ s.description = %q{Simple library to find high quality posters for movies}
14
+ s.email = %q{jon@mustacheinc.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.textile",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "impawards.gemspec",
27
+ "lib/impawards.rb",
28
+ "test/impawards_test.rb",
29
+ "test/test_helper.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/maddox/impawards}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{Simple library to find high quality posters for movies}
36
+ s.test_files = [
37
+ "test/impawards_test.rb",
38
+ "test/test_helper.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
47
+ s.add_runtime_dependency(%q<hpricot>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
+ s.add_dependency(%q<hpricot>, [">= 0"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ s.add_dependency(%q<hpricot>, [">= 0"])
55
+ end
56
+ end
@@ -8,12 +8,18 @@ module IMPAwards
8
8
  class IMPAwards
9
9
 
10
10
  def self.search_posters(query)
11
- results_url = "http://www.google.com/cse?cx=partner-pub-6811780361519631%3A48v46vdqqnk&cof=FORID%3A9&ie=ISO-8859-1&q=#{CGI.escape(query)}&sa=Search&ad=w9&num=10&rurl=http%3A%2F%2Fwww.impawards.com%2Fgooglesearch.html%3Fcx%3Dpartner-pub-6811780361519631%253A48v46vdqqnk%26cof%3DFORID%253A9%26ie%3DISO-8859-1%26q%3Doverboard%2B1987%26sa%3DSearch"
12
- doc = Hpricot open(results_url)
13
- movie_urls = (doc/"div.g h2.r a")
11
+ movie_urls = get_movie_results(query)
14
12
 
15
- movie_urls.delete_if{|movie_url| movie_url.inner_text !~ /Poster - Internet/i}
13
+ if movie_urls.size > 0
14
+ posters_for_url(movie_urls.first['href'])
15
+ else
16
+ []
17
+ end
18
+ end
16
19
 
20
+ def self.get_posters(query)
21
+ movie_urls = get_movie_results(query)
22
+ movie_urls.delete_if{|movie_url| movie_url.inner_text !~ /#{query}/i}
17
23
  if movie_urls.size > 0
18
24
  posters_for_url(movie_urls.first['href'])
19
25
  else
@@ -37,6 +43,14 @@ module IMPAwards
37
43
  end
38
44
 
39
45
  private
46
+
47
+ def self.get_movie_results(query)
48
+ results_url = "http://www.google.com/cse?cx=partner-pub-6811780361519631%3A48v46vdqqnk&cof=FORID%3A9&ie=ISO-8859-1&q=#{CGI.escape(query)}&sa=Search&ad=w9&num=10&rurl=http%3A%2F%2Fwww.impawards.com%2Fgooglesearch.html%3Fcx%3Dpartner-pub-6811780361519631%253A48v46vdqqnk%26cof%3DFORID%253A9%26ie%3DISO-8859-1%26q%3Doverboard%2B1987%26sa%3DSearch"
49
+ doc = Hpricot open(results_url)
50
+ movie_urls = (doc/"div.g h2.r a")
51
+ movie_urls.delete_if{|movie_url| movie_url.inner_text !~ /Poster - Internet/i}
52
+ end
53
+
40
54
  def self.markup_for_movie_url(url)
41
55
  markup = open(url).read
42
56
  if markup.match(/URL=\.\.(\/.*\/.*.html)/)
@@ -5,13 +5,13 @@ class ImpawardsTest < Test::Unit::TestCase
5
5
 
6
6
  context "searching for posters by title" do
7
7
  setup do
8
- @results = IMPAwards::IMPAwards.search_posters("The Dark Knight")
8
+ @results = IMPAwards::IMPAwards.search_posters("K-11")
9
9
  end
10
10
 
11
11
  should "return an array" do
12
12
  assert_equal Array, @results.class
13
13
  end
14
-
14
+
15
15
  should "return an array of hashes" do
16
16
  assert_equal Hash, @results.first.class
17
17
  end
@@ -20,27 +20,83 @@ class ImpawardsTest < Test::Unit::TestCase
20
20
  setup do
21
21
  @result = @results.first
22
22
  end
23
-
23
+
24
24
  should "have 3 sizes" do
25
25
  assert_equal 3, @result.keys.size
26
26
  end
27
-
27
+
28
28
  should "have xlg url" do
29
29
  assert_match /http.*xlg/, @result[:xlg]
30
30
  end
31
-
31
+
32
32
  should "have thumb url" do
33
33
  assert_match /http.*/, @result[:thumb]
34
34
  end
35
-
35
+
36
36
  should "have tiny url" do
37
37
  assert_match /http.*/, @result[:tiny]
38
38
  end
39
+
40
+ end
41
+ end
39
42
 
43
+ context "GETTING for posters for exact title" do
44
+
45
+ context "with good result" do
46
+ setup do
47
+ @results = IMPAwards::IMPAwards.get_posters("The Dark Knight")
48
+ end
49
+
50
+ should "return an array" do
51
+ assert_equal Array, @results.class
52
+ end
53
+
54
+ should "return an array of hashes" do
55
+ assert_equal Hash, @results.first.class
56
+ end
57
+
58
+ context "returned poster" do
59
+ setup do
60
+ @result = @results.first
61
+ end
62
+
63
+ should "have 3 sizes" do
64
+ assert_equal 3, @result.keys.size
65
+ end
66
+
67
+ should "have xlg url" do
68
+ assert_match /http.*xlg/, @result[:xlg]
69
+ end
70
+
71
+ should "have thumb url" do
72
+ assert_match /http.*/, @result[:thumb]
73
+ end
74
+
75
+ should "have tiny url" do
76
+ assert_match /http.*/, @result[:tiny]
77
+ end
78
+
79
+ end
40
80
  end
41
81
 
82
+ context "with bad results" do
83
+ setup do
84
+ @results = IMPAwards::IMPAwards.get_posters("k-11")
85
+ end
86
+
87
+ should "return an array" do
88
+ assert_equal Array, @results.class
89
+ end
90
+
91
+ should "return an empty array" do
92
+ assert @results.empty?
93
+ end
42
94
 
95
+ end
43
96
 
97
+
44
98
  end
99
+
100
+
45
101
  end
46
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: impawards
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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: 2009-10-09 00:00:00 -04:00
12
+ date: 2009-10-30 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -47,6 +47,8 @@ files:
47
47
  - LICENSE
48
48
  - README.textile
49
49
  - Rakefile
50
+ - VERSION
51
+ - impawards.gemspec
50
52
  - lib/impawards.rb
51
53
  - test/impawards_test.rb
52
54
  - test/test_helper.rb