onebox 1.6.9 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/onebox.rb +1 -2
- data/lib/onebox/engine.rb +3 -0
- data/lib/onebox/engine/bandcamp_onebox.rb +32 -0
- data/lib/onebox/engine/coub_onebox.rb +21 -0
- data/lib/onebox/engine/mixcloud_onebox.rb +20 -0
- data/lib/onebox/engine/standard_embed.rb +8 -4
- data/lib/onebox/engine/whitelisted_generic_onebox.rb +17 -13
- data/lib/onebox/matcher.rb +0 -7
- data/lib/onebox/version.rb +1 -1
- data/lib/onebox/web.rb +3 -0
- data/spec/lib/onebox/matcher_spec.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da1cb3e58693506b68988b477855a2058bf0b878
|
4
|
+
data.tar.gz: 81f59c2fee6f69e6903a4d928d4eafa2ab784026
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ccc65c55cf7a0b6b6caf8249db8c998e53eb27d40fe3f06e54a51977a8d3b7d856d6a058615f4e85c6e040fe3f8efe79abde319228a93a006b7bbc425ad8400
|
7
|
+
data.tar.gz: 09cbb07a7b3275dffb6ddb076f07b04b806474e682c9aabd7311d9400fc280b0daa2bd4787d9be5a3f1970403aebb5c6c0baaf6f36e811e821b74454bf7e63ef
|
data/lib/onebox.rb
CHANGED
data/lib/onebox/engine.rb
CHANGED
@@ -168,3 +168,6 @@ require_relative "engine/sketchfab_onebox"
|
|
168
168
|
require_relative "engine/audioboom_onebox"
|
169
169
|
require_relative "engine/replit_onebox"
|
170
170
|
require_relative "engine/asciinema_onebox"
|
171
|
+
require_relative "engine/mixcloud_onebox"
|
172
|
+
require_relative "engine/bandcamp_onebox"
|
173
|
+
require_relative "engine/coub_onebox"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class BandCampOnebox
|
4
|
+
include Engine
|
5
|
+
include StandardEmbed
|
6
|
+
|
7
|
+
matches_regexp(/^https?:\/\/.*bandcamp\.com\/album\//)
|
8
|
+
always_https
|
9
|
+
|
10
|
+
def placeholder_html
|
11
|
+
og = get_opengraph
|
12
|
+
"<img src='#{og[:image]}' height='#{og[:video_height]}' #{Helpers.title_attr(og)}>"
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_html
|
16
|
+
og = get_opengraph
|
17
|
+
src = og[:video_secure_url] || og[:video]
|
18
|
+
|
19
|
+
<<-HTML
|
20
|
+
<iframe src="#{src}"
|
21
|
+
width="#{og[:video_width]}"
|
22
|
+
height="#{og[:video_height]}"
|
23
|
+
scrolling="no"
|
24
|
+
frameborder="0"
|
25
|
+
allowfullscreen>
|
26
|
+
</iframe>
|
27
|
+
HTML
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class CoubOnebox
|
4
|
+
include Engine
|
5
|
+
include StandardEmbed
|
6
|
+
|
7
|
+
matches_regexp(/^https?:\/\/coub\.com\/view\//)
|
8
|
+
always_https
|
9
|
+
|
10
|
+
def placeholder_html
|
11
|
+
oembed = get_oembed
|
12
|
+
"<img src='#{oembed[:thumbnail_url]}' height='#{oembed[:thumbnail_height]}' width='#{oembed[:thumbnail_width]}' #{Helpers.title_attr(oembed)}>"
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_html
|
16
|
+
get_oembed[:html]
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class MixcloudOnebox
|
4
|
+
include Engine
|
5
|
+
include StandardEmbed
|
6
|
+
|
7
|
+
matches_regexp(/^https?:\/\/www\.mixcloud\.com\//)
|
8
|
+
always_https
|
9
|
+
|
10
|
+
def placeholder_html
|
11
|
+
oembed = get_oembed
|
12
|
+
"<img src='#{oembed[:image]}' height='#{oembed[:height]}' #{Helpers.title_attr(oembed)}>"
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_html
|
16
|
+
get_oembed[:html]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -22,6 +22,8 @@ module Onebox
|
|
22
22
|
add_oembed_provider(/www\.meetup\.com\//, 'http://api.meetup.com/oembed')
|
23
23
|
# In order to support Private Videos
|
24
24
|
add_oembed_provider(/vimeo\.com\//, 'https://vimeo.com/api/oembed.json')
|
25
|
+
# NYT requires login so use oembed only
|
26
|
+
add_oembed_provider(/nytimes\.com\//, 'https://www.nytimes.com/svc/oembed/json/')
|
25
27
|
|
26
28
|
def always_https?
|
27
29
|
WhitelistedGenericOnebox.host_matches(uri, WhitelistedGenericOnebox.https_hosts) || super
|
@@ -46,9 +48,7 @@ module Onebox
|
|
46
48
|
protected
|
47
49
|
|
48
50
|
def html_doc
|
49
|
-
|
50
|
-
response = Onebox::Helpers.fetch_response(url)
|
51
|
-
@html_doc = Nokogiri::HTML(response.body)
|
51
|
+
@html_doc ||= Nokogiri::HTML(Onebox::Helpers.fetch_response(url).body) rescue nil
|
52
52
|
end
|
53
53
|
|
54
54
|
def get_oembed
|
@@ -79,11 +79,13 @@ module Onebox
|
|
79
79
|
oe.delete(:html) if oe[:html] && oe[:html]["wp-embedded-content"]
|
80
80
|
|
81
81
|
oe
|
82
|
-
rescue Errno::ECONNREFUSED, Net::HTTPError, MultiJson::LoadError
|
82
|
+
rescue Errno::ECONNREFUSED, Net::HTTPError, Net::HTTPFatalError, MultiJson::LoadError
|
83
83
|
{}
|
84
84
|
end
|
85
85
|
|
86
86
|
def get_opengraph
|
87
|
+
return {} unless html_doc
|
88
|
+
|
87
89
|
og = {}
|
88
90
|
|
89
91
|
html_doc.css('meta').each do |m|
|
@@ -103,6 +105,8 @@ module Onebox
|
|
103
105
|
end
|
104
106
|
|
105
107
|
def get_twitter
|
108
|
+
return {} unless html_doc
|
109
|
+
|
106
110
|
twitter = {}
|
107
111
|
|
108
112
|
html_doc.css('meta').each do |m|
|
@@ -177,11 +177,9 @@ module Onebox
|
|
177
177
|
end
|
178
178
|
|
179
179
|
def self.===(other)
|
180
|
-
|
181
|
-
host_matches(other, whitelist) || probable_wordpress(other) || probable_discourse(other)
|
182
|
-
else
|
180
|
+
other.kind_of?(URI) ?
|
181
|
+
host_matches(other, whitelist) || probable_wordpress(other) || probable_discourse(other) :
|
183
182
|
super
|
184
|
-
end
|
185
183
|
end
|
186
184
|
|
187
185
|
def to_html
|
@@ -199,16 +197,25 @@ module Onebox
|
|
199
197
|
@data ||= begin
|
200
198
|
html_entities = HTMLEntities.new
|
201
199
|
d = { link: link }.merge(raw)
|
200
|
+
|
202
201
|
if !Onebox::Helpers.blank?(d[:title])
|
203
202
|
d[:title] = html_entities.decode(Onebox::Helpers.truncate(d[:title].strip, 80))
|
204
203
|
end
|
204
|
+
|
205
|
+
d[:description] ||= d[:summary]
|
205
206
|
if !Onebox::Helpers.blank?(d[:description])
|
206
207
|
d[:description] = html_entities.decode(Onebox::Helpers.truncate(d[:description].strip, 250))
|
207
208
|
end
|
209
|
+
|
208
210
|
if !Onebox::Helpers.blank?(d[:domain])
|
209
211
|
d[:domain] = "http://#{d[:domain]}" unless d[:domain] =~ /^https?:\/\//
|
210
212
|
d[:domain] = URI(d[:domain]).host.to_s.sub(/^www\./, '')
|
211
213
|
end
|
214
|
+
|
215
|
+
# prefer secure URLs
|
216
|
+
d[:image] = d[:image_secure_url] || d[:image_url] || d[:thumbnail_url] || d[:image]
|
217
|
+
d[:video] = d[:video_secure_url] || d[:video_url] || d[:video]
|
218
|
+
|
212
219
|
d
|
213
220
|
end
|
214
221
|
end
|
@@ -226,8 +233,8 @@ module Onebox
|
|
226
233
|
return article_html if is_article?
|
227
234
|
return video_html if is_video?
|
228
235
|
return image_html if is_image?
|
229
|
-
return article_html if has_text?
|
230
236
|
return embedded_html if is_embedded?
|
237
|
+
return article_html if has_text?
|
231
238
|
end
|
232
239
|
|
233
240
|
def is_article?
|
@@ -247,8 +254,7 @@ module Onebox
|
|
247
254
|
end
|
248
255
|
|
249
256
|
def has_image?
|
250
|
-
!Onebox::Helpers.blank?(data[:image])
|
251
|
-
!Onebox::Helpers.blank?(data[:thumbnail_url])
|
257
|
+
!Onebox::Helpers.blank?(data[:image])
|
252
258
|
end
|
253
259
|
|
254
260
|
def is_video?
|
@@ -269,17 +275,15 @@ module Onebox
|
|
269
275
|
end
|
270
276
|
|
271
277
|
def image_html
|
272
|
-
|
273
|
-
return if Onebox::Helpers.blank?(src)
|
278
|
+
return if Onebox::Helpers.blank?(data[:image])
|
274
279
|
|
275
280
|
alt = data[:description] || data[:title]
|
276
281
|
width = data[:image_width] || data[:thumbnail_width]
|
277
282
|
height = data[:image_height] || data[:thumbnail_height]
|
278
|
-
"<img src='#{
|
283
|
+
"<img src='#{data[:image]}' alt='#{alt}' width='#{width}' height='#{height}'>"
|
279
284
|
end
|
280
285
|
|
281
286
|
def video_html
|
282
|
-
video_url = !Onebox::Helpers.blank?(data[:video_secure_url]) ? data[:video_secure_url] : data[:video]
|
283
287
|
if data[:video_type] == "video/mp4"
|
284
288
|
<<-HTML
|
285
289
|
<video title='#{data[:title]}'
|
@@ -287,12 +291,12 @@ module Onebox
|
|
287
291
|
height='#{data[:video_height]}'
|
288
292
|
style='max-width:100%'
|
289
293
|
controls=''>
|
290
|
-
<source src='#{
|
294
|
+
<source src='#{data[:video]}'>
|
291
295
|
</video>
|
292
296
|
HTML
|
293
297
|
else
|
294
298
|
<<-HTML
|
295
|
-
<iframe src='#{
|
299
|
+
<iframe src='#{data[:video]}'
|
296
300
|
title='#{data[:title]}'
|
297
301
|
width='#{data[:video_width]}'
|
298
302
|
height='#{data[:video_height]}'
|
data/lib/onebox/matcher.rb
CHANGED
@@ -12,15 +12,8 @@ module Onebox
|
|
12
12
|
|
13
13
|
def oneboxed
|
14
14
|
uri = URI(@url)
|
15
|
-
|
16
|
-
# A onebox needs a path, query or fragment string to be considered
|
17
|
-
return if (uri.query.nil? || uri.query.size == 0) &&
|
18
|
-
(uri.fragment.nil? || uri.fragment.size == 0) &&
|
19
|
-
(uri.path.size == 0 || uri.path == "/")
|
20
|
-
|
21
15
|
ordered_engines.find { |engine| engine === uri }
|
22
16
|
rescue URI::InvalidURIError
|
23
|
-
# If it's not a valid URL, don't even match
|
24
17
|
nil
|
25
18
|
end
|
26
19
|
end
|
data/lib/onebox/version.rb
CHANGED
data/lib/onebox/web.rb
CHANGED
@@ -11,6 +11,9 @@ module Onebox
|
|
11
11
|
set :root, File.expand_path(File.dirname(__FILE__) + "/../../web")
|
12
12
|
set :public_folder, Proc.new { "#{root}/assets" }
|
13
13
|
set :views, Proc.new { "#{root}/views" }
|
14
|
+
configure :development do
|
15
|
+
enable :logging
|
16
|
+
end
|
14
17
|
|
15
18
|
helpers WebHelpers
|
16
19
|
|
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
|
+
version: 1.7.0
|
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: 2017-01-
|
13
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -318,6 +318,8 @@ files:
|
|
318
318
|
- lib/onebox/engine/asciinema_onebox.rb
|
319
319
|
- lib/onebox/engine/audio_onebox.rb
|
320
320
|
- lib/onebox/engine/audioboom_onebox.rb
|
321
|
+
- lib/onebox/engine/bandcamp_onebox.rb
|
322
|
+
- lib/onebox/engine/coub_onebox.rb
|
321
323
|
- lib/onebox/engine/douban_onebox.rb
|
322
324
|
- lib/onebox/engine/gfycat_onebox.rb
|
323
325
|
- lib/onebox/engine/giphy_onebox.rb
|
@@ -334,6 +336,7 @@ files:
|
|
334
336
|
- lib/onebox/engine/image_onebox.rb
|
335
337
|
- lib/onebox/engine/imgur_onebox.rb
|
336
338
|
- lib/onebox/engine/json.rb
|
339
|
+
- lib/onebox/engine/mixcloud_onebox.rb
|
337
340
|
- lib/onebox/engine/pastebin_onebox.rb
|
338
341
|
- lib/onebox/engine/pubmed_onebox.rb
|
339
342
|
- lib/onebox/engine/replit_onebox.rb
|
@@ -466,7 +469,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
466
469
|
version: '0'
|
467
470
|
requirements: []
|
468
471
|
rubyforge_project:
|
469
|
-
rubygems_version: 2.
|
472
|
+
rubygems_version: 2.5.1
|
470
473
|
signing_key:
|
471
474
|
specification_version: 4
|
472
475
|
summary: A gem for turning URLs into previews.
|