link_thumbnailer 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/link_thumbnailer/fetcher.rb +3 -1
- data/lib/link_thumbnailer/version.rb +1 -1
- data/link_thumbnailer.gemspec +1 -1
- data/spec/fetcher_spec.rb +34 -10
- metadata +4 -4
@@ -21,7 +21,9 @@ module LinkThumbnailer
|
|
21
21
|
resp = http.request(self.url)
|
22
22
|
case resp
|
23
23
|
when Net::HTTPSuccess then resp.body
|
24
|
-
when Net::HTTPRedirection
|
24
|
+
when Net::HTTPRedirection
|
25
|
+
location = resp['location'].start_with?('http') ? resp['location'] : "#{self.url.scheme}://#{self.url.host}#{resp['location']}"
|
26
|
+
fetch(location, redirect_count + 1)
|
25
27
|
else resp.error!
|
26
28
|
end
|
27
29
|
end
|
data/link_thumbnailer.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = LinkThumbnailer::VERSION
|
17
17
|
|
18
18
|
gem.add_dependency(%q{nokogiri}, ['~> 1.5.5'])
|
19
|
-
gem.add_dependency(%q{hashie}, ['
|
19
|
+
gem.add_dependency(%q{hashie}, ['>= 1.2.0'])
|
20
20
|
gem.add_dependency(%q{net-http-persistent}, ['~> 2.7'])
|
21
21
|
gem.add_dependency(%q{rmagick}, ['~> 2.13.1'])
|
22
22
|
gem.add_dependency(%q{json}, ['~> 1.7.6'])
|
data/spec/fetcher_spec.rb
CHANGED
@@ -40,20 +40,44 @@ describe LinkThumbnailer::Fetcher do
|
|
40
40
|
|
41
41
|
context "when http redirection" do
|
42
42
|
|
43
|
-
|
43
|
+
context "and relative uri" do
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
let(:another_url) { '/bar' }
|
46
|
+
|
47
|
+
before do
|
48
|
+
stub_request(:get, url).to_return(status: 300, body: 'foo', headers: { 'Location' => another_url })
|
49
|
+
stub_request(:get, url + another_url).to_return(status: 200, body: 'bar', headers: {})
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns body response" do
|
53
|
+
fetcher.fetch(url).should eq('bar')
|
54
|
+
end
|
55
|
+
|
56
|
+
it "sets fetcher url" do
|
57
|
+
fetcher.fetch(url)
|
58
|
+
fetcher.url.to_s.should eq(url + another_url)
|
59
|
+
end
|
49
60
|
|
50
|
-
it "returns body response" do
|
51
|
-
fetcher.fetch(url).should eq('bar')
|
52
61
|
end
|
53
62
|
|
54
|
-
|
55
|
-
|
56
|
-
|
63
|
+
context "and absolute uri" do
|
64
|
+
|
65
|
+
let(:another_url) { 'http://bar.com' }
|
66
|
+
|
67
|
+
before do
|
68
|
+
stub_request(:get, url).to_return(status: 300, body: 'foo', headers: { 'Location' => another_url })
|
69
|
+
stub_request(:get, another_url).to_return(status: 200, body: 'bar', headers: {})
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns body response" do
|
73
|
+
fetcher.fetch(url).should eq('bar')
|
74
|
+
end
|
75
|
+
|
76
|
+
it "sets fetcher url" do
|
77
|
+
fetcher.fetch(url)
|
78
|
+
fetcher.url.to_s.should eq(another_url)
|
79
|
+
end
|
80
|
+
|
57
81
|
end
|
58
82
|
|
59
83
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: link_thumbnailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: 1.2.0
|
38
38
|
type: :runtime
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 1.2.0
|
46
46
|
- !ruby/object:Gem::Dependency
|