Class: UnvlogIt

Inherits:
Object show all
Defined in:
lib/acts_as_unvlogable.rb

Instance Method Summary collapse

Constructor Details

#initialize(url = nil, options = {}) ⇒ UnvlogIt

Returns a new instance of UnvlogIt.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
# File 'lib/acts_as_unvlogable.rb', line 23

def initialize(url=nil, options={})
  raise ArgumentError.new("We need a video url") if url.blank?
  @object ||= "vg_#{get_domain(url).downcase}".camelize.constantize.new(url, options) 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").noembed
  end
end

Instance Method Details

#download_urlObject



60
61
62
# File 'lib/acts_as_unvlogable.rb', line 60

def download_url
  @object.download_url rescue nil
end

#durationObject

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 embed_html(width=425, height=344, options={})
  @object.embed_html(width, height, options) rescue nil
end

#embed_urlObject



44
45
46
# File 'lib/acts_as_unvlogable.rb', line 44

def embed_url
  @object.embed_url rescue nil
end

#flvObject



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

#serviceObject



64
65
66
# File 'lib/acts_as_unvlogable.rb', line 64

def service
  @object.service rescue nil
end

#thumbnailObject



36
37
38
# File 'lib/acts_as_unvlogable.rb', line 36

def thumbnail
  @object.thumbnail rescue nil
end

#titleObject



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_url,
    :embed_html => @object.embed_html(width, height),
    :flv => @object.flv,
    :download_url => @object.download_url,
    :service => @object.service,
    :duration => @object.duration
  }
end

#video_idObject



48
49
50
# File 'lib/acts_as_unvlogable.rb', line 48

def video_id
  @object.video_id rescue nil
end