Created — forked from trevorturk/gist:454990

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:739513
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
View gist:739513
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.