plumnailer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,11 +7,18 @@ begin
7
7
  gemspec.email = 'matthewm@boedicker.org'
8
8
  gemspec.homepage = 'http://github.com/mmb/plumnailer'
9
9
  gemspec.authors = ['Matthew M. Boedicker']
10
+ gemspec.license = 'MIT'
10
11
 
11
12
  %w{
13
+ net-http-persistent ~> 1.0
12
14
  nokogiri >= 1.4.3.1
13
15
  rmagick >= 1.15.14
14
16
  }.each_slice(3) { |g,o,v| gemspec.add_dependency(g, "#{o} #{v}") }
17
+ %w{
18
+ sinatra >= 1.1.0
19
+ }.each_slice(3) do |g,o,v|
20
+ gemspec.add_development_dependency(g, "#{o} #{v}")
21
+ end
15
22
  end
16
23
  rescue LoadError
17
24
  puts "Jeweler not available. Install it with: gem install jeweler"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -1,17 +1,37 @@
1
- require 'open-uri'
1
+ require 'net/http/persistent'
2
2
 
3
3
  module Plumnailer
4
4
 
5
5
  # Fetch the contents of a url.
6
6
  class Fetcher
7
7
 
8
+ # User agent to send with requests.
8
9
  UserAgent = 'plumnailer (http://github.com/mmb/plumnailer)'
9
10
 
11
+ # Follow this many chained HTTP redirects at most.
12
+ RedirectLimit = 3
13
+
10
14
  # Fetch the contents of a url.
11
- def fetch(url)
15
+ #
16
+ # * url - url to fetch, can be string or URI
17
+ # * orig_url - passed in from redirects
18
+ # * redirect_count - the number of redirects so far
19
+ def fetch(url, orig_url=nil, redirect_count=0)
20
+ if redirect_count > RedirectLimit
21
+ raise ArgumentError,
22
+ "too many redirects (#{redirect_count}) for #{orig_url}"
23
+ end
24
+
12
25
  uri = url.is_a?(URI) ? url : URI(url)
13
26
  if uri.is_a?(URI::HTTP)
14
- open(uri, 'User-Agent' => UserAgent) { |f| f.read }
27
+ http = Net::HTTP::Persistent.new('plumnailer')
28
+ resp = http.request(uri)
29
+ case resp
30
+ when Net::HTTPSuccess; resp.body
31
+ when Net::HTTPRedirection; fetch(resp['location'], orig_url || url,
32
+ redirect_count + 1)
33
+ else resp.error!
34
+ end
15
35
  end
16
36
  end
17
37
 
@@ -28,12 +28,14 @@ module Plumnailer
28
28
  # Fetch image data from a url, load into Magick::ImageList and set some
29
29
  # additional fields.
30
30
  def parse_one(img_url)
31
- img_data = fetcher.fetch(img_url)
32
- unless not img_data or img_data.empty?
31
+ begin
32
+ img_data = fetcher.fetch(img_url)
33
33
  img = Magick::ImageList.new.from_blob(img_data).extend(
34
34
  Plumnailer::WebImage)
35
35
  img.source_url = img_url
36
36
  img
37
+ rescue Exception
38
+ nil
37
39
  end
38
40
  end
39
41
 
data/plumnailer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{plumnailer}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matthew M. Boedicker"]
12
- s.date = %q{2010-11-21}
12
+ s.date = %q{2010-12-08}
13
13
  s.description = %q{Choose the most representative image on an HTML page for use as a thumbnail}
14
14
  s.email = %q{matthewm@boedicker.org}
15
15
  s.extra_rdoc_files = [
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
34
34
  "test.rb"
35
35
  ]
36
36
  s.homepage = %q{http://github.com/mmb/plumnailer}
37
+ s.licenses = ["MIT"]
37
38
  s.require_paths = ["lib"]
38
39
  s.rubygems_version = %q{1.3.7}
39
40
  s.summary = %q{Choose the most representative image on an HTML page}
@@ -43,15 +44,21 @@ Gem::Specification.new do |s|
43
44
  s.specification_version = 3
44
45
 
45
46
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<net-http-persistent>, ["~> 1.0"])
46
48
  s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.3.1"])
47
49
  s.add_runtime_dependency(%q<rmagick>, [">= 1.15.14"])
50
+ s.add_development_dependency(%q<sinatra>, [">= 1.1.0"])
48
51
  else
52
+ s.add_dependency(%q<net-http-persistent>, ["~> 1.0"])
49
53
  s.add_dependency(%q<nokogiri>, [">= 1.4.3.1"])
50
54
  s.add_dependency(%q<rmagick>, [">= 1.15.14"])
55
+ s.add_dependency(%q<sinatra>, [">= 1.1.0"])
51
56
  end
52
57
  else
58
+ s.add_dependency(%q<net-http-persistent>, ["~> 1.0"])
53
59
  s.add_dependency(%q<nokogiri>, [">= 1.4.3.1"])
54
60
  s.add_dependency(%q<rmagick>, [">= 1.15.14"])
61
+ s.add_dependency(%q<sinatra>, [">= 1.1.0"])
55
62
  end
56
63
  end
57
64
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plumnailer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew M. Boedicker
@@ -15,13 +15,28 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-21 00:00:00 -05:00
18
+ date: 2010-12-08 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: nokogiri
22
+ name: net-http-persistent
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 1
32
+ - 0
33
+ version: "1.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: nokogiri
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
25
40
  none: false
26
41
  requirements:
27
42
  - - ">="
@@ -34,11 +49,11 @@ dependencies:
34
49
  - 1
35
50
  version: 1.4.3.1
36
51
  type: :runtime
37
- version_requirements: *id001
52
+ version_requirements: *id002
38
53
  - !ruby/object:Gem::Dependency
39
54
  name: rmagick
40
55
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
56
+ requirement: &id003 !ruby/object:Gem::Requirement
42
57
  none: false
43
58
  requirements:
44
59
  - - ">="
@@ -50,7 +65,23 @@ dependencies:
50
65
  - 14
51
66
  version: 1.15.14
52
67
  type: :runtime
53
- version_requirements: *id002
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 19
78
+ segments:
79
+ - 1
80
+ - 1
81
+ - 0
82
+ version: 1.1.0
83
+ type: :development
84
+ version_requirements: *id004
54
85
  description: Choose the most representative image on an HTML page for use as a thumbnail
55
86
  email: matthewm@boedicker.org
56
87
  executables: []
@@ -78,8 +109,8 @@ files:
78
109
  - test.rb
79
110
  has_rdoc: true
80
111
  homepage: http://github.com/mmb/plumnailer
81
- licenses: []
82
-
112
+ licenses:
113
+ - MIT
83
114
  post_install_message:
84
115
  rdoc_options: []
85
116