class Google::Apis::Core::CallSerializer
Serializes a command for embedding in a multipart batch request @private
Constants
- HTTP_CONTENT_TYPE
Public Instance Methods
to_upload_io(call)
click to toggle source
Serialize a single batched call for assembling the multipart message
@param [Google::Apis::Core::HttpCommand] call
the call to serialize.
@return [Hurley::UploadIO]
the serialized request
# File lib/google/apis/core/batch.rb, line 167 def to_upload_io(call) call.prepare! parts = [] parts << build_head(call) parts << build_body(call) unless call.body.nil? length = parts.inject(0) { |a, e| a + e.length } Hurley::UploadIO.new(Hurley::CompositeReadIO.new(length, *parts), HTTP_CONTENT_TYPE, 'ruby-api-request') end
Protected Instance Methods
build_body(call)
click to toggle source
# File lib/google/apis/core/batch.rb, line 190 def build_body(call) return nil if call.body.nil? return call.body if call.body.respond_to?(:read) StringIO.new(call.body) end
build_head(call)
click to toggle source
# File lib/google/apis/core/batch.rb, line 180 def build_head(call) request_head = "#{call.method.to_s.upcase} #{Addressable::URI.parse(call.url).request_uri} HTTP/1.1" call.header.each do |key, value| request_head << sprintf("\r\n%s: %s", key, value) end request_head << sprintf("\r\nHost: %s", call.url.host) request_head << "\r\n\r\n" StringIO.new(request_head) end