Last active
December 14, 2015 02:29
-
-
Save Marchino/5014076 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
attr_accessible :credits, :image, :link, :title, :video_category_id, :homepage, :client | |
belongs_to :video_category | |
before_validation :update_attributes_through_api | |
mount_uploader :image, ImageUploader | |
acts_as_list | |
def vimeo_url | |
return "http://vimeo.com/api/v2/video/#{self.link}.json" | |
end | |
private | |
def update_attributes_through_api | |
if self.title.blank? or self.credits.blank? or self.image.blank? | |
video = JSON.parse(open(self.vimeo_url).read).last | |
if video.present? | |
self.title = video["title"] unless self.title.present? | |
self.credits = video["description"] unless self.credits.present? | |
self.image = video["thumbnail_large"] unless self.image.present? | |
end | |
end | |
return self | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment