onebox 2.1.2 → 2.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6f726ba81d305fdfdcdf70d442441504694c33cd249a7d2ff1fb147fa8809c6
4
- data.tar.gz: 6bc5a22ad48c12bbe411fdeca6736a9d1faec3f3f718a561739850623a38fc5b
3
+ metadata.gz: d9a1e5a4239bdcf5a170e23cb70ae17f581cd25de8c6b72eb911d953119fb8cb
4
+ data.tar.gz: 80057c1f0667b807e1e5be53ff283dabeabe64aa3c3f53d1c63658346e7d12ab
5
5
  SHA512:
6
- metadata.gz: 1dc2c71dc5265ee9ffc39b493693c24c536c3812d25078c4e5ea828c435990f40edeb6a4efbef8697f465a9f79b69efd6c1f353c8581fcd60ddf09ed560112f5
7
- data.tar.gz: 181e7ca402b1c0977d28f77135c63232d2cbe57169d2f5a7a78ec1076824d0b56f8699945b1a0df560c7f167ab378033ba664f0f934cc0c70c6fa3913f90ffc7
6
+ metadata.gz: 94a0e7ecc496f75f5f59f40701247fba1bff1068a21c91773e43285c3bf83eadd945ecdd910a8becb454870f5c790baed7626e5cd7d2fe7a6951e7da5fb3e701
7
+ data.tar.gz: 1ad163ff7cfad65008902d27244bd74a9d84e2e49d8600c9ed6f48e74f0fff4d8e77250b36cb4c03e68fdf6f29ab67a8e3e1238b7645156f3f93269f94548329
@@ -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,52 @@
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]*(\/\w*){2}\/tree/)
11
+ always_https
12
+
13
+ private
14
+
15
+ def data
16
+ og = get_opengraph
17
+
18
+ max_length = 250
19
+
20
+ display_path = extract_path(og.url, max_length)
21
+ display_description = clean_description(og.description, og.title, max_length)
22
+
23
+ {
24
+ link: og.url,
25
+ path_link: url,
26
+ image: og.image,
27
+ title: og.title,
28
+ path: display_path,
29
+ description: display_description,
30
+ favicon: get_favicon
31
+ }
32
+ end
33
+
34
+ def extract_path(root, max_length)
35
+ path = url.split('#')[0].split('?')[0]
36
+ path = path["#{root}/tree/".length..-1]
37
+ path.length > max_length ? path[-max_length..-1] : path
38
+ end
39
+
40
+ def clean_description(description, title, max_length)
41
+ return unless description
42
+
43
+ desc_end = " - #{title}"
44
+ if description[-desc_end.length..-1] == desc_end
45
+ description = description[0...-desc_end.length]
46
+ end
47
+
48
+ Onebox::Helpers.truncate(description, max_length)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -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' height='#{og.image_height}' width='#{og.image_width}'>
61
+ <img src='#{og.get_secure_image.chomp("?fb")}' #{og.title_attr} alt='Imgur'>
62
62
  </a>
63
63
  HTML
64
64
  end
@@ -16,19 +16,31 @@ module Onebox
16
16
 
17
17
  def data
18
18
  oembed = get_oembed
19
+ raise "No oEmbed data found. Ensure 'facebook_app_access_token' is valid" if oembed.data.empty?
20
+
19
21
  permalink = clean_url.gsub("/#{oembed.author_name}/", "/")
20
22
 
21
23
  { link: permalink,
22
24
  title: "@#{oembed.author_name}",
23
- image: "#{permalink}/media/?size=l",
24
- description: Onebox::Helpers.truncate(oembed.title, 250)
25
+ image: oembed.thumbnail_url,
26
+ description: Onebox::Helpers.truncate(oembed.title, 250),
25
27
  }
28
+
26
29
  end
27
30
 
28
31
  protected
29
32
 
33
+ def access_token
34
+ (options[:facebook_app_access_token] || Onebox.options.facebook_app_access_token).to_s
35
+ end
36
+
30
37
  def get_oembed_url
31
- 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
32
44
  end
33
45
  end
34
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
 
@@ -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 "https://fast.wistia.com"
10
+ requires_iframe_origins("https://fast.wistia.com", "https://fast.wistia.net")
11
11
  always_https
12
12
 
13
13
  def to_html
@@ -156,6 +156,7 @@ module Onebox
156
156
  end
157
157
 
158
158
  def self.truncate(string, length = 50)
159
+ return string if string.nil?
159
160
  string.size > length ? string[0...(string.rindex(" ", length) || length)] + "..." : string
160
161
  end
161
162
 
@@ -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.2"
4
+ VERSION = "2.1.7"
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='{{path_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.2
4
+ version: 2.1.7
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-09-09 00:00:00.000000000 Z
13
+ date: 2020-11-20 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