onebox 2.1.1 → 2.1.6
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.rb +2 -0
- data/lib/onebox/engine/allowlisted_generic_onebox.rb +12 -4
- data/lib/onebox/engine/imgur_onebox.rb +1 -1
- data/lib/onebox/engine/instagram_onebox.rb +13 -3
- data/lib/onebox/engine/standard_embed.rb +1 -1
- data/lib/onebox/engine/wistia_onebox.rb +1 -1
- data/lib/onebox/helpers.rb +1 -0
- data/lib/onebox/preview.rb +11 -1
- data/lib/onebox/version.rb +1 -1
- data/onebox.gemspec +1 -1
- data/templates/allowlistedgeneric.mustache +2 -0
- data/templates/instagram.mustache +3 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6fd88926ec341ed84409e7c77dbfcce244dbf2a0c74e0a19736e81b2b693e84
|
4
|
+
data.tar.gz: 18f53e5fb7b1fa4eab35ea27f87e97600e82af0eaf4fd5eed0809744bf7e53c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a5c344336f529d53b51ac47b5b0efee1b6fb29b0b2541948d650fa1d81e11f97edfa3d1a2f8abb7915b8cf9c86e41c74b64cb40b26924e380f68d52e0015c33
|
7
|
+
data.tar.gz: 9cefe31755197bbfb71ba3e741329c7bdba10fd9bb19892b237cb78b22769e0e19824119b94cb3cdd24f7bec10f4aeb91cbad3a7d40eefd84c2cbe64866908b0
|
data/lib/onebox/engine.rb
CHANGED
@@ -30,6 +30,7 @@ module Onebox
|
|
30
30
|
|
31
31
|
attr_reader :url, :uri
|
32
32
|
attr_reader :timeout
|
33
|
+
attr :errors
|
33
34
|
|
34
35
|
DEFAULT = {}
|
35
36
|
def options
|
@@ -44,6 +45,7 @@ module Onebox
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def initialize(link, timeout = nil)
|
48
|
+
@errors = {}
|
47
49
|
@options = DEFAULT
|
48
50
|
class_name = self.class.name.split("::").last.to_s
|
49
51
|
|
@@ -256,6 +256,15 @@ module Onebox
|
|
256
256
|
d[:data_1] = Onebox::Helpers.truncate("#{d[:price_currency].strip} #{d[:price_amount].strip}")
|
257
257
|
end
|
258
258
|
|
259
|
+
skip_missing_tags = [:video]
|
260
|
+
d.each do |k, v|
|
261
|
+
next if skip_missing_tags.include?(k)
|
262
|
+
if v == nil || v == ''
|
263
|
+
errors[k] ||= []
|
264
|
+
errors[k] << 'is blank'
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
259
268
|
d
|
260
269
|
end
|
261
270
|
end
|
@@ -292,8 +301,7 @@ module Onebox
|
|
292
301
|
end
|
293
302
|
|
294
303
|
def has_text?
|
295
|
-
!Onebox::Helpers.blank?(data[:title])
|
296
|
-
!Onebox::Helpers.blank?(data[:description])
|
304
|
+
!Onebox::Helpers.blank?(data[:title])
|
297
305
|
end
|
298
306
|
|
299
307
|
def is_image?
|
@@ -317,7 +325,7 @@ module Onebox
|
|
317
325
|
return true if AllowlistedGenericOnebox.html_providers.include?(data[:provider_name])
|
318
326
|
return false unless data[:html]["iframe"]
|
319
327
|
|
320
|
-
fragment = Nokogiri::
|
328
|
+
fragment = Nokogiri::HTML5::fragment(data[:html])
|
321
329
|
src = fragment.at_css('iframe')&.[]("src")
|
322
330
|
options[:allowed_iframe_regexes]&.any? { |r| src =~ r }
|
323
331
|
end
|
@@ -368,7 +376,7 @@ module Onebox
|
|
368
376
|
end
|
369
377
|
|
370
378
|
def embedded_html
|
371
|
-
fragment = Nokogiri::
|
379
|
+
fragment = Nokogiri::HTML5::fragment(data[:html])
|
372
380
|
fragment.css("img").each { |img| img["class"] = "thumbnail" }
|
373
381
|
if iframe = fragment.at_css("iframe")
|
374
382
|
iframe.remove_attribute("style")
|
@@ -58,7 +58,7 @@ module Onebox
|
|
58
58
|
|
59
59
|
<<-HTML
|
60
60
|
<a href='#{escaped_url}' target='_blank' rel='noopener' class="onebox">
|
61
|
-
<img src='#{og.get_secure_image}' #{og.title_attr} alt='Imgur'
|
61
|
+
<img src='#{og.get_secure_image.chomp("?fb")}' #{og.title_attr} alt='Imgur'>
|
62
62
|
</a>
|
63
63
|
HTML
|
64
64
|
end
|
@@ -20,15 +20,25 @@ module Onebox
|
|
20
20
|
|
21
21
|
{ link: permalink,
|
22
22
|
title: "@#{oembed.author_name}",
|
23
|
-
image:
|
24
|
-
description: Onebox::Helpers.truncate(oembed.title, 250)
|
23
|
+
image: oembed.thumbnail_url,
|
24
|
+
description: Onebox::Helpers.truncate(oembed.title, 250),
|
25
25
|
}
|
26
|
+
|
26
27
|
end
|
27
28
|
|
28
29
|
protected
|
29
30
|
|
31
|
+
def access_token
|
32
|
+
(options[:facebook_app_access_token] || Onebox.options.facebook_app_access_token).to_s
|
33
|
+
end
|
34
|
+
|
30
35
|
def get_oembed_url
|
31
|
-
|
36
|
+
if access_token != ''
|
37
|
+
oembed_url = "https://graph.facebook.com/v9.0/instagram_oembed?url=#{clean_url}&access_token=#{access_token}"
|
38
|
+
else
|
39
|
+
# The following is officially deprecated by Instagram, but works in some limited circumstances.
|
40
|
+
oembed_url = "https://api.instagram.com/oembed/?url=#{clean_url}"
|
41
|
+
end
|
32
42
|
end
|
33
43
|
end
|
34
44
|
end
|
@@ -91,7 +91,7 @@ module Onebox
|
|
91
91
|
html_doc.css('meta').each do |m|
|
92
92
|
if (m["property"] && m["property"][/^twitter:(.+)$/i]) || (m["name"] && m["name"][/^twitter:(.+)$/i])
|
93
93
|
value = (m["content"] || m["value"]).to_s
|
94
|
-
twitter[$1.tr('-:' , '_').to_sym] ||= value unless Onebox::Helpers::blank?(value)
|
94
|
+
twitter[$1.tr('-:' , '_').to_sym] ||= value unless (Onebox::Helpers::blank?(value) || value == "0 minutes")
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -7,7 +7,7 @@ module Onebox
|
|
7
7
|
include StandardEmbed
|
8
8
|
|
9
9
|
matches_regexp(/https?:\/\/(.+)?(wistia.com|wi.st)\/(medias|embed)\/.*/)
|
10
|
-
requires_iframe_origins
|
10
|
+
requires_iframe_origins("https://fast.wistia.com", "https://fast.wistia.net")
|
11
11
|
always_https
|
12
12
|
|
13
13
|
def to_html
|
data/lib/onebox/helpers.rb
CHANGED
data/lib/onebox/preview.rb
CHANGED
@@ -31,6 +31,16 @@ module Onebox
|
|
31
31
|
""
|
32
32
|
end
|
33
33
|
|
34
|
+
def errors
|
35
|
+
return {} unless engine
|
36
|
+
engine.errors
|
37
|
+
end
|
38
|
+
|
39
|
+
def data
|
40
|
+
return {} unless engine
|
41
|
+
engine.data
|
42
|
+
end
|
43
|
+
|
34
44
|
def options
|
35
45
|
OpenStruct.new(@options)
|
36
46
|
end
|
@@ -45,7 +55,7 @@ module Onebox
|
|
45
55
|
return "" unless html
|
46
56
|
|
47
57
|
if @options[:max_width]
|
48
|
-
doc = Nokogiri::
|
58
|
+
doc = Nokogiri::HTML5::fragment(html)
|
49
59
|
if doc
|
50
60
|
doc.css('[width]').each do |e|
|
51
61
|
width = e['width'].to_i
|
data/lib/onebox/version.rb
CHANGED
data/onebox.gemspec
CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_development_dependency 'fakeweb', '~> 1.3'
|
34
34
|
spec.add_development_dependency 'pry', '~> 0.10'
|
35
35
|
spec.add_development_dependency 'mocha', '~> 1.1'
|
36
|
-
spec.add_development_dependency 'rubocop-discourse', '~> 2.
|
36
|
+
spec.add_development_dependency 'rubocop-discourse', '~> 2.4.0'
|
37
37
|
spec.add_development_dependency 'twitter', '~> 4.8'
|
38
38
|
spec.add_development_dependency 'guard-rspec', '~> 4.2.8'
|
39
39
|
spec.add_development_dependency 'sinatra', '~> 1.4'
|
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: 2.1.
|
4
|
+
version: 2.1.6
|
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: 2020-
|
13
|
+
date: 2020-11-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: addressable
|
@@ -186,14 +186,14 @@ dependencies:
|
|
186
186
|
requirements:
|
187
187
|
- - "~>"
|
188
188
|
- !ruby/object:Gem::Version
|
189
|
-
version: 2.
|
189
|
+
version: 2.4.0
|
190
190
|
type: :development
|
191
191
|
prerelease: false
|
192
192
|
version_requirements: !ruby/object:Gem::Requirement
|
193
193
|
requirements:
|
194
194
|
- - "~>"
|
195
195
|
- !ruby/object:Gem::Version
|
196
|
-
version: 2.
|
196
|
+
version: 2.4.0
|
197
197
|
- !ruby/object:Gem::Dependency
|
198
198
|
name: twitter
|
199
199
|
requirement: !ruby/object:Gem::Requirement
|