Class: Googol::YoutubeResource

Inherits:
Object
  • Object
show all
Includes:
Readable, Requestable, ServerTokens
Defined in:
lib/googol/youtube_resource.rb

Overview

Provides read-only access to a Youtube resource (a channel or a video).

Note that this class does not require the user to authenticate.

Examples:

Get the description of the video “Tongue” by R.E.M.:


resource = Googol::YoutubeResource.new url: 'youtu.be/Kd5M17e7Wek'
resource.description # => "© 2006 WMG\nTongue (Video)"

Get the description of the R.E.M. channel:


resource = Googol::YoutubeResource.new url: 'youtube.com/remhq'
resource.description # => "R.E.M.'s Official YouTube Channel"

Instance Method Summary collapse

Methods included from ServerTokens

#server_key, server_key=

Methods included from Readable

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

Methods included from Requestable

#request!, #symbolize

Constructor Details

#initialize(attrs = {}) ⇒ YoutubeResource

Initialize a resource by URL

Parameters:

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

Options Hash (attrs):

  • :url (String)

    The URL of the Youtube channel or video



28
29
30
# File 'lib/googol/youtube_resource.rb', line 28

def initialize(attrs = {})
  @url = attrs[:url]
end

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 (channel: 88px x 88px, video: 120px x 90px) + :medium [Hash] Medium thumbnail URL (channel: 240px x 240px, video: 320px x 180px) + :high [Hash] High thumbnail URL (channel: 800px x 800px, video: 480px x 360px)

See Also:



48
49
50
51
52
53
54
55
# File 'lib/googol/youtube_resource.rb', line 48

def info
  @info_response ||= request! host: 'https://www.googleapis.com', path: "/youtube/v3/#{info_path}"
  if @info_response[:items].any?
    @info_response[:items].first
  else
    raise RequestError, "Youtube resource not found at #{@url}"
  end
end