Sha256: 25a4315917a22391c14d832af362da20e00c2bcada140b3acbfd4533745c1398

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

require 'logger'

class YouTubeG
  class Client
    attr_accessor :logger
    
    def initialize(logger=Logger.new(STDOUT))
      @logger = logger
    end

    # Params can be one of :most_viewed, :top_rated, :recently_featured, :watch_on_mobile
    # Or :tags, :categories, :query, :user
    def videos_by(params, options={})
      if params.respond_to?(:to_hash) and not params[:user]
        request = YouTubeG::Request::VideoSearch.new(params)

      elsif (params.respond_to?(:to_hash) && params[:user]) || (params == :favorites)
        request = YouTubeG::Request::UserSearch.new(params, options)

      else
        request = YouTubeG::Request::StandardSearch.new(params, options)
      end
      
      logger.debug "Submitting request [url=#{request.url}]."
      parser = YouTubeG::Parser::VideosFeedParser.new(request.url)
      parser.parse
    end
    
    def video_by(vid)
      video_id = vid =~ /^http/ ? vid : "http://gdata.youtube.com/feeds/videos/#{vid}"
      parser = YouTubeG::Parser::VideoFeedParser.new(video_id)
      parser.parse
    end
    
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
FiXato-youtube-g-0.4.5 lib/youtube_g/client.rb
msp-youtube-g-0.4.5 lib/youtube_g/client.rb
msp-youtube-g-0.4.6 lib/youtube_g/client.rb
msp-youtube-g-0.4.7 lib/youtube_g/client.rb
tmm1-youtube-g-0.4.5 lib/youtube_g/client.rb