Class: Yt::Models::Snippet

Inherits:
Object
  • 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.

Instance Method Summary collapse

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:



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

def category_id
  @category_id ||= @data['categoryId']
end

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



81
82
83
# File 'lib/yt/models/snippet.rb', line 81

def channel_id
  @channel_id ||= @data['channelId']
end

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



92
93
94
# File 'lib/yt/models/snippet.rb', line 92

def channel_title
  @channel_title ||= @data['channelTitle']
end

#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

def description
  @description ||= Description.new @data.fetch('description', '')
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.



123
124
125
# File 'lib/yt/models/snippet.rb', line 123

def live_broadcast_content
  @live_broadcast_content ||= @data['liveBroadcastContent']
end

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



132
133
134
# File 'lib/yt/models/snippet.rb', line 132

def playlist_id
  @playlist_id ||= @data['playlistId']
end

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



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

def position
  @position ||= @data['position'].to_i
end

#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
52
53
# File 'lib/yt/models/snippet.rb', line 51

def published_at
  @published_at ||= Time.parse @data['publishedAt']
end

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



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

def tags
  @tags ||= @data.fetch 'tags', []
end

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



69
70
71
72
# File 'lib/yt/models/snippet.rb', line 69

def thumbnail_url(size = :default)
  @thumbnails ||= @data.fetch 'thumbnails', {}
  @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
27
28
# File 'lib/yt/models/snippet.rb', line 26

def title
  @title ||= @data.fetch 'title', ''
end

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



160
161
162
# File 'lib/yt/models/snippet.rb', line 160

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.



151
152
153
# File 'lib/yt/models/snippet.rb', line 151

def video_id
  @video_id ||= @data.fetch('resourceId', {})['videoId']
end