Class: Yt::Models::Video

Inherits:
Resource show all
Defined in:
lib/yt/models/video.rb

Overview

Provides methods to interact with YouTube videos.

Instance Attribute Summary collapse

Attributes inherited from Resource

#auth

Instance Method Summary collapse

Methods inherited from Resource

#initialize, #kind, #username

Methods included from Associations::HasReports

#has_report

Methods included from Associations::HasOne

#has_one

Methods included from Associations::HasMany

#has_many

Methods included from Associations::HasAuthentication

#has_authentication

Constructor Details

This class inherits a constructor from Yt::Models::Resource

Instance Attribute Details

#annotationsYt::Collections::Annotations (readonly)

Returns the video’s annotations.

Returns:



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

has_many :annotations

#content_detailYt::Models::ContentDetail (readonly)

Returns the video’s content details.

Returns:



13
# File 'lib/yt/models/video.rb', line 13

has_one :content_detail

#ratingYt::Models::Rating (readonly)

Returns the video’s rating.

Returns:



19
# File 'lib/yt/models/video.rb', line 19

has_one :rating

#statistics_setYt::Models::StatisticsSet (readonly)

Returns the statistics for the video.

Returns:



48
# File 'lib/yt/models/video.rb', line 48

has_one :statistics_set

Instance Method Details

#comments(options = {}) ⇒ Hash<Date, Float>

Returns the comments for a range of a days.

Parameters:

  • options (Hash) (defaults to: {})

    the range of days to get the comments for.

Options Hash (options):

  • :since (#to_date)

    The first day of the range. Also aliased as :from.

  • :until (#to_date)

    The last day of the range. Also aliased as :to.

Returns:

  • (Hash<Date, Float>)

    the comments for a range of a days.



32
# File 'lib/yt/models/video.rb', line 32

has_report :comments

#comments_on(date) ⇒ Float

Returns the comments for a single day.

Parameters:

  • date (#to_date)

    The single day to get the comments for.

Returns:

  • (Float)

    the comments for a single day.



32
# File 'lib/yt/models/video.rb', line 32

has_report :comments

#dislikeBoolean

Dislikes the video on behalf of the authenticated account.

This method requires auth to return an authenticated instance of Account.

Returns:

  • (Boolean)

    whether the account does not like the video.

Raises:



101
102
103
104
# File 'lib/yt/models/video.rb', line 101

def dislike
  rating.update :dislike
  !liked?
end

#dislikes(options = {}) ⇒ Hash<Date, Float>

Returns the dislikes for a range of a days.

Parameters:

  • options (Hash) (defaults to: {})

    the range of days to get the dislikes for.

Options Hash (options):

  • :since (#to_date)

    The first day of the range. Also aliased as :from.

  • :until (#to_date)

    The last day of the range. Also aliased as :to.

Returns:

  • (Hash<Date, Float>)

    the dislikes for a range of a days.



38
# File 'lib/yt/models/video.rb', line 38

has_report :dislikes

#dislikes_on(date) ⇒ Float

Returns the dislikes for a single day.

Parameters:

  • date (#to_date)

    The single day to get the dislikes for.

Returns:

  • (Float)

    the dislikes for a single day.



38
# File 'lib/yt/models/video.rb', line 38

has_report :dislikes

#earnings(options = {}) ⇒ Hash<Date, Float>

Returns the earnings for a range of a days.

Parameters:

  • options (Hash) (defaults to: {})

    the range of days to get the earnings for.

Options Hash (options):

  • :since (#to_date)

    The first day of the range. Also aliased as :from.

  • :until (#to_date)

    The last day of the range. Also aliased as :to.

Returns:

  • (Hash<Date, Float>)

    the earnings for a range of a days.



26
# File 'lib/yt/models/video.rb', line 26

has_report :earnings

#earnings_on(date) ⇒ Float

Returns the earnings for a single day.

Parameters:

  • date (#to_date)

    The single day to get the earnings for.

Returns:

  • (Float)

    the earnings for a single day.



26
# File 'lib/yt/models/video.rb', line 26

has_report :earnings

#impressions(options = {}) ⇒ Hash<Date, Float>

Returns the impressions for a range of a days.

Parameters:

  • options (Hash) (defaults to: {})

    the range of days to get the impressions for.

Options Hash (options):

  • :since (#to_date)

    The first day of the range. Also aliased as :from.

  • :until (#to_date)

    The last day of the range. Also aliased as :to.

Returns:

  • (Hash<Date, Float>)

    the impressions for a range of a days.



44
# File 'lib/yt/models/video.rb', line 44

has_report :impressions

#impressions_on(date) ⇒ Float

Returns the impressions for a single day.

Parameters:

  • date (#to_date)

    The single day to get the impressions for.

Returns:

  • (Float)

    the impressions for a single day.



44
# File 'lib/yt/models/video.rb', line 44

has_report :impressions

#likeBoolean

Likes the video on behalf of the authenticated account.

This method requires auth to return an authenticated instance of Account.

Returns:

  • (Boolean)

    whether the account likes the video.

Raises:



89
90
91
92
# File 'lib/yt/models/video.rb', line 89

def like
  rating.update :like
  liked?
end

#liked?Boolean

Returns whether the authenticated account likes the video.

This method requires auth to return an authenticated instance of Account.

Returns:

  • (Boolean)

    whether the account likes the video.

Raises:



78
79
80
# File 'lib/yt/models/video.rb', line 78

def liked?
  rating.rating == :like
end

#likes(options = {}) ⇒ Hash<Date, Float>

Returns the likes for a range of a days.

Parameters:

  • options (Hash) (defaults to: {})

    the range of days to get the likes for.

Options Hash (options):

  • :since (#to_date)

    The first day of the range. Also aliased as :from.

  • :until (#to_date)

    The last day of the range. Also aliased as :to.

Returns:

  • (Hash<Date, Float>)

    the likes for a range of a days.



35
# File 'lib/yt/models/video.rb', line 35

has_report :likes

#likes_on(date) ⇒ Float

Returns the likes for a single day.

Parameters:

  • date (#to_date)

    The single day to get the likes for.

Returns:

  • (Float)

    the likes for a single day.



35
# File 'lib/yt/models/video.rb', line 35

has_report :likes

#shares(options = {}) ⇒ Hash<Date, Float>

Returns the shares for a range of a days.

Parameters:

  • options (Hash) (defaults to: {})

    the range of days to get the shares for.

Options Hash (options):

  • :since (#to_date)

    The first day of the range. Also aliased as :from.

  • :until (#to_date)

    The last day of the range. Also aliased as :to.

Returns:

  • (Hash<Date, Float>)

    the shares for a range of a days.



41
# File 'lib/yt/models/video.rb', line 41

has_report :shares

#shares_on(date) ⇒ Float

Returns the shares for a single day.

Parameters:

  • date (#to_date)

    The single day to get the shares for.

Returns:

  • (Float)

    the shares for a single day.



41
# File 'lib/yt/models/video.rb', line 41

has_report :shares

#unlikeBoolean

Resets the rating of the video on behalf of the authenticated account.

This method requires auth to return an authenticated instance of Account.

Returns:

  • (Boolean)

    whether the account does not like the video.

Raises:



113
114
115
116
# File 'lib/yt/models/video.rb', line 113

def unlike
  rating.update :none
  !liked?
end

#update(options = {}) ⇒ Object

TODO:

Update the status, not just the snippet. This requires some caution, as the whole status object needs to be updated, not just privacyStatus, but also embeddable, license, publicStatsViewable, and publishAt



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

def update(options = {})
  options[:title] ||= title
  options[:description] ||= description
  options[:tags] ||= tags
  options[:categoryId] ||= category_id
  snippet = options.slice :title, :description, :tags, :categoryId
  body = {id: @id, snippet: snippet}

  do_update(params: {part: 'snippet'}, body: body) do |data|
    @id = data['id']
    @snippet = Snippet.new data: data['snippet'] if data['snippet']
    true
  end
end

#views(options = {}) ⇒ Hash<Date, Float>

Returns the views for a range of a days.

Parameters:

  • options (Hash) (defaults to: {})

    the range of days to get the views for.

Options Hash (options):

  • :since (#to_date)

    The first day of the range. Also aliased as :from.

  • :until (#to_date)

    The last day of the range. Also aliased as :to.

Returns:

  • (Hash<Date, Float>)

    the views for a range of a days.



29
# File 'lib/yt/models/video.rb', line 29

has_report :views

#views_on(date) ⇒ Float

Returns the views for a single day.

Parameters:

  • date (#to_date)

    The single day to get the views for.

Returns:

  • (Float)

    the views for a single day.



29
# File 'lib/yt/models/video.rb', line 29

has_report :views