onebox 1.4.4 → 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/onebox/engine/whitelisted_generic_onebox.rb +2 -0
- data/lib/onebox/engine/youtube_onebox.rb +95 -19
- data/lib/onebox/version.rb +1 -1
- data/spec/fixtures/youtube-channel.response +5446 -0
- data/spec/lib/onebox/engine/youtube_onebox_spec.rb +64 -6
- metadata +5 -5
- data/spec/fixtures/youtube-json.response +0 -1
@@ -3,15 +3,35 @@ require 'spec_helper'
|
|
3
3
|
describe Onebox::Engine::YoutubeOnebox do
|
4
4
|
before do
|
5
5
|
fake("http://www.youtube.com/watch?feature=player_embedded&v=21Lk4YiASMo", response("youtube"))
|
6
|
-
fake("
|
6
|
+
fake("https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ", response("youtube-channel"))
|
7
7
|
end
|
8
8
|
|
9
9
|
it "adds wmode=opaque" do
|
10
|
-
Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo')
|
10
|
+
Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo')
|
11
|
+
.to_s.should match(/wmode=opaque/)
|
11
12
|
end
|
12
13
|
|
13
|
-
it "rewrites URLs to be
|
14
|
-
|
14
|
+
it "rewrites URLs for videos to be HTTPS" do
|
15
|
+
# match: plain HTTP and protocol agnostic
|
16
|
+
regex = /(http:|["']\/\/)/
|
17
|
+
|
18
|
+
Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo')
|
19
|
+
.to_s.should_not match(regex)
|
20
|
+
Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo')
|
21
|
+
.placeholder_html.should_not match(regex)
|
22
|
+
Onebox.preview('https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ')
|
23
|
+
.to_s.should_not match(regex)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can onebox a channel page" do
|
27
|
+
Onebox.preview('https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ')
|
28
|
+
.to_s.should match(/Google Chrome/)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "can onebox a playlist" do
|
32
|
+
pending('no opengraph on playlists, needs special handling')
|
33
|
+
|
34
|
+
Onebox.preview('https://www.youtube.com/playlist?list=PL5308B2E5749D1696').to_s
|
15
35
|
end
|
16
36
|
|
17
37
|
it "does not make HTTP requests unless necessary" do
|
@@ -21,11 +41,49 @@ describe Onebox::Engine::YoutubeOnebox do
|
|
21
41
|
end
|
22
42
|
|
23
43
|
it "does not fail if we cannot get the video ID from the URL" do
|
24
|
-
|
44
|
+
# TODO this test no longer makes sense - the video ID is successfully retrieved and no fakeweb request is made
|
45
|
+
Onebox.preview('http://www.youtube.com/watch?feature=player_embedded&v=21Lk4YiASMo')
|
46
|
+
.to_s.should match(/embed/)
|
25
47
|
end
|
26
48
|
|
27
49
|
it "returns an image as the placeholder" do
|
28
|
-
Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo')
|
50
|
+
Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo')
|
51
|
+
.placeholder_html.should match(/<img/)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "passes the playlist ID through" do
|
55
|
+
Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&list=UUQau-O2C0kGJpR3_CHBTGbw&index=1')
|
56
|
+
.to_s.should match(/UUQau-O2C0kGJpR3_CHBTGbw/)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "filters out nonsense parameters" do
|
60
|
+
Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&potential[]=exploit&potential[]=fun')
|
61
|
+
.to_s.should_not match(/potential|exploit|fun/)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "converts time strings into a &start= parameter" do
|
65
|
+
Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&start=3782')
|
66
|
+
.to_s.should match(/start=3782/)
|
67
|
+
Onebox.preview('https://www.youtube.com/watch?start=1h3m2s&v=21Lk4YiASMo')
|
68
|
+
.to_s.should match(/start=3782/)
|
69
|
+
Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&t=1h3m2s')
|
70
|
+
.to_s.should match(/start=3782/)
|
71
|
+
Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&start=1h3m2s')
|
72
|
+
.to_s.should match(/start=3782/)
|
73
|
+
Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo#t=1h3m2s')
|
74
|
+
.to_s.should match(/start=3782/)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "allows both start and end" do
|
78
|
+
preview = Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&start=2m&end=3m').to_s
|
79
|
+
preview.should match(/start=120/)
|
80
|
+
preview.should match(/end=180/)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "permits looping videos" do
|
84
|
+
preview = Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo&loop').to_s
|
85
|
+
preview.should match(/loop=1/)
|
86
|
+
preview.should match(/playlist=21Lk4YiASMo/)
|
29
87
|
end
|
30
88
|
end
|
31
89
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onebox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joanna Zeta
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-08-
|
13
|
+
date: 2014-08-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -284,7 +284,7 @@ files:
|
|
284
284
|
- spec/fixtures/video.response
|
285
285
|
- spec/fixtures/wikipedia.response
|
286
286
|
- spec/fixtures/wikipediaredirected.response
|
287
|
-
- spec/fixtures/youtube-
|
287
|
+
- spec/fixtures/youtube-channel.response
|
288
288
|
- spec/fixtures/youtube.response
|
289
289
|
- spec/lib/onebox/engine/amazon_onebox_spec.rb
|
290
290
|
- spec/lib/onebox/engine/audio_onebox_spec.rb
|
@@ -342,7 +342,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
342
342
|
version: '0'
|
343
343
|
requirements: []
|
344
344
|
rubyforge_project:
|
345
|
-
rubygems_version: 2.
|
345
|
+
rubygems_version: 2.2.2
|
346
346
|
signing_key:
|
347
347
|
specification_version: 4
|
348
348
|
summary: A gem for turning URLs into previews.
|
@@ -361,7 +361,7 @@ test_files:
|
|
361
361
|
- spec/fixtures/video.response
|
362
362
|
- spec/fixtures/wikipedia.response
|
363
363
|
- spec/fixtures/wikipediaredirected.response
|
364
|
-
- spec/fixtures/youtube-
|
364
|
+
- spec/fixtures/youtube-channel.response
|
365
365
|
- spec/fixtures/youtube.response
|
366
366
|
- spec/lib/onebox/engine/amazon_onebox_spec.rb
|
367
367
|
- spec/lib/onebox/engine/audio_onebox_spec.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
{"author_url": "http:\/\/www.youtube.com\/user\/korotto5810", "version": "1.0", "title": "96neko - orange", "author_name": "korotto5810", "provider_url": "http:\/\/www.youtube.com\/", "thumbnail_width": 480, "width": 480, "provider_name": "YouTube", "thumbnail_height": 360, "height": 270, "type": "video", "thumbnail_url": "http:\/\/i1.ytimg.com\/vi\/21Lk4YiASMo\/hqdefault.jpg", "html": "\u003ciframe width=\"480\" height=\"270\" src=\"http:\/\/www.youtube.com\/embed\/21Lk4YiASMo?feature=oembed\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e"}
|