onebox 1.6.2 → 1.6.3
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/audioboom_onebox.rb +1 -1
- data/lib/onebox/engine/giphy_onebox.rb +1 -1
- data/lib/onebox/engine/imgur_onebox.rb +5 -5
- data/lib/onebox/engine/soundcloud_onebox.rb +1 -1
- data/lib/onebox/engine/vimeo_onebox.rb +1 -1
- data/lib/onebox/engine/youtube_onebox.rb +13 -5
- data/lib/onebox/helpers.rb +4 -0
- data/lib/onebox/version.rb +1 -1
- data/spec/fixtures/youtube-json.response +1 -0
- data/spec/fixtures/youtube-list-json.response +1 -0
- data/spec/lib/onebox/engine/youtube_onebox_spec.rb +9 -2
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c058240b30efa1a0c9228acb70ab03469bbcda8
|
4
|
+
data.tar.gz: 2c3ac99c67db56e5da345cb5dd5e836ba432db9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcf90694c1049cf40c59cb4aac01b9aec75629ccd20fc92d30bab5a6035c831230f9fa43c2676fa6bd9adfc07d2d1901066d8ed5b1f825224fd06bea96b1c6e9
|
7
|
+
data.tar.gz: 22cf1597307e68d2bd242b712f23da3f2f851279c821074da8c5a2be4611559bb84a42467fecf08fba2897a6cbcb94e7321f1b6c028cd1256f1823d3ba4a27d5
|
@@ -13,7 +13,7 @@ module Onebox
|
|
13
13
|
# we want the image to have the same dimensions as the embedded html
|
14
14
|
|
15
15
|
<<-HTML
|
16
|
-
<img src="#{oembed[:thumbnail_url]}" style="max-width: #{oembed[:width]}px; max-height: #{oembed[:height]}px;">
|
16
|
+
<img src="#{oembed[:thumbnail_url]}" style="max-width: #{oembed[:width]}px; max-height: #{oembed[:height]}px;" #{Helpers.title_attr(oembed)}>
|
17
17
|
HTML
|
18
18
|
end
|
19
19
|
|
@@ -12,7 +12,7 @@ module Onebox
|
|
12
12
|
|
13
13
|
<<-HTML
|
14
14
|
<a href="#{oembed[:url]}" target="_blank">
|
15
|
-
<img src="#{oembed[:image]}" width="#{oembed[:width]}" height="#{oembed[:height]}">
|
15
|
+
<img src="#{oembed[:image]}" width="#{oembed[:width]}" height="#{oembed[:height]}" #{Helpers.title_attr(oembed)}>
|
16
16
|
</a>
|
17
17
|
HTML
|
18
18
|
end
|
@@ -9,16 +9,16 @@ module Onebox
|
|
9
9
|
|
10
10
|
def to_html
|
11
11
|
imgur_data = get_imgur_data
|
12
|
-
return "<video width='#{imgur_data[:"video:width"]}' height='#{imgur_data[:"video:height"]}' controls autoplay loop><source src='#{imgur_data[:"video:secure_url"]}' type='video/mp4'><source src='#{imgur_data[:"video:secure_url"].gsub('mp4', 'webm')}' type='video/webm'></video>" if imgur_data[:"video:secure_url"]
|
13
|
-
return "<div class='onebox imgur-album'><a href='#{url}' target='_blank'><span class='outer-box' style='width:#{imgur_data[:"image:width"]}px'><span class='inner-box'><span class='album-title'>[Album] #{imgur_data[:title]}</span></span></span><img src='#{get_secure_link(imgur_data[:image])}'
|
14
|
-
return "<a href='#{url}' target='_blank'><img src='#{get_secure_link(imgur_data[:image])}' alt='Imgur' height='#{imgur_data[:"image:height"]}' width='#{imgur_data[:"image:width"]}'></a>" if imgur_data[:image]
|
12
|
+
return "<video width='#{imgur_data[:"video:width"]}' height='#{imgur_data[:"video:height"]}' #{Helpers.title_attr(imgur_data)} controls autoplay loop><source src='#{imgur_data[:"video:secure_url"]}' type='video/mp4'><source src='#{imgur_data[:"video:secure_url"].gsub('mp4', 'webm')}' type='video/webm'></video>" if imgur_data[:"video:secure_url"]
|
13
|
+
return "<div class='onebox imgur-album'><a href='#{url}' target='_blank'><span class='outer-box' style='width:#{imgur_data[:"image:width"]}px'><span class='inner-box'><span class='album-title'>[Album] #{imgur_data[:title]}</span></span></span><img src='#{get_secure_link(imgur_data[:image])}' #{Helpers.title_attr(imgur_data)} height='#{imgur_data[:"image:height"]}' width='#{imgur_data[:"image:width"]}'></a></div>" if is_album?
|
14
|
+
return "<a href='#{url}' target='_blank'><img src='#{get_secure_link(imgur_data[:image])}' #{Helpers.title_attr(imgur_data)} alt='Imgur' height='#{imgur_data[:"image:height"]}' width='#{imgur_data[:"image:width"]}'></a>" if imgur_data[:image]
|
15
15
|
return nil
|
16
16
|
end
|
17
17
|
|
18
18
|
def placeholder_html
|
19
19
|
imgur_data = get_imgur_data
|
20
|
-
return "<video width='#{imgur_data[:"video:width"]}' height='#{imgur_data[:"video:height"]}' controls autoplay loop><source src='#{imgur_data[:"video:secure_url"]}' type='video/mp4'><source src='#{imgur_data[:"video:secure_url"].gsub('mp4', 'webm')}' type='video/webm'></video>" if imgur_data[:"video:secure_url"]
|
21
|
-
return "<img src='#{get_secure_link(imgur_data[:image])}' alt='Imgur' height='#{imgur_data[:"image:height"]}' width='#{imgur_data[:"image:width"]}'>"
|
20
|
+
return "<video width='#{imgur_data[:"video:width"]}' height='#{imgur_data[:"video:height"]}' #{Helpers.title_attr(imgur_data)} controls autoplay loop><source src='#{imgur_data[:"video:secure_url"]}' type='video/mp4'><source src='#{imgur_data[:"video:secure_url"].gsub('mp4', 'webm')}' type='video/webm'></video>" if imgur_data[:"video:secure_url"]
|
21
|
+
return "<img src='#{get_secure_link(imgur_data[:image])}' #{Helpers.title_attr(imgur_data)} alt='Imgur' height='#{imgur_data[:"image:height"]}' width='#{imgur_data[:"image:width"]}'>"
|
22
22
|
return nil
|
23
23
|
end
|
24
24
|
|
@@ -9,7 +9,7 @@ module Onebox
|
|
9
9
|
|
10
10
|
def placeholder_html
|
11
11
|
oembed = get_oembed
|
12
|
-
"<img src='#{oembed[:thumbnail_url]}' width='#{oembed[:thumbnail_width]}' height='#{oembed[:thumbnail_height]}'>"
|
12
|
+
"<img src='#{oembed[:thumbnail_url]}' width='#{oembed[:thumbnail_width]}' height='#{oembed[:thumbnail_height]}' #{Helpers.title_attr(oembed)}>"
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_html
|
@@ -12,9 +12,9 @@ module Onebox
|
|
12
12
|
|
13
13
|
def placeholder_html
|
14
14
|
if video_id
|
15
|
-
"<img src='https://i.ytimg.com/vi/#{video_id}/hqdefault.jpg' width='#{WIDTH}' height='#{HEIGHT}'>"
|
15
|
+
"<img src='https://i.ytimg.com/vi/#{video_id}/hqdefault.jpg' width='#{WIDTH}' height='#{HEIGHT}' #{Helpers.title_attr(video_oembed_data)}>"
|
16
16
|
elsif list_id
|
17
|
-
"<img src='#{list_thumbnail_url}' width='#{WIDTH}' height='#{HEIGHT}'>"
|
17
|
+
"<img src='#{list_thumbnail_url}' width='#{WIDTH}' height='#{HEIGHT}' #{Helpers.title_attr(list_oembed_data)}>"
|
18
18
|
else
|
19
19
|
to_html
|
20
20
|
end
|
@@ -50,9 +50,7 @@ module Onebox
|
|
50
50
|
|
51
51
|
def video_title
|
52
52
|
@video_title ||= begin
|
53
|
-
|
54
|
-
data = Onebox::Helpers.symbolize_keys(::MultiJson.load(Onebox::Helpers.fetch_response(url).body))
|
55
|
-
data[:title]
|
53
|
+
video_oembed_data[:title]
|
56
54
|
rescue
|
57
55
|
nil
|
58
56
|
end
|
@@ -93,6 +91,16 @@ module Onebox
|
|
93
91
|
end
|
94
92
|
end
|
95
93
|
|
94
|
+
def video_oembed_data
|
95
|
+
url = "https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/watch?v=#{video_id}"
|
96
|
+
Onebox::Helpers.symbolize_keys(::MultiJson.load(Onebox::Helpers.fetch_response(url).body))
|
97
|
+
end
|
98
|
+
|
99
|
+
def list_oembed_data
|
100
|
+
url = "https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/playlist?list=#{list_id}"
|
101
|
+
Onebox::Helpers.symbolize_keys(::MultiJson.load(Onebox::Helpers.fetch_response(url).body))
|
102
|
+
end
|
103
|
+
|
96
104
|
def embed_params
|
97
105
|
p = {'feature' => 'oembed', 'wmode' => 'opaque'}
|
98
106
|
|
data/lib/onebox/helpers.rb
CHANGED
@@ -63,5 +63,9 @@ module Onebox
|
|
63
63
|
def self.truncate(string, length = 50)
|
64
64
|
string.size > length ? string[0..length] + "..." : string
|
65
65
|
end
|
66
|
+
|
67
|
+
def self.title_attr(meta)
|
68
|
+
(meta && !blank?(meta[:title])) ? "title='#{CGI.escapeHTML(meta[:title])}'" : ""
|
69
|
+
end
|
66
70
|
end
|
67
71
|
end
|
data/lib/onebox/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"type":"video","provider_url":"https:\/\/www.youtube.com\/","thumbnail_url":"https:\/\/i.ytimg.com\/vi\/21Lk4YiASMo\/hqdefault.jpg","author_name":"korotto5810","title":"96neko - orange","thumbnail_width":480,"width":480,"version":"1.0","html":"\u003ciframe width=\"480\" height=\"270\" src=\"https:\/\/www.youtube.com\/embed\/21Lk4YiASMo?feature=oembed\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e","thumbnail_height":360,"height":270,"author_url":"https:\/\/www.youtube.com\/user\/korotto5810","provider_name":"YouTube"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":"1.0","title":"The web is what you make of it","thumbnail_url":"https:\/\/i.ytimg.com\/vi\/R4vkVHijdQk\/hqdefault.jpg","type":"video","height":270,"thumbnail_height":360,"provider_name":"YouTube","provider_url":"https:\/\/www.youtube.com\/","author_name":"Google Chrome","width":480,"author_url":"https:\/\/www.youtube.com\/user\/googlechrome","html":"\u003ciframe width=\"480\" height=\"270\" src=\"https:\/\/www.youtube.com\/embed\/videoseries?list=PL5308B2E5749D1696\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e","thumbnail_width":480}
|
@@ -4,9 +4,10 @@ describe Onebox::Engine::YoutubeOnebox do
|
|
4
4
|
before do
|
5
5
|
fake("https://www.youtube.com/watch?feature=player_embedded&v=21Lk4YiASMo", response("youtube"))
|
6
6
|
fake("https://youtu.be/21Lk4YiASMo", response("youtube"))
|
7
|
-
fake("http://www.youtube.com/oembed?format=json&url=http://www.youtube.com/watch?v=21Lk4YiASMo", response("youtube"))
|
8
7
|
fake("https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ", response("youtube-channel"))
|
9
8
|
fake("https://www.youtube.com/playlist?list=PL5308B2E5749D1696", response("youtube-playlist"))
|
9
|
+
fake("https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/watch?v=21Lk4YiASMo", response("youtube-json"))
|
10
|
+
fake("https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/playlist?list=PL5308B2E5749D1696", response("youtube-list-json"))
|
10
11
|
end
|
11
12
|
|
12
13
|
it "adds wmode=opaque" do
|
@@ -28,7 +29,9 @@ describe Onebox::Engine::YoutubeOnebox do
|
|
28
29
|
|
29
30
|
it "can onebox a playlist" do
|
30
31
|
expect(Onebox.preview('https://www.youtube.com/playlist?list=PL5308B2E5749D1696').to_s).to match(/iframe/)
|
31
|
-
|
32
|
+
placeholder_html = Onebox.preview('https://www.youtube.com/playlist?list=PL5308B2E5749D1696').placeholder_html
|
33
|
+
expect(placeholder_html).to match(/<img/)
|
34
|
+
expect(placeholder_html).to include("The web is what you make of it")
|
32
35
|
end
|
33
36
|
|
34
37
|
it "does not make HTTP requests unless necessary" do
|
@@ -73,4 +76,8 @@ describe Onebox::Engine::YoutubeOnebox do
|
|
73
76
|
preview.to match(/loop=1/)
|
74
77
|
preview.to match(/playlist=21Lk4YiASMo/)
|
75
78
|
end
|
79
|
+
|
80
|
+
it "includes title in preview" do
|
81
|
+
expect(Onebox.preview("https://youtu.be/21Lk4YiASMo").placeholder_html).to include("96neko - orange")
|
82
|
+
end
|
76
83
|
end
|
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.6.
|
4
|
+
version: 1.6.3
|
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: 2016-
|
13
|
+
date: 2016-12-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -372,6 +372,8 @@ files:
|
|
372
372
|
- spec/fixtures/youku-meta.response
|
373
373
|
- spec/fixtures/youku.response
|
374
374
|
- spec/fixtures/youtube-channel.response
|
375
|
+
- spec/fixtures/youtube-json.response
|
376
|
+
- spec/fixtures/youtube-list-json.response
|
375
377
|
- spec/fixtures/youtube.response
|
376
378
|
- spec/lib/onebox/engine/amazon_onebox_spec.rb
|
377
379
|
- spec/lib/onebox/engine/audio_onebox_spec.rb
|
@@ -447,7 +449,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
447
449
|
version: '0'
|
448
450
|
requirements: []
|
449
451
|
rubyforge_project:
|
450
|
-
rubygems_version: 2.
|
452
|
+
rubygems_version: 2.6.7
|
451
453
|
signing_key:
|
452
454
|
specification_version: 4
|
453
455
|
summary: A gem for turning URLs into previews.
|
@@ -476,6 +478,8 @@ test_files:
|
|
476
478
|
- spec/fixtures/youku-meta.response
|
477
479
|
- spec/fixtures/youku.response
|
478
480
|
- spec/fixtures/youtube-channel.response
|
481
|
+
- spec/fixtures/youtube-json.response
|
482
|
+
- spec/fixtures/youtube-list-json.response
|
479
483
|
- spec/fixtures/youtube.response
|
480
484
|
- spec/lib/onebox/engine/amazon_onebox_spec.rb
|
481
485
|
- spec/lib/onebox/engine/audio_onebox_spec.rb
|
@@ -508,3 +512,4 @@ test_files:
|
|
508
512
|
- spec/lib/onebox_spec.rb
|
509
513
|
- spec/spec_helper.rb
|
510
514
|
- spec/support/html_spec_helper.rb
|
515
|
+
has_rdoc:
|