class Yt::Models::ResumableSession

@private Provides methods to upload videos with the resumable upload protocol. @see developers.google.com/youtube/v3/guides/using_resumable_upload_protocol

Public Class Methods

new(options = {}) click to toggle source

Sets up a resumable session using the URI returned by YouTube

# File lib/yt/models/resumable_session.rb, line 11
def initialize(options = {})
  @uri = URI.parse options[:url]
  @auth = options[:auth]
  @headers = options[:headers]
end

Public Instance Methods

update(params = {}) { |data| ... } click to toggle source
# File lib/yt/models/resumable_session.rb, line 17
def update(params = {})
  do_update(params) {|data| yield data}
end
upload_thumbnail(file) click to toggle source

Uploads a thumbnail using the current resumable session @param [#read] file A binary object that contains the image content.

Can either be a File, a StringIO (for instance using open-uri), etc.

@return the new thumbnail resource for the given image. @see developers.google.com/youtube/v3/docs/thumbnails#resource

# File lib/yt/models/resumable_session.rb, line 26
def upload_thumbnail(file)
  do_update(body: file) {|data| data['items'].first}
end

Private Instance Methods

session_params() click to toggle source
# File lib/yt/models/resumable_session.rb, line 32
def session_params
  CGI::parse(@uri.query).tap{|hash| hash.each{|k,v| hash[k] = v.first}}
end
update_params() click to toggle source

@note: YouTube documentation states that a valid upload returns an HTTP

code of 201 Created -- however it looks like the actual code is 200.
To be sure to include both cases, HTTPSuccess is used
Calls superclass method Yt::Actions::Update#update_params
# File lib/yt/models/resumable_session.rb, line 39
def update_params
  super.tap do |params|
    params[:request_format] = :file
    params[:host] = @uri.host
    params[:path] = @uri.path
    params[:expected_response] = Net::HTTPSuccess
    params[:headers] = @headers
    params[:camelize_params] = false
    params[:params] = session_params
  end
end