link_preview 0.3.0.pre.2 → 0.3.0
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/configuration.rb +10 -0
- data/lib/link_preview/content.rb +36 -9
- data/lib/link_preview/http_client.rb +22 -7
- data/lib/link_preview/http_crawler.rb +2 -17
- data/lib/link_preview/parser.rb +62 -26
- data/lib/link_preview/version.rb +1 -1
- data/spec/files/requests/flickr_oembed.yml +21983 -0
- data/spec/files/requests/kaltura_html5_embed.yml +1799 -0
- data/spec/files/requests/kaltura_html5_ignore_video_type_html.yml +1799 -0
- data/spec/files/requests/kaltura_html5_video.yml +1799 -0
- data/spec/link_preview/http_crawler_spec.rb +2 -2
- data/spec/link_preview/parser_spec.rb +2 -0
- data/spec/link_preview_spec.rb +274 -37
- metadata +16 -10
- data/spec/files/requests/kalture_html5.yml +0 -490
@@ -34,13 +34,13 @@ describe LinkPreview::HTTPCrawler do
|
|
34
34
|
|
35
35
|
context 'when http_client.get raises an exception' do
|
36
36
|
before do
|
37
|
-
allow(config.http_client).to receive(:get).and_raise(Timeout::Error)
|
37
|
+
allow(config.http_client.connection).to receive(:get).and_raise(Timeout::Error)
|
38
38
|
expect(config.error_handler).to receive(:call).once { 'something' }
|
39
39
|
end
|
40
40
|
|
41
41
|
subject(:response) { crawler.dequeue! }
|
42
42
|
|
43
|
-
it '
|
43
|
+
it 'receives error_handler call and return non successful response' do
|
44
44
|
should be_a(Faraday::Response)
|
45
45
|
should_not be_success
|
46
46
|
end
|
@@ -40,12 +40,14 @@ describe LinkPreview::Parser do
|
|
40
40
|
expect(parser.parse_image_file_name(response)).to eq('image-cd.jpg')
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
43
44
|
context 'when the content-disposition header does not contain a filename' do
|
44
45
|
let(:content_disposition) { 'inline;' }
|
45
46
|
it 'parses the filename from the url' do
|
46
47
|
expect(parser.parse_image_file_name(response)).to eq('image-url.jpg')
|
47
48
|
end
|
48
49
|
end
|
50
|
+
|
49
51
|
context 'when the content-disposition header contains a blank filename' do
|
50
52
|
let(:content_disposition) { 'inline;filename=""' }
|
51
53
|
it 'parses the filename from the url' do
|
data/spec/link_preview_spec.rb
CHANGED
@@ -38,7 +38,7 @@ describe LinkPreview do
|
|
38
38
|
it { should be_a(LinkPreview::Content) }
|
39
39
|
end
|
40
40
|
|
41
|
-
context 'open graph data', vcr: { cassette_name: 'ogp.me' } do
|
41
|
+
context 'with open graph data', vcr: { cassette_name: 'ogp.me' } do
|
42
42
|
let(:url) { 'http://ogp.me' }
|
43
43
|
|
44
44
|
it_behaves_like 'link_preview'
|
@@ -89,13 +89,13 @@ describe LinkPreview do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'should issue minimum number of requests' do
|
92
|
-
expect(http_client).to receive(:get).with('http://ogp.me/').ordered.and_call_original
|
92
|
+
expect(http_client).to receive(:get).with('http://ogp.me/', {}).ordered.and_call_original
|
93
93
|
content.title
|
94
|
-
expect(http_client).to receive(:get).with('http://ogp.me/logo.png').ordered.and_call_original
|
94
|
+
expect(http_client).to receive(:get).with('http://ogp.me/logo.png', {}).ordered.and_call_original
|
95
95
|
content.image_data
|
96
96
|
end
|
97
97
|
|
98
|
-
|
98
|
+
describe '#as_oembed' do
|
99
99
|
subject(:oembed) { content.as_oembed }
|
100
100
|
|
101
101
|
it 'should encode as link' do
|
@@ -112,7 +112,7 @@ describe LinkPreview do
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
context 'youtube oembed', vcr: { cassette_name: 'youtube' } do
|
115
|
+
context 'with youtube oembed', vcr: { cassette_name: 'youtube' } do
|
116
116
|
let(:url) { 'http://youtube.com/watch?v=M3r2XDceM6A' }
|
117
117
|
|
118
118
|
it_behaves_like 'link_preview'
|
@@ -163,15 +163,15 @@ describe LinkPreview do
|
|
163
163
|
end
|
164
164
|
|
165
165
|
it 'should issue minimum number of requests' do
|
166
|
-
expect(http_client).to receive(:get).with('https://www.youtube.com/oembed?scheme=https&format=json&url=http%3A%2F%2Fyoutube.com%2Fwatch%3Fv%3DM3r2XDceM6A').ordered.and_call_original
|
166
|
+
expect(http_client).to receive(:get).with('https://www.youtube.com/oembed?scheme=https&format=json&url=http%3A%2F%2Fyoutube.com%2Fwatch%3Fv%3DM3r2XDceM6A', {}).ordered.and_call_original
|
167
167
|
content.title
|
168
|
-
expect(http_client).to receive(:get).with('http://youtube.com/watch?v=M3r2XDceM6A').ordered.and_call_original
|
168
|
+
expect(http_client).to receive(:get).with('http://youtube.com/watch?v=M3r2XDceM6A', {}).ordered.and_call_original
|
169
169
|
content.description
|
170
|
-
expect(http_client).to receive(:get).with('https://i.ytimg.com/vi/M3r2XDceM6A/hqdefault.jpg').ordered.and_call_original
|
170
|
+
expect(http_client).to receive(:get).with('https://i.ytimg.com/vi/M3r2XDceM6A/hqdefault.jpg', {}).ordered.and_call_original
|
171
171
|
content.image_data
|
172
172
|
end
|
173
173
|
|
174
|
-
|
174
|
+
describe '#as_oembed' do
|
175
175
|
subject(:oembed) { content.as_oembed }
|
176
176
|
|
177
177
|
it 'should proxy oembed content' do
|
@@ -196,7 +196,7 @@ describe LinkPreview do
|
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
199
|
-
context 'kaltura oembed', vcr: { cassette_name: 'kaltura' } do
|
199
|
+
context 'with kaltura oembed', vcr: { cassette_name: 'kaltura' } do
|
200
200
|
let(:url) { 'http://videos.kaltura.com/oembed?url=http%3A%2F%2Fvideos.kaltura.com%2Fmedia%2F%2Fid%2F1_abxlxlll&playerId=3073841&entryId=1_abxlxlll' }
|
201
201
|
let(:options) { { width: 420 } }
|
202
202
|
|
@@ -248,16 +248,16 @@ describe LinkPreview do
|
|
248
248
|
end
|
249
249
|
|
250
250
|
it 'should issue minimum number of requests' do
|
251
|
-
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
|
251
|
+
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', width: 420).ordered.and_call_original
|
252
252
|
content.title
|
253
|
-
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
|
253
|
+
expect(http_client).to receive(:get).with('http://cdnbakmi.kaltura.com/p/811441/sp/81144100/thumbnail/entry_id/1_abxlxlll/version/100012/width//height/', width: 420).ordered.and_call_original
|
254
254
|
content.image_data
|
255
|
-
expect(http_client).to receive(:get).with('http://videos.kaltura.com/media//id/1_abxlxlll').ordered.and_call_original
|
255
|
+
expect(http_client).to receive(:get).with('http://videos.kaltura.com/media//id/1_abxlxlll', width: 420).ordered.and_call_original
|
256
256
|
content.description
|
257
257
|
end
|
258
258
|
end
|
259
259
|
|
260
|
-
context 'sliderocket oembed discovery', vcr: { cassette_name: 'sliderocket' } do
|
260
|
+
context 'with sliderocket oembed discovery', vcr: { cassette_name: 'sliderocket' } do
|
261
261
|
let(:url) { 'http://portal.sliderocket.com/SlideRocket-Presentations/Hoshyar-Foundation' }
|
262
262
|
let(:options) { { width: 420 } }
|
263
263
|
|
@@ -309,15 +309,15 @@ describe LinkPreview do
|
|
309
309
|
end
|
310
310
|
|
311
311
|
it 'should issue minimum number of requests' do
|
312
|
-
expect(http_client).to receive(:get).with('http://portal.sliderocket.com/SlideRocket-Presentations/Hoshyar-Foundation').ordered.and_call_original
|
312
|
+
expect(http_client).to receive(:get).with('http://portal.sliderocket.com/SlideRocket-Presentations/Hoshyar-Foundation', width: 420).ordered.and_call_original
|
313
313
|
content.title
|
314
|
-
expect(http_client).to receive(:get).with('http://cdn.sliderocket.com/thumbnails/4/43/43b475a4-192e-455e-832f-4a40697d8d25.jpg').ordered.and_call_original
|
314
|
+
expect(http_client).to receive(:get).with('http://cdn.sliderocket.com/thumbnails/4/43/43b475a4-192e-455e-832f-4a40697d8d25.jpg', width: 420).ordered.and_call_original
|
315
315
|
content.image_data
|
316
|
-
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
|
316
|
+
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', width: 420).ordered.and_call_original
|
317
317
|
content.as_oembed
|
318
318
|
end
|
319
319
|
|
320
|
-
|
320
|
+
describe '#as_oembed' do
|
321
321
|
subject(:oembed) { content.as_oembed }
|
322
322
|
|
323
323
|
it 'should proxy oembed content' do
|
@@ -338,7 +338,7 @@ describe LinkPreview do
|
|
338
338
|
end
|
339
339
|
end
|
340
340
|
|
341
|
-
context 'html data with unescaped html', vcr: { cassette_name: 'support.apple.com' } do
|
341
|
+
context 'with html data with unescaped html', vcr: { cassette_name: 'support.apple.com' } do
|
342
342
|
let(:url) { 'http://support.apple.com/kb/HT5642' }
|
343
343
|
|
344
344
|
it_behaves_like 'link_preview'
|
@@ -389,12 +389,12 @@ describe LinkPreview do
|
|
389
389
|
end
|
390
390
|
|
391
391
|
it 'should issue minimum number of requests' do
|
392
|
-
expect(http_client).to receive(:get).with('http://support.apple.com/kb/HT5642').ordered.and_call_original
|
392
|
+
expect(http_client).to receive(:get).with('http://support.apple.com/kb/HT5642', {}).ordered.and_call_original
|
393
393
|
content.title
|
394
394
|
content.image_data
|
395
395
|
end
|
396
396
|
|
397
|
-
|
397
|
+
describe '#as_oembed' do
|
398
398
|
subject(:oembed) { content.as_oembed }
|
399
399
|
|
400
400
|
it 'should convert to oembed link' do
|
@@ -410,7 +410,7 @@ describe LinkPreview do
|
|
410
410
|
end
|
411
411
|
end
|
412
412
|
|
413
|
-
context 'image data', vcr: { cassette_name: 'ggp.png' } do
|
413
|
+
context 'with image data', vcr: { cassette_name: 'ggp.png' } do
|
414
414
|
let(:url) { 'http://www.golden-gate-park.com/wp-content/uploads/2011/02/Golden_Gate_Park_Logo_Header.png' }
|
415
415
|
|
416
416
|
it_behaves_like 'link_preview'
|
@@ -461,7 +461,7 @@ describe LinkPreview do
|
|
461
461
|
end
|
462
462
|
|
463
463
|
# FIXME: should convert to photo via paperclip
|
464
|
-
|
464
|
+
describe '#as_oembed' do
|
465
465
|
subject(:oembed) { content.as_oembed }
|
466
466
|
|
467
467
|
it 'should convert to oembed link' do
|
@@ -477,18 +477,18 @@ describe LinkPreview do
|
|
477
477
|
end
|
478
478
|
end
|
479
479
|
|
480
|
-
context 'youtube oembed 404', vcr: { cassette_name: 'youtube 404' } do
|
480
|
+
context 'with youtube oembed 404', vcr: { cassette_name: 'youtube 404' } do
|
481
481
|
let(:url) { 'http://youtube.com/watch?v=1' }
|
482
482
|
|
483
483
|
it_behaves_like 'link_preview'
|
484
484
|
it { should_not be_found }
|
485
485
|
it 'should issue minimum number of requests' do
|
486
|
-
expect(http_client).to receive(:get).with('https://www.youtube.com/oembed?scheme=https&format=json&url=http%3A%2F%2Fyoutube.com%2Fwatch%3Fv%3D1').ordered.and_call_original
|
487
|
-
expect(http_client).to receive(:get).with('http://youtube.com/watch?v=1').ordered.and_call_original
|
486
|
+
expect(http_client).to receive(:get).with('https://www.youtube.com/oembed?scheme=https&format=json&url=http%3A%2F%2Fyoutube.com%2Fwatch%3Fv%3D1', {}).ordered.and_call_original
|
487
|
+
expect(http_client).to receive(:get).with('http://youtube.com/watch?v=1', {}).ordered.and_call_original
|
488
488
|
content.title
|
489
489
|
end
|
490
490
|
|
491
|
-
|
491
|
+
describe '#as_oembed' do
|
492
492
|
subject(:oembed) { content.as_oembed }
|
493
493
|
it 'should return basic oembed' do
|
494
494
|
should == {
|
@@ -502,7 +502,7 @@ describe LinkPreview do
|
|
502
502
|
end
|
503
503
|
end
|
504
504
|
|
505
|
-
context 'kaltura opengraph', vcr: { cassette_name: 'kaltura_opengraph' } do
|
505
|
+
context 'with kaltura opengraph', vcr: { cassette_name: 'kaltura_opengraph' } do
|
506
506
|
let(:url) { 'https://media.mediaspace.kaltura.com/media/Despicable+Me/0_w2zsofdj/6065172' }
|
507
507
|
|
508
508
|
it_behaves_like 'link_preview'
|
@@ -553,14 +553,14 @@ describe LinkPreview do
|
|
553
553
|
end
|
554
554
|
|
555
555
|
it 'should issue minimum number of requests' do
|
556
|
-
expect(http_client).to receive(:get).with('https://media.mediaspace.kaltura.com/media/Despicable+Me/0_w2zsofdj/6065172').ordered.and_call_original
|
556
|
+
expect(http_client).to receive(:get).with('https://media.mediaspace.kaltura.com/media/Despicable+Me/0_w2zsofdj/6065172', {}).ordered.and_call_original
|
557
557
|
content.title
|
558
|
-
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
|
558
|
+
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
|
559
559
|
content.image_data
|
560
560
|
content.description
|
561
561
|
end
|
562
562
|
|
563
|
-
|
563
|
+
describe '#as_oembed' do
|
564
564
|
subject(:oembed) { content.as_oembed }
|
565
565
|
|
566
566
|
it 'should convert opengraph to oembed' do
|
@@ -580,7 +580,7 @@ describe LinkPreview do
|
|
580
580
|
end
|
581
581
|
end
|
582
582
|
|
583
|
-
context 'elasticsearch', vcr: { cassette_name: 'elasticsearch' } do
|
583
|
+
context 'with elasticsearch', vcr: { cassette_name: 'elasticsearch' } do
|
584
584
|
let(:url) { 'http://www.elasticsearch.org/overview/hadoop' }
|
585
585
|
|
586
586
|
it_behaves_like 'link_preview'
|
@@ -630,7 +630,7 @@ describe LinkPreview do
|
|
630
630
|
it { should == 'blank_hero.png' }
|
631
631
|
end
|
632
632
|
|
633
|
-
|
633
|
+
describe '#as_oembed' do
|
634
634
|
subject(:oembed) { content.as_oembed }
|
635
635
|
|
636
636
|
it 'should encode as link' do
|
@@ -647,7 +647,7 @@ describe LinkPreview do
|
|
647
647
|
end
|
648
648
|
end
|
649
649
|
|
650
|
-
context 'resource with bad utf-8 in response', vcr: { cassette_name: 'bad_utf8' } do
|
650
|
+
context 'with resource with bad utf-8 in response', vcr: { cassette_name: 'bad_utf8' } do
|
651
651
|
let(:url) { 'http://s.taobao.com' }
|
652
652
|
|
653
653
|
it_behaves_like 'link_preview'
|
@@ -683,8 +683,9 @@ describe LinkPreview do
|
|
683
683
|
end
|
684
684
|
end
|
685
685
|
|
686
|
-
context 'kaltura with html5 response', vcr: { cassette_name: '
|
686
|
+
context 'with kaltura with html5 video response fallback', vcr: { cassette_name: 'kaltura_html5_video' } do
|
687
687
|
let(:url) { 'http://player.kaltura.com/modules/KalturaSupport/components/share/Share.html' }
|
688
|
+
let(:options) { { width: 600 } }
|
688
689
|
|
689
690
|
it_behaves_like 'link_preview'
|
690
691
|
|
@@ -733,10 +734,164 @@ describe LinkPreview do
|
|
733
734
|
it { should == '400' }
|
734
735
|
end
|
735
736
|
|
736
|
-
|
737
|
+
describe '#as_oembed' do
|
737
738
|
subject(:oembed) { content.as_oembed }
|
738
739
|
|
739
|
-
it 'should convert opengraph to oembed' do
|
740
|
+
it 'should issue minimum number of requests convert opengraph to oembed' do
|
741
|
+
expect(http_client).to receive(:get).with('http://player.kaltura.com/modules/KalturaSupport/components/share/Share.html', width: 600).ordered.and_call_original
|
742
|
+
expect(http_client).to receive(:get).with('https://cdnapisec.kaltura.com/p/243342/sp/24334200/embedIframeJs/uiconf_id/28685261/partner_id/243342?iframeembed=true&playerId=kaltura_player&entry_id=1_sf5ovm7u', width: 600).ordered.and_return(Faraday::Response.new(status: 404))
|
743
|
+
expect(http_client).to receive(:get).with('http://cdnbakmi.kaltura.com/p/243342/sp/24334200/thumbnail/entry_id/1_sf5ovm7u/version/100003/width/400', width: 600).ordered.and_call_original
|
744
|
+
should == {
|
745
|
+
version: '1.0',
|
746
|
+
provider_name: %(Kaltura),
|
747
|
+
provider_url: 'http://player.kaltura.com',
|
748
|
+
title: %(Kaltura Player: Share Plugin example),
|
749
|
+
description: %(Kaltura Player: Share plugin demonstrates the ease of which social share can be configured with the kaltura player toolkit.),
|
750
|
+
type: 'video',
|
751
|
+
thumbnail_url: 'http://cdnbakmi.kaltura.com/p/243342/sp/24334200/thumbnail/entry_id/1_sf5ovm7u/version/100003/width/400',
|
752
|
+
html: %(<video width="600" height="338" controls><source src="https://cdnapisec.kaltura.com/p/243342/sp/24334200/playManifest/entryId/1_sf5ovm7u/flavorId/1_d2uwy7vv/format/url/protocol/http/a.mp4" type="video/mp4" /></video>),
|
753
|
+
width: 600,
|
754
|
+
height: 338
|
755
|
+
}
|
756
|
+
end
|
757
|
+
end
|
758
|
+
end
|
759
|
+
|
760
|
+
context 'with kaltura with html5 embed response', vcr: { cassette_name: 'kaltura_html5_embed' } do
|
761
|
+
let(:url) { 'http://player.kaltura.com/modules/KalturaSupport/components/share/Share.html' }
|
762
|
+
|
763
|
+
it_behaves_like 'link_preview'
|
764
|
+
|
765
|
+
describe '#url' do
|
766
|
+
subject { content.url }
|
767
|
+
it { should == url }
|
768
|
+
end
|
769
|
+
|
770
|
+
describe '#title' do
|
771
|
+
subject { content.title }
|
772
|
+
it { should == %(Kaltura Player: Share Plugin example) }
|
773
|
+
end
|
774
|
+
|
775
|
+
describe '#description' do
|
776
|
+
subject { content.description }
|
777
|
+
it { should == %(Kaltura Player: Share plugin demonstrates the ease of which social share can be configured with the kaltura player toolkit.) }
|
778
|
+
end
|
779
|
+
|
780
|
+
describe '#site_name' do
|
781
|
+
subject { content.site_name }
|
782
|
+
it { should == 'Kaltura' }
|
783
|
+
end
|
784
|
+
|
785
|
+
describe '#site_url' do
|
786
|
+
subject { content.site_url }
|
787
|
+
it { should == 'http://player.kaltura.com' }
|
788
|
+
end
|
789
|
+
|
790
|
+
describe '#image_url' do
|
791
|
+
subject { content.image_url }
|
792
|
+
it { should == 'http://cdnbakmi.kaltura.com/p/243342/sp/24334200/thumbnail/entry_id/1_sf5ovm7u/version/100003/width/400' }
|
793
|
+
end
|
794
|
+
|
795
|
+
describe '#image_data' do
|
796
|
+
subject { content.image_data }
|
797
|
+
it { should be_a(StringIO) }
|
798
|
+
end
|
799
|
+
|
800
|
+
describe '#image_content_type' do
|
801
|
+
subject { content.image_content_type }
|
802
|
+
it { should == 'image/jpeg' }
|
803
|
+
end
|
804
|
+
|
805
|
+
describe '#image_file_name' do
|
806
|
+
subject { content.image_file_name }
|
807
|
+
it { should == '400' }
|
808
|
+
end
|
809
|
+
|
810
|
+
describe '#as_oembed' do
|
811
|
+
subject(:oembed) { content.as_oembed }
|
812
|
+
|
813
|
+
it 'should issue minimum number of requests convert opengraph to oembed' do
|
814
|
+
expect(http_client).to receive(:get).with('http://player.kaltura.com/modules/KalturaSupport/components/share/Share.html', {}).ordered.and_call_original
|
815
|
+
expect(http_client).to receive(:get).with('https://cdnapisec.kaltura.com/p/243342/sp/24334200/embedIframeJs/uiconf_id/28685261/partner_id/243342?iframeembed=true&playerId=kaltura_player&entry_id=1_sf5ovm7u', {}).ordered.and_call_original
|
816
|
+
expect(http_client).to receive(:get).with('http://cdnbakmi.kaltura.com/p/243342/sp/24334200/thumbnail/entry_id/1_sf5ovm7u/version/100003/width/400', {}).ordered.and_call_original
|
817
|
+
should == {
|
818
|
+
version: '1.0',
|
819
|
+
provider_name: %(Kaltura),
|
820
|
+
provider_url: 'http://player.kaltura.com',
|
821
|
+
title: %(Kaltura Player: Share Plugin example),
|
822
|
+
description: %(Kaltura Player: Share plugin demonstrates the ease of which social share can be configured with the kaltura player toolkit.),
|
823
|
+
type: 'video',
|
824
|
+
thumbnail_url: 'http://cdnbakmi.kaltura.com/p/243342/sp/24334200/thumbnail/entry_id/1_sf5ovm7u/version/100003/width/400',
|
825
|
+
html: content.sources[:opengraph_embed][:html],
|
826
|
+
width: 560,
|
827
|
+
height: 395
|
828
|
+
}
|
829
|
+
end
|
830
|
+
end
|
831
|
+
end
|
832
|
+
|
833
|
+
context 'with kaltura with html5 video response with configuration ignore_opengraph_video_type_html', vcr: { cassette_name: 'kaltura_html5_ignore_video_type_html' } do
|
834
|
+
let(:url) { 'http://player.kaltura.com/modules/KalturaSupport/components/share/Share.html' }
|
835
|
+
|
836
|
+
around do |example|
|
837
|
+
LinkPreview.configuration.ignore_opengraph_video_type_html = true
|
838
|
+
example.run
|
839
|
+
LinkPreview.configuration.ignore_opengraph_video_type_html = nil
|
840
|
+
end
|
841
|
+
|
842
|
+
it_behaves_like 'link_preview'
|
843
|
+
|
844
|
+
describe '#url' do
|
845
|
+
subject { content.url }
|
846
|
+
it { should == url }
|
847
|
+
end
|
848
|
+
|
849
|
+
describe '#title' do
|
850
|
+
subject { content.title }
|
851
|
+
it { should == %(Kaltura Player: Share Plugin example) }
|
852
|
+
end
|
853
|
+
|
854
|
+
describe '#description' do
|
855
|
+
subject { content.description }
|
856
|
+
it { should == %(Kaltura Player: Share plugin demonstrates the ease of which social share can be configured with the kaltura player toolkit.) }
|
857
|
+
end
|
858
|
+
|
859
|
+
describe '#site_name' do
|
860
|
+
subject { content.site_name }
|
861
|
+
it { should == 'Kaltura' }
|
862
|
+
end
|
863
|
+
|
864
|
+
describe '#site_url' do
|
865
|
+
subject { content.site_url }
|
866
|
+
it { should == 'http://player.kaltura.com' }
|
867
|
+
end
|
868
|
+
|
869
|
+
describe '#image_url' do
|
870
|
+
subject { content.image_url }
|
871
|
+
it { should == 'http://cdnbakmi.kaltura.com/p/243342/sp/24334200/thumbnail/entry_id/1_sf5ovm7u/version/100003/width/400' }
|
872
|
+
end
|
873
|
+
|
874
|
+
describe '#image_data' do
|
875
|
+
subject { content.image_data }
|
876
|
+
it { should be_a(StringIO) }
|
877
|
+
end
|
878
|
+
|
879
|
+
describe '#image_content_type' do
|
880
|
+
subject { content.image_content_type }
|
881
|
+
it { should == 'image/jpeg' }
|
882
|
+
end
|
883
|
+
|
884
|
+
describe '#image_file_name' do
|
885
|
+
subject { content.image_file_name }
|
886
|
+
it { should == '400' }
|
887
|
+
end
|
888
|
+
|
889
|
+
describe '#as_oembed' do
|
890
|
+
subject(:oembed) { content.as_oembed }
|
891
|
+
|
892
|
+
it 'should issue minimum number of requests convert opengraph to oembed' do
|
893
|
+
expect(http_client).to receive(:get).with('http://player.kaltura.com/modules/KalturaSupport/components/share/Share.html', {}).ordered.and_call_original
|
894
|
+
expect(http_client).to receive(:get).with('http://cdnbakmi.kaltura.com/p/243342/sp/24334200/thumbnail/entry_id/1_sf5ovm7u/version/100003/width/400', {}).ordered.and_call_original
|
740
895
|
should == {
|
741
896
|
version: '1.0',
|
742
897
|
provider_name: %(Kaltura),
|
@@ -752,4 +907,86 @@ describe LinkPreview do
|
|
752
907
|
end
|
753
908
|
end
|
754
909
|
end
|
910
|
+
|
911
|
+
context 'with flickr with oembed response', vcr: { cassette_name: 'flickr_oembed' } do
|
912
|
+
let(:url) { 'https://www.flickr.com/photos/bees/2341623661' }
|
913
|
+
let(:options) { { width: 600 } }
|
914
|
+
|
915
|
+
it_behaves_like 'link_preview'
|
916
|
+
|
917
|
+
describe '#url' do
|
918
|
+
subject { content.url }
|
919
|
+
it { should == 'https://farm4.staticflickr.com/3123/2341623661_7c99f48bbf_n.jpg' }
|
920
|
+
end
|
921
|
+
|
922
|
+
describe '#title' do
|
923
|
+
subject { content.title }
|
924
|
+
it { should == %(ZB8T0193) }
|
925
|
+
end
|
926
|
+
|
927
|
+
describe '#description' do
|
928
|
+
subject { content.description }
|
929
|
+
it { should == %(Explore bees's photos on Flickr. bees has uploaded 10229 photos to Flickr.) }
|
930
|
+
end
|
931
|
+
|
932
|
+
describe '#site_name' do
|
933
|
+
subject { content.site_name }
|
934
|
+
it { should == 'Flickr' }
|
935
|
+
end
|
936
|
+
|
937
|
+
describe '#site_url' do
|
938
|
+
subject { content.site_url }
|
939
|
+
it { should == 'https://www.flickr.com/' }
|
940
|
+
end
|
941
|
+
|
942
|
+
describe '#image_url' do
|
943
|
+
subject { content.image_url }
|
944
|
+
it { should == 'https://farm4.staticflickr.com/3123/2341623661_7c99f48bbf_q.jpg' }
|
945
|
+
end
|
946
|
+
|
947
|
+
describe '#image_data' do
|
948
|
+
subject { content.image_data }
|
949
|
+
it { should be_a(StringIO) }
|
950
|
+
end
|
951
|
+
|
952
|
+
describe '#image_content_type' do
|
953
|
+
subject { content.image_content_type }
|
954
|
+
it { should == 'image/jpeg' }
|
955
|
+
end
|
956
|
+
|
957
|
+
describe '#image_file_name' do
|
958
|
+
subject { content.image_file_name }
|
959
|
+
it { should == '2341623661_7c99f48bbf_q.jpg' }
|
960
|
+
end
|
961
|
+
|
962
|
+
describe '#as_oembed' do
|
963
|
+
subject(:oembed) { content.as_oembed }
|
964
|
+
|
965
|
+
it 'should convert opengraph to oembed' do
|
966
|
+
should == {
|
967
|
+
author_name: "\u202e\u202d\u202cbees\u202c",
|
968
|
+
author_url: 'https://www.flickr.com/photos/bees/',
|
969
|
+
cache_age: 3600,
|
970
|
+
description: "Explore bees's photos on Flickr. bees has uploaded 10229 photos to Flickr.",
|
971
|
+
flickr_type: 'photo',
|
972
|
+
height: 213,
|
973
|
+
html: %(<a data-flickr-embed="true" href="https://www.flickr.com/photos/bees/2341623661/" title="ZB8T0193 by \u202e\u202d\u202cbees\u202c, on Flickr"><img src="https://farm4.staticflickr.com/3123/2341623661_7c99f48bbf_n.jpg" width="320" height="213" alt="ZB8T0193"></a><script async src="https://embedr.flickr.com/assets/client-code.js" charset="utf-8"></script>),
|
974
|
+
license: 'All Rights Reserved',
|
975
|
+
license_id: 0,
|
976
|
+
provider_name: 'Flickr',
|
977
|
+
provider_url: 'https://www.flickr.com/',
|
978
|
+
thumbnail_height: 150,
|
979
|
+
thumbnail_url: 'https://farm4.staticflickr.com/3123/2341623661_7c99f48bbf_q.jpg',
|
980
|
+
thumbnail_width: 150,
|
981
|
+
title: 'ZB8T0193',
|
982
|
+
type: 'photo',
|
983
|
+
url: 'https://farm4.staticflickr.com/3123/2341623661_7c99f48bbf_n.jpg',
|
984
|
+
version: '1.0',
|
985
|
+
web_page: 'https://www.flickr.com/photos/bees/2341623661/',
|
986
|
+
web_page_short_url: 'https://flic.kr/p/4yVr8K',
|
987
|
+
width: '320'
|
988
|
+
}
|
989
|
+
end
|
990
|
+
end
|
991
|
+
end
|
755
992
|
end
|