class

Yt::YouTubeClient

Inherits Reference < Object

Handles interactions with the YouTube Data API v3.

This class provides methods to list, upload, update, and delete videos using either API key or OAuth2 access token authentication.

Example with API Key

client = YouTubeClient.new(api_key: "your_api_key")
video = client.get_video("dQw4w9WgXcQ")

Example with OAuth2

client = YouTubeClient.new(access_token: "your_access_token")
video = client.upload_video("video.mp4", "My Video Title")

Constants

BASE_URL = "https://www.googleapis.com/youtube/v3"
DEFAULT_CATEGORY_ID = "22"
DEFAULT_TIMEOUT = 30.seconds
UPLOAD_URL = "https://www.googleapis.com/upload/youtube/v3"

Constructors

new(api_key : String | Nil = nil, access_token : String | Nil = nil, timeout : Time::Span = DEFAULT_TIMEOUT)
Source

Instance methods

delete_video(video_id : String) : Nil

Delete a video by ID

video_id - The YouTube video ID (11 characters) Raises AuthenticationError if no access token is provided Raises ValidationError if video_id is invalid Raises NetworkError on network failures

Source
get_video(video_id : String) : Models::Video

Get a video by ID with full metadata

video_id - The YouTube video ID (11 characters) Returns the Video object with complete metadata Raises ValidationError if video_id is invalid Raises NotFoundError if video is not found Raises NetworkError on network failures

Source
list_videos(limit : Int32 | Nil = nil) : Array(Models::Video)

List videos from the authenticated user's channel

limit - Maximum number of videos to return (1-50, default: 5) Returns an array of Video objects Raises NetworkError on network failures Raises AuthenticationError on authentication failures Raises RateLimitError when rate limit is exceeded Raises ParseError on malformed responses

Source
update_video(video_id : String, title : String | Nil = nil, description : String | Nil = nil, privacy_status : String | Nil = nil, tags : Array(String) | Nil = nil, category_id : String | Nil = nil, default_language : String | Nil = nil, default_audio_language : String | Nil = nil, preserve_existing : Bool = true) : Models::Video

Update a video's metadata

video_id - The YouTube video ID to update title - New video title (optional) description - New video description (optional) privacy_status - New privacy status: "public", "private", or "unlisted" (optional) tags - Array of tags (optional) category_id - YouTube category ID (optional) default_language - Default language code (optional) default_audio_language - Default audio language code (optional) preserve_existing - If true, fetches existing video metadata to merge unchanged fields (default: true) Returns the updated Video object Raises ValidationError on invalid input Raises AuthenticationError if no access token is provided Raises NetworkError on network failures

Source
upload_video(file_path : String, title : String, description : String | Nil = nil, privacy_status : String = "private", progress_callback : Int64, Int64 -> Nil | Nil = nil) : Models::Video

Upload a new video to YouTube

Source