class Yt::Collections::ResumableSessions

@private Provides methods to upload videos with the resumable upload protocol.

Resources with resumable sessions are: {Yt::Models::Account accounts}.

@see developers.google.com/youtube/v3/guides/using_resumable_upload_protocol

Public Instance Methods

insert(content_length, body = {}) click to toggle source

Starts a resumable session by sending to YouTube the metadata of the object to upload. If the request succeeds, YouTube returns a unique URL to upload the object file (and eventually resume the upload). @param [Integer] content_length the size (bytes) of the object to upload. @param [Hash] body the metadata to add to the uploaded object.

# File lib/yt/collections/resumable_sessions.rb, line 19
def insert(content_length, body = {})
  @headers = headers_for content_length
  do_insert body: body, headers: @headers
end

Private Instance Methods

attributes_for_new_item(data) click to toggle source
# File lib/yt/collections/resumable_sessions.rb, line 26
def attributes_for_new_item(data)
  {url: data['Location'], headers: @headers, auth: @auth}
end
extract_data_from(response) click to toggle source

The result is not in the body but in the headers

# File lib/yt/collections/resumable_sessions.rb, line 46
def extract_data_from(response)
  response.header
end
headers_for(content_length) click to toggle source
# File lib/yt/collections/resumable_sessions.rb, line 38
def headers_for(content_length)
  {}.tap do |headers|
    headers['x-upload-content-length'] = content_length
    headers['X-Upload-Content-Type'] = @parent.upload_content_type
  end
end
insert_params() click to toggle source
Calls superclass method Yt::Actions::Insert#insert_params
# File lib/yt/collections/resumable_sessions.rb, line 30
def insert_params
  super.tap do |params|
    params[:response_format] = nil
    params[:path] = @parent.upload_path
    params[:params] = @parent.upload_params.merge uploadType: 'resumable'
  end
end