onebox 2.1.4 → 2.1.9

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
  SHA256:
3
- metadata.gz: cba7774ebf124a2d110630be26869977c6acf71d1a07603e890d3a1231430834
4
- data.tar.gz: fe5de86e2abdc20fee6139c596da13e1249a6d38d9c40a7759adbbaa5065c8f0
3
+ metadata.gz: d555fa4be5db2d4437afe2b951d7af3efff8e399fc30a2bc425d5f6a791f8ea2
4
+ data.tar.gz: d70a7b81ee90f534faa251b5b73af40077aec16f1450a08ef6adf195f5e725ef
5
5
  SHA512:
6
- metadata.gz: e9d0e1df1c6d14c4984b30c7b3392d519b0eeec63ee7a34656e3089d9c1bc81e1d7e801660ceb2d4da0ea89a779e64a0cb7cd332485b584a9d6873866dbe8819
7
- data.tar.gz: 4c3587d5445c97480c3d5dd4ee514ea9df427d26fb1fed1ace681b95aa6012d79c84323bd915803c4409b21695f4f2f28a6baf6016a8f50dc0f76a65d79be04d
6
+ metadata.gz: 30bc63c0960c76fd6ed876a43554502346cd5b31bf101075307aeb3c4341c32202d9700ef5a5097a46512745cb6659c152a4c9266a7b79769957a33ebf2db92b
7
+ data.tar.gz: 55f73e9b974ce8d5ad272335beaf1a72843fcfcd6b7be2b79988550c7cb33aa5ba6e0d3f419d4341a270d8f0232a849181332e3a3cc7ad07b93f5f432da2a7d1
@@ -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
 
@@ -150,6 +152,7 @@ require_relative "engine/amazon_onebox"
150
152
  require_relative "engine/github_issue_onebox"
151
153
  require_relative "engine/github_blob_onebox"
152
154
  require_relative "engine/github_commit_onebox"
155
+ require_relative "engine/github_folder_onebox"
153
156
  require_relative "engine/github_gist_onebox"
154
157
  require_relative "engine/github_pullrequest_onebox"
155
158
  require_relative "engine/google_calendar_onebox"
@@ -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
@@ -316,7 +325,7 @@ module Onebox
316
325
  return true if AllowlistedGenericOnebox.html_providers.include?(data[:provider_name])
317
326
  return false unless data[:html]["iframe"]
318
327
 
319
- fragment = Nokogiri::HTML::fragment(data[:html])
328
+ fragment = Nokogiri::HTML5::fragment(data[:html])
320
329
  src = fragment.at_css('iframe')&.[]("src")
321
330
  options[:allowed_iframe_regexes]&.any? { |r| src =~ r }
322
331
  end
@@ -367,7 +376,7 @@ module Onebox
367
376
  end
368
377
 
369
378
  def embedded_html
370
- fragment = Nokogiri::HTML::fragment(data[:html])
379
+ fragment = Nokogiri::HTML5::fragment(data[:html])
371
380
  fragment.css("img").each { |img| img["class"] = "thumbnail" }
372
381
  if iframe = fragment.at_css("iframe")
373
382
  iframe.remove_attribute("style")
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Onebox
4
+ module Engine
5
+ class GithubFolderOnebox
6
+ include Engine
7
+ include StandardEmbed
8
+ include LayoutSupport
9
+
10
+ matches_regexp Regexp.new(/^https?:\/\/(?:www\.)?(?:(?:\w)+\.)?(github)\.com[\:\d]*(\/[^\/]+){2}/)
11
+ always_https
12
+
13
+ def self.priority
14
+ # This engine should have lower priority than the other Github engines
15
+ 150
16
+ end
17
+
18
+ private
19
+
20
+ def data
21
+ og = get_opengraph
22
+
23
+ max_length = 250
24
+
25
+ display_path = extract_path(og.url, max_length)
26
+ display_description = clean_description(og.description, og.title, max_length)
27
+
28
+ title = og.title
29
+
30
+ fragment = Addressable::URI.parse(url).fragment
31
+ if fragment
32
+ fragment = Addressable::URI.unencode(fragment)
33
+
34
+ if html_doc.css('.Box.md')
35
+ # For links to markdown docs
36
+ node = html_doc.css('a.anchor').find { |n| n['href'] == "##{fragment}" }
37
+ subtitle = node&.parent&.text
38
+ elsif html_doc.css('.Box.rdoc')
39
+ # For links to rdoc docs
40
+ node = html_doc.css('h3').find { |n| n['id'] == "user-content-#{fragment.downcase}" }
41
+ subtitle = node&.css('text()')&.first&.text
42
+ end
43
+
44
+ title = "#{title} - #{subtitle}" if subtitle
45
+ end
46
+
47
+ {
48
+ link: url,
49
+ image: og.image,
50
+ title: Onebox::Helpers.truncate(title, 250),
51
+ path: display_path,
52
+ description: display_description,
53
+ favicon: get_favicon
54
+ }
55
+ end
56
+
57
+ def extract_path(root, max_length)
58
+ path = url.split('#')[0].split('?')[0]
59
+ path = path["#{root}/tree/".length..-1]
60
+
61
+ return unless path
62
+
63
+ path.length > max_length ? path[-max_length..-1] : path
64
+ end
65
+
66
+ def clean_description(description, title, max_length)
67
+ return unless description
68
+
69
+ desc_end = " - #{title}"
70
+ if description[-desc_end.length..-1] == desc_end
71
+ description = description[0...-desc_end.length]
72
+ end
73
+
74
+ Onebox::Helpers.truncate(description, max_length)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -15,21 +15,32 @@ module Onebox
15
15
  end
16
16
 
17
17
  def data
18
- og = get_opengraph
19
- author_name = og.description.match(/\(@(\w+)\) on Instagram/)[1]
20
- permalink = clean_url.gsub("/#{author_name}/", "/")
18
+ oembed = get_oembed
19
+ raise "No oEmbed data found. Ensure 'facebook_app_access_token' is valid" if oembed.data.empty?
20
+
21
+ permalink = clean_url.gsub("/#{oembed.author_name}/", "/")
21
22
 
22
23
  { link: permalink,
23
- title: "@#{author_name}",
24
- image: "#{permalink}/media/?size=l",
25
- description: Onebox::Helpers.truncate(og.title, 250)
24
+ title: "@#{oembed.author_name}",
25
+ image: oembed.thumbnail_url,
26
+ description: Onebox::Helpers.truncate(oembed.title, 250),
26
27
  }
28
+
27
29
  end
28
30
 
29
31
  protected
30
32
 
33
+ def access_token
34
+ (options[:facebook_app_access_token] || Onebox.options.facebook_app_access_token).to_s
35
+ end
36
+
31
37
  def get_oembed_url
32
- oembed_url = "https://api.instagram.com/oembed/?url=#{clean_url}"
38
+ if access_token != ''
39
+ oembed_url = "https://graph.facebook.com/v9.0/instagram_oembed?url=#{clean_url}&access_token=#{access_token}"
40
+ else
41
+ # The following is officially deprecated by Instagram, but works in some limited circumstances.
42
+ oembed_url = "https://api.instagram.com/oembed/?url=#{clean_url}"
43
+ end
33
44
  end
34
45
  end
35
46
  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
 
@@ -27,7 +27,7 @@ module Onebox
27
27
  def self.fetch_html_doc(url, headers = nil)
28
28
  response = (fetch_response(url, nil, nil, headers) rescue nil)
29
29
  doc = Nokogiri::HTML(response)
30
- uri = URI(url)
30
+ uri = Addressable::URI.parse(url)
31
31
 
32
32
  ignore_canonical_tag = doc.at('meta[property="og:ignore_canonical"]')
33
33
  should_ignore_canonical = IGNORE_CANONICAL_DOMAINS.map { |hostname| uri.hostname.match?(hostname) }.any?
@@ -35,8 +35,9 @@ module Onebox
35
35
  unless (ignore_canonical_tag && ignore_canonical_tag['content'].to_s == 'true') || should_ignore_canonical
36
36
  # prefer canonical link
37
37
  canonical_link = doc.at('//link[@rel="canonical"]/@href')
38
- if canonical_link && "#{URI(canonical_link).host}#{URI(canonical_link).path}" != "#{uri.host}#{uri.path}"
39
- response = (fetch_response(canonical_link, nil, nil, headers) rescue nil)
38
+ canonical_uri = Addressable::URI.parse(canonical_link)
39
+ if canonical_link && "#{canonical_uri.host}#{canonical_uri.path}" != "#{uri.host}#{uri.path}"
40
+ response = (fetch_response(canonical_uri.to_s, nil, nil, headers) rescue nil)
40
41
  doc = Nokogiri::HTML(response) if response
41
42
  end
42
43
  end
@@ -156,6 +157,7 @@ module Onebox
156
157
  end
157
158
 
158
159
  def self.truncate(string, length = 50)
160
+ return string if string.nil?
159
161
  string.size > length ? string[0...(string.rindex(" ", length) || length)] + "..." : string
160
162
  end
161
163
 
@@ -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::HTML::fragment(html)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Onebox
4
- VERSION = "2.1.4"
4
+ VERSION = "2.1.9"
5
5
  end
@@ -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.1.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'
@@ -0,0 +1,11 @@
1
+ {{#image}}<img src="{{image}}" class="thumbnail"/>{{/image}}
2
+
3
+ <h3><a href='{{link}}' target="_blank" rel="noopener">{{title}}</a></h3>
4
+
5
+ {{#path}}
6
+ <p><a href='{{link}}' target="_blank" rel="noopener">{{path}}</a></p>
7
+ {{/path}}
8
+
9
+ {{#description}}
10
+ <p><span class="label1">{{description}}</span></p>
11
+ {{/description}}
@@ -8,4 +8,6 @@
8
8
  </div>
9
9
  {{/image}}
10
10
 
11
- <div class="instagram-description">{{description}}</div>
11
+ {{#description}}
12
+ <div class="instagram-description">{{description}}</div>
13
+ {{/description}}
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
4
+ version: 2.1.9
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-10-21 00:00:00.000000000 Z
13
+ date: 2020-12-07 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.1.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.1.2
196
+ version: 2.4.0
197
197
  - !ruby/object:Gem::Dependency
198
198
  name: twitter
199
199
  requirement: !ruby/object:Gem::Requirement
@@ -316,6 +316,7 @@ files:
316
316
  - lib/onebox/engine/giphy_onebox.rb
317
317
  - lib/onebox/engine/github_blob_onebox.rb
318
318
  - lib/onebox/engine/github_commit_onebox.rb
319
+ - lib/onebox/engine/github_folder_onebox.rb
319
320
  - lib/onebox/engine/github_gist_onebox.rb
320
321
  - lib/onebox/engine/github_issue_onebox.rb
321
322
  - lib/onebox/engine/github_pullrequest_onebox.rb
@@ -383,6 +384,7 @@ files:
383
384
  - templates/amazon.mustache
384
385
  - templates/githubblob.mustache
385
386
  - templates/githubcommit.mustache
387
+ - templates/githubfolder.mustache
386
388
  - templates/githubgist.mustache
387
389
  - templates/githubissue.mustache
388
390
  - templates/githubpullrequest.mustache