Class: UnvlogIt
Instance Method Summary collapse
- #download_url ⇒ Object
-
#duration ⇒ Object
duration is in seconds.
- #embed_html(width = 425, height = 344, options = {}) ⇒ Object
- #embed_url ⇒ Object
- #flv ⇒ Object
- #get_domain(url) ⇒ Object
-
#initialize(url = nil, options = {}) ⇒ UnvlogIt
constructor
A new instance of UnvlogIt.
- #service ⇒ Object
- #thumbnail ⇒ Object
- #title ⇒ Object
- #video_details(width = 425, height = 344) ⇒ Object
- #video_id ⇒ Object
Constructor Details
#initialize(url = nil, options = {}) ⇒ UnvlogIt
Returns a new instance of UnvlogIt.
23 24 25 26 27 28 29 30 |
# File 'lib/acts_as_unvlogable.rb', line 23 def initialize(url=nil, ={}) raise ArgumentError.new("We need a video url") if url.blank? @object ||= "vg_#{get_domain(url).downcase}".camelize.constantize.new(url, ) rescue nil raise ArgumentError.new("Unsuported url or service") and return if @object.nil? unless @object.instance_variable_get("@details").nil? || !@object.instance_variable_get("@details").respond_to?("noembed") raise ArgumentError.new("Embedding disabled by request") and return if @object.instance_variable_get("@details"). end end |
Instance Method Details
#download_url ⇒ Object
60 61 62 |
# File 'lib/acts_as_unvlogable.rb', line 60 def download_url @object.download_url rescue nil end |
#duration ⇒ Object
duration is in seconds
40 41 42 |
# File 'lib/acts_as_unvlogable.rb', line 40 def duration # duration is in seconds @object.duration rescue nil end |
#embed_html(width = 425, height = 344, options = {}) ⇒ Object
52 53 54 |
# File 'lib/acts_as_unvlogable.rb', line 52 def (width=425, height=344, ={}) @object.(width, height, ) rescue nil end |
#embed_url ⇒ Object
44 45 46 |
# File 'lib/acts_as_unvlogable.rb', line 44 def @object. rescue nil end |
#flv ⇒ Object
56 57 58 |
# File 'lib/acts_as_unvlogable.rb', line 56 def flv @object.flv rescue nil end |
#get_domain(url) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/acts_as_unvlogable.rb', line 82 def get_domain(url) host = URI::parse(url).host.split(".") unless host.size == 1 host[host.size-2] else host[0] end end |
#service ⇒ Object
64 65 66 |
# File 'lib/acts_as_unvlogable.rb', line 64 def service @object.service rescue nil end |
#thumbnail ⇒ Object
36 37 38 |
# File 'lib/acts_as_unvlogable.rb', line 36 def thumbnail @object.thumbnail rescue nil end |
#title ⇒ Object
32 33 34 |
# File 'lib/acts_as_unvlogable.rb', line 32 def title @object.title #rescue nil end |
#video_details(width = 425, height = 344) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/acts_as_unvlogable.rb', line 68 def video_details(width=425, height=344) { :title => @object.title, :thumbnail => @object.thumbnail, :embed_url => @object., :embed_html => @object.(width, height), :flv => @object.flv, :download_url => @object.download_url, :service => @object.service, :duration => @object.duration } end |
#video_id ⇒ Object
48 49 50 |
# File 'lib/acts_as_unvlogable.rb', line 48 def video_id @object.video_id rescue nil end |