28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/models/video.rb', line 28
def oembed_cached(maxwidth = nil)
Rails.cache.fetch(oembed_cache_key(maxwidth), :expires_in => 1.hour) do
options = {}
options["maxwidth"] = maxwidth if maxwidth
provider = OEmbed::Providers.find(url)
if provider && provider.endpoint.include?("embed.ly") && SpreeEmbeddedVideos::Config.embedly_api_key
options["key"] = SpreeEmbeddedVideos::Config.embedly_api_key
end
response = nil
if provider
response = provider.get(url, options)
end
response.nil? ? nil : OpenStruct.new(response.fields).freeze
end
end
|