class Google::Apis::Core::Multipart

Helper for building multipart requests

Constants

DEFAULT_BOUNDARY

Attributes

content_type[R]

@return [String]

Content type header

Public Class Methods

new(content_type: MULTIPART_RELATED, boundary: nil) click to toggle source

@param [String] #content_type

Content type for the multipart request

@param [String] boundary

Part delimiter
# File lib/google/apis/core/multipart.rb, line 136
def initialize(content_type: MULTIPART_RELATED, boundary: nil)
  @parts = []
  @boundary = boundary || DEFAULT_BOUNDARY
  @content_type = "#{content_type}; boundary=#{boundary}"
end

Public Instance Methods

add_json(body, content_id: nil) click to toggle source

Append JSON data part

@param [String] body

JSON text

@param [String] content_id

Optional unique ID of this part

@return [self]

# File lib/google/apis/core/multipart.rb, line 149
def add_json(body, content_id: nil)
  header = { :content_id => content_id }
  @parts << Google::Apis::Core::JsonPart.new(@boundary, body, header)
  self
end
add_upload(upload_io, content_id: nil) click to toggle source

Append arbitrary data as a part

@param [Google::Apis::Core::UploadIO] upload_io

IO stream

@param [String] content_id

Optional unique ID of this part

@return [self]

# File lib/google/apis/core/multipart.rb, line 162
def add_upload(upload_io, content_id: nil)
  header = { :content_id => content_id }
  @parts << Google::Apis::Core::FilePart.new(@boundary,
                                             upload_io,
                                             header)
  self
end
assemble() click to toggle source

Assemble the multipart requests

@return [IO]

IO stream
# File lib/google/apis/core/multipart.rb, line 174
def assemble
  @parts << Hurley::Multipart::EpiloguePart.new(@boundary)
  ios = []
  len = 0
  @parts.each do |part|
    len += part.length
    ios << part.to_io
  end
  Hurley::CompositeReadIO.new(len, *ios)
end