onebox 2.1.1 → 2.1.6

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: ebbcb2268bcade7ace9670046cfbf13f58862561b59802ef0011bc8ae869a6a7
4
- data.tar.gz: 51e35394339f1cdd6c6dc7be9971bbc7a0e8b8f9a31b483d877e96be86319e0f
3
+ metadata.gz: b6fd88926ec341ed84409e7c77dbfcce244dbf2a0c74e0a19736e81b2b693e84
4
+ data.tar.gz: 18f53e5fb7b1fa4eab35ea27f87e97600e82af0eaf4fd5eed0809744bf7e53c7
5
5
  SHA512:
6
- metadata.gz: 9f540f3437675e0abb5ccb25013b9b516e6bb101a21a26e00a2ecf111940bc660ef8706122f805a279cb67e85823be82183d9f095bc86a7aa7f494c0ecd68645
7
- data.tar.gz: 82295ede48990cf922e1e3e6cce645cd1caf4f9965d8e289d756d727f4b7886e116a5ffa1676f7df3873d524b28161c30c75478e2008887a80324e2ed8639fde
6
+ metadata.gz: 5a5c344336f529d53b51ac47b5b0efee1b6fb29b0b2541948d650fa1d81e11f97edfa3d1a2f8abb7915b8cf9c86e41c74b64cb40b26924e380f68d52e0015c33
7
+ data.tar.gz: 9cefe31755197bbfb71ba3e741329c7bdba10fd9bb19892b237cb78b22769e0e19824119b94cb3cdd24f7bec10f4aeb91cbad3a7d40eefd84c2cbe64866908b0
@@ -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
 
@@ -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
@@ -292,8 +301,7 @@ module Onebox
292
301
  end
293
302
 
294
303
  def has_text?
295
- !Onebox::Helpers.blank?(data[:title]) &&
296
- !Onebox::Helpers.blank?(data[:description])
304
+ !Onebox::Helpers.blank?(data[:title])
297
305
  end
298
306
 
299
307
  def is_image?
@@ -317,7 +325,7 @@ module Onebox
317
325
  return true if AllowlistedGenericOnebox.html_providers.include?(data[:provider_name])
318
326
  return false unless data[:html]["iframe"]
319
327
 
320
- fragment = Nokogiri::HTML::fragment(data[:html])
328
+ fragment = Nokogiri::HTML5::fragment(data[:html])
321
329
  src = fragment.at_css('iframe')&.[]("src")
322
330
  options[:allowed_iframe_regexes]&.any? { |r| src =~ r }
323
331
  end
@@ -368,7 +376,7 @@ module Onebox
368
376
  end
369
377
 
370
378
  def embedded_html
371
- fragment = Nokogiri::HTML::fragment(data[:html])
379
+ fragment = Nokogiri::HTML5::fragment(data[:html])
372
380
  fragment.css("img").each { |img| img["class"] = "thumbnail" }
373
381
  if iframe = fragment.at_css("iframe")
374
382
  iframe.remove_attribute("style")
@@ -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
@@ -20,15 +20,25 @@ module Onebox
20
20
 
21
21
  { link: permalink,
22
22
  title: "@#{oembed.author_name}",
23
- image: "#{permalink}/media/?size=l",
24
- description: Onebox::Helpers.truncate(oembed.title, 250)
23
+ image: oembed.thumbnail_url,
24
+ description: Onebox::Helpers.truncate(oembed.title, 250),
25
25
  }
26
+
26
27
  end
27
28
 
28
29
  protected
29
30
 
31
+ def access_token
32
+ (options[:facebook_app_access_token] || Onebox.options.facebook_app_access_token).to_s
33
+ end
34
+
30
35
  def get_oembed_url
31
- oembed_url = "https://api.instagram.com/oembed/?url=#{clean_url}"
36
+ if access_token != ''
37
+ oembed_url = "https://graph.facebook.com/v9.0/instagram_oembed?url=#{clean_url}&access_token=#{access_token}"
38
+ else
39
+ # The following is officially deprecated by Instagram, but works in some limited circumstances.
40
+ oembed_url = "https://api.instagram.com/oembed/?url=#{clean_url}"
41
+ end
32
42
  end
33
43
  end
34
44
  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.1"
4
+ VERSION = "2.1.6"
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'
@@ -2,7 +2,9 @@
2
2
 
3
3
  <h3><a href='{{link}}' target="_blank" rel="noopener">{{title}}</a></h3>
4
4
 
5
+ {{#description}}
5
6
  <p>{{description}}</p>
7
+ {{/description}}
6
8
 
7
9
  {{#data_1}}
8
10
  <p><span class="label1">{{label_1}}: {{data_1}}</span>
@@ -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.1
4
+ version: 2.1.6
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-08-27 00:00:00.000000000 Z
13
+ date: 2020-11-16 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