Class: Yt::Models::Snippet

Inherits:
Base
  • Object
show all
Defined in:
lib/yt/models/snippet.rb

Overview

Contains basic information about the resource. The details of the snippet are different for the different types of resources.

Resources with a snippet are: channels, playlists, playlist items and videos.

Constant Summary collapse

BROADCAST_TYPES =
%q(live none upcoming)

Instance Method Summary collapse

Methods included from Associations::HasReports

#has_report

Methods included from Associations::HasViewerPercentages

#has_viewer_percentages

Methods included from Associations::HasOne

#has_one

Methods included from Associations::HasMany

#has_many

Methods included from Associations::HasAuthentication

#has_authentication

Constructor Details

#initialize(options = {}) ⇒ Snippet

Returns a new instance of Snippet.



15
16
17
18
# File 'lib/yt/models/snippet.rb', line 15

def initialize(options = {})
  @data = options[:data]
  @auth = options[:auth]
end

Instance Method Details

#category_idString?

Returns:

  • (String)

    if the resource is a video, the YouTube video category associated with the video.

  • (nil)

    if the resource is a channel.

  • (nil)

    if the resource is a playlist.

  • (nil)

    if the resource is a playlist item.

See Also:



103
# File 'lib/yt/models/snippet.rb', line 103

has_attribute :category_id

#channel_idString?

Returns:

  • (String)

    if the resource is a playlist, the ID that YouTube uses to uniquely identify the channel that the playlist belongs to.

  • (String)

    if the resource is a playlist item, the ID that YouTube uses to uniquely identify the channel that the playlist belongs to.

  • (String)

    if the resource is a video, the ID that YouTube uses to uniquely identify the channel that the video was uploaded to.

  • (nil)

    if the resource is a channel.



76
# File 'lib/yt/models/snippet.rb', line 76

has_attribute :channel_id

#channel_titleString?

Returns:

  • (String)

    if the resource is a playlist, the title of the channel that the playlist belongs to.

  • (String)

    if the resource is a playlist item, the title of the channel that the playlist item belongs to.

  • (String)

    if the resource is a video, the title of the channel that the video was uploaded to.

  • (nil)

    if the resource is a channel.



85
# File 'lib/yt/models/snippet.rb', line 85

has_attribute :channel_title

#descriptionYt::Models::Description

Returns:

  • (Yt::Models::Description)

    if the resource is a channel, the channel’s description. Has a maximum of 1000 characters.

  • (Yt::Models::Description)

    if the resource is a playlist, the playlist’s description.

  • (Yt::Models::Description)

    if the resource is a playlist item, the item’s description.

  • (Yt::Models::Description)

    if the resource is a video, the video’s description. Has a maximum of 5000 bytes and may contain all valid UTF-8 characters except < and >.



37
38
39
# File 'lib/yt/models/snippet.rb', line 37

has_attribute :description, default: '' do |description_text|
  Description.new description_text
end

#includes_tagsBoolean

Returns whether YouTube API includes tags in this snippet. YouTube API only returns tags on Videos#list, not on Videos#search. This method is used to guarantee that, when a video was instantiated by calling account.videos or channel.videos, then video.tags is not simply returned as empty, but an additional call to Videos#list is made to retrieve the correct tags.

Returns:

  • (Boolean)

    whether YouTube API includes tags in this snippet.

See Also:



155
156
157
# File 'lib/yt/models/snippet.rb', line 155

def includes_tags
  @includes_tags ||= @data.fetch :includes_tags, true
end

#live_broadcast_contentString?

Returns:

  • (String)

    if the resource is a video, whether the resource is a live broadcast. Valid values are: live, none, upcoming.

  • (nil)

    if the resource is a channel.

  • (nil)

    if the resource is a playlist.

  • (nil)

    if the resource is a playlist item.



112
# File 'lib/yt/models/snippet.rb', line 112

has_attribute :live_broadcast_content

#playlist_idString?

Returns:

  • (String)

    if the resource is a playlist item, the ID that YouTube uses to uniquely identify the playlist that the item is in.

  • (nil)

    if the resource is a channel.

  • (nil)

    if the resource is a playlist.

  • (nil)

    if the resource is a video.



119
# File 'lib/yt/models/snippet.rb', line 119

has_attribute :playlist_id

#positionInteger?

Returns:

  • (Integer)

    if the resource is a playlist item, the order in which the item appears in a playlist. The value is zero-based, so the first item has a position of 0, the second item of 1, and so forth.

  • (nil)

    if the resource is a channel.

  • (nil)

    if the resource is a playlist.

  • (nil)

    if the resource is a video.



127
# File 'lib/yt/models/snippet.rb', line 127

has_attribute :position, type: Integer

#published_atTime

Returns:

  • (Time)

    if the resource is a channel, the date and time that the channel was created.

  • (Time)

    if the resource is a playlist, the date and time that the playlist was created.

  • (Time)

    if the resource is a playlist item, the date and time that the item was added to the playlist.

  • (Time)

    if the resource is a video, the date and time that the video was published.



49
# File 'lib/yt/models/snippet.rb', line 49

has_attribute :published_at, type: Time

#tagsArray<Yt::Models::Tag>

Returns:

  • (Array<Yt::Models::Tag>)

    if the resource is a channel, an empty array.

  • (Array<Yt::Models::Tag>)

    if the resource is a playlist, the list of keyword tags associated with the playlist.

  • (Array<Yt::Models::Tag>)

    if the resource is a playlist item, an empty array.

  • (Array<Yt::Models::Tag>)

    if the resource is a video, the list of keyword tags associated with the video.



95
# File 'lib/yt/models/snippet.rb', line 95

has_attribute :tags, default: []

#thumbnail_url(size = :default) ⇒ String?

Parameters:

  • size (Symbol, String) (defaults to: :default)

    The size of the thumbnail to retrieve.

Returns:

  • (String)

    if the resource is a channel and size is default, the URL of an 88x88px image.

  • (String)

    if the resource is a playlist, a PlaylistItem or a Video and size is default, the URL of an 120x90px image.

  • (String)

    if the resource is a channel and size is medium, the URL of an 240x240px image.

  • (String)

    if the resource is a playlist, a PlaylistItem or a Video and size is medium, the URL of an 320x180px image.

  • (String)

    if the resource is a channel and size is high, the URL of an 800x800px image.

  • (String)

    if the resource is a playlist, a PlaylistItem or a Video and size is high, the URL of an 480x360px image.

  • (nil)

    if the size is not default, medium or high.



65
66
67
# File 'lib/yt/models/snippet.rb', line 65

def thumbnail_url(size = :default)
  thumbnails.fetch(size.to_s, {})['url']
end

#titleString

Returns:

  • (String)

    if the resource is a channel, the channel’s title.

  • (String)

    if the resource is a playlist, the playlist’s title.

  • (String)

    if the resource is a playlist item, the item’s title.

  • (String)

    if the resource is a video, the video’s title. Has a maximum of 100 characters and may contain all valid UTF-8 characters except < and >.



26
# File 'lib/yt/models/snippet.rb', line 26

has_attribute :title, default: ''

#videoYt::Models::Video?

Returns:

  • (Yt::Models::Video)

    the video the playlist item represents in the playlist.

  • (nil)

    if the resource is a channel.

  • (nil)

    if the resource is a playlist.

  • (nil)

    if the resource is a video.



143
144
145
# File 'lib/yt/models/snippet.rb', line 143

def video
  @video ||= Video.new id: video_id, auth: @auth if video_id
end

#video_idString?

Returns:

  • (String)

    if the resource is a playlist item, the ID of the video the playlist item represents in the playlist.

  • (nil)

    if the resource is a channel.

  • (nil)

    if the resource is a playlist.

  • (nil)

    if the resource is a video.



134
135
136
# File 'lib/yt/models/snippet.rb', line 134

def video_id
  resource_id['videoId']
end