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



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?



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

has_attribute :category_id

#channel_idString?



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

has_attribute :channel_id

#channel_titleString?



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

has_attribute :channel_title

#complete?Boolean

Returns whether YouTube API includes all attributes in this snippet. For instance, YouTube API only returns tags on Videos#list, not on Videos#search. And returns position on PlaylistItems#list, not on PlaylistItems#insert. This method is used to guarantee that, when a video was instantiated by one of the methods above, an additional call to is made to retrieve the full snippet in case an attribute is missing.



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

def complete?
  @complete ||= data.fetch :complete, true
end

#descriptionYt::Models::Description



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

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

#live_broadcast_contentString?



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

has_attribute :live_broadcast_content

#playlist_idString?



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

has_attribute :playlist_id

#positionInteger?



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

has_attribute :position, type: Integer

#published_atTime



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

has_attribute :published_at, type: Time

#tagsArray<Yt::Models::Tag>



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

has_attribute :tags, default: []

#thumbnail_url(size = :default) ⇒ String?



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

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

#titleString



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

has_attribute :title, default: ''

#videoYt::Models::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?



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

def video_id
  resource_id['videoId']
end