Class: Yt::Models::Snippet

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

Overview

Encapsulates information about the snippet of a resource, for instance a channel.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Snippet

Returns a new instance of Snippet.



9
10
11
# File 'lib/yt/models/snippet.rb', line 9

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

Instance Method Details

#descriptionYt::Models::Description

Returns the resource’s description.

Returns:



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

def description
  @description ||= Description.new @data.fetch('description', '')
end

#published_atTime or nil

Returns the date and time that the resource was created.

Returns:

  • (Time or nil)

    the date and time that the resource was created.



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

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

#tagsArray

Note:

YouTube API only includes tags in a resource’s snippet if the resource is a video belonging to the authenticated account.

Return the tags of a YouTube resource.

Returns:

  • (Array)

    An array of Yt::Tag object, one for each tag of the resource.



34
35
36
# File 'lib/yt/models/snippet.rb', line 34

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

#thumbnail_url(size = :default) ⇒ String

Returns a thumbnail image associated with the resource.

Parameters:

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

    The size of the thumbnail to retrieve. Valid values are: default, medium, high. For a resource that refers to a video, default equals 120x90px, medium equals 320x180px, high equals 480x360px. For a resource that refers to a channel, default equals 88x88px, medium equals 240x240px, high equals 800x800px.

Returns:

  • (String)

    a thumbnail image associated with the resource.



45
46
47
48
# File 'lib/yt/models/snippet.rb', line 45

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

#titleString

Returns the resource’s title.

Returns:

  • (String)

    the resource’s title.



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

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