Class: Viddler::Video
- Inherits:
-
Object
- Object
- Viddler::Video
- Includes:
- Comparable
- Defined in:
- lib/viddler/video.rb
Overview
This class wraps Viddler’s video’s information.
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#comment_count ⇒ Object
Returns the value of attribute comment_count.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#description ⇒ Object
Returns the value of attribute description.
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
Returns the value of attribute id.
-
#length_seconds ⇒ Object
Returns the value of attribute length_seconds.
-
#permissions ⇒ Object
Returns the value of attribute permissions.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#thumbnail_url ⇒ Object
Returns the value of attribute thumbnail_url.
-
#title ⇒ Object
Returns the value of attribute title.
-
#upload_time ⇒ Object
Returns the value of attribute upload_time.
-
#url ⇒ Object
Returns the value of attribute url.
-
#view_count ⇒ Object
Returns the value of attribute view_count.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#embed_code(options = {}) ⇒ Object
Returns proper HTML code for embedding.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(attributes = {}) ⇒ Video
constructor
:nodoc:.
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
#author ⇒ Object
Returns the value of attribute author.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def @author end |
#comment_count ⇒ Object
Returns the value of attribute comment_count.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def comment_count @comment_count end |
#comments ⇒ Object
Returns the value of attribute comments.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def comments @comments end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def description @description end |
#height ⇒ Object
Returns the value of attribute height.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def height @height end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def id @id end |
#length_seconds ⇒ Object
Returns the value of attribute length_seconds.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def length_seconds @length_seconds end |
#permissions ⇒ Object
Returns the value of attribute permissions.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def @permissions end |
#tags ⇒ Object
Returns the value of attribute tags.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def @tags end |
#thumbnail_url ⇒ Object
Returns the value of attribute thumbnail_url.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def thumbnail_url @thumbnail_url end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def title @title end |
#upload_time ⇒ Object
Returns the value of attribute upload_time.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def upload_time @upload_time end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def url @url end |
#view_count ⇒ Object
Returns the value of attribute view_count.
7 8 9 |
# File 'lib/viddler/video.rb', line 7 def view_count @view_count end |
#width ⇒ Object
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.(: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 (={}) .reverse_merge! \ :player_type => 'player', :width => 437, :height => 370, :autoplay => 'f', :use_secret_url => false # get non flashvars from options player_type = .delete(:player_type) width = .delete(:width) height = .delete(:height) use_secret_url = .delete(:use_secret_url) flashvars = .collect{|key,value| "#{key}=#{value}"}.join('&') additional = use_secret_url ? "0/#{['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
94 95 96 |
# File 'lib/viddler/video.rb', line 94 def eql?(other) id == other.id end |
#hash ⇒ Object
98 99 100 |
# File 'lib/viddler/video.rb', line 98 def hash id.to_i end |