Class: RubyTubeNoAuth
- Inherits:
-
Object
- Object
- RubyTubeNoAuth
- Defined in:
- lib/ruby_tube_no_auth.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #comments(id) ⇒ Object
- #find(id) ⇒ Object
-
#initialize(dev_key = "") ⇒ RubyTubeNoAuth
constructor
A new instance of RubyTubeNoAuth.
Constructor Details
#initialize(dev_key = "") ⇒ RubyTubeNoAuth
Returns a new instance of RubyTubeNoAuth.
4 5 6 7 8 9 10 |
# File 'lib/ruby_tube_no_auth.rb', line 4 def initialize(dev_key="") @client = GData::Client::YouTube.new @client.source = "RubyTube" if dev_key @client.developer_key = dev_key end end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
2 3 4 |
# File 'lib/ruby_tube_no_auth.rb', line 2 def client @client end |
Instance Method Details
#comments(id) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ruby_tube_no_auth.rb', line 38 def comments(id) res = @client.get("http://gdata.youtube.com/feeds/api/videos/#{id}/comments") xml = Hpricot.XML(res.body) comments = Array.new if (xml/"entry").nitems > 0 (xml/"entry").each do |entry| cmt = YTComment.new({ :title => (entry/"title").text, :content => (entry/"content").text, :author => (entry/"author").search("name").text, :author_uri => (entry/"author").search("uri").text, :video_uri => (entry/"link[@rel='related']").attr("href") }) comments << cmt end end comments end |
#find(id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ruby_tube_no_auth.rb', line 12 def find(id) res = @client.get("http://gdata.youtube.com/feeds/api/videos/#{id}") xml = Hpricot.XML(res.body) entry = xml.at("entry") vid = YTVideo.new({ :id => entry.at("yt:videoid").inner_text, :title => entry.at("media:title").inner_text, :description => entry.at("media:description").inner_text, :keywords => entry.at("media:keywords").inner_text, :duration => entry.at("yt:duration")["seconds"].to_i, :player_uri => entry.at("link[@rel='alternate']")["href"], :ratings_uri => entry.at("link[@rel$='ratings']")["href"], :comments_uri => entry.at("gd:comments").at("gd:feedLink")["href"], :comment_count => entry.at("gd:comments").at("gd:feedLink")["countHint"].to_i, :published_at => Time.parse(entry.at("published").inner_text), :updated_at => Time.parse(entry.at("updated").inner_text), :view_count => entry.at("yt:statistics").nil? ? 0 : entry.at("yt:statistics")["viewCount"].to_i, :favorite_count => entry.at("yt:statistics").nil? ? 0 : entry.at("yt:statistics")["favoriteCount"].to_i, :comments => comments(entry.at("yt:videoid").inner_text), :ratings => (entry), :status => status(entry), :thumbnails => process_thumbnail_urls(entry) }) vid end |