Class: Yt::Models::Resource

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

Direct Known Subclasses

Channel, Playlist, PlaylistItem, Video, VideoCategory

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



42
43
44
45
46
47
48
# File 'lib/yt/models/resource.rb', line 42

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

#idString (readonly)

Returns the ID that YouTube uses to identify each resource.

Returns:

  • (String)

    the ID that YouTube uses to identify each resource.



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

has_one :id

Instance Method Details

#kindObject



50
51
52
# File 'lib/yt/models/resource.rb', line 50

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

#privacy_statusString

Returns the privacy status of the resource. Possible values are: ‘private’, ‘public’, ‘unlisted’.

Returns:

  • (String)

    the privacy status of the resource. Possible values are: ‘private’, ‘public’, ‘unlisted’.



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

delegate :privacy_status, to: :status

#private?Boolean

Returns whether the resource is private.

Returns:

  • (Boolean)

    whether the resource is private.



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

def private?
  privacy_status == 'private'
end

#public?Boolean

Returns whether the resource is public.

Returns:

  • (Boolean)

    whether the resource is public.



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

def public?
  privacy_status == 'public'
end

#unlisted?Boolean

Returns whether the resource is unlisted.

Returns:

  • (Boolean)

    whether the resource is unlisted.



36
37
38
# File 'lib/yt/models/resource.rb', line 36

def unlisted?
  privacy_status == 'unlisted'
end

#update(attributes = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/yt/models/resource.rb', line 58

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



54
55
56
# File 'lib/yt/models/resource.rb', line 54

def username
  @url.username if @url
end