link_preview 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/link_preview/parser.rb +3 -2
- data/lib/link_preview/uri.rb +8 -8
- data/lib/link_preview/version.rb +3 -3
- data/spec/link_preview/http_crawler_spec.rb +2 -2
- data/spec/link_preview/parser_spec.rb +58 -0
- data/spec/link_preview/uri_spec.rb +23 -23
- data/spec/link_preview_spec.rb +405 -95
- data/spec/support/link_preview/link_preview_stubs.rb +3 -3
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b34a79a352d9223fbe397ceb04ce50919f9b3542
|
4
|
+
data.tar.gz: 0f1258749159fa44af9a12876dbcce438e174da3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bc7c72b3f941bacd49a9be7917065258026284008b1e9f073a97185480d55ceea2442d957691d0bed12efa2e3b1a7f68601a3c2ea500318e50fc6059b5dc366
|
7
|
+
data.tar.gz: 30c706fc5fff2c6424695c0c30d003fbfcb9e3993c58228a9d575635b0128e6809402020a565f3a381985f58b945153d768d83b080588b0be78e0152deb881c1
|
data/lib/link_preview/parser.rb
CHANGED
@@ -115,8 +115,9 @@ module LinkPreview
|
|
115
115
|
end
|
116
116
|
|
117
117
|
def parse_image_file_name(data)
|
118
|
-
|
119
|
-
|
118
|
+
content_disposition_filename = parse_content_disposition_filename(data)
|
119
|
+
if content_disposition_filename.present?
|
120
|
+
content_disposition_filename
|
120
121
|
elsif data.url
|
121
122
|
parsed_uri = LinkPreview::URI.parse(data.url, @options)
|
122
123
|
parsed_uri.path.split('/').last || parsed_uri.hostname.gsub('.', '_')
|
data/lib/link_preview/uri.rb
CHANGED
@@ -109,6 +109,14 @@ module LinkPreview
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
def oembed_uri?
|
113
|
+
query_values.present? && path =~ /oembed/i && query_values['url']
|
114
|
+
end
|
115
|
+
|
116
|
+
def kaltura_uri?
|
117
|
+
query_values.present? && query_values['playerId'] && query_values['entryId']
|
118
|
+
end
|
119
|
+
|
112
120
|
private
|
113
121
|
|
114
122
|
def merge_query(query)
|
@@ -124,14 +132,6 @@ module LinkPreview
|
|
124
132
|
self
|
125
133
|
end
|
126
134
|
|
127
|
-
def oembed_uri?
|
128
|
-
query_values.present? && path =~ /oembed/i && query_values['url']
|
129
|
-
end
|
130
|
-
|
131
|
-
def kaltura_uri?
|
132
|
-
query_values.present? && query_values['playerId'] && query_values['entryId']
|
133
|
-
end
|
134
|
-
|
135
135
|
def oembed_query
|
136
136
|
{:maxwidth => @options[:width], :maxheight => @options[:height]}.reject { |_,value| value.nil? }
|
137
137
|
end
|
data/lib/link_preview/version.rb
CHANGED
@@ -6,10 +6,10 @@
|
|
6
6
|
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
7
|
# of the Software, and to permit persons to whom the Software is furnished to do
|
8
8
|
# so, subject to the following conditions:
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# The above copyright notice and this permission notice shall be included in all
|
11
11
|
# copies or substantial portions of the Software.
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
14
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
15
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
@@ -19,5 +19,5 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
module LinkPreview
|
22
|
-
VERSION = '0.2.
|
22
|
+
VERSION = '0.2.8'
|
23
23
|
end
|
@@ -34,8 +34,8 @@ describe LinkPreview::HTTPCrawler do
|
|
34
34
|
|
35
35
|
context 'when http_client.get raises an exception' do
|
36
36
|
before do
|
37
|
-
config.http_client.
|
38
|
-
config.error_handler.
|
37
|
+
allow(config.http_client).to receive(:get).and_raise(Timeout::Error)
|
38
|
+
expect(config.error_handler).to receive(:call).once { 'something' }
|
39
39
|
end
|
40
40
|
|
41
41
|
subject(:response) { crawler.dequeue! }
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright (c) 2014, VMware, Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
9
|
+
# of the Software, and to permit persons to whom the Software is furnished to do
|
10
|
+
# so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
require 'spec_helper'
|
24
|
+
|
25
|
+
describe LinkPreview::Parser do
|
26
|
+
describe '#parse_image_file_name' do
|
27
|
+
let(:config) { double(LinkPreview::Configuration) }
|
28
|
+
let(:parser) { LinkPreview::Parser.new(config) }
|
29
|
+
let(:response) do
|
30
|
+
Faraday::Response.new.tap do |response|
|
31
|
+
allow(response).to receive(:headers).and_return({
|
32
|
+
:'content-disposition' => content_disposition
|
33
|
+
})
|
34
|
+
|
35
|
+
allow(response).to receive(:url).and_return('http://example.com/image-url.jpg')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when the content-disposition header contains a valid filename" do
|
40
|
+
let(:content_disposition) { 'inline;filename="image-cd.jpg"' }
|
41
|
+
it 'parses the filename from the header' do
|
42
|
+
expect(parser.parse_image_file_name(response)).to eq('image-cd.jpg')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
context "when the content-disposition header does not contain a filename" do
|
46
|
+
let(:content_disposition) { 'inline;' }
|
47
|
+
it 'parses the filename from the url' do
|
48
|
+
expect(parser.parse_image_file_name(response)).to eq('image-url.jpg')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context "when the content-disposition header contains a blank filename" do
|
52
|
+
let(:content_disposition) { 'inline;filename=""' }
|
53
|
+
it 'parses the filename from the url' do
|
54
|
+
expect(parser.parse_image_file_name(response)).to eq('image-url.jpg')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -30,41 +30,41 @@ describe LinkPreview::URI do
|
|
30
30
|
|
31
31
|
context 'with nil' do
|
32
32
|
let(:uri) { nil }
|
33
|
-
it { parsed_uri.
|
33
|
+
it { expect(parsed_uri).to be_nil }
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'with parsed LinkPreview::URI' do
|
37
37
|
let(:uri) { LinkPreview::URI.parse('http://socialcast.com') }
|
38
38
|
|
39
|
-
it { parsed_uri.
|
40
|
-
it { parsed_uri.to_s.
|
41
|
-
it { parsed_uri.
|
42
|
-
it { parsed_uri.
|
39
|
+
it { expect(parsed_uri).to be_a(LinkPreview::URI) }
|
40
|
+
it { expect(parsed_uri.to_s).to eq('http://socialcast.com/') }
|
41
|
+
it { expect(parsed_uri).not_to be_a_kaltura_uri }
|
42
|
+
it { expect(parsed_uri).not_to be_a_oembed_uri }
|
43
43
|
end
|
44
44
|
|
45
45
|
context 'with common uri' do
|
46
46
|
let(:uri) { 'http://socialcast.com' }
|
47
47
|
|
48
|
-
it { parsed_uri.
|
49
|
-
it { parsed_uri.to_s.
|
50
|
-
it { parsed_uri.
|
51
|
-
it { parsed_uri.
|
48
|
+
it { expect(parsed_uri).to be_a(LinkPreview::URI) }
|
49
|
+
it { expect(parsed_uri.to_s).to eq('http://socialcast.com/') }
|
50
|
+
it { expect(parsed_uri).not_to be_a_kaltura_uri }
|
51
|
+
it { expect(parsed_uri).not_to be_a_oembed_uri }
|
52
52
|
end
|
53
53
|
|
54
54
|
context 'with kaltura uri' do
|
55
55
|
let(:uri) { 'http://demo.kaltura.com/mediaspace/media/index.php/action/oembed?url=http%3A%2F%2Fdemo.kaltura.com%2Fmediaspace%2Fmedia%2F%2Fid%2F1_h9tin5on&playerId=3073841&entryId=1_h9tin5on' }
|
56
|
-
it { parsed_uri.
|
57
|
-
it { parsed_uri.to_s.
|
58
|
-
it { parsed_uri.
|
59
|
-
it { parsed_uri.
|
56
|
+
it { expect(parsed_uri).to be_a(LinkPreview::URI) }
|
57
|
+
it { expect(parsed_uri.to_s).to eq('http://demo.kaltura.com/mediaspace/media/index.php/action/oembed/?url=http%3A%2F%2Fdemo.kaltura.com%2Fmediaspace%2Fmedia%2F%2Fid%2F1_h9tin5on&playerId=3073841&entryId=1_h9tin5on&width=420') }
|
58
|
+
it { expect(parsed_uri).to be_a_kaltura_uri }
|
59
|
+
it { expect(parsed_uri).to be_a_oembed_uri }
|
60
60
|
end
|
61
61
|
|
62
62
|
context 'with kaltura uri with space error' do
|
63
63
|
let(:uri) { 'https://cdnsecakmi.kaltura.com/ index.php/kwidget/wid/_1257971/uiconf_id//entry_id/0_aivu6h6k' }
|
64
|
-
it { parsed_uri.
|
65
|
-
it { parsed_uri.to_s.
|
66
|
-
it { parsed_uri.
|
67
|
-
it { parsed_uri.
|
64
|
+
it { expect(parsed_uri).to be_a(LinkPreview::URI) }
|
65
|
+
it { expect(parsed_uri.to_s).to eq('https://cdnsecakmi.kaltura.com/%20index.php/kwidget/wid/_1257971/uiconf_id//entry_id/0_aivu6h6k') }
|
66
|
+
it { expect(parsed_uri).not_to be_a_kaltura_uri }
|
67
|
+
it { expect(parsed_uri).not_to be_a_oembed_uri }
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -78,22 +78,22 @@ describe LinkPreview::URI do
|
|
78
78
|
context 'with absolute uri ' do
|
79
79
|
let(:uri) { 'http://socialcast.com/a/b/c' }
|
80
80
|
|
81
|
-
it { absolute_uri.
|
82
|
-
it { absolute_uri.to_s.
|
81
|
+
it { expect(absolute_uri).to be_a(LinkPreview::URI) }
|
82
|
+
it { expect(absolute_uri.to_s).to eq('http://socialcast.com/a/b/c') }
|
83
83
|
end
|
84
84
|
|
85
85
|
context 'with relative uri' do
|
86
86
|
let(:uri) { 'a/b/c' }
|
87
87
|
|
88
|
-
it { absolute_uri.
|
89
|
-
it { absolute_uri.to_s.
|
88
|
+
it { expect(absolute_uri).to be_a(LinkPreview::URI) }
|
89
|
+
it { expect(absolute_uri.to_s).to eq('http://socialcast.com/a/b/c') }
|
90
90
|
end
|
91
91
|
|
92
92
|
context 'with another relative uri' do
|
93
93
|
let(:uri) { 'a/b/../../z' }
|
94
94
|
|
95
|
-
it { absolute_uri.
|
96
|
-
it { absolute_uri.to_s.
|
95
|
+
it { expect(absolute_uri).to be_a(LinkPreview::URI) }
|
96
|
+
it { expect(absolute_uri.to_s).to eq('http://socialcast.com/z') }
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
data/spec/link_preview_spec.rb
CHANGED
@@ -35,20 +35,56 @@ describe LinkPreview do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it { should be_a(LinkPreview::Content) }
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
|
39
|
+
describe '#url' do
|
40
|
+
subject { content.url }
|
41
|
+
it { should == url }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#title' do
|
45
|
+
subject { content.title }
|
46
|
+
it { should == %Q{Open Graph protocol} }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#description' do
|
50
|
+
subject { content.description }
|
51
|
+
it { should == %Q{The Open Graph protocol enables any web page to become a rich object in a social graph.} }
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#site_name' do
|
55
|
+
subject { content.site_name }
|
56
|
+
it { should == 'ogp.me' }
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#site_url' do
|
60
|
+
subject { content.site_url }
|
61
|
+
it { should == url }
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#image_url' do
|
65
|
+
subject { content.image_url }
|
66
|
+
it { should == 'http://ogp.me/logo.png' }
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#image_data' do
|
70
|
+
subject { content.image_data }
|
71
|
+
it { should be_a(StringIO) }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#image_content_type' do
|
75
|
+
subject { content.image_content_type }
|
76
|
+
it { should == 'image/png' }
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#image_file_name' do
|
80
|
+
subject { content.image_file_name }
|
81
|
+
it { should == 'logo.png' }
|
82
|
+
end
|
47
83
|
|
48
84
|
it 'should issue minimum number of requests' do
|
49
|
-
http_client.
|
85
|
+
expect(http_client).to receive(:get).with('http://ogp.me/').ordered.and_call_original
|
50
86
|
content.title
|
51
|
-
http_client.
|
87
|
+
expect(http_client).to receive(:get).with('http://ogp.me/logo.png').ordered.and_call_original
|
52
88
|
content.image_data
|
53
89
|
end
|
54
90
|
|
@@ -75,22 +111,58 @@ describe LinkPreview do
|
|
75
111
|
end
|
76
112
|
|
77
113
|
it { should be_a(LinkPreview::Content) }
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
114
|
+
|
115
|
+
describe '#url' do
|
116
|
+
subject { content.url }
|
117
|
+
it { should == 'http://youtube.com/watch?v=M3r2XDceM6A' }
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#title' do
|
121
|
+
subject { content.title }
|
122
|
+
it { should == %Q{Amazing Nintendo Facts} }
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '#description' do
|
126
|
+
subject { content.description }
|
127
|
+
it { should == %Q{Learn about the history of Nintendo, its gaming systems, and Mario! It's 21 amazing facts about Nintendo you may have never known. Update: As of late 2008, W...} }
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '#site_name' do
|
131
|
+
subject { content.site_name }
|
132
|
+
it { should == 'YouTube' }
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#site_url' do
|
136
|
+
subject { content.site_url }
|
137
|
+
it { should == 'http://www.youtube.com/' }
|
138
|
+
end
|
139
|
+
|
140
|
+
describe '#image_url' do
|
141
|
+
subject { content.image_url }
|
142
|
+
it { should == 'http://i1.ytimg.com/vi/M3r2XDceM6A/hqdefault.jpg' }
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '#image_data' do
|
146
|
+
subject { content.image_data }
|
147
|
+
it { should be_a(StringIO) }
|
148
|
+
end
|
149
|
+
|
150
|
+
describe '#image_content_type' do
|
151
|
+
subject { content.image_content_type }
|
152
|
+
it { should == 'image/jpeg' }
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#image_file_name' do
|
156
|
+
subject { content.image_file_name }
|
157
|
+
it { should == 'hqdefault.jpg' }
|
158
|
+
end
|
87
159
|
|
88
160
|
it 'should issue minimum number of requests' do
|
89
|
-
http_client.
|
161
|
+
expect(http_client).to receive(:get).with('http://www.youtube.com/oembed?format=json&url=http%3A%2F%2Fyoutube.com%2Fwatch%3Fv%3DM3r2XDceM6A').ordered.and_call_original
|
90
162
|
content.title
|
91
|
-
http_client.
|
163
|
+
expect(http_client).to receive(:get).with('http://youtube.com/watch?v=M3r2XDceM6A').ordered.and_call_original
|
92
164
|
content.description
|
93
|
-
http_client.
|
165
|
+
expect(http_client).to receive(:get).with('http://i1.ytimg.com/vi/M3r2XDceM6A/hqdefault.jpg').ordered.and_call_original
|
94
166
|
content.image_data
|
95
167
|
end
|
96
168
|
|
@@ -125,22 +197,58 @@ describe LinkPreview do
|
|
125
197
|
end
|
126
198
|
|
127
199
|
it { should be_a(LinkPreview::Content) }
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
200
|
+
|
201
|
+
describe '#url' do
|
202
|
+
subject { content.url }
|
203
|
+
it { should == 'http://videos.kaltura.com/media//id/1_abxlxlll' }
|
204
|
+
end
|
205
|
+
|
206
|
+
describe '#title' do
|
207
|
+
subject { content.title }
|
208
|
+
it { should == %Q{KMC Overview | Kaltura KMC Tutorial} }
|
209
|
+
end
|
210
|
+
|
211
|
+
describe '#description' do
|
212
|
+
subject { content.description }
|
213
|
+
it { should be_nil }
|
214
|
+
end
|
215
|
+
|
216
|
+
describe '#site_name' do
|
217
|
+
subject { content.site_name }
|
218
|
+
it { should == 'Kaltura Videos' }
|
219
|
+
end
|
220
|
+
|
221
|
+
describe '#site_url' do
|
222
|
+
subject { content.site_url }
|
223
|
+
it { should == 'http://videos.kaltura.com/' }
|
224
|
+
end
|
225
|
+
|
226
|
+
describe '#image_url' do
|
227
|
+
subject { content.image_url }
|
228
|
+
it { should == "http://cdnbakmi.kaltura.com/p/811441/sp/81144100/thumbnail/entry_id/1_abxlxlll/version/100012/width//height/" }
|
229
|
+
end
|
230
|
+
|
231
|
+
describe '#image_data' do
|
232
|
+
subject { content.image_data }
|
233
|
+
it { should be_a(StringIO) }
|
234
|
+
end
|
235
|
+
|
236
|
+
describe '#image_content_type' do
|
237
|
+
subject { content.image_content_type }
|
238
|
+
it { should == 'image/jpeg' }
|
239
|
+
end
|
240
|
+
|
241
|
+
describe '#image_file_name' do
|
242
|
+
subject { content.image_file_name }
|
243
|
+
it { should == 'height' }
|
244
|
+
end
|
137
245
|
|
138
246
|
it 'should issue minimum number of requests' do
|
139
|
-
http_client.
|
247
|
+
expect(http_client).to receive(:get).with('http://videos.kaltura.com/oembed/?url=http%3A%2F%2Fvideos.kaltura.com%2Fmedia%2F%2Fid%2F1_abxlxlll&playerId=3073841&entryId=1_abxlxlll&width=420').ordered.and_call_original
|
140
248
|
content.title
|
141
|
-
http_client.
|
249
|
+
expect(http_client).to receive(:get).with('http://cdnbakmi.kaltura.com/p/811441/sp/81144100/thumbnail/entry_id/1_abxlxlll/version/100012/width//height/').ordered.and_call_original
|
142
250
|
content.image_data
|
143
|
-
http_client.
|
251
|
+
expect(http_client).to receive(:get).with('http://videos.kaltura.com/media//id/1_abxlxlll').ordered.and_call_original
|
144
252
|
content.description
|
145
253
|
end
|
146
254
|
end
|
@@ -151,22 +259,58 @@ describe LinkPreview do
|
|
151
259
|
end
|
152
260
|
|
153
261
|
it { should be_a(LinkPreview::Content) }
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
262
|
+
|
263
|
+
describe '#url' do
|
264
|
+
subject { content.url }
|
265
|
+
it { should == 'http://portal.sliderocket.com/SlideRocket-Presentations/Hoshyar-Foundation' }
|
266
|
+
end
|
267
|
+
|
268
|
+
describe '#title' do
|
269
|
+
subject { content.title }
|
270
|
+
it { should == %Q{Hoshyar-Foundation} }
|
271
|
+
end
|
272
|
+
|
273
|
+
describe '#description' do
|
274
|
+
subject { content.description }
|
275
|
+
it { should == %Q{Proudly crafted with SlideRocket.} }
|
276
|
+
end
|
277
|
+
|
278
|
+
describe '#site_name' do
|
279
|
+
subject { content.site_name }
|
280
|
+
it { should == 'SlideRocket' }
|
281
|
+
end
|
282
|
+
|
283
|
+
describe '#site_url' do
|
284
|
+
subject { content.site_url }
|
285
|
+
it { should == 'http://sliderocket.com/' }
|
286
|
+
end
|
287
|
+
|
288
|
+
describe '#image_url' do
|
289
|
+
subject { content.image_url }
|
290
|
+
it { should == 'http://cdn.sliderocket.com/thumbnails/4/43/43b475a4-192e-455e-832f-4a40697d8d25.jpg' }
|
291
|
+
end
|
292
|
+
|
293
|
+
describe '#image_data' do
|
294
|
+
subject { content.image_data }
|
295
|
+
it { should be_a(StringIO) }
|
296
|
+
end
|
297
|
+
|
298
|
+
describe '#image_content_type' do
|
299
|
+
subject { content.image_content_type }
|
300
|
+
it { should == 'binary/octet-stream' }
|
301
|
+
end
|
302
|
+
|
303
|
+
describe '#image_file_name' do
|
304
|
+
subject { content.image_file_name }
|
305
|
+
it { should == '43b475a4-192e-455e-832f-4a40697d8d25.jpg' }
|
306
|
+
end
|
163
307
|
|
164
308
|
it 'should issue minimum number of requests' do
|
165
|
-
http_client.
|
309
|
+
expect(http_client).to receive(:get).with('http://portal.sliderocket.com/SlideRocket-Presentations/Hoshyar-Foundation').ordered.and_call_original
|
166
310
|
content.title
|
167
|
-
http_client.
|
311
|
+
expect(http_client).to receive(:get).with('http://cdn.sliderocket.com/thumbnails/4/43/43b475a4-192e-455e-832f-4a40697d8d25.jpg').ordered.and_call_original
|
168
312
|
content.image_data
|
169
|
-
http_client.
|
313
|
+
expect(http_client).to receive(:get).with('http://app.sliderocket.com/app/oEmbed.aspx?url=http%3A%2F%2Fapp.sliderocket.com%2Fapp%2Ffullplayer.aspx%3Fid%3Df614ec65-0f9b-4167-bb2a-b384dad535f3&maxwidth=420').ordered.and_call_original
|
170
314
|
content.as_oembed
|
171
315
|
end
|
172
316
|
|
@@ -197,18 +341,54 @@ describe LinkPreview do
|
|
197
341
|
end
|
198
342
|
|
199
343
|
it { should be_a(LinkPreview::Content) }
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
344
|
+
|
345
|
+
describe '#url' do
|
346
|
+
subject { content.url }
|
347
|
+
it { should == 'http://support.apple.com/kb/HT5642' }
|
348
|
+
end
|
349
|
+
|
350
|
+
describe '#title' do
|
351
|
+
subject { content.title }
|
352
|
+
it { should == %Q{About the security content of iOS 6.1 Software Update} }
|
353
|
+
end
|
354
|
+
|
355
|
+
describe '#description' do
|
356
|
+
subject { content.description }
|
357
|
+
it { should == %Q{This document describes the security content of iOS 6.1.\nFor the protection of our customers, Apple does not disclose, discuss, or confirm security issues until a full investigation has occurred and any necessary patches or releases are available. To learn more about Apple Product Security, see the Apple Product Security website.\nFor information about the Apple Product Security PGP Key, see How to use the Apple Product Security PGP Key.\nWhere possible, CVE IDs are used to reference the vulnerabilities for further information.\nTo learn about other Security Updates, see Apple Security Updates.} }
|
358
|
+
end
|
359
|
+
|
360
|
+
describe '#site_name' do
|
361
|
+
subject { content.site_name }
|
362
|
+
it { should == 'support.apple.com' }
|
363
|
+
end
|
364
|
+
|
365
|
+
describe '#site_url' do
|
366
|
+
subject { content.site_url }
|
367
|
+
it { should == 'http://support.apple.com' }
|
368
|
+
end
|
369
|
+
|
370
|
+
describe '#image_url' do
|
371
|
+
subject { content.image_url }
|
372
|
+
it { should be_nil }
|
373
|
+
end
|
374
|
+
|
375
|
+
describe '#image_data' do
|
376
|
+
subject { content.image_data }
|
377
|
+
it { should be_nil }
|
378
|
+
end
|
379
|
+
|
380
|
+
describe '#image_content_type' do
|
381
|
+
subject { content.image_content_type }
|
382
|
+
it { should be_nil }
|
383
|
+
end
|
384
|
+
|
385
|
+
describe '#image_file_name' do
|
386
|
+
subject { content.image_file_name }
|
387
|
+
it { should be_nil }
|
388
|
+
end
|
209
389
|
|
210
390
|
it 'should issue minimum number of requests' do
|
211
|
-
http_client.
|
391
|
+
expect(http_client).to receive(:get).with('http://support.apple.com/kb/HT5642').ordered.and_call_original
|
212
392
|
content.title
|
213
393
|
content.image_data
|
214
394
|
end
|
@@ -235,15 +415,51 @@ describe LinkPreview do
|
|
235
415
|
end
|
236
416
|
|
237
417
|
it { should be_a(LinkPreview::Content) }
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
418
|
+
|
419
|
+
describe '#url' do
|
420
|
+
subject { content.url }
|
421
|
+
it { should == 'http://www.golden-gate-park.com/wp-content/uploads/2011/02/Golden_Gate_Park_Logo_Header.png' }
|
422
|
+
end
|
423
|
+
|
424
|
+
describe '#title' do
|
425
|
+
subject { content.title }
|
426
|
+
it { should == 'http://www.golden-gate-park.com/wp-content/uploads/2011/02/Golden_Gate_Park_Logo_Header.png' }
|
427
|
+
end
|
428
|
+
|
429
|
+
describe '#description' do
|
430
|
+
subject { content.description }
|
431
|
+
it { should be_nil }
|
432
|
+
end
|
433
|
+
|
434
|
+
describe '#site_name' do
|
435
|
+
subject { content.site_name }
|
436
|
+
it { should == 'www.golden-gate-park.com' }
|
437
|
+
end
|
438
|
+
|
439
|
+
describe '#site_url' do
|
440
|
+
subject { content.site_url }
|
441
|
+
it { should == 'http://www.golden-gate-park.com' }
|
442
|
+
end
|
443
|
+
|
444
|
+
describe '#image_url' do
|
445
|
+
subject { content.image_url }
|
446
|
+
it { should == 'http://www.golden-gate-park.com/wp-content/uploads/2011/02/Golden_Gate_Park_Logo_Header.png' }
|
447
|
+
end
|
448
|
+
|
449
|
+
describe '#image_data' do
|
450
|
+
subject { content.image_data }
|
451
|
+
it { should be_a(StringIO) }
|
452
|
+
end
|
453
|
+
|
454
|
+
describe '#image_content_type' do
|
455
|
+
subject { content.image_content_type }
|
456
|
+
it { should == 'image/png' }
|
457
|
+
end
|
458
|
+
|
459
|
+
describe '#image_file_name' do
|
460
|
+
subject { content.image_file_name }
|
461
|
+
it { should == 'Golden_Gate_Park_Logo_Header.png' }
|
462
|
+
end
|
247
463
|
|
248
464
|
# FIXME should convert to photo via paperclip
|
249
465
|
context '#as_oembed' do
|
@@ -269,8 +485,8 @@ describe LinkPreview do
|
|
269
485
|
|
270
486
|
it { should_not be_found }
|
271
487
|
it 'should issue minimum number of requests' do
|
272
|
-
http_client.
|
273
|
-
http_client.
|
488
|
+
expect(http_client).to receive(:get).with('http://www.youtube.com/oembed?format=json&url=http%3A%2F%2Fyoutube.com%2Fwatch%3Fv%3D1').ordered.and_call_original
|
489
|
+
expect(http_client).to receive(:get).with('http://youtube.com/watch?v=1').ordered.and_call_original
|
274
490
|
content.title
|
275
491
|
end
|
276
492
|
|
@@ -294,21 +510,57 @@ describe LinkPreview do
|
|
294
510
|
end
|
295
511
|
|
296
512
|
it { should be_a(LinkPreview::Content) }
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
513
|
+
|
514
|
+
describe '#url' do
|
515
|
+
subject { content.url }
|
516
|
+
it { should == 'http://media.mediaspace.kaltura.com/media/Despicable+Me/0_w2zsofdj' }
|
517
|
+
end
|
518
|
+
|
519
|
+
describe '#title' do
|
520
|
+
subject { content.title }
|
521
|
+
it { should == %Q{Despicable Me} }
|
522
|
+
end
|
523
|
+
|
524
|
+
describe '#description' do
|
525
|
+
subject { content.description }
|
526
|
+
it { should == %Q{In a happy suburban neighborhood surrounded by white picket fences with flowering rose bushes, sits a black house with a dead lawn. Unbeknownst to the neighbors, hidden beneath this home is a vast secret hideout. Surrounded by a small army of minions, we discover Gru planning the biggest heist in the history of the world. He is going to steal the moon, yes, the moon. Gru delights in all things wicked. Armed with his arsenal of shrink rays, freeze rays, and battle-ready vehicles for land and air, he vanquishes all who stand in his way. Until the day he encounters the immense will of three little orphaned girls who look at him and see something that no one else has ever seen: a potential Dad. The world's greatest villain has just met his greatest challenge: three little girls named Margo, Edith and Agnes.} }
|
527
|
+
end
|
528
|
+
|
529
|
+
describe '#site_name' do
|
530
|
+
subject { content.site_name }
|
531
|
+
it { should == 'MediaSpace Demo Site' }
|
532
|
+
end
|
533
|
+
|
534
|
+
describe '#site_url' do
|
535
|
+
subject { content.site_url }
|
536
|
+
it { should == 'http://media.mediaspace.kaltura.com' }
|
537
|
+
end
|
538
|
+
|
539
|
+
describe '#image_url' do
|
540
|
+
subject { content.image_url }
|
541
|
+
it { should == 'https://cdnbakmi.kaltura.com/p/1059491/sp/105949100/thumbnail/entry_id/0_w2zsofdj/version/100021/width/400' }
|
542
|
+
end
|
543
|
+
|
544
|
+
describe '#image_data' do
|
545
|
+
subject { content.image_data }
|
546
|
+
it { should be_a(StringIO) }
|
547
|
+
end
|
548
|
+
|
549
|
+
describe '#image_content_type' do
|
550
|
+
subject { content.image_content_type }
|
551
|
+
it { should == 'image/jpeg' }
|
552
|
+
end
|
553
|
+
|
554
|
+
describe '#image_file_name' do
|
555
|
+
subject { content.image_file_name }
|
556
|
+
it { should == '400' }
|
557
|
+
end
|
306
558
|
|
307
559
|
it 'should issue minimum number of requests' do
|
308
|
-
http_client.
|
560
|
+
expect(http_client).to receive(:get).with('https://media.mediaspace.kaltura.com/media/Despicable+Me/0_w2zsofdj/6065172').ordered.and_call_original
|
309
561
|
content.title
|
310
|
-
http_client.
|
311
|
-
http_client.
|
562
|
+
expect(http_client).to receive(:get).with('https://cdnbakmi.kaltura.com/p/1059491/sp/105949100/thumbnail/entry_id/0_w2zsofdj/version/100021/width/400').ordered.and_call_original
|
563
|
+
expect(http_client).to receive(:get).with('http://cdnbakmi.kaltura.com/p/1059491/sp/105949100/thumbnail/entry_id/0_w2zsofdj/version/100021/width/400').ordered.and_call_original
|
312
564
|
content.image_data
|
313
565
|
content.description
|
314
566
|
end
|
@@ -340,15 +592,50 @@ describe LinkPreview do
|
|
340
592
|
LinkPreview.fetch(url)
|
341
593
|
end
|
342
594
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
595
|
+
describe '#url' do
|
596
|
+
subject { content.url }
|
597
|
+
it { should == url }
|
598
|
+
end
|
599
|
+
|
600
|
+
describe '#title' do
|
601
|
+
subject { content.title }
|
602
|
+
it { should == %Q{Hadoop | Elasticsearch} }
|
603
|
+
end
|
604
|
+
|
605
|
+
describe '#description' do
|
606
|
+
subject { content.description }
|
607
|
+
it { should == %Q{Search your Hadoop Data and Get Real-Time Results Deep API integration makes searching data in Hadoop easy Elasticsearch for Apache Hadoop enables real-time searching against data stored in Apache Hadoop. It provides native integration with Map/Reduce, Hive, Pig, and Cascading, all with no customization. Download Elasticsearch for Apache Hadoop Documentation Great fit for “Big Data” [...]} }
|
608
|
+
end
|
609
|
+
|
610
|
+
describe '#site_name' do
|
611
|
+
subject { content.site_name }
|
612
|
+
it { should == 'Elasticsearch.org' }
|
613
|
+
end
|
614
|
+
|
615
|
+
describe '#site_url' do
|
616
|
+
subject { content.site_url }
|
617
|
+
it { should_not be_nil }
|
618
|
+
end
|
619
|
+
|
620
|
+
describe '#image_url' do
|
621
|
+
subject { content.image_url }
|
622
|
+
it { should == 'http://www.elasticsearch.org/content/uploads/2013/10/blank_hero.png' }
|
623
|
+
end
|
624
|
+
|
625
|
+
describe '#image_data' do
|
626
|
+
subject { content.image_data }
|
627
|
+
it { should be_a(StringIO) }
|
628
|
+
end
|
629
|
+
|
630
|
+
describe '#image_content_type' do
|
631
|
+
subject { content.image_content_type }
|
632
|
+
it { should == 'image/png' }
|
633
|
+
end
|
634
|
+
|
635
|
+
describe '#image_file_name' do
|
636
|
+
subject { content.image_file_name }
|
637
|
+
it { should == 'blank_hero.png' }
|
638
|
+
end
|
352
639
|
|
353
640
|
context '#as_oembed' do
|
354
641
|
subject(:oembed) { content.as_oembed }
|
@@ -373,11 +660,34 @@ describe LinkPreview do
|
|
373
660
|
LinkPreview.fetch(url)
|
374
661
|
end
|
375
662
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
663
|
+
describe '#url' do
|
664
|
+
subject { content.url }
|
665
|
+
it { should == url }
|
666
|
+
end
|
667
|
+
|
668
|
+
describe '#title' do
|
669
|
+
subject { content.title }
|
670
|
+
it { should == url }
|
671
|
+
end
|
672
|
+
|
673
|
+
describe '#description' do
|
674
|
+
subject { content.description }
|
675
|
+
it { should be_nil }
|
676
|
+
end
|
677
|
+
|
678
|
+
describe '#site_name' do
|
679
|
+
subject { content.site_name }
|
680
|
+
it { should == 's.taobao.com' }
|
681
|
+
end
|
682
|
+
|
683
|
+
describe '#site_url' do
|
684
|
+
subject { content.site_url }
|
685
|
+
it { should == url }
|
686
|
+
end
|
687
|
+
|
688
|
+
describe '#image_url' do
|
689
|
+
subject { content.image_url }
|
690
|
+
it { should be_nil }
|
691
|
+
end
|
382
692
|
end
|
383
693
|
end
|
@@ -12,8 +12,8 @@ module LinkPreviewStubs
|
|
12
12
|
simple_properties = properties.reject { |k, v| v.is_a?(Hash) }
|
13
13
|
|
14
14
|
content = double('content', DEFAULT_PROPERTIES.merge(:found? => true).merge(simple_properties))
|
15
|
-
content.
|
16
|
-
content.
|
15
|
+
allow(content).to receive(:sources).and_return(nested_properties)
|
16
|
+
allow(content).to receive(:as_oembed).and_return({ :version => '1.0', :type => 'link' }.merge(nested_properties[:oembed]))
|
17
17
|
|
18
18
|
stub_content_helper uri, content
|
19
19
|
end
|
@@ -21,6 +21,6 @@ module LinkPreviewStubs
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def stub_content_helper(uri, content)
|
24
|
-
LinkPreview.
|
24
|
+
allow(LinkPreview).to receive(:fetch).with(uri, an_instance_of(Hash), an_instance_of(Hash)).and_return(content)
|
25
25
|
end
|
26
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: link_preview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Andrews
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-oembed
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '2.9'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '2.9'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: vcr
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,7 +151,7 @@ dependencies:
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: byebug
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
@@ -196,6 +196,7 @@ files:
|
|
196
196
|
- spec/files/requests/youtube.yml
|
197
197
|
- spec/files/requests/youtube_404.yml
|
198
198
|
- spec/link_preview/http_crawler_spec.rb
|
199
|
+
- spec/link_preview/parser_spec.rb
|
199
200
|
- spec/link_preview/uri_spec.rb
|
200
201
|
- spec/link_preview_spec.rb
|
201
202
|
- spec/spec_helper.rb
|
@@ -235,6 +236,7 @@ test_files:
|
|
235
236
|
- spec/files/requests/youtube.yml
|
236
237
|
- spec/files/requests/youtube_404.yml
|
237
238
|
- spec/link_preview/http_crawler_spec.rb
|
239
|
+
- spec/link_preview/parser_spec.rb
|
238
240
|
- spec/link_preview/uri_spec.rb
|
239
241
|
- spec/link_preview_spec.rb
|
240
242
|
- spec/spec_helper.rb
|