Class: MTV::Video
Overview
This class represents a music video in MTV’s database.
Instance Attribute Summary collapse
-
#artist ⇒ Object
MTV::Video.search(‘gold’).first.artist.
-
#artist_name ⇒ Object
Returns the value of attribute artist_name.
-
#artist_uri ⇒ Object
Returns the value of attribute artist_uri.
-
#category ⇒ Object
Returns the value of attribute category.
-
#content ⇒ Object
Returns the value of attribute content.
-
#credit ⇒ Object
Returns the value of attribute credit.
-
#media_category ⇒ Object
Returns the value of attribute media_category.
-
#media_credits ⇒ Object
Returns the value of attribute media_credits.
-
#media_description ⇒ Object
Returns the value of attribute media_description.
-
#media_duration ⇒ Object
Returns the value of attribute media_duration.
-
#media_expression ⇒ Object
Returns the value of attribute media_expression.
-
#media_keywords ⇒ Object
Returns the value of attribute media_keywords.
-
#media_medium ⇒ Object
Returns the value of attribute media_medium.
-
#media_player_url ⇒ Object
Returns the value of attribute media_player_url.
-
#media_thumbnails ⇒ Object
Returns the value of attribute media_thumbnails.
-
#media_title ⇒ Object
Returns the value of attribute media_title.
-
#media_type ⇒ Object
Returns the value of attribute media_type.
-
#media_url ⇒ Object
Returns the value of attribute media_url.
-
#published ⇒ Object
Returns the value of attribute published.
-
#title ⇒ Object
Returns the value of attribute title.
-
#uid ⇒ Object
Returns the value of attribute uid.
-
#updated ⇒ Object
Returns the value of attribute updated.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#vid ⇒ Object
Returns the value of attribute vid.
Class Method Summary collapse
-
.find(uid, options = {}) ⇒ Object
MTV::Video.find ‘1234abcd’.
-
.from_artist(artist) ⇒ Object
MTV::Video.from_artist(Artist.find(‘beck’)) MTV::Video.from_artist(‘beck’).
-
.search(term = nil, options = {}) ⇒ Object
api.mtvnservices.com/1/video/search/[parameters] MTV::Video.search ‘the golden age’, :max_results => 1, :start_index => 1.
Instance Method Summary collapse
-
#embed_code(options = {}) ⇒ Object
HTML to embed the Flash player for this video.
-
#initialize(values = {}) ⇒ Video
constructor
—————– Instance Methods —————–.
- #inspect ⇒ Object
- #thumbnails=(val) ⇒ Object
Methods inherited from Base
#attribute_for_inspect, request
Constructor Details
#initialize(values = {}) ⇒ Video
Instance Methods
100 101 102 103 104 |
# File 'lib/mtv/video.rb', line 100 def initialize(values={}) super(values) self.uid = uri.gsub(self.class.base_url + "/video", '').delete '/' unless @uid self.vid = media_url.split(':').last end |
Instance Attribute Details
#artist ⇒ Object
MTV::Video.search(‘gold’).first.artist
107 108 109 |
# File 'lib/mtv/video.rb', line 107 def artist @artist end |
#artist_name ⇒ Object
Returns the value of attribute artist_name.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def artist_name @artist_name end |
#artist_uri ⇒ Object
Returns the value of attribute artist_uri.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def artist_uri @artist_uri end |
#category ⇒ Object
Returns the value of attribute category.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def category @category end |
#content ⇒ Object
Returns the value of attribute content.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def content @content end |
#credit ⇒ Object
Returns the value of attribute credit.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def credit @credit end |
#media_category ⇒ Object
Returns the value of attribute media_category.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_category @media_category end |
#media_credits ⇒ Object
Returns the value of attribute media_credits.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_credits @media_credits end |
#media_description ⇒ Object
Returns the value of attribute media_description.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_description @media_description end |
#media_duration ⇒ Object
Returns the value of attribute media_duration.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_duration @media_duration end |
#media_expression ⇒ Object
Returns the value of attribute media_expression.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_expression @media_expression end |
#media_keywords ⇒ Object
Returns the value of attribute media_keywords.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_keywords @media_keywords end |
#media_medium ⇒ Object
Returns the value of attribute media_medium.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_medium @media_medium end |
#media_player_url ⇒ Object
Returns the value of attribute media_player_url.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_player_url @media_player_url end |
#media_thumbnails ⇒ Object
Returns the value of attribute media_thumbnails.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_thumbnails @media_thumbnails end |
#media_title ⇒ Object
Returns the value of attribute media_title.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_title @media_title end |
#media_type ⇒ Object
Returns the value of attribute media_type.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_type @media_type end |
#media_url ⇒ Object
Returns the value of attribute media_url.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_url @media_url end |
#published ⇒ Object
Returns the value of attribute published.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def published @published end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def title @title end |
#uid ⇒ Object
Returns the value of attribute uid.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def uid @uid end |
#updated ⇒ Object
Returns the value of attribute updated.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def updated @updated end |
#uri ⇒ Object
Returns the value of attribute uri.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def uri @uri end |
#vid ⇒ Object
Returns the value of attribute vid.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def vid @vid end |
Class Method Details
.find(uid, options = {}) ⇒ Object
MTV::Video.find ‘1234abcd’
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mtv/video.rb', line 15 def find(uid, ={}) return uid if uid.is_a? Artist .symbolize_keys! uid = [:uid] || uid response = request "video/#{uid}/" raise Error, "That video not found!" if response.nil? || response.empty? parse_one response end |
.from_artist(artist) ⇒ Object
MTV::Video.from_artist(Artist.find(‘beck’)) MTV::Video.from_artist(‘beck’)
28 29 30 31 32 33 34 |
# File 'lib/mtv/video.rb', line 28 def from_artist(artist) artist_uid = artist.is_a?(Artist) ? artist.uid : string_to_uid(artist) response = request "artist/#{artist_uid}/videos" raise Error, "No videos found!" if response.nil? || response.empty? parse_many response end |
.search(term = nil, options = {}) ⇒ Object
api.mtvnservices.com/1/video/search/[parameters] MTV::Video.search ‘the golden age’, :max_results => 1, :start_index => 1
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mtv/video.rb', line 38 def search(term=nil, ={}) .symbolize_keys! params = { :'max-results' => ([:max_results] || 1), :'start-index' => [:start_index] }.reject { |k,v| v.nil? || v.to_s.empty? }.to_query params = "&#{params}" unless params.empty? term = ([:term] || term).to_query('term') response = request "video/search?#{term}#{params}" raise Error, "No videos not found!" if response.nil? || response.empty? parse_many response end |
Instance Method Details
#embed_code(options = {}) ⇒ Object
HTML to embed the Flash player for this video
112 113 114 115 116 117 118 119 120 |
# File 'lib/mtv/video.rb', line 112 def (={}) [:width] ||= ([:height] ? (([:height]*448).to_f/366).to_i : 448) [:height] ||= ([:width]==448 ? 366 : (([:width]*366).to_f/448).to_i) <<-EOS <embed src="#{media_url}" type="#{media_type}" width="#{[:width]}" height="#{[:height]}" allowFullScreen="true" allowScriptAccess="always" /> EOS end |
#inspect ⇒ Object
122 123 124 125 |
# File 'lib/mtv/video.rb', line 122 def inspect attrs = [:title, :artist_uri].map { |name| "#{name}: #{attribute_for_inspect(name)}" }.compact.join(", ") "#<#{self.class} #{attrs}>" end |