class Google::Apis::Core::CallSerializer
Serializes a command for embedding in a multipart batch request @private
Public Instance Methods
to_part(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 [IO]
the serialized request
# File lib/google/apis/core/batch.rb, line 165 def to_part(call) call.prepare! # This will add the Authorization header if needed. call.apply_request_options(call.header) parts = [] parts << build_head(call) parts << build_body(call) unless call.body.nil? length = parts.inject(0) { |a, e| a + e.length } Google::Apis::Core::CompositeIO.new(*parts) end
Protected Instance Methods
build_body(call)
click to toggle source
# File lib/google/apis/core/batch.rb, line 188 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 178 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