class YouTube::Client

Main client class managing all interaction with the YouTube server. Server communication is handled via method_missing() emulating an RPC-like call and performing all of the work to send out the HTTP request and retrieve the XML response. Inspired by the Flickr interface by Scott Raymond <redgreenblu.com/flickr/>.

Constants

DEFAULT_API_PATH

the default api path to the YouTube API

DEFAULT_HOST

the default hostname at which the YouTube API is hosted

Public Class Methods

new(dev_id = nil, host = DEFAULT_HOST, api_path = DEFAULT_API_PATH) click to toggle source
# File lib/youtube.rb, line 56
def initialize(dev_id = nil, host = DEFAULT_HOST, api_path = DEFAULT_API_PATH)
  raise "developer id required" unless dev_id

  @host = host
  @api_path = api_path
  @dev_id = dev_id
end

Public Instance Methods

favorite_videos(username) click to toggle source

Returns a list of YouTube::Video objects detailing the favorite videos of the supplied username.

# File lib/youtube.rb, line 73
def favorite_videos(username)
  response = users_list_favorite_videos(:user => username)
  _parse_video_response(response)
end
friends(username) click to toggle source

Returns a list of YouTube::Friend objects detailing the friends of the supplied username.

# File lib/youtube.rb, line 80
def friends(username)
  response = users_list_friends(:user => username)
  friends = response['friend_list']['friend']
  friends.is_a?(Array) ? friends.compact.map { |friend| Friend.new(friend) } : nil        
end
profile(username) click to toggle source

Returns a YouTube::Profile object detailing the profile information regarding the supplied username.

# File lib/youtube.rb, line 66
def profile(username)
  response = users_get_profile(:user => username)
  Profile.new response['user_profile']
end
video_details(video_id) click to toggle source

Returns a YouTube::VideoDetails object detailing additional information on the supplied video id, obtained from a YouTube::Video object from a previous client call.

# File lib/youtube.rb, line 175
def video_details(video_id)
  raise ArgumentError.new("invalid video id parameter, must be string") unless video_id.is_a?(String)
  response = videos_get_details(:video_id => video_id)
  VideoDetails.new(response['video_details'])
end
videos_by_category_and_tag(category, tag, page = 1, per_page = 20) click to toggle source

Returns a list of YouTube::Video objects detailing the videos matching the supplied category and tag.

Available categories: YouTube::Category::FILMS_ANIMATION YouTube::Category::AUTOS_VEHICLES YouTube::Category::COMEDY YouTube::Category::ENTERTAINMENT YouTube::Category::MUSIC YouTube::Category::NEWS_POLITICS YouTube::Category::PEOPLE_BLOGS YouTube::Category::PETS_ANIMALS YouTube::Category::HOWTO_DIY YouTube::Category::SPORTS YouTube::Category::TRAVEL_PLACES YouTube::Category::GADGETS_GAMES

Optional parameters are: page = the “page” of results to retrieve (e.g. 1, 2, 3) per_page = the number of results per page (default: 20, max 100).

# File lib/youtube.rb, line 150
def videos_by_category_and_tag(category, tag, page = 1, per_page = 20)
  videos_by_category_id_and_tag(category, tag, page, per_page)
end
videos_by_category_id_and_tag(id, tag, page = 1, per_page = 20) click to toggle source

Returns a list of YouTube::Video objects detailing the videos matching the supplied category id and tag.

Optional parameters are: page = the “page” of results to retrieve (e.g. 1, 2, 3) per_page = the number of results per page (default: 20, max 100).

# File lib/youtube.rb, line 125
def videos_by_category_id_and_tag(id, tag, page = 1, per_page = 20)
  response = videos_list_by_category_and_tag(:category_id => id, :tag => tag, :page => page, :per_page => per_page)
  _parse_video_response(response)
end
videos_by_playlist(id, page = 1, per_page = 20) click to toggle source

Returns a list of YouTube::Video objects with the specified playlist id.

Optional parameters are: page = the “page” of results to retrieve (e.g. 1, 2, 3) per_page = the number of results per page (default: 20, max 100).

# File lib/youtube.rb, line 114
def videos_by_playlist(id, page = 1, per_page = 20)
  response = videos_list_by_playlist(:id => id, :page => page, :per_page => per_page)
  _parse_video_response(response)
end
videos_by_tag(tag, page = 1, per_page = 20) click to toggle source

Returns a list of YouTube::Video objects detailing the videos matching the supplied tag.

Optional parameters are: page = the “page” of results to retrieve (e.g. 1, 2, 3) per_page = the number of results per page (default: 20, max 100).

# File lib/youtube.rb, line 92
def videos_by_tag(tag, page = 1, per_page = 20)
  response = videos_list_by_tag(:tag => tag, :page => page, :per_page => per_page)
  _parse_video_response(response)
end
videos_by_user(username, page = 1, per_page = 20) click to toggle source

Returns a list of YouTube::Video objects detailing the videos uploaded by the specified username.

Optional parameters are: page = the “page” of results to retrieve (e.g. 1, 2, 3) per_page = the number of results per page (default: 20, max 100).

# File lib/youtube.rb, line 160
def videos_by_user(username, page = 1, per_page = 20)
  response = videos_list_by_user(:user => username, :page => page, :per_page => per_page)
   _parse_video_response(response)
 end