linkser 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,7 +24,7 @@ module Linkser
24
24
  if ogp and ogp.image
25
25
  begin
26
26
  img_spec = ImageSpec.new(ogp.image)
27
- if valid_img? img_spec.width.to_f, img_spec.height.to_f
27
+ if valid_img? img_spec.width.to_f, img_spec.height.to_f and can_hotlink_img? ogp.image
28
28
  images << Linkser::Resource.new({:type => "image", :url => ogp.image, :width => img_spec.width, :height => img_spec.height})
29
29
  end
30
30
  rescue
@@ -42,7 +42,7 @@ module Linkser
42
42
  if [".jpg", ".jpeg", ".png"].include? img_ext
43
43
  begin
44
44
  img_spec = ImageSpec.new(img_src)
45
- if valid_img? img_spec.width.to_f, img_spec.height.to_f
45
+ if valid_img? img_spec.width.to_f, img_spec.height.to_f and can_hotlink_img? img_src
46
46
  images << Linkser::Resource.new({:type => "image", :url => img_src, :width => img_spec.width, :height => img_spec.height})
47
47
  end
48
48
  rescue
@@ -98,6 +98,25 @@ module Linkser
98
98
  end
99
99
  false
100
100
  end
101
+
102
+ def can_hotlink_img? url, limit=10
103
+ uri = URI.parse(url)
104
+ http = Net::HTTP.new uri.host, uri.port
105
+ http.start do |agent|
106
+ agent.add_field 'Referrer', 'http://www.linkser.com/'
107
+ response = agent.head uri.request_uri
108
+ case response
109
+ when Net::HTTPSuccess then
110
+ return true
111
+ when Net::HTTPRedirection then
112
+ location = response['location']
113
+ warn "Redirecting image to #{location}"
114
+ return can_hotlink_img? location, limit - 1
115
+ else
116
+ return false
117
+ end
118
+ end
119
+ end
101
120
  end
102
121
  end
103
122
  end
@@ -1,3 +1,3 @@
1
1
  module Linkser
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,101 +1,158 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: linkser
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.8
3
+ version: !ruby/object:Gem::Version
4
+ hash: 13
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 9
10
+ version: 0.0.9
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Eduardo Casanova
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-12-14 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2011-12-22 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: rake
16
- requirement: &68540820 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
17
24
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
22
32
  type: :runtime
23
- prerelease: false
24
- version_requirements: *68540820
25
- - !ruby/object:Gem::Dependency
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
26
35
  name: nokogiri
27
- requirement: &68520250 !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
28
38
  none: false
29
- requirements:
39
+ requirements:
30
40
  - - ~>
31
- - !ruby/object:Gem::Version
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 1
45
+ - 4
46
+ - 2
32
47
  version: 1.4.2
33
48
  type: :runtime
34
- prerelease: false
35
- version_requirements: *68520250
36
- - !ruby/object:Gem::Dependency
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
37
51
  name: rmagick
38
- requirement: &68518340 !ruby/object:Gem::Requirement
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
39
54
  none: false
40
- requirements:
55
+ requirements:
41
56
  - - ~>
42
- - !ruby/object:Gem::Version
57
+ - !ruby/object:Gem::Version
58
+ hash: 57
59
+ segments:
60
+ - 2
61
+ - 13
62
+ - 1
43
63
  version: 2.13.1
44
64
  type: :runtime
45
- prerelease: false
46
- version_requirements: *68518340
47
- - !ruby/object:Gem::Dependency
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
48
67
  name: ruby-imagespec
49
- requirement: &68517680 !ruby/object:Gem::Requirement
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
50
70
  none: false
51
- requirements:
71
+ requirements:
52
72
  - - ~>
53
- - !ruby/object:Gem::Version
73
+ - !ruby/object:Gem::Version
74
+ hash: 23
75
+ segments:
76
+ - 0
77
+ - 2
78
+ - 0
54
79
  version: 0.2.0
55
80
  type: :runtime
56
- prerelease: false
57
- version_requirements: *68517680
58
- - !ruby/object:Gem::Dependency
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
59
83
  name: opengraph
60
- requirement: &68517170 !ruby/object:Gem::Requirement
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
61
86
  none: false
62
- requirements:
87
+ requirements:
63
88
  - - ~>
64
- - !ruby/object:Gem::Version
89
+ - !ruby/object:Gem::Version
90
+ hash: 23
91
+ segments:
92
+ - 0
93
+ - 0
94
+ - 4
65
95
  version: 0.0.4
66
96
  type: :runtime
67
- prerelease: false
68
- version_requirements: *68517170
69
- - !ruby/object:Gem::Dependency
97
+ version_requirements: *id005
98
+ - !ruby/object:Gem::Dependency
70
99
  name: activesupport
71
- requirement: &68516320 !ruby/object:Gem::Requirement
100
+ prerelease: false
101
+ requirement: &id006 !ruby/object:Gem::Requirement
72
102
  none: false
73
- requirements:
74
- - - ! '>'
75
- - !ruby/object:Gem::Version
103
+ requirements:
104
+ - - ">"
105
+ - !ruby/object:Gem::Version
106
+ hash: 5
107
+ segments:
108
+ - 2
109
+ - 2
110
+ - 1
76
111
  version: 2.2.1
77
112
  type: :runtime
113
+ version_requirements: *id006
114
+ - !ruby/object:Gem::Dependency
115
+ name: ruby-debug
78
116
  prerelease: false
79
- version_requirements: *68516320
80
- - !ruby/object:Gem::Dependency
117
+ requirement: &id007 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 49
123
+ segments:
124
+ - 0
125
+ - 10
126
+ - 3
127
+ version: 0.10.3
128
+ type: :development
129
+ version_requirements: *id007
130
+ - !ruby/object:Gem::Dependency
81
131
  name: rspec
82
- requirement: &68515620 !ruby/object:Gem::Requirement
132
+ prerelease: false
133
+ requirement: &id008 !ruby/object:Gem::Requirement
83
134
  none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ hash: 19
139
+ segments:
140
+ - 2
141
+ - 7
142
+ - 0
87
143
  version: 2.7.0
88
144
  type: :development
89
- prerelease: false
90
- version_requirements: *68515620
91
- description: Linkser is a link parser for Ruby. It gets an URI, tries to dereference
92
- it and returns the relevant information about the resource.
93
- email:
145
+ version_requirements: *id008
146
+ description: Linkser is a link parser for Ruby. It gets an URI, tries to dereference it and returns the relevant information about the resource.
147
+ email:
94
148
  - ecasanovac@gmail.com
95
149
  executables: []
150
+
96
151
  extensions: []
152
+
97
153
  extra_rdoc_files: []
98
- files:
154
+
155
+ files:
99
156
  - .gitignore
100
157
  - .rspec
101
158
  - .travis.yml
@@ -114,26 +171,36 @@ files:
114
171
  - spec/spec_helper.rb
115
172
  homepage: https://github.com/ging/linkser
116
173
  licenses: []
174
+
117
175
  post_install_message:
118
176
  rdoc_options: []
119
- require_paths:
177
+
178
+ require_paths:
120
179
  - lib
121
- required_ruby_version: !ruby/object:Gem::Requirement
180
+ required_ruby_version: !ruby/object:Gem::Requirement
122
181
  none: false
123
- requirements:
124
- - - ! '>='
125
- - !ruby/object:Gem::Version
126
- version: '0'
127
- required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ hash: 3
186
+ segments:
187
+ - 0
188
+ version: "0"
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
190
  none: false
129
- requirements:
130
- - - ! '>='
131
- - !ruby/object:Gem::Version
132
- version: '0'
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ hash: 3
195
+ segments:
196
+ - 0
197
+ version: "0"
133
198
  requirements: []
199
+
134
200
  rubyforge_project:
135
201
  rubygems_version: 1.8.10
136
202
  signing_key:
137
203
  specification_version: 3
138
204
  summary: A link parser for Ruby
139
205
  test_files: []
206
+