uri-meta 0.9.4 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.4
1
+ 0.11.0
data/lib/uri/meta.rb CHANGED
@@ -4,10 +4,11 @@ require 'yaml'
4
4
  require 'moneta'
5
5
  require 'moneta/memory'
6
6
  require 'digest/sha1'
7
+ require 'zlib'
7
8
 
8
9
  module URI
9
10
  class Meta
10
- attr_accessor :headers, :uri, :title, :feed, :last_modified, :content_type, :charset, :last_effective_uri, :status, :errors
11
+ attr_accessor :headers, :uri, :title, :feed, :last_modified, :content_type, :charset, :last_effective_uri, :status, :errors, :primary_image, :primary_image_caption, :primary_image_thumbnail
11
12
  @@service_host = 'www.metauri.com'
12
13
  @@user_agent = 'uri-meta rubygem'
13
14
 
@@ -32,7 +33,7 @@ module URI
32
33
  def initialize(options = {})
33
34
  self.errors = []
34
35
  options.each do |k, v|
35
- case k
36
+ case k.to_sym
36
37
  when :last_effective_uri, :uri, :feed then send("#{k}=", v.to_s == '' ? nil : (URI.parse(v.to_s) rescue nil))
37
38
  when :error, :errors then self.errors.push(*[v].flatten)
38
39
  else send("#{k}=", v) if respond_to?("#{k}=")
@@ -73,8 +74,8 @@ module URI
73
74
  block.call(meta) if block
74
75
  else
75
76
  easy = curl(uri, options)
76
- easy.on_complete do |curl|
77
- args = YAML.load(curl.body_str) rescue {:errors => "YAML Error, #{$!.message}"}
77
+ easy.on_complete do |req|
78
+ args = YAML.load(self.decode_content(req)) rescue {:errors => "YAML Error, #{$!.message}"}
78
79
  args = {:errors => "YAML Error, server returned unknown format."} unless args.is_a?(Hash)
79
80
 
80
81
  metas << meta = URI::Meta.new({:uri => uri}.update(args))
@@ -96,10 +97,26 @@ module URI
96
97
  options = options.update(:uri => uri)
97
98
  options = options.map{|k, v| "#{k}=" + URI.escape(v.to_s, UNSAFE)}.join('&')
98
99
  c = Curl::Easy.new("http://#{service_host}/show.yaml?#{options}")
99
- c.headers['User-Agent'] = user_agent
100
+ c.headers['User-Agent'] = user_agent
101
+ c.headers['Accept-encoding'] = 'gzip,deflate'
100
102
  c
101
103
  end
102
104
 
105
+ def self.decode_content(request)
106
+ if request.header_str.match(/Content-Encoding: gzip/)
107
+ begin
108
+ gz = Zlib::GzipReader.new(StringIO.new(request.body_str))
109
+ yaml = gz.read
110
+ gz.close
111
+ rescue Zlib::GzipFile::Error => e
112
+ yaml = request.body_str
113
+ end
114
+ else
115
+ yaml = request.body_str
116
+ end
117
+ yaml
118
+ end
119
+
103
120
  module Mixin
104
121
  def meta(options = {})
105
122
  @meta ||= URI::Meta.get(self, options)
@@ -12,6 +12,7 @@ class UriMetaTest < Test::Unit::TestCase
12
12
  'http://bit.ly/rvQhW',
13
13
  'http://digg.com/educational/Can_you_teach_men_who_pick_up_prostitutes_not_to_buy_sex',
14
14
  'http://img11.yfrog.com/i/vaix.jpg/',
15
+ 'http://imgur.com/GTgb4',
15
16
  'http://rss.slashdot.org/Slashdot/slashdot',
16
17
  'http://slashdot.org/',
17
18
  'http://taptaptap.com/+MqN',
@@ -419,8 +420,19 @@ class UriMetaTest < Test::Unit::TestCase
419
420
 
420
421
  context '.charset' do
421
422
  should 'be UTF-8' do
422
- assert_equal 'UTF-8', @meta.charset
423
+ assert @meta.charset.match(/^utf-8$/i)
423
424
  end
424
425
  end
425
426
  end
427
+
428
+ context %Q(URI.parse('http://imgur.com/GTgb4').meta) do
429
+ setup do
430
+ @meta = URI.parse('http://imgur.com/GTgb4').meta
431
+ end
432
+
433
+ should 'be a redirect' do
434
+ assert @meta.redirect?
435
+ assert_not_equal 'http://imgur.com/GTgb4', @meta.last_effective_uri
436
+ end
437
+ end
426
438
  end
data/uri-meta.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{uri-meta}
8
- s.version = "0.9.4"
8
+ s.version = "0.11.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Stateless Systems"]
12
- s.date = %q{2009-10-17}
12
+ s.date = %q{2011-06-23}
13
13
  s.description = %q{Retrieves meta information for a URI from the meturi.com service.}
14
14
  s.email = %q{production@statelesssystems.com}
15
15
  s.extra_rdoc_files = [
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.homepage = %q{http://www.metauri.com/}
33
33
  s.rdoc_options = ["--charset=UTF-8"]
34
34
  s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.5}
35
+ s.rubygems_version = %q{1.3.6}
36
36
  s.summary = %q{Meta information for a URI}
37
37
  s.test_files = [
38
38
  "test/test_helper.rb",
metadata CHANGED
@@ -1,67 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: uri-meta
3
- version: !ruby/object:Gem::Version
4
- version: 0.9.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.0
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Stateless Systems
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2009-10-17 00:00:00 +11:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-06-23 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: curb
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
16
+ requirement: &11542860 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 0.5.4
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: moneta
27
22
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
23
+ prerelease: false
24
+ version_requirements: *11542860
25
+ - !ruby/object:Gem::Dependency
26
+ name: moneta
27
+ requirement: &11542380 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
33
32
  version: 0.6.0
34
- version:
35
- - !ruby/object:Gem::Dependency
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *11542380
36
+ - !ruby/object:Gem::Dependency
36
37
  name: shoulda
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
38
+ requirement: &11541900 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
43
  version: 2.10.2
44
- version:
45
- - !ruby/object:Gem::Dependency
46
- name: gemcutter
47
44
  type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
45
+ prerelease: false
46
+ version_requirements: *11541900
47
+ - !ruby/object:Gem::Dependency
48
+ name: gemcutter
49
+ requirement: &11541420 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
53
54
  version: 0.1.5
54
- version:
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *11541420
55
58
  description: Retrieves meta information for a URI from the meturi.com service.
56
59
  email: production@statelesssystems.com
57
60
  executables: []
58
-
59
61
  extensions: []
60
-
61
- extra_rdoc_files:
62
+ extra_rdoc_files:
62
63
  - LICENSE
63
64
  - README.markdown
64
- files:
65
+ files:
65
66
  - .document
66
67
  - .gitignore
67
68
  - LICENSE
@@ -73,34 +74,31 @@ files:
73
74
  - test/test_helper.rb
74
75
  - test/uri-meta_test.rb
75
76
  - uri-meta.gemspec
76
- has_rdoc: true
77
77
  homepage: http://www.metauri.com/
78
78
  licenses: []
79
-
80
79
  post_install_message:
81
- rdoc_options:
80
+ rdoc_options:
82
81
  - --charset=UTF-8
83
- require_paths:
82
+ require_paths:
84
83
  - lib
85
- required_ruby_version: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: "0"
90
- version:
91
- required_rubygems_version: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: "0"
96
- version:
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
97
96
  requirements: []
98
-
99
97
  rubyforge_project:
100
- rubygems_version: 1.3.5
98
+ rubygems_version: 1.8.2
101
99
  signing_key:
102
100
  specification_version: 3
103
101
  summary: Meta information for a URI
104
- test_files:
102
+ test_files:
105
103
  - test/test_helper.rb
106
104
  - test/uri-meta_test.rb