osem-fcy/app/models/commercial.rb
chrisbr 58974d6914 Implement simplified commercials workflow
It's now possible to simply enter the url of the third party provider to enter a commercial.
2015-04-22 21:30:32 +02:00

43 lines
1,022 B
Ruby

class Commercial < ActiveRecord::Base
require 'oembed'
belongs_to :commercialable, polymorphic: true
attr_accessible :url
validates :url, presence: true
validates :url, format: URI::regexp(%w(http https))
def self.provider
{
youtube: 'YouTube',
slideshare: 'SlideShare',
flickr: 'Flickr',
vimeo: 'Vimeo',
speakerdeck: 'Speakerdeck',
instagram: 'Instagram'
}
end
def self.get_content(url)
speakerdeck = OEmbed::Provider.new('http://speakerdeck.com/oembed.json')
speakerdeck << 'https://speakerdeck.com/*'
speakerdeck << 'http://speakerdeck.com/*'
OEmbed::Providers.register(
OEmbed::Providers::Youtube,
OEmbed::Providers::Vimeo,
OEmbed::Providers::Slideshare,
OEmbed::Providers::Flickr,
OEmbed::Providers::Instagram,
speakerdeck
)
begin
resource = OEmbed::Providers.get(url, maxwidth: 560, maxheight: 315)
resource.html
rescue StandardError
''
end
end
end