class Yt::Models::Account
Provides methods to interact with YouTube accounts. @see developers.google.com/youtube/v3/guides/authentication
Attributes
The name of the content owner managing the account. @return [String] name of the CMS account, if the account is partnered. @return [nil] if the account is not a partnered content owner.
Public Class Methods
@private Initialize user info if included in the response
# File lib/yt/models/account.rb, line 180 def initialize(options = {}) super options if options[:user_info] @user_info = UserInfo.new data: options[:user_info] end end
Public Instance Methods
@return [String] the URL
of the account’s (Google +) profile picture.
# File lib/yt/models/account.rb, line 45 def avatar_url user_info.picture end
Creates a playlist in the account’s channel. @return [Yt::Models::Playlist] the newly created playlist. @param [Hash] params the attributes of the playlist. @option params [String] :title The new playlist’s title.
Cannot have more than 100 characters. Can include the characters < and >, which are replaced to ‹ › in order to be accepted by YouTube.
@option params [String] :description The new playlist’s description.
Cannot have more than 5000 bytes. Can include the characters < and >, which are replaced to ‹ › in order to be accepted by YouTube.
@option params [Array<String>] :tags The new playlist’s tags.
Cannot have more than 500 characters. Can include the characters < and >, which are replaced to ‹ › in order to be accepted by YouTube.
@option params [String] :privacy_status The new playlist’s privacy
status. Must be one of: private, unscheduled, public.
@example Create a playlist titled “My favorites”.
account.create_playlist title: 'My favorites'
# File lib/yt/models/account.rb, line 102 def create_playlist(params = {}) playlists.insert params end
@return [Boolean] whether the email address is verified.
# File lib/yt/models/account.rb, line 23 def has_verified_email? user_info.verified_email end
# File lib/yt/models/account.rb, line 253 def insert_playlist_item_params {} end
# File lib/yt/models/account.rb, line 201 def playlist_items_params {} end
@return [String] the URL
of the account’s (Google +) profile page.
# File lib/yt/models/account.rb, line 40 def profile_url user_info.link end
# File lib/yt/models/account.rb, line 245 def update_playlist_params {} end
# File lib/yt/models/account.rb, line 241 def update_video_params {} end
@private Tells `has_many :resumable_sessions` what metadata to set in the object associated to the uploaded file.
# File lib/yt/models/account.rb, line 220 def upload_body(params = {}) {}.tap do |body| snippet = params.slice :title, :description, :tags, :category_id snippet[:categoryId] = snippet.delete(:category_id) if snippet[:category_id] body[:snippet] = snippet if snippet.any? privacy_status = params[:privacy_status] self_declared_made_for_kids = params[:self_declared_made_for_kids] body[:status] = {} body[:status][:privacyStatus] = privacy_status if privacy_status body[:status][:selfDeclaredMadeForKids] = self_declared_made_for_kids unless self_declared_made_for_kids.nil? end end
@private Tells `has_many :resumable_sessions` what type of file can be uploaded.
# File lib/yt/models/account.rb, line 237 def upload_content_type 'video/*' end
@private Tells `has_many :resumable_sessions` what params are set for the object associated to the uploaded file.
# File lib/yt/models/account.rb, line 213 def upload_params {part: 'snippet,status'} end
@private Tells `has_many :resumable_sessions` what path to hit to upload a file.
# File lib/yt/models/account.rb, line 207 def upload_path '/upload/youtube/v3/videos' end
# File lib/yt/models/account.rb, line 249 def upload_thumbnail_params {} end
Uploads a video to the account’s channel. @param [String] path_or_url the video to upload. Can either be the
path of a local file or the URL of a remote file.
@param [Hash] params the metadata to add to the uploaded video. @option params [String] :title The video’s title. @option params [String] :description The video’s description. @option params [Array<String>] :tags The video’s tags. @option params [String] :privacy_status The video’s privacy status. @option params [Boolean] :self_declared_made_for_kids The video’s made for kids self-declaration. @return [Yt::Models::Video] the newly uploaded video.
# File lib/yt/models/account.rb, line 72 def upload_video(path_or_url, params = {}) file = open path_or_url, 'rb' session = resumable_sessions.insert file.size, upload_body(params) session.update(body: file) do |data| Yt::Video.new( id: data['id'], snippet: data['snippet'], status: data['status'], auth: self ) end end
@private Tells `has_many :video_groups` that content_owner.groups should return all the video-groups *owned by* the account
# File lib/yt/models/account.rb, line 197 def video_groups_params {mine: true} end
@private Tells `has_many :videos` that account.videos should return all the videos *owned by* the account (public, private, unlisted).
# File lib/yt/models/account.rb, line 190 def videos_params {for_mine: true} end