Created
June 27, 2010 15:57
-
-
Save trevorturk/454990 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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