require 'multipart_post'
require 'parts'

Parts::ParamPart.class_eval do
  def build_part(boundary, name, value)
    part = ""
    part << "--#{boundary}\r\n"
    part << "Content-Type: application/json\r\n" #Add the content type which isn't present in the multipart-post gem, but DocuSign requires
    part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\r\n"
    part << "\r\n"
    part << "#{value}\r\n"
  end
end

require 'multipart_post'
require 'parts'

Parts::ParamPart.class_eval do
  def build_part(boundary, name, value, headers = {})
    part = ""
    part << "--#{boundary}\r\n"

    # TODO (2014-02-03) jonk => multipart-post seems to allow for adding
    # a configurable header, hence the headers param in the method definition
    # above. However, I can't seem to figure out how to acctually get it passed
    # all the way through to line 42 of the Parts module in the parts.rb file.
    # So for now, we still monkeypatch the content-type in directly.

    part << "Content-Type: application/json\r\n"
    part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\r\n"
    part << "\r\n"
    part << "#{value}\r\n"
  end
end

Update monkeypatch for multipart-post to be compatible with version 2.0
Update monkeypatch for multipart-post to be compatible with version 2.0

Just needed to add another option to the method definition to pass along the headers hash.

I made some notes in the file, but it seems like I should be able to pass along the proper content-type and remove this patch entirely, I just can't figure out exactly how multipart-post passes along the headers yet