Sha256: ec4ad5d3658b91ee957b5bc9d5b024f685c3c31ba9cfc622d212b6e85ecb41b6
Contents?: true
Size: 961 Bytes
Versions: 1
Compression:
Stored size: 961 Bytes
Contents
module Humpyard module Assets class YoutubeAsset < ::ActiveRecord::Base attr_accessible :youtube_video_id acts_as_humpyard_asset :system_asset => true validates_presence_of :youtube_video_id before_save :update_youtube_data def url "http://www.youtube.com/watch?v=#{youtube_video_id}" end def title youtube_title || "YouTube #{youtube_video_id}" end def content_type 'video/youtube' end def update_youtube_data begin require 'net/http' xml = Net::HTTP.get_response(URI.parse("http://gdata.youtube.com/feeds/api/videos/#{youtube_video_id}")).body title = xml.force_encoding("UTF-8").scan(/<title.*>(.+?)<\/title>/).first.first self.youtube_title = title rescue self.youtube_title = "YouTube #{youtube_video_id}" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
humpyard-0.0.1 | app/models/humpyard/assets/youtube_asset.rb |