Class: VgYoutube
Overview
Class for Youtube (youtube.com)
http://www.youtube.com/watch?v=MVa4q-YVjD8
Direct Known Subclasses
Instance Method Summary collapse
- #duration ⇒ Object
- #embed_html(width = 425, height = 344, options = {}, params = {}) ⇒ Object
- #embed_url ⇒ Object
-
#initialize(url = nil, options = {}) ⇒ VgYoutube
constructor
A new instance of VgYoutube.
- #service ⇒ Object
- #thumbnail ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(url = nil, options = {}) ⇒ VgYoutube
Returns a new instance of VgYoutube.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 8 def initialize(url=nil, ={}) settings ||= YAML.load_file(RAILS_ROOT + '/config/unvlogable.yml') rescue {} Yt.configure do |config| config.api_key = .nil? || [:key].nil? ? settings['youtube_key'] : [:key] end @url = url @video_id = @url.query_param('v') begin @details = Yt::Video.new id: @video_id raise if @details.blank? || !@details. rescue raise ArgumentError, "Unsuported url or service" end end |
Instance Method Details
#duration ⇒ Object
32 33 34 |
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 32 def duration @details.duration end |
#embed_html(width = 425, height = 344, options = {}, params = {}) ⇒ Object
41 42 43 |
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 41 def (width=425, height=344, ={}, params={}) "<iframe id='ytplayer' type='text/html' width='#{width}' height='#{height}' src='#{}#{.map {|k,v| "&#{k}=#{v}"}}' frameborder='0'/>" if @details. end |
#embed_url ⇒ Object
36 37 38 |
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 36 def "http://www.youtube.com/embed/#{@video_id}" if @details. end |
#service ⇒ Object
45 46 47 |
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 45 def service "Youtube" end |
#thumbnail ⇒ Object
28 29 30 |
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 28 def thumbnail @details.thumbnail_url end |
#title ⇒ Object
24 25 26 |
# File 'lib/acts_as_unvlogable/vg_youtube.rb', line 24 def title @details.title end |