Class: Yt::Resource

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

Overview

Provides a base class for YouTube channels, videos, playlists and items. This is an abstract class and should not be instantiated directly.

Direct Known Subclasses

Channel, Comment, CommentThread, Group, Playlist, PlaylistItem, Video

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Resource

Returns a new instance of Resource.

Options Hash (data):

  • :id (String)

    The unique ID of a YouTube resource.



7
8
9
10
# File 'lib/yt/resource.rb', line 7

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

Instance Attribute Details

#dataHash (readonly)



18
19
20
# File 'lib/yt/resource.rb', line 18

def data
  @data
end

Class Method Details

.where(conditions = {}) ⇒ Yt::Relation<Yt::Video>



34
35
36
37
38
39
40
41
# File 'lib/yt/resource.rb', line 34

def self.where(conditions = {})
  @where ||= Relation.new(self) do |options|
    slicing_conditions_every(50) do |slice_options|
      get resources_path, where_params(slice_options)
    end
  end
  @where.where conditions
end

Instance Method Details

#idString



13
14
15
# File 'lib/yt/resource.rb', line 13

def id
  @data[:id]
end

#inspectString



21
22
23
# File 'lib/yt/resource.rb', line 21

def inspect
  "#<#{self.class} @id=#{id}>"
end

#select(*parts) ⇒ Yt::Resource

Specifies which parts of the resource to fetch when hitting the data API.



28
29
30
31
# File 'lib/yt/resource.rb', line 28

def select(*parts)
  @selected_data_parts = parts
  self
end