onebox 1.9.20 → 1.9.21

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: 419d39dcf42db192d7a4ad9b9433d9116b8681a1fe0dc26f7769e483ab96e70a
4
- data.tar.gz: c982a68192d84f2f68baeb470554b7153ccbfe7d9536e92080031f1ad9d60bb6
3
+ metadata.gz: 28fed1b823b219fc6c2a79da05780d57b31a267b01d511ddace59e56a74c25f5
4
+ data.tar.gz: fe64ab418c72f1cc58fd84692cf3033ef68488cea9c4918c575a0fcd016ab443
5
5
  SHA512:
6
- metadata.gz: 3e9be16ec4a7830baae8ed2169a4f18ab2c73efd46035c408c7ce13eddb628dd0e47bcd04e4f883421f0b2629387bb9db8b801ac8e36bcb5374292f20ebcb45e
7
- data.tar.gz: adf223e50bfa42f55aeb7f15696dc2ccd2f9616bacb1d2e3b022c4a7dc4f0e66d193cf1527d86f38c2eb0ea723dfee4fd0aae01281935b20511c2da8a01b3d5a
6
+ metadata.gz: efa8c02adf4fdfab9e50ce3a8827eb57184189f5f36beb186495e9978f9c6f33b969c51020485f3a97bd85c09ffb71b0398bec7e9ae853177f5f4a0c1c11ffd6
7
+ data.tar.gz: 6f5ae220a2523ce9f100e3e83eeea9ad3c2ddfcbc488e1f29cd486017c4fd95df058e15d9ff6d4c3752fc8d546e22ab13e79f8db340841fb19c199ee0300541e
data/README.md CHANGED
@@ -46,30 +46,6 @@ preview = Onebox.preview(url)
46
46
  "#{preview}" == preview.to_s #=> true
47
47
  ```
48
48
 
49
- Onebox has its own caching system but you can also provide (or turn off) your own system:
50
-
51
- ``` ruby
52
- require "onebox"
53
-
54
- url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
55
- preview = Onebox.preview(url, cache: Rails.cache)
56
- "#{preview}" == preview.to_s #=> true
57
- ```
58
-
59
- In addition you can set your own options with this handy interface:
60
-
61
- ``` ruby
62
- require "onebox"
63
-
64
- Onebox.options = {
65
- cache: Rails.cache
66
- }
67
-
68
- url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
69
- preview = Onebox.preview(url)
70
- "#{preview}" == preview.to_s #=> true
71
- ```
72
-
73
49
  Ruby Support
74
50
  ------------
75
51
 
@@ -6,7 +6,6 @@ require "multi_json"
6
6
  require "nokogiri"
7
7
  require "mustache"
8
8
  require "ostruct"
9
- require "moneta"
10
9
  require "cgi"
11
10
  require "net/http"
12
11
  require "digest"
@@ -15,7 +14,6 @@ require_relative "onebox/sanitize_config"
15
14
 
16
15
  module Onebox
17
16
  DEFAULTS = {
18
- cache: Moneta.new(:Memory, expires: true, serializer: :json),
19
17
  connect_timeout: 5,
20
18
  timeout: 10,
21
19
  max_download_kb: (10 * 1024), # 10MB
@@ -29,6 +27,11 @@ module Onebox
29
27
  @@options = DEFAULTS
30
28
 
31
29
  def self.preview(url, options = Onebox.options)
30
+ # onebox does not have native caching
31
+ unless Onebox::Helpers.blank?(options[:cache])
32
+ warn "Onebox no longer has inbuilt caching so `cache` option will be ignored."
33
+ end
34
+
32
35
  Preview.new(url, options)
33
36
  end
34
37
 
@@ -13,7 +13,6 @@ module Onebox
13
13
  end
14
14
 
15
15
  attr_reader :url, :uri
16
- attr_reader :cache
17
16
  attr_reader :timeout
18
17
 
19
18
  DEFAULT = {}
@@ -28,10 +27,12 @@ module Onebox
28
27
  @options
29
28
  end
30
29
 
31
- def initialize(link, cache = nil, timeout = nil)
30
+ def initialize(link, timeout = nil)
32
31
  @options = DEFAULT
33
32
  class_name = self.class.name.split("::").last.to_s
34
- self.options = Onebox.options[class_name] || {} #Set the engine options extracted from global options.
33
+
34
+ # Set the engine options extracted from global options.
35
+ self.options = Onebox.options[class_name] || {}
35
36
 
36
37
  @url = link
37
38
  @uri = URI(link)
@@ -39,7 +40,6 @@ module Onebox
39
40
  @uri.scheme = 'https'
40
41
  @url = @uri.to_s
41
42
  end
42
- @cache = cache || Onebox.options.cache
43
43
  @timeout = timeout || Onebox.options.timeout
44
44
  end
45
45
 
@@ -63,13 +63,6 @@ module Onebox
63
63
 
64
64
  private
65
65
 
66
- def record
67
- url_result = url
68
- result = cache.fetch(url_result) { data }
69
- cache[url_result] = result if cache.respond_to?(:key?)
70
- result
71
- end
72
-
73
66
  # raises error if not defined in onebox engine
74
67
  # in each onebox, uses either Nokogiri or StandardEmbed to get raw HTML from url
75
68
  def raw
@@ -38,7 +38,7 @@ module Onebox
38
38
  # Matches URLs for the old Google Maps domain which we occasionally get redirected to
39
39
  matches_regexp :canonical, %r"^(?:https?:)?//maps\.google(?:\.(?:\w{2,}))+/maps\?"
40
40
 
41
- def initialize(url, cache = nil, timeout = nil)
41
+ def initialize(url, timeout = nil)
42
42
  super
43
43
  resolve_url!
44
44
  rescue Net::HTTPServerException, Timeout::Error, Net::HTTPError, Errno::ECONNREFUSED, RuntimeError => err
@@ -18,7 +18,6 @@ module Onebox
18
18
  end
19
19
 
20
20
  escaped_url = ::Onebox::Helpers.normalize_url_for_output(@url)
21
-
22
21
  <<-HTML
23
22
  <a href="#{escaped_url}" target="_blank" class="onebox">
24
23
  <img src="#{escaped_url}">
@@ -26,7 +26,7 @@ module Onebox
26
26
  </aside>
27
27
  HTML
28
28
  else
29
- html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @cache, @timeout).to_html
29
+ html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @timeout).to_html
30
30
  return if Onebox::Helpers.blank?(html)
31
31
  html
32
32
  end
@@ -12,6 +12,11 @@ module Onebox
12
12
  end
13
13
 
14
14
  def to_html
15
+ # Fix Dropbox image links
16
+ if @url[/^https:\/\/www.dropbox.com\/s\//]
17
+ @url.sub!("https://www.dropbox.com", "https://dl.dropboxusercontent.com")
18
+ end
19
+
15
20
  escaped_url = ::Onebox::Helpers.normalize_url_for_output(@url)
16
21
  <<-HTML
17
22
  <div class="onebox video-onebox">
@@ -45,7 +45,7 @@ module Onebox
45
45
  HTML
46
46
  else
47
47
  # for channel pages
48
- html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @cache, @timeout).to_html
48
+ html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @timeout).to_html
49
49
  return if Onebox::Helpers.blank?(html)
50
50
  html.gsub!(/['"]\/\//, "https://")
51
51
  html
@@ -8,12 +8,10 @@ module Onebox
8
8
 
9
9
  VERSION = "1.0.0"
10
10
 
11
- attr_reader :cache
12
11
  attr_reader :record
13
12
  attr_reader :view
14
13
 
15
- def initialize(name, record, cache)
16
- @cache = cache
14
+ def initialize(name, record)
17
15
  @record = Onebox::Helpers.symbolize_keys(record)
18
16
 
19
17
  # Fix any relative paths
@@ -28,9 +26,7 @@ module Onebox
28
26
  end
29
27
 
30
28
  def to_html
31
- result = cache.fetch(checksum) { render(details) }
32
- cache[checksum] = result if cache.respond_to?(:key?)
33
- result
29
+ render(details)
34
30
  end
35
31
 
36
32
  private
@@ -8,7 +8,7 @@ module Onebox
8
8
  end
9
9
 
10
10
  def layout
11
- @layout ||= Layout.new(self.class.onebox_name, record, @cache)
11
+ @layout ||= Layout.new(self.class.onebox_name, data)
12
12
  end
13
13
 
14
14
  def to_html
@@ -25,9 +25,9 @@ module Onebox
25
25
  }
26
26
 
27
27
  module InstanceMethods
28
- def initialize(link, cache = nil, timeout = nil)
29
- super link, cache , timeout
30
- #merge engine options from global Onebox.options interface
28
+ def initialize(link, timeout = nil)
29
+ super link, timeout
30
+ # merge engine options from global Onebox.options interface
31
31
  # self.options = Onebox.options["GithubBlobOnebox"] # self.class.name.split("::").last.to_s
32
32
  # self.options = Onebox.options[self.class.name.split("::").last.to_s] #We can use this a more generic approach. extract the engine class name automatically
33
33
 
@@ -174,9 +174,9 @@ module Onebox
174
174
 
175
175
  cr = calc_range(m, contents_lines_size) #calculate the range of lines for output
176
176
  selected_one_liner = cr[:selected_one_liner] #if url is a one-liner calc_range will return it
177
- from = cr[:from]
178
- to = cr[:to]
179
- @truncated = cr[:truncated]
177
+ from = cr[:from]
178
+ to = cr[:to]
179
+ @truncated = cr[:truncated]
180
180
  range_provided = cr[:range_provided]
181
181
  @cr_results = cr
182
182
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Onebox
4
4
  class Preview
5
- attr_reader :cache
6
5
 
7
6
  # see https://bugs.ruby-lang.org/issues/14688
8
7
  client_exception = defined?(Net::HTTPClientException) ? Net::HTTPClientException : Net::HTTPServerException
@@ -11,7 +10,6 @@ module Onebox
11
10
  def initialize(link, parameters = Onebox.options)
12
11
  @url = link
13
12
  @options = parameters
14
- @cache = options.cache
15
13
  @engine_class = Matcher.new(@url).oneboxed
16
14
  end
17
15
 
@@ -72,7 +70,7 @@ module Onebox
72
70
  return nil unless @engine_class
73
71
  return @engine if @engine
74
72
 
75
- @engine = @engine_class.new(@url, cache)
73
+ @engine = @engine_class.new(@url)
76
74
  @engine.options = @options
77
75
  @engine
78
76
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Onebox
4
- VERSION = "1.9.20"
4
+ VERSION = "1.9.21"
5
5
  end
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency 'multi_json', '~> 1.11'
24
24
  spec.add_runtime_dependency 'mustache'
25
25
  spec.add_runtime_dependency 'nokogiri', '~> 1.7'
26
- spec.add_runtime_dependency 'moneta', '~> 1.0'
27
26
  spec.add_runtime_dependency 'htmlentities', '~> 4.3'
28
27
  spec.add_runtime_dependency 'sanitize'
29
28
 
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.9.20
4
+ version: 1.9.21
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: 2019-10-22 00:00:00.000000000 Z
13
+ date: 2019-11-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
@@ -54,20 +54,6 @@ dependencies:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
56
  version: '1.7'
57
- - !ruby/object:Gem::Dependency
58
- name: moneta
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: '1.0'
64
- type: :runtime
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - "~>"
69
- - !ruby/object:Gem::Version
70
- version: '1.0'
71
57
  - !ruby/object:Gem::Dependency
72
58
  name: htmlentities
73
59
  requirement: !ruby/object:Gem::Requirement