Merge 58974d6914 into eface6a91b
This commit is contained in:
commit
b1c131c524
26 changed files with 194 additions and 188 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue