Class: YouTubeG::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/youtube_g/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger = Logger.new(STDOUT)) ⇒ Client

Returns a new instance of Client.



7
8
9
# File 'lib/youtube_g/client.rb', line 7

def initialize(logger=Logger.new(STDOUT))
  @logger = logger
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/youtube_g/client.rb', line 5

def logger
  @logger
end

Instance Method Details

#video_by(video_id) ⇒ Object



29
30
31
32
# File 'lib/youtube_g/client.rb', line 29

def video_by(video_id)
  parser = YouTubeG::Parser::VideoFeedParser.new(video_id)
  parser.parse
end

#videos_by(params, options = {}) ⇒ Object

Params can be one of :most_viewed, :top_rated, :recently_featured, :watch_on_mobile Or :tags, :categories, :query, :user



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/youtube_g/client.rb', line 13

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