Class: BlipTV::Video
- Inherits:
-
Object
- Object
- BlipTV::Video
- Defined in:
- lib/bliptv/video.rb
Overview
This class wraps Blip.tv’s video’s information.
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#deleted ⇒ Object
Returns the value of attribute deleted.
-
#description ⇒ Object
Returns the value of attribute description.
-
#embed_code ⇒ Object
Returns the value of attribute embed_code.
-
#embed_url ⇒ Object
Returns the value of attribute embed_url.
-
#explicit ⇒ Object
Returns the value of attribute explicit.
-
#guid ⇒ Object
Returns the value of attribute guid.
-
#id ⇒ Object
Returns the value of attribute id.
-
#license ⇒ Object
Returns the value of attribute license.
-
#links ⇒ Object
Returns the value of attribute links.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
-
#update_time ⇒ Object
Returns the value of attribute update_time.
-
#view_count ⇒ Object
Returns the value of attribute view_count.
Instance Method Summary collapse
-
#delete!(creds = {}, section = "file", reason = "because") ⇒ Object
delete! will delete the file from Blip.tv.
-
#get_attributes ⇒ Object
fire off a HTTP GET response to Blip.tv.
-
#initialize(blip_id) ⇒ Video
constructor
:nodoc:.
-
#refresh ⇒ Object
Refresh the current video object.
- #update_attributes_from_hash(a) ⇒ Object
- #update_attributes_from_id(blip_id) ⇒ Object
Constructor Details
#initialize(blip_id) ⇒ Video
:nodoc:
40 41 42 43 44 45 46 47 48 |
# File 'lib/bliptv/video.rb', line 40 def initialize(blip_id) #:nodoc: blip_id = blip_id.to_s if blip_id.class == Fixnum if blip_id.class == String && blip_id.match(BLIP_TV_ID_EXPR) update_attributes_from_id(blip_id) elsif blip_id.class == Hash update_attributes_from_hash(blip_id) end end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def @author end |
#deleted ⇒ Object
Returns the value of attribute deleted.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def deleted @deleted end |
#description ⇒ Object
Returns the value of attribute description.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def description @description end |
#embed_code ⇒ Object
Returns the value of attribute embed_code.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def @embed_code end |
#embed_url ⇒ Object
Returns the value of attribute embed_url.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def @embed_url end |
#explicit ⇒ Object
Returns the value of attribute explicit.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def explicit @explicit end |
#guid ⇒ Object
Returns the value of attribute guid.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def guid @guid end |
#id ⇒ Object
Returns the value of attribute id.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def id @id end |
#license ⇒ Object
Returns the value of attribute license.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def license @license end |
#links ⇒ Object
Returns the value of attribute links.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def links @links end |
#notes ⇒ Object
Returns the value of attribute notes.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def notes @notes end |
#tags ⇒ Object
Returns the value of attribute tags.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def title @title end |
#update_time ⇒ Object
Returns the value of attribute update_time.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def update_time @update_time end |
#view_count ⇒ Object
Returns the value of attribute view_count.
24 25 26 |
# File 'lib/bliptv/video.rb', line 24 def view_count @view_count end |
Instance Method Details
#delete!(creds = {}, section = "file", reason = "because") ⇒ Object
delete! will delete the file from Blip.tv
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/bliptv/video.rb', line 114 def delete!(creds = {}, section = "file", reason = "because") BlipTV::ApiSpec.check_attributes('videos.delete', creds) reason = reason.gsub(" ", "%20") # TODO write a method to handle this and other illegalities of URL if creds[:username] && !creds[:userlogin] creds[:userlogin] = creds[:username] end url, path = "www.blip.tv", "/?userlogin=#{creds[:userlogin]}&password=#{creds[:password]}&cmd=delete&s=file&id=#{@id}&reason=#{reason}&skin=api" request = Net::HTTP.get(url, path) hash = Hash.from_xml(request) make_sure_video_was_deleted(hash) end |
#get_attributes ⇒ Object
fire off a HTTP GET response to Blip.tv
In the future, this should probably be rolled into the BlipTV::Request class, so that all exception raising and network communication exists in instances of that class.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/bliptv/video.rb', line 84 def get_attributes url = URI.parse('http://www.blip.tv/') res = Net::HTTP.start(url.host, url.port) {|http| http.get("http://www.blip.tv/file/#{@id.to_s}?skin=api") } hash = Hash.from_xml(res.body) if hash["response"]["status"] != "OK" raise VideoResponseError.new(hash["response"]["notice"]) end if hash["response"]["payload"]["asset"].is_a?(Array) return hash["response"]["payload"]["asset"][0] # there may be several assets. In that case, read the first one else return hash["response"]["payload"]["asset"] end end |
#refresh ⇒ Object
Refresh the current video object. Useful to check up on encoding progress, etc.
107 108 109 |
# File 'lib/bliptv/video.rb', line 107 def refresh update_attributes_from_id(@id) end |
#update_attributes_from_hash(a) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/bliptv/video.rb', line 57 def update_attributes_from_hash(a) @id = a['item_id'] if @id == nil @title = a['title'] @description = a['description'] @guid = a['guid'] @deleted = a['deleted'] @view_count = a['views'] @tags = a['tags'] @links = a['links']['link'] @thumbnail_url = a['thumbnail_url'] @author = a['created_by']['login'] if a['created_by'] @update_time = a['timestamp'] ? Time.at(a['update_time'].to_i) : nil @explicit = a['explicit'] @license = a['license'] @notes = a['notes'] @embed_url = a['embed_url'] @embed_code = a['embed_code'] end |
#update_attributes_from_id(blip_id) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/bliptv/video.rb', line 50 def update_attributes_from_id(blip_id) @id = blip_id a = get_attributes update_attributes_from_hash(a) end |