Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial

  • Loading branch information...
commit 06a02c4446e80e618e4cb8dd306ad323f35815e2 1 parent 8e4bc73
@maddox authored
View
18 README.rdoc
@@ -1,18 +0,0 @@
-= impawards
-
-Description goes here.
-
-== Note on Patches/Pull Requests
-
-* Fork the project.
-* Make your feature addition or bug fix.
-* Add tests for it. This is important so I don't break it in a
- future version unintentionally.
-* Commit, do not mess with rakefile, version, or history.
- (if you want to have your own version, that is fine but
- bump version in a commit by itself I can ignore when I pull)
-* Send me a pull request. Bonus points for topic branches.
-
-== Copyright
-
-Copyright (c) 2009 Jon Maddox. See LICENSE for details.
View
23 README.textile
@@ -0,0 +1,23 @@
+h1. IMPAwards!
+
+h2. What?
+
+A simple library to get nice posters from IMPAwards:http://impawards.com
+
+h2. How?
+
+require 'impawards'
+include IMPAwards
+
+<pre>
+<code>IMPAwards.search_posters("The Dark Knight").first</code>
+=> {:xlg=>"http://www.impawards.com/2008/posters/dark_knight_xlg.jpg",
+ :thumb=>"http://www.impawards.com/2008/posters/dark_knight.jpg",
+ :tiny=>"http://www.impawards.com/2008/thumbs/imp_dark_knight.jpg"}
+</pre>
+
+h2. Installation
+
+gem install impawards
+
+gem hosted at Gemcutter
View
8 Rakefile
@@ -5,13 +5,13 @@ begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "impawards"
- gem.summary = %Q{TODO: one-line summary of your gem}
- gem.description = %Q{TODO: longer description of your gem}
- gem.email = "jon@jonsthoughtsoneverything.com"
+ gem.summary = %Q{Simple library to find high quality posters for movies}
+ gem.description = %Q{Simple library to find high quality posters for movies}
+ gem.email = "jon@mustacheinc.com"
gem.homepage = "http://github.com/maddox/impawards"
gem.authors = ["Jon Maddox"]
gem.add_development_dependency "thoughtbot-shoulda"
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ gem.add_dependency "hpricot"
end
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
View
60 lib/impawards.rb
@@ -0,0 +1,60 @@
+require 'rubygems'
+require 'hpricot'
+require 'open-uri'
+require 'pathname'
+require 'cgi'
+
+module IMPAwards
+ class IMPAwards
+
+ def self.search_posters(query)
+ 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"
+ doc = Hpricot open(results_url)
+ movie_urls = (doc/"div.g h2.r a")
+
+ movie_urls.delete_if{|movie_url| movie_url.inner_text !~ /Poster - Internet/i}
+
+ if movie_urls.size > 0
+ posters_for_url(movie_urls.first['href'])
+ else
+ []
+ end
+ end
+
+ def self.posters_for_url(url)
+ posters = []
+ url_path = Pathname.new(url)
+
+ doc = Hpricot markup_for_movie_url(url)
+
+ (doc/"#altdesigns img").each do |element|
+ posters << get_poster_hash(url_path.dirname.to_s + '/' + element['src'])
+ end
+
+ # if no posters were found at the bottom use the one on the page
+ posters << get_poster_hash(url_path.dirname.to_s + '/' + doc.at("#left_half img")['src']) if posters.size == 0
+ posters
+ end
+
+ private
+ def self.markup_for_movie_url(url)
+ markup = open(url).read
+ if markup.match(/URL=\.\.(\/.*\/.*.html)/)
+ markup_for_movie_url("http://impawards.com#{$1}")
+ else
+ markup
+ end
+ end
+
+ def self.get_poster_hash(poster_path)
+ tiny_path = poster_path
+ thumb_path = poster_path.gsub('thumbs', 'posters').gsub('imp_', '')
+ xlg_path = poster_path.gsub('thumbs', 'posters').gsub('imp_', '').gsub('.jpg', '_xlg.jpg')
+
+ poster_hash = { :tiny => tiny_path,
+ :thumb => thumb_path,
+ :xlg => xlg_path}
+ end
+ end
+end
+
View
43 test/impawards_test.rb
@@ -1,7 +1,46 @@
require 'test_helper'
class ImpawardsTest < Test::Unit::TestCase
- should "probably rename this file and start testing for real" do
- flunk "hey buddy, you should probably rename this file and start testing for real"
+ context "IMPAwards" do
+
+ context "searching for posters by title" do
+ setup do
+ @results = IMPAwards::IMPAwards.search_posters("The Dark Knight")
+ end
+
+ should "return an array" do
+ assert_equal Array, @results.class
+ end
+
+ should "return an array of hashes" do
+ assert_equal Hash, @results.first.class
+ end
+
+ context "returned poster" do
+ setup do
+ @result = @results.first
+ end
+
+ should "have 3 sizes" do
+ assert_equal 3, @result.keys.size
+ end
+
+ should "have xlg url" do
+ assert_match /http.*xlg/, @result[:xlg]
+ end
+
+ should "have thumb url" do
+ assert_match /http.*/, @result[:thumb]
+ end
+
+ should "have tiny url" do
+ assert_match /http.*/, @result[:tiny]
+ end
+
+ end
+
+
+
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.