public
Last active — forked from trevorturk/gist:454990

  • Download Gist
gistfile1.builder
Ruby
1 2 3 4 5 6 7 8 9 10 11 12
class Video < ActiveRecord::Base
 
before_validation :set_attrs_via_embedly, :on => :create
 
def set_attrs_via_embedly
# example url: http://www.youtube.com/watch?v=oHg5SJYRHA0
attrs = Embedly.get_attrs url
errors[:base] << "is not a video" unless attrs['type'] == 'video'
self.attributes = attrs
end
 
end
gistfile2.builder
Ruby
1 2 3 4 5 6 7 8 9 10 11
class Embedly
 
def self.get_attrs(url)
embedly_url = "http://api.embed.ly/v1/api/oembed?url=#{url}"
response = RestClient.get embedly_url
attrs = JSON.parse response.body
rescue
{}
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.