Class: Yt::Models::Resource

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

Direct Known Subclasses

Channel, Playlist, PlaylistItem, Video

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 = {}) ⇒ Resource

Returns a new instance of Resource.



19
20
21
22
23
24
25
# File 'lib/yt/models/resource.rb', line 19

def initialize(options = {})
  @url = URL.new(options[:url]) if options[:url]
  @id = options[:id] || (@url.id if @url)
  @auth = options[:auth]
  @snippet = Snippet.new(data: options[:snippet]) if options[:snippet]
  @status = Status.new(data: options[:status]) if options[:status]
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



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

def auth
  @auth
end

Instance Method Details

#kindObject



27
28
29
# File 'lib/yt/models/resource.rb', line 27

def kind
  @url ? @url.kind.to_s : self.class.to_s.demodulize.underscore
end

#update(attributes = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/yt/models/resource.rb', line 35

def update(attributes = {})
  underscore_keys! attributes
  body = build_update_body attributes
  params = {part: body.keys.join(',')}
  do_update params: params, body: body.merge(id: @id) do |data|
    @id = data['id']
    @snippet = Snippet.new data: data['snippet'] if data['snippet']
    @status = Status.new data: data['status'] if data['status']
    true
  end
end

#usernameObject



31
32
33
# File 'lib/yt/models/resource.rb', line 31

def username
  @url.username if @url
end