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 Attribute Summary collapse

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.



17
18
19
20
# File 'lib/yt/models/snippet.rb', line 17

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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
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:



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

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.



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

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.



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

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 >.



39
40
41
# File 'lib/yt/models/snippet.rb', line 39

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:



157
158
159
# File 'lib/yt/models/snippet.rb', line 157

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.



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

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.



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

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.



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

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.



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

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.



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

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.



67
68
69
# File 'lib/yt/models/snippet.rb', line 67

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 >.



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

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.



145
146
147
# File 'lib/yt/models/snippet.rb', line 145

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.



136
137
138
# File 'lib/yt/models/snippet.rb', line 136

def video_id
  resource_id['videoId']
end