Implement simplified commercials workflow

It's now possible to simply enter the url of the third party provider to enter a commercial.
This commit is contained in:
chrisbr 2015-04-22 21:30:32 +02:00
parent e6bb168c5e
commit 58974d6914
26 changed files with 194 additions and 188 deletions

View file

@ -1,10 +1,43 @@
class Commercial < ActiveRecord::Base
require 'oembed'
belongs_to :commercialable, polymorphic: true
attr_accessible :commercial_id, :commercial_type
attr_accessible :url
validates :commercial_id, presence: true
validates :commercial_type, presence: true
validates :url, presence: true
validates :url, format: URI::regexp(%w(http https))
validates :commercial_type, inclusion: { in: CONFIG['commercial_types'].values }
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