Class: Googol::YoutubeAccount

Inherits:
Object
  • Object
show all
Includes:
Authenticable, PlaylistItems, Playlists, Readable, Subscriptions
Defined in:
lib/googol/youtube_account.rb

Overview

Provides read & write access to a Youtube account (also known as Channel).

Examples:

Like the video “Tongue” by R.E.M. as a specific Youtube account:

* Set up two pages: one with a link to authenticate, one to redirect to
* In the first page, add a link to the authentication page:

    Googol::YoutubeAccount.oauth_url(redirect_url)

* The user authenticates and lands on the second page, with an extra +code+ query parameter
* Use the authorization code to initialize the YoutubeAccount and like the video:

    account = Googol::YoutubeAccount.new code: code, redirect_url: redirect_url
    account.like! video_id: 'Kd5M17e7Wek' # => likes the video

Instance Method Summary collapse

Methods included from Subscriptions

#subscribe_to, #subscribe_to!, #unsubscribe_from, #unsubscribe_from!

Methods included from PlaylistItems

#add_item_to!, #add_videos_to!, #remove_all_items_from!

Methods included from Playlists

#create_playlist!, #delete_playlists!, #find_or_create_playlist_by, #find_playlist_by, #update_playlist!

Methods included from Readable

#description, #id, #kind, #thumbnail_url, #title

Methods included from Authenticable

#credentials, #initialize

Methods included from Requestable

#request!, #symbolize

Methods included from ClientTokens

#client_id, client_id=, #client_secret, client_secret=

Instance Method Details

#infoHash

Return the profile info of a Youtube account/channel.

Returns:

  • (Hash)
    • :id [String] The ID that YouTube uses to uniquely identify the channel.

    • :etag [String] The Etag of this resource.

    • :kind [String] The value will be youtube#channel.

    • :snippet [Hash]

      • :title [String] The channel’s title.

      • :description [String] The channel’s description.

      • :publishedAt [String] The date and time that the channel was created. The value is specified in ISO 8601 (YYYY-MM-DDThh:mm:ss.sZ) format.

      • :thumbnails [Hash] + :default [Hash] Default thumbnail URL (88px x 88px) + :medium [Hash] Medium thumbnail URL (88px x 88px) + :high [Hash] High thumbnail URL (88px x 88px)

See Also:



44
45
46
47
# File 'lib/googol/youtube_account.rb', line 44

def info
  @info_response ||= youtube_request! path: '/channels?part=id,snippet&mine=true'
  @info_response[:items].first
end

#like!(target = {}) ⇒ Object

Note:

Liking a video does not also subscribe to its channel

Like a video as a Youtube account

Parameters:

  • target (Hash) (defaults to: {})

    The target of the ‘like’ activity

Options Hash (target):

  • :video_id (String)

    The ID of the video to like

See Also:



58
59
60
61
62
# File 'lib/googol/youtube_account.rb', line 58

def like!(target = {})
  video_id = fetch! target, :video_id
  path = "/videos/rate?rating=like&id=#{video_id}"
  youtube_request! path: path, method: :post, code: 204
end