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
Source
# File lib/yt/models/resumable_session.rb, line 11 def initialize(options = {}) @uri = URI.parse options[:url] @auth = options[:auth] @headers = options[:headers] end
Sets up a resumable session using the URI returned by YouTube
Public Instance Methods
Source
# File lib/yt/models/resumable_session.rb, line 17 def update(params = {}) do_update(params) {|data| yield data} end
Source
# File lib/yt/models/resumable_session.rb, line 26 def upload_thumbnail(file) do_update(body: file) {|data| data['items'].first} end
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
Private Instance Methods
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
Source
# 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
@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