onebox 2.2.12 → 2.2.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +0 -4
  3. data/lib/onebox/engine.rb +7 -11
  4. data/lib/onebox/engine/allowlisted_generic_onebox.rb +11 -18
  5. data/lib/onebox/engine/amazon_onebox.rb +26 -17
  6. data/lib/onebox/engine/asciinema_onebox.rb +0 -1
  7. data/lib/onebox/engine/audioboom_onebox.rb +5 -2
  8. data/lib/onebox/engine/bandcamp_onebox.rb +8 -8
  9. data/lib/onebox/engine/cloudapp_onebox.rb +12 -12
  10. data/lib/onebox/engine/coub_onebox.rb +0 -1
  11. data/lib/onebox/engine/facebook_media_onebox.rb +8 -7
  12. data/lib/onebox/engine/five_hundred_px_onebox.rb +0 -1
  13. data/lib/onebox/engine/flickr_onebox.rb +14 -15
  14. data/lib/onebox/engine/gfycat_onebox.rb +26 -26
  15. data/lib/onebox/engine/giphy_onebox.rb +0 -1
  16. data/lib/onebox/engine/github_blob_onebox.rb +4 -0
  17. data/lib/onebox/engine/github_commit_onebox.rb +13 -16
  18. data/lib/onebox/engine/github_folder_onebox.rb +1 -1
  19. data/lib/onebox/engine/github_gist_onebox.rb +1 -2
  20. data/lib/onebox/engine/github_issue_onebox.rb +16 -18
  21. data/lib/onebox/engine/github_pullrequest_onebox.rb +7 -4
  22. data/lib/onebox/engine/gitlab_blob_onebox.rb +4 -0
  23. data/lib/onebox/engine/google_calendar_onebox.rb +1 -1
  24. data/lib/onebox/engine/google_docs_onebox.rb +23 -41
  25. data/lib/onebox/engine/google_drive_onebox.rb +7 -7
  26. data/lib/onebox/engine/google_maps_onebox.rb +10 -8
  27. data/lib/onebox/engine/google_photos_onebox.rb +18 -18
  28. data/lib/onebox/engine/google_play_app_onebox.rb +3 -7
  29. data/lib/onebox/engine/imgur_onebox.rb +2 -2
  30. data/lib/onebox/engine/instagram_onebox.rb +4 -5
  31. data/lib/onebox/engine/kaltura_onebox.rb +8 -6
  32. data/lib/onebox/engine/opengraph_image.rb +0 -1
  33. data/lib/onebox/engine/pastebin_onebox.rb +11 -15
  34. data/lib/onebox/engine/pdf_onebox.rb +7 -15
  35. data/lib/onebox/engine/pubmed_onebox.rb +17 -12
  36. data/lib/onebox/engine/replit_onebox.rb +0 -1
  37. data/lib/onebox/engine/sketchfab_onebox.rb +8 -8
  38. data/lib/onebox/engine/slides_onebox.rb +10 -10
  39. data/lib/onebox/engine/soundcloud_onebox.rb +0 -1
  40. data/lib/onebox/engine/stack_exchange_onebox.rb +3 -2
  41. data/lib/onebox/engine/standard_embed.rb +2 -5
  42. data/lib/onebox/engine/steam_store_onebox.rb +6 -5
  43. data/lib/onebox/engine/trello_onebox.rb +4 -7
  44. data/lib/onebox/engine/twitch_clips_onebox.rb +1 -3
  45. data/lib/onebox/engine/twitch_stream_onebox.rb +1 -2
  46. data/lib/onebox/engine/twitch_video_onebox.rb +0 -2
  47. data/lib/onebox/engine/typeform_onebox.rb +7 -6
  48. data/lib/onebox/engine/vimeo_onebox.rb +9 -7
  49. data/lib/onebox/engine/wikimedia_onebox.rb +1 -2
  50. data/lib/onebox/engine/wikipedia_onebox.rb +12 -8
  51. data/lib/onebox/engine/youku_onebox.rb +7 -13
  52. data/lib/onebox/engine/youtube_onebox.rb +14 -13
  53. data/lib/onebox/file_type_finder.rb +0 -1
  54. data/lib/onebox/helpers.rb +7 -24
  55. data/lib/onebox/layout.rb +2 -14
  56. data/lib/onebox/matcher.rb +10 -8
  57. data/lib/onebox/mixins/git_blob_onebox.rb +8 -8
  58. data/lib/onebox/mixins/github_body.rb +30 -0
  59. data/lib/onebox/mixins/twitch_onebox.rb +0 -1
  60. data/lib/onebox/open_graph.rb +4 -4
  61. data/lib/onebox/preview.rb +3 -4
  62. data/lib/onebox/version.rb +1 -1
  63. data/templates/_layout.mustache +6 -2
  64. data/templates/allowlistedgeneric.mustache +8 -9
  65. data/templates/amazon.mustache +5 -2
  66. data/templates/github/github_body.mustache +5 -0
  67. data/templates/githubblob.mustache +44 -34
  68. data/templates/githubcommit.mustache +2 -10
  69. data/templates/githubfolder.mustache +2 -2
  70. data/templates/githubgist.mustache +9 -6
  71. data/templates/githubissue.mustache +9 -11
  72. data/templates/githubpullrequest.mustache +6 -18
  73. data/templates/gitlabblob.mustache +11 -4
  74. data/templates/googledocs.mustache +2 -2
  75. data/templates/googledrive.mustache +2 -2
  76. data/templates/googleplayapp.mustache +2 -1
  77. data/templates/instagram.mustache +1 -1
  78. data/templates/pastebin.mustache +6 -2
  79. data/templates/pdf.mustache +6 -3
  80. data/templates/stackexchange.mustache +1 -0
  81. data/templates/twitterstatus.mustache +20 -5
  82. data/templates/wikimedia.mustache +2 -2
  83. data/templates/wikipedia.mustache +2 -2
  84. data/templates/xkcd.mustache +2 -2
  85. metadata +7 -5
@@ -11,24 +11,20 @@ module Onebox
11
11
  MAX_DESCRIPTION_CHARS: 500
12
12
  }
13
13
 
14
- matches_regexp Regexp.new("^https?://play\\.(?:(?:\\w)+\\.)?(google)\\.com(?:/)?/store/apps/")
14
+ matches_regexp(/^https?:\/\/play\.(?:(?:\w)+\.)?(google)\.com(?:\/)?\/store\/apps\//)
15
15
  always_https
16
16
 
17
17
  private
18
18
 
19
19
  def data
20
20
  price = raw.css("meta[itemprop=price]").first["content"] rescue "Free"
21
- result = {
21
+ {
22
22
  link: link,
23
23
  title: raw.css("meta[property='og:title']").first["content"].gsub(" - Apps on Google Play", ""),
24
24
  image: ::Onebox::Helpers.normalize_url_for_output(raw.css("meta[property='og:image']").first["content"]),
25
25
  description: raw.css("meta[name=description]").first["content"][0..DEFAULTS[:MAX_DESCRIPTION_CHARS]].chop + "...",
26
- price: price
26
+ price: price == "0" ? "Free" : price
27
27
  }
28
- if result[:price] == "0"
29
- result[:price] = "Free"
30
- end
31
- result
32
28
  end
33
29
  end
34
30
  end
@@ -40,7 +40,7 @@ module Onebox
40
40
  <span class='album-title'>#{album_title}</span>
41
41
  </span>
42
42
  </span>
43
- <img src='#{og.get_secure_image}' #{og.title_attr} height='#{og.image_height}' width='#{og.image_width}'>
43
+ <img src='#{og.secure_image_url}' #{og.title_attr} height='#{og.image_height}' width='#{og.image_width}'>
44
44
  </a>
45
45
  </div>
46
46
  HTML
@@ -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.chomp("?fb")}' #{og.title_attr} alt='Imgur'>
61
+ <img src='#{og.secure_image_url.chomp("?fb")}' #{og.title_attr} alt='Imgur'>
62
62
  </a>
63
63
  HTML
64
64
  end
@@ -18,9 +18,8 @@ module Onebox
18
18
  oembed = get_oembed
19
19
  raise "No oEmbed data found. Ensure 'facebook_app_access_token' is valid" if oembed.data.empty?
20
20
 
21
- permalink = clean_url.gsub("/#{oembed.author_name}/", "/")
22
-
23
- { link: permalink,
21
+ {
22
+ link: clean_url.gsub("/#{oembed.author_name}/", "/"),
24
23
  title: "@#{oembed.author_name}",
25
24
  image: oembed.thumbnail_url,
26
25
  description: Onebox::Helpers.truncate(oembed.title, 250),
@@ -36,10 +35,10 @@ module Onebox
36
35
 
37
36
  def get_oembed_url
38
37
  if access_token != ''
39
- oembed_url = "https://graph.facebook.com/v9.0/instagram_oembed?url=#{clean_url}&access_token=#{access_token}"
38
+ "https://graph.facebook.com/v9.0/instagram_oembed?url=#{clean_url}&access_token=#{access_token}"
40
39
  else
41
40
  # The following is officially deprecated by Instagram, but works in some limited circumstances.
42
- oembed_url = "https://api.instagram.com/oembed/?url=#{clean_url}"
41
+ "https://api.instagram.com/oembed/?url=#{clean_url}"
43
42
  end
44
43
  end
45
44
  end
@@ -14,7 +14,7 @@ module Onebox
14
14
  og = get_opengraph
15
15
 
16
16
  <<~HTML
17
- <img src="#{og.image_secure_url}" width="#{og.video_width}" height="#{og.video_height}" >
17
+ <img src="#{og.image_secure_url}" width="#{og.video_width}" height="#{og.video_height}">
18
18
  HTML
19
19
  end
20
20
 
@@ -22,11 +22,13 @@ module Onebox
22
22
  og = get_opengraph
23
23
 
24
24
  <<~HTML
25
- <iframe src="#{og.video_secure_url}"
26
- width="#{og.video_width}" height="#{og.video_height}"
27
- frameborder='0'
28
- allowfullscreen >
29
- </iframe>
25
+ <iframe
26
+ src="#{og.video_secure_url}"
27
+ width="#{og.video_width}"
28
+ height="#{og.video_height}"
29
+ frameborder='0'
30
+ allowfullscreen
31
+ ></iframe>
30
32
  HTML
31
33
  end
32
34
  end
@@ -8,7 +8,6 @@ module Onebox
8
8
  og = get_opengraph
9
9
  "<img src='#{og.image}' width='#{og.image_width}' height='#{og.image_height}' class='onebox' #{og.title_attr}>"
10
10
  end
11
-
12
11
  end
13
12
  end
14
13
  end
@@ -30,29 +30,25 @@ module Onebox
30
30
  end
31
31
 
32
32
  def lines
33
- return @lines if @lines
33
+ return @lines if defined?(@lines)
34
34
  response = Onebox::Helpers.fetch_response("http://pastebin.com/raw/#{paste_key}", redirect_limit: 1) rescue ""
35
35
  @lines = response.split("\n")
36
36
  end
37
37
 
38
38
  def paste_key
39
- if uri.path =~ /\/raw\//
40
- match = uri.path.match(/\/raw\/([^\/]+)/)
41
- return match[1] if match && match[1]
42
- elsif uri.path =~ /\/download\//
43
- match = uri.path.match(/\/download\/([^\/]+)/)
44
- return match[1] if match && match[1]
45
- elsif uri.path =~ /\/embed\//
46
- match = uri.path.match(/\/embed\/([^\/]+)/)
47
- return match[1] if match && match[1]
39
+ regex = case uri
40
+ when /\/raw\//
41
+ /\/raw\/([^\/]+)/
42
+ when /\/download\//
43
+ /\/download\/([^\/]+)/
44
+ when /\/embed\//
45
+ /\/embed\/([^\/]+)/
48
46
  else
49
- match = uri.path.match(/\/([^\/]+)/)
50
- return match[1] if match && match[1]
47
+ /\/([^\/]+)/
51
48
  end
52
49
 
53
- nil
54
- rescue
55
- nil
50
+ match = uri.path.match(regex)
51
+ match[1] if match && match[1]
56
52
  end
57
53
  end
58
54
  end
@@ -12,25 +12,17 @@ module Onebox
12
12
  private
13
13
 
14
14
  def data
15
- pdf_info = get_pdf_info
16
- raise "Unable to read pdf file: #{@url}" if pdf_info.nil?
15
+ begin
16
+ size = Onebox::Helpers.fetch_content_length(@url)
17
+ rescue
18
+ raise "Unable to read pdf file: #{@url}"
19
+ end
17
20
 
18
- result = { link: link,
19
- title: pdf_info[:name],
20
- filesize: pdf_info[:filesize]
21
- }
22
- result
23
- end
24
-
25
- def get_pdf_info
26
- uri = URI.parse(@url)
27
- size = Onebox::Helpers.fetch_content_length(@url)
28
21
  {
22
+ link: link,
23
+ title: File.basename(uri.path),
29
24
  filesize: size ? Onebox::Helpers.pretty_filesize(size.to_i) : nil,
30
- name: File.basename(uri.path)
31
25
  }
32
- rescue
33
- nil
34
26
  end
35
27
  end
36
28
  end
@@ -6,17 +6,18 @@ module Onebox
6
6
  include Engine
7
7
  include LayoutSupport
8
8
 
9
- matches_regexp Regexp.new("^https?://(?:(?:\\w)+\\.)?(www.ncbi.nlm.nih)\\.gov(?:/)?/pubmed/\\d+")
9
+ matches_regexp(/^https?:\/\/(?:(?:\w)+\.)?(www.ncbi.nlm.nih)\.gov(?:\/)?\/pubmed\/\d+/)
10
10
 
11
11
  private
12
12
 
13
- def get_xml
13
+ def xml
14
+ return @xml if defined?(@xml)
14
15
  doc = Nokogiri::XML(URI.open(URI.join(@url, "?report=xml&format=text")))
15
16
  pre = doc.xpath("//pre")
16
- Nokogiri::XML("<root>" + pre.text + "</root>")
17
+ @xml = Nokogiri::XML("<root>" + pre.text + "</root>")
17
18
  end
18
19
 
19
- def authors_of_xml(xml)
20
+ def authors
20
21
  initials = xml.css("Initials").map { |x| x.content }
21
22
  last_names = xml.css("LastName").map { |x| x.content }
22
23
  author_list = (initials.zip(last_names)).map { |i, l| i + " " + l }
@@ -27,21 +28,25 @@ module Onebox
27
28
  author_list.join(", ")
28
29
  end
29
30
 
30
- def date_of_xml(xml)
31
- date_arr = (xml.css("PubDate").children).map { |x| x.content }
32
- date_arr = date_arr.select { |s| !s.match(/^\s+$/) }
33
- date_arr = (date_arr.map { |s| s.split }).flatten
34
- date_arr.sort.reverse.join(" ") # Reverse sort so month before year.
31
+ def date
32
+ xml.css("PubDate")
33
+ .children
34
+ .map { |x| x.content }
35
+ .select { |s| !s.match(/^\s+$/) }
36
+ .map { |s| s.split }
37
+ .flatten
38
+ .sort
39
+ .reverse
40
+ .join(" ") # Reverse sort so month before year.
35
41
  end
36
42
 
37
43
  def data
38
- xml = get_xml()
39
44
  {
40
45
  title: xml.css("ArticleTitle").text,
41
- authors: authors_of_xml(xml),
46
+ authors: authors,
42
47
  journal: xml.css("Title").text,
43
48
  abstract: xml.css("AbstractText").text,
44
- date: date_of_xml(xml),
49
+ date: date,
45
50
  link: @url,
46
51
  pmid: match[:pmid]
47
52
  }
@@ -20,7 +20,6 @@ module Onebox
20
20
  def to_html
21
21
  get_oembed.html
22
22
  end
23
-
24
23
  end
25
24
  end
26
25
  end
@@ -15,20 +15,20 @@ module Onebox
15
15
  src = og.video_url.gsub("autostart=1", "")
16
16
 
17
17
  <<-HTML
18
- <iframe src="#{src}"
19
- width="#{og.video_width}"
20
- height="#{og.video_height}"
21
- scrolling="no"
22
- frameborder="0"
23
- allowfullscreen>
24
- </iframe>
18
+ <iframe
19
+ src="#{src}"
20
+ width="#{og.video_width}"
21
+ height="#{og.video_height}"
22
+ scrolling="no"
23
+ frameborder="0"
24
+ allowfullscreen
25
+ ></iframe>
25
26
  HTML
26
27
  end
27
28
 
28
29
  def placeholder_html
29
30
  "<img src='#{get_opengraph.image}'>"
30
31
  end
31
-
32
32
  end
33
33
  end
34
34
  end
@@ -11,15 +11,16 @@ module Onebox
11
11
 
12
12
  def to_html
13
13
  <<-HTML
14
- <iframe src="https://slides.com#{uri.path}/embed?style=light"
15
- width="576"
16
- height="420"
17
- scrolling="no"
18
- frameborder="0"
19
- webkitallowfullscreen
20
- mozallowfullscreen
21
- allowfullscreen>
22
- </iframe>
14
+ <iframe
15
+ src="https://slides.com#{uri.path}/embed?style=light"
16
+ width="576"
17
+ height="420"
18
+ scrolling="no"
19
+ frameborder="0"
20
+ webkitallowfullscreen
21
+ mozallowfullscreen
22
+ allowfullscreen
23
+ ></iframe>
23
24
  HTML
24
25
  end
25
26
 
@@ -27,7 +28,6 @@ module Onebox
27
28
  escaped_src = ::Onebox::Helpers.normalize_url_for_output(raw[:image])
28
29
  "<img src='#{escaped_src}'>"
29
30
  end
30
-
31
31
  end
32
32
  end
33
33
  end
@@ -28,7 +28,6 @@ module Onebox
28
28
  oembed_url += "&maxheight=166" unless url["/sets/"]
29
29
  oembed_url
30
30
  end
31
-
32
31
  end
33
32
  end
34
33
  end
@@ -25,7 +25,7 @@ module Onebox
25
25
  end
26
26
 
27
27
  def url
28
- domain = URI(@url).host
28
+ domain = uri.host
29
29
  question_id = match[:question_id]
30
30
  answer_id = match[:answer_id2] || match[:answer_id1]
31
31
 
@@ -37,7 +37,7 @@ module Onebox
37
37
  end
38
38
 
39
39
  def data
40
- return @data if @data
40
+ return @data if defined?(@data)
41
41
 
42
42
  result = raw['items'][0]
43
43
  if result
@@ -48,6 +48,7 @@ module Onebox
48
48
  result['is_answer'] = result.key?('answer_id')
49
49
  result['is_question'] = result.key?('question_id')
50
50
  end
51
+
51
52
  @data = result
52
53
  end
53
54
  end
@@ -7,7 +7,6 @@ require 'onebox/oembed'
7
7
  module Onebox
8
8
  module Engine
9
9
  module StandardEmbed
10
-
11
10
  def self.oembed_providers
12
11
  @@oembed_providers ||= {}
13
12
  end
@@ -37,7 +36,7 @@ module Onebox
37
36
  end
38
37
 
39
38
  def raw
40
- return @raw if @raw
39
+ return @raw if defined?(@raw)
41
40
 
42
41
  og = get_opengraph
43
42
  twitter = get_twitter
@@ -67,7 +66,7 @@ module Onebox
67
66
  protected
68
67
 
69
68
  def html_doc
70
- return @html_doc if @html_doc
69
+ return @html_doc if defined?(@html_doc)
71
70
 
72
71
  headers = nil
73
72
  headers = { 'Cookie' => options[:cookie] } if options[:cookie]
@@ -117,8 +116,6 @@ module Onebox
117
116
  "{}"
118
117
  end
119
118
 
120
- protected
121
-
122
119
  def get_oembed_url
123
120
  oembed_url = nil
124
121
 
@@ -28,11 +28,12 @@ module Onebox
28
28
  escaped_src = ::Onebox::Helpers.normalize_url_for_output(iframe_url)
29
29
 
30
30
  <<-HTML
31
- <iframe src='#{escaped_src}'
32
- frameborder='0'
33
- width='100%'
34
- height='190'>
35
- </iframe>
31
+ <iframe
32
+ src='#{escaped_src}'
33
+ frameborder='0'
34
+ width='100%'
35
+ height='190'
36
+ ></iframe>
36
37
  HTML
37
38
  end
38
39
  end
@@ -11,12 +11,11 @@ module Onebox
11
11
  always_https
12
12
 
13
13
  def to_html
14
- link = "https://trello.com/#{match[:type]}/#{match[:key]}.html"
15
-
14
+ src = "https://trello.com/#{match[:type]}/#{match[:key]}.html"
16
15
  height = match[:type] == 'b' ? 400 : 200
17
16
 
18
17
  <<-HTML
19
- <iframe src=\"#{link}\" width=\"100%\" height=\"#{height}\" frameborder=\"0\" style=\"border:0\"></iframe>
18
+ <iframe src="#{src}" width="100%" height="#{height}" frameborder="0" style="border:0"></iframe>
20
19
  HTML
21
20
  end
22
21
 
@@ -25,12 +24,10 @@ module Onebox
25
24
  end
26
25
 
27
26
  private
28
- def match
29
- return @match if @match
30
27
 
28
+ def match
29
+ return @match if defined?(@match)
31
30
  @match = @url.match(%{trello\.com/(?<type>[^/]+)/(?<key>[^/]+)/?\W*})
32
-
33
- @match
34
31
  end
35
32
  end
36
33
  end
@@ -3,12 +3,11 @@
3
3
  require_relative '../mixins/twitch_onebox'
4
4
 
5
5
  class Onebox::Engine::TwitchClipsOnebox
6
-
7
6
  def self.twitch_regexp
8
7
  /^https?:\/\/clips\.twitch\.tv\/([a-zA-Z0-9_]+\/?[^#\?\/]+)/
9
8
  end
10
- include Onebox::Mixins::TwitchOnebox
11
9
 
10
+ include Onebox::Mixins::TwitchOnebox
12
11
  requires_iframe_origins "https://clips.twitch.tv"
13
12
 
14
13
  def query_params
@@ -18,5 +17,4 @@ class Onebox::Engine::TwitchClipsOnebox
18
17
  def base_url
19
18
  "clips.twitch.tv/embed?"
20
19
  end
21
-
22
20
  end