Class: Viddler::Video

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/viddler/video.rb

Overview

This class wraps Viddler’s video’s information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Video

:nodoc:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/viddler/video.rb', line 23

def initialize(attributes={}) #:nodoc:
  @id               = attributes['id']
  @title            = attributes['title']
  @description      = attributes['description']
  @tags             = attributes['tags'] ? attributes['tags']['global'].to_a : []
  @url              = attributes['url']
  @thumbnail_url    = attributes['thumbnail_url']
  @author           = attributes['author']
  @length_seconds   = attributes['length_seconds'].to_i
  @view_count       = attributes['view_count'].to_i
  @comment_count    = attributes['comment_count'].to_i
  @upload_time      = attributes['upload_time'] ? Time.at(attributes['upload_time'].to_i/1000) : nil
  @permissions      = attributes['permissions'] ? attributes['permissions'] : nil
  @comments         = attributes['comment_list'].values.flatten.collect do |comment| 
                        Viddler::Comment.new(comment)
                      end if attributes['comment_list']
  @width            = attributes['width'].to_i
  @height           = attributes['height'].to_i
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



7
8
9
# File 'lib/viddler/video.rb', line 7

def author
  @author
end

#comment_countObject

Returns the value of attribute comment_count.



7
8
9
# File 'lib/viddler/video.rb', line 7

def comment_count
  @comment_count
end

#commentsObject

Returns the value of attribute comments.



7
8
9
# File 'lib/viddler/video.rb', line 7

def comments
  @comments
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/viddler/video.rb', line 7

def description
  @description
end

#heightObject

Returns the value of attribute height.



7
8
9
# File 'lib/viddler/video.rb', line 7

def height
  @height
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/viddler/video.rb', line 7

def id
  @id
end

#length_secondsObject

Returns the value of attribute length_seconds.



7
8
9
# File 'lib/viddler/video.rb', line 7

def length_seconds
  @length_seconds
end

#permissionsObject

Returns the value of attribute permissions.



7
8
9
# File 'lib/viddler/video.rb', line 7

def permissions
  @permissions
end

#tagsObject

Returns the value of attribute tags.



7
8
9
# File 'lib/viddler/video.rb', line 7

def tags
  @tags
end

#thumbnail_urlObject

Returns the value of attribute thumbnail_url.



7
8
9
# File 'lib/viddler/video.rb', line 7

def thumbnail_url
  @thumbnail_url
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/viddler/video.rb', line 7

def title
  @title
end

#upload_timeObject

Returns the value of attribute upload_time.



7
8
9
# File 'lib/viddler/video.rb', line 7

def upload_time
  @upload_time
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/viddler/video.rb', line 7

def url
  @url
end

#view_countObject

Returns the value of attribute view_count.



7
8
9
# File 'lib/viddler/video.rb', line 7

def view_count
  @view_count
end

#widthObject

Returns the value of attribute width.



7
8
9
# File 'lib/viddler/video.rb', line 7

def width
  @width
end

Instance Method Details

#<=>(other) ⇒ Object



102
103
104
# File 'lib/viddler/video.rb', line 102

def <=>(other)
  title <=> other.title
end

#==(other) ⇒ Object



90
91
92
# File 'lib/viddler/video.rb', line 90

def ==(other)
  eql?(other)
end

#embed_code(options = {}) ⇒ Object

Returns proper HTML code for embedding

options hash could contain:

  • player_type: The type of player to embed, either “simple” or “player” (default is “player”);

  • width: The width of the player (default is 437);

  • height: The height of the player (default is 370);

  • autoplay: Whether or not to autoplay the video, either “t” or “f” (default is “f”);

  • playAll: Set to “true” to enable play all player (requires player_type to be “player”);

Any additional options passed to the method will be added as flashvars

Example:

@video.embed_code(:player_type => 'simple', :width => 300, :height => 300, autoplay => 't')

Returns embed code for auto playing simple player with 300px width and height



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/viddler/video.rb', line 60

def embed_code(options={})
  options.reverse_merge! \
              :player_type => 'player',
              :width => 437,
              :height => 370,
              :autoplay => 'f',
              :use_secret_url => false

  # get non flashvars from options
  player_type     = options.delete(:player_type)
  width           = options.delete(:width)
  height          = options.delete(:height)
  use_secret_url  = options.delete(:use_secret_url)

  flashvars = options.collect{|key,value| "#{key}=#{value}"}.join('&')

  additional = use_secret_url ? "0/#{permissions['view']['secreturl']}/" : ''

  html = <<CODE
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="#{width}" height="#{height}" id="viddlerplayer-#{self.id}">
<param name="movie" value="http://www.viddler.com/#{player_type}/#{self.id}/#{additional}" />
<param name="allowScriptAccess" value="always" />
<param name="allowFullScreen" value="true" />
<param name="flashvars" value="#{flashvars}" />
<embed src="http://www.viddler.com/#{player_type}/#{self.id}/#{additional}" width="#{width}" height="#{height}" type="application/x-shockwave-flash" allowScriptAccess="always" flashvars="#{flashvars}" allowFullScreen="true" name="viddlerplayer-#{self.id}" >
</embed>
</object>
CODE
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/viddler/video.rb', line 94

def eql?(other)
  id == other.id
end

#hashObject



98
99
100
# File 'lib/viddler/video.rb', line 98

def hash
  id.to_i
end