onebox 1.8.3 → 1.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 988dda6f5b64b8781329e91c3f0b8dc826d0e8bc
4
- data.tar.gz: df7b513451cfb05039fd6d45ff236d042bd8359c
3
+ metadata.gz: 98fc21836d5ddcb857c0bb72f823c23d5e269496
4
+ data.tar.gz: 0686f0001610272d1faafc07c36128d24aa7a4b3
5
5
  SHA512:
6
- metadata.gz: 50f11c399aaf148cc15111f3bc420f1f7dfd1e39c301b1757008ba13bc71f7ea73745f4c22e25c372696cb50587215b38510e47f835567545934028a12a2c2d7
7
- data.tar.gz: 727cbe61c73b320fb63a9232a88afe41e75e231dfcb3d169d6571875c4bc5693688381f964454f77ce8e5c47a08813f0ccf1966d64517f0bb157aec77b6e0db0
6
+ metadata.gz: 31092ef0ffdfd513fc8b1f1f8e6ce4422eb451e48c749635b824bacb0305364e49ade2c27adba386d740b4a5e140891f509ad16c7760dcce8edfe04db49097f5
7
+ data.tar.gz: a73d3abdb2f91231f273e4f7e7fea101f5592b2f8e32984c425d4da209fabd33c310540b0acb1026a574f4b72581241428dda64a0ffc1437f81179b627b8643c
data/lib/onebox/engine.rb CHANGED
@@ -149,6 +149,7 @@ require_relative "engine/video_onebox"
149
149
  require_relative "engine/audio_onebox"
150
150
  require_relative "engine/stack_exchange_onebox"
151
151
  require_relative "engine/twitter_status_onebox"
152
+ require_relative "engine/wikimedia_onebox"
152
153
  require_relative "engine/wikipedia_onebox"
153
154
  require_relative "engine/youtube_onebox"
154
155
  require_relative "engine/youku_onebox"
@@ -162,6 +163,7 @@ require_relative "engine/slides_onebox"
162
163
  require_relative "engine/xkcd_onebox"
163
164
  require_relative "engine/giphy_onebox"
164
165
  require_relative "engine/gfycat_onebox"
166
+ require_relative "engine/typeform_onebox"
165
167
  require_relative "engine/vimeo_onebox"
166
168
  require_relative "engine/steam_store_onebox"
167
169
  require_relative "engine/sketchfab_onebox"
@@ -2,36 +2,60 @@ module Onebox
2
2
  module Engine
3
3
  class GfycatOnebox
4
4
  include Engine
5
- include StandardEmbed
5
+ include JSON
6
6
 
7
7
  matches_regexp(/^https?:\/\/gfycat\.com\//)
8
8
  always_https
9
9
 
10
- def to_html
11
- oembed = get_oembed
12
- src = Nokogiri::HTML::fragment(oembed[:html]).at_css("iframe")["src"]
13
- escaped_src = ::Onebox::Helpers.normalize_url_for_output(src)
10
+ def self.priority
11
+ # This engine should have priority over WhitelistedGenericOnebox.
12
+ 1
13
+ end
14
14
 
15
+ def url
16
+ "https://gfycat.com/cajax/get/#{match[:name]}"
17
+ end
18
+
19
+ def to_html
15
20
  <<-HTML
16
- <iframe src="#{escaped_src}"
17
- width="#{oembed[:width]}"
18
- height="#{oembed[:height]}"
19
- scrolling="no"
20
- frameborder="0"
21
- allowfullscreen>
22
- </iframe>
21
+ <div>
22
+ <video controls loop autoplay muted poster="#{data[:posterUrl]}" width="#{data[:width]}" height="#{data[:height]}">
23
+ <source id="webmSource" src="#{data[:webmUrl]}" type="video/webm">
24
+ <source id="mp4Source" src="#{data[:mp4Url]}" type="video/mp4">
25
+ <img title="Sorry, your browser doesn't support HTML5 video." src="#{data[:posterUrl]}">
26
+ </video><br/>
27
+ <a href="#{data[:url]}">#{data[:name]}</a>
28
+ </div>
23
29
  HTML
24
30
  end
25
31
 
26
32
  def placeholder_html
27
- og = get_opengraph
28
- escaped_src = ::Onebox::Helpers.normalize_url_for_output(og[:image])
29
-
30
33
  <<-HTML
31
- <img src="#{escaped_src}" width="#{og[:image_width]}" height="#{og[:image_height]}">
34
+ <a href="#{data[:url]}">
35
+ <img src="#{data[:posterUrl]}" width="#{data[:width]}" height="#{data[:height]}"><br/>
36
+ #{data[:gfyName]}
37
+ </a>
32
38
  HTML
33
39
  end
34
40
 
41
+ private
42
+
43
+ def match
44
+ @match ||= @url.match(/^https?:\/\/gfycat\.com\/(?<name>.+)/)
45
+ end
46
+
47
+ def data
48
+ {
49
+ name: raw['gfyItem']['gfyName'],
50
+ url: @url,
51
+ posterUrl: raw['gfyItem']['posterUrl'],
52
+ webmUrl: raw['gfyItem']['webmUrl'],
53
+ mp4Url: raw['gfyItem']['mp4Url'],
54
+ width: raw['gfyItem']['width'],
55
+ height: raw['gfyItem']['height']
56
+ }
57
+ end
58
+
35
59
  end
36
60
  end
37
61
  end
@@ -48,7 +48,7 @@ module Onebox
48
48
  end
49
49
 
50
50
  def to_html
51
- "<div class='maps-onebox'>#{Helpers.click_to_scroll_div + "<iframe src=\"#{link}\" width=\"690\" height=\"400\" frameborder=\"0\" style=\"border:0\">#{placeholder_html}</iframe>"}</div>"
51
+ "<div class='maps-onebox'><iframe src=\"#{link}\" width=\"690\" height=\"400\" frameborder=\"0\" style=\"border:0\">#{placeholder_html}</iframe></div>"
52
52
  end
53
53
 
54
54
  def placeholder_html
@@ -0,0 +1,35 @@
1
+ module Onebox
2
+ module Engine
3
+ class TypeformOnebox
4
+ include Engine
5
+
6
+ matches_regexp(/^https?:\/\/[a-z0-9]+\.typeform\.com\/to\/[a-zA-Z0-9]+/)
7
+ always_https
8
+
9
+ def placeholder_html
10
+ escaped_url = ::Onebox::Helpers.normalize_url_for_output(@url)
11
+
12
+ <<-HTML
13
+ <iframe src="#{escaped_url}"
14
+ width="100%"
15
+ height="600px"
16
+ scrolling="no"
17
+ frameborder="0">
18
+ </iframe>
19
+ HTML
20
+ end
21
+
22
+ def to_html
23
+ escaped_url = ::Onebox::Helpers.normalize_url_for_output(@url)
24
+ <<-HTML
25
+ <iframe src="#{escaped_url}"
26
+ width="100%"
27
+ height="600px"
28
+ scrolling="no"
29
+ frameborder="0">
30
+ </iframe>
31
+ HTML
32
+ end
33
+ end
34
+ end
35
+ end
@@ -61,7 +61,6 @@ module Onebox
61
61
  forbes.com
62
62
  foxnews.com
63
63
  funnyordie.com
64
- gfycat.com
65
64
  groupon.com
66
65
  howtogeek.com
67
66
  huffingtonpost.ca
@@ -258,8 +257,7 @@ module Onebox
258
257
  end
259
258
 
260
259
  def is_video?
261
- data[:type] =~ /video/ &&
262
- !Onebox::Helpers.blank?(data[:video])
260
+ data[:type] =~ /^video\// && !Onebox::Helpers.blank?(data[:video])
263
261
  end
264
262
 
265
263
  def is_embedded?
@@ -290,26 +288,15 @@ module Onebox
290
288
  def video_html
291
289
  escaped_src = ::Onebox::Helpers.normalize_url_for_output(data[:video])
292
290
 
293
- if data[:video_type] == "video/mp4"
294
- <<-HTML
295
- <video title='#{data[:title]}'
296
- width='#{data[:video_width]}'
297
- height='#{data[:video_height]}'
298
- style='max-width:100%'
299
- controls=''>
300
- <source src='#{escaped_src}'>
301
- </video>
302
- HTML
303
- else
304
- <<-HTML
305
- <iframe src='#{escaped_src}'
306
- title='#{data[:title]}'
307
- width='#{data[:video_width]}'
308
- height='#{data[:video_height]}'
309
- frameborder='0'>
310
- </iframe>
311
- HTML
312
- end
291
+ <<-HTML
292
+ <video title='#{data[:title]}'
293
+ width='#{data[:video_width]}'
294
+ height='#{data[:video_height]}'
295
+ style='max-width:100%'
296
+ controls=''>
297
+ <source src='#{escaped_src}'>
298
+ </video>
299
+ HTML
313
300
  end
314
301
 
315
302
  def embedded_html
@@ -0,0 +1,42 @@
1
+ module Onebox
2
+ module Engine
3
+ class WikimediaOnebox
4
+ include Engine
5
+ include LayoutSupport
6
+ include JSON
7
+
8
+ matches_regexp /^https?:\/\/commons\.wikimedia\.org\/wiki\/(File:.+)/
9
+ always_https
10
+
11
+ def self.priority
12
+ # Wikimedia links end in an image extension.
13
+ # E.g. https://commons.wikimedia.org/wiki/File:Stones_members_montage2.jpg
14
+ # This engine should have priority over the generic ImageOnebox.
15
+
16
+ 1
17
+ end
18
+
19
+ def url
20
+ "https://en.wikipedia.org/w/api.php?action=query&titles=#{match[:name]}&prop=imageinfo&iilimit=50&iiprop=timestamp|user|url&iiurlwidth=500&format=json"
21
+ end
22
+
23
+ private
24
+
25
+ def match
26
+ @match ||= @url.match(/^https?:\/\/commons\.wikimedia\.org\/wiki\/(?<name>File:.+)/)
27
+ end
28
+
29
+ def data
30
+ first_page = raw['query']['pages'].first[1]
31
+
32
+ {
33
+ link: first_page['imageinfo'].first['descriptionurl'],
34
+ title: first_page['title'],
35
+ image: first_page['imageinfo'].first['url'],
36
+ thumbnail: first_page['imageinfo'].first['thumburl']
37
+ }
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Onebox
2
- VERSION = "1.8.3"
2
+ VERSION = "1.8.4"
3
3
  end
@@ -0,0 +1 @@
1
+ {"gfyItem":{"gfyId":"amusingposhcleanerwrasse","gfyName":"AmusingPoshCleanerwrasse","gfyNumber":"679816419","userName":"anonymous","width":"1920","height":"1080","frameRate":"60","numFrames":"407","mp4Url":"https:\/\/giant.gfycat.com\/AmusingPoshCleanerwrasse.mp4","webmUrl":"https:\/\/fat.gfycat.com\/AmusingPoshCleanerwrasse.webm","webpUrl":"https:\/\/thumbs.gfycat.com\/AmusingPoshCleanerwrasse.webp","mobileUrl":"https:\/\/thumbs.gfycat.com\/AmusingPoshCleanerwrasse-mobile.mp4","mobilePosterUrl":"https:\/\/thumbs.gfycat.com\/AmusingPoshCleanerwrasse-mobile.jpg","posterUrl":"https:\/\/thumbs.gfycat.com\/AmusingPoshCleanerwrasse-poster.jpg","thumb360Url":"https:\/\/thumbs.gfycat.com\/AmusingPoshCleanerwrasse-360.mp4","thumb360PosterUrl":"https:\/\/thumbs.gfycat.com\/AmusingPoshCleanerwrasse-thumb360.jpg","thumb100PosterUrl":"https:\/\/thumbs.gfycat.com\/AmusingPoshCleanerwrasse-thumb100.jpg","max5mbGif":"https:\/\/thumbs.gfycat.com\/AmusingPoshCleanerwrasse-size_restricted.gif","max2mbGif":"https:\/\/thumbs.gfycat.com\/AmusingPoshCleanerwrasse-small.gif","mjpgUrl":"https:\/\/thumbs.gfycat.com\/AmusingPoshCleanerwrasse.mjpg","gifUrl":"https:\/\/giant.gfycat.com\/AmusingPoshCleanerwrasse.gif","gifSize":"12850292","mp4Size":"12420204","webmSize":"2146835","createDate":"1488568617","views":150,"viewsNewEpoch":"149","title":null,"extraLemmas":null,"md5":"3c9261db26eda7e8f251f0abab64f8ca","tags":null,"userTags":null,"nsfw":"0","sar":null,"url":null,"source":"1","dynamo":null,"subreddit":null,"redditId":null,"redditIdText":null,"likes":null,"dislikes":null,"published":null,"description":null,"copyrightClaimaint":null,"languageText":null,"fullDomainWhitelist":[],"fullGeoWhitelist":[],"iframeProfileImageVisible":true}}
@@ -0,0 +1 @@
1
+ {"batchcomplete":"","query":{"normalized":[{"from":"File:Stones_members_montage2.jpg","to":"File:Stones members montage2.jpg"}],"pages":{"-1":{"ns":6,"title":"File:Stones members montage2.jpg","missing":"","known":"","imagerepository":"shared","imageinfo":[{"timestamp":"2010-12-07T23:13:30Z","user":"84user","thumburl":"https://upload.wikimedia.org/wikipedia/commons/thumb/a/af/Stones_members_montage2.jpg/500px-Stones_members_montage2.jpg","thumbwidth":500,"thumbheight":459,"url":"https://upload.wikimedia.org/wikipedia/commons/a/af/Stones_members_montage2.jpg","descriptionurl":"https://commons.wikimedia.org/wiki/File:Stones_members_montage2.jpg","descriptionshorturl":"https://commons.wikimedia.org/w/index.php?curid=12245228"}]}}}}
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ describe Onebox::Engine::GfycatOnebox do
4
+ let(:link) { "https://gfycat.com/AmusingPoshCleanerwrasse" }
5
+ let(:api_link) { "https://gfycat.com/cajax/get/AmusingPoshCleanerwrasse" }
6
+ let(:html) { described_class.new(link).to_html }
7
+ let(:placeholder_html) { described_class.new(link).placeholder_html }
8
+
9
+ before do
10
+ fake(api_link, response("gfycat"))
11
+ end
12
+
13
+ it "has the title" do
14
+ expect(html).to include("AmusingPoshCleanerwrasse")
15
+ expect(placeholder_html).to include("AmusingPoshCleanerwrasse")
16
+ end
17
+
18
+ it "has the link" do
19
+ expect(html).to include(link)
20
+ expect(placeholder_html).to include(link)
21
+ end
22
+
23
+ it "has the poster" do
24
+ expect(html).to include("https://thumbs.gfycat.com/AmusingPoshCleanerwrasse-poster.jpg")
25
+ end
26
+
27
+ it "has the webm video" do
28
+ expect(html).to include("https://fat.gfycat.com/AmusingPoshCleanerwrasse.webm")
29
+ end
30
+
31
+ it "has the mp4 video" do
32
+ expect(html).to include("https://giant.gfycat.com/AmusingPoshCleanerwrasse.mp4")
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe Onebox::Engine::WikimediaOnebox do
4
+ let(:link) { "https://commons.wikimedia.org/wiki/File:Stones_members_montage2.jpg" }
5
+ let(:api_link) { "https://en.wikipedia.org/w/api.php?action=query&titles=File:Stones_members_montage2.jpg&prop=imageinfo&iilimit=50&iiprop=timestamp|user|url&iiurlwidth=500&format=json" }
6
+ let(:html) { described_class.new(link).to_html }
7
+
8
+ before do
9
+ fake(api_link, response("wikimedia"))
10
+ end
11
+
12
+ it "has the title" do
13
+ expect(html).to include("File:Stones members montage2.jpg")
14
+ end
15
+
16
+ it "has the link" do
17
+ expect(html).to include(link)
18
+ end
19
+
20
+ it "has the image" do
21
+ expect(html).to include("https://upload.wikimedia.org/wikipedia/commons/a/af/Stones_members_montage2.jpg")
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ {{#image}}<img src="{{image}}" class="thumbnail"/>{{/image}}
2
+
3
+ <h3><a href='{{link}}' target='_blank'>{{title}}</a></h3>
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.8.3
4
+ version: 1.8.4
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-03-13 00:00:00.000000000 Z
13
+ date: 2017-04-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
@@ -364,9 +364,11 @@ files:
364
364
  - lib/onebox/engine/standard_embed.rb
365
365
  - lib/onebox/engine/steam_store_onebox.rb
366
366
  - lib/onebox/engine/twitter_status_onebox.rb
367
+ - lib/onebox/engine/typeform_onebox.rb
367
368
  - lib/onebox/engine/video_onebox.rb
368
369
  - lib/onebox/engine/vimeo_onebox.rb
369
370
  - lib/onebox/engine/whitelisted_generic_onebox.rb
371
+ - lib/onebox/engine/wikimedia_onebox.rb
370
372
  - lib/onebox/engine/wikipedia_onebox.rb
371
373
  - lib/onebox/engine/xkcd_onebox.rb
372
374
  - lib/onebox/engine/youku_onebox.rb
@@ -388,6 +390,7 @@ files:
388
390
  - spec/fixtures/amazon.response
389
391
  - spec/fixtures/dailymail.response
390
392
  - spec/fixtures/douban.response
393
+ - spec/fixtures/gfycat.response
391
394
  - spec/fixtures/githubblob.response
392
395
  - spec/fixtures/githubcommit.response
393
396
  - spec/fixtures/githubgist.response
@@ -405,6 +408,7 @@ files:
405
408
  - spec/fixtures/stackexchange-question.response
406
409
  - spec/fixtures/twitterstatus.response
407
410
  - spec/fixtures/video.response
411
+ - spec/fixtures/wikimedia.response
408
412
  - spec/fixtures/wikipedia.response
409
413
  - spec/fixtures/wikipediaredirected.response
410
414
  - spec/fixtures/xkcd.response
@@ -417,6 +421,7 @@ files:
417
421
  - spec/lib/onebox/engine/amazon_onebox_spec.rb
418
422
  - spec/lib/onebox/engine/audio_onebox_spec.rb
419
423
  - spec/lib/onebox/engine/douban_onebox_spec.rb
424
+ - spec/lib/onebox/engine/gfycat_onebox_spec.rb
420
425
  - spec/lib/onebox/engine/github_blob_onebox_spec.rb
421
426
  - spec/lib/onebox/engine/github_commit_onebox_spec.rb
422
427
  - spec/lib/onebox/engine/github_gist_onebox_spec.rb
@@ -434,6 +439,7 @@ files:
434
439
  - spec/lib/onebox/engine/twitter_status_onebox_spec.rb
435
440
  - spec/lib/onebox/engine/video_onebox_spec.rb
436
441
  - spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
442
+ - spec/lib/onebox/engine/wikimedia_onebox_spec.rb
437
443
  - spec/lib/onebox/engine/wikipedia_onebox_spec.rb
438
444
  - spec/lib/onebox/engine/xkcd_spec.rb
439
445
  - spec/lib/onebox/engine/youku_onebox_spec.rb
@@ -463,6 +469,7 @@ files:
463
469
  - templates/stackexchange.mustache
464
470
  - templates/twitterstatus.mustache
465
471
  - templates/whitelistedgeneric.mustache
472
+ - templates/wikimedia.mustache
466
473
  - templates/wikipedia.mustache
467
474
  - templates/xkcd.mustache
468
475
  - web/assets/javascripts/jquery.js
@@ -499,6 +506,7 @@ test_files:
499
506
  - spec/fixtures/amazon.response
500
507
  - spec/fixtures/dailymail.response
501
508
  - spec/fixtures/douban.response
509
+ - spec/fixtures/gfycat.response
502
510
  - spec/fixtures/githubblob.response
503
511
  - spec/fixtures/githubcommit.response
504
512
  - spec/fixtures/githubgist.response
@@ -516,6 +524,7 @@ test_files:
516
524
  - spec/fixtures/stackexchange-question.response
517
525
  - spec/fixtures/twitterstatus.response
518
526
  - spec/fixtures/video.response
527
+ - spec/fixtures/wikimedia.response
519
528
  - spec/fixtures/wikipedia.response
520
529
  - spec/fixtures/wikipediaredirected.response
521
530
  - spec/fixtures/xkcd.response
@@ -528,6 +537,7 @@ test_files:
528
537
  - spec/lib/onebox/engine/amazon_onebox_spec.rb
529
538
  - spec/lib/onebox/engine/audio_onebox_spec.rb
530
539
  - spec/lib/onebox/engine/douban_onebox_spec.rb
540
+ - spec/lib/onebox/engine/gfycat_onebox_spec.rb
531
541
  - spec/lib/onebox/engine/github_blob_onebox_spec.rb
532
542
  - spec/lib/onebox/engine/github_commit_onebox_spec.rb
533
543
  - spec/lib/onebox/engine/github_gist_onebox_spec.rb
@@ -545,6 +555,7 @@ test_files:
545
555
  - spec/lib/onebox/engine/twitter_status_onebox_spec.rb
546
556
  - spec/lib/onebox/engine/video_onebox_spec.rb
547
557
  - spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
558
+ - spec/lib/onebox/engine/wikimedia_onebox_spec.rb
548
559
  - spec/lib/onebox/engine/wikipedia_onebox_spec.rb
549
560
  - spec/lib/onebox/engine/xkcd_spec.rb
550
561
  - spec/lib/onebox/engine/youku_onebox_spec.rb