Skip to content

@kivanio /gist:739513 forked from trevorturk/gist:454990
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
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.