lib/onebox/engine.rb in onebox-1.5.21 vs lib/onebox/engine.rb in onebox-1.5.22
- old
+ new
@@ -8,11 +8,11 @@
constants.select do |constant|
constant.to_s =~ /Onebox$/
end.map(&method(:const_get))
end
- attr_reader :url
+ attr_reader :url, :uri
attr_reader :cache
attr_reader :timeout
DEFAULT = {}
def options
@@ -35,10 +35,15 @@
@options = DEFAULT
class_name = self.class.name.split("::").last.to_s
self.options = Onebox.options[class_name] || {} #Set the engine options extracted from global options.
@url = link
+ @uri = URI(link)
+ if always_https?
+ @uri.scheme = 'https'
+ @url = @uri.to_s
+ end
@cache = cache || Onebox.options.cache
@timeout = timeout || Onebox.options.timeout
end
# raises error if not defined in onebox engine. This is the output method for
@@ -79,19 +84,23 @@
def data
fail NoMethodError, "Engines need this method defined"
end
def link
- @url.gsub(/['\"<>]/, {
+ @url.gsub(/['\"&<>]/, {
"'" => ''',
'&' => '&',
'"' => '"',
'<' => '<',
'>' => '>',
})
end
+ def always_https?
+ self.class.always_https?
+ end
+
module ClassMethods
def ===(other)
if other.kind_of?(URI)
!!(other.to_s =~ class_variable_get(:@@matcher))
else
@@ -110,9 +119,16 @@
# calculates a name for onebox using the class name of engine
def onebox_name
name.split("::").last.downcase.gsub(/onebox/, "")
end
+ def always_https
+ @https = true
+ end
+
+ def always_https?
+ @https
+ end
end
end
end
require_relative "helpers"