Coder Social home page Coder Social logo

Comments (4)

jondkinney avatar jondkinney commented on June 17, 2024

Hi @davenguyen,

It looks like I specified:

gem.add_dependency('multipart-post', '>= 1.1.5')

Which is probably a mistake, since it's letting you update to 2.0 when I guess it's incompatible with the current code in the gem. I'm using multipart-post up to 1.2 in my current app that uses this gem, I haven't tried to go any further than that, but I don't think it'll be too tough to figure out what is going on and make it compatible. I should probably lock the gemspec to ~>1.2 for now until I can investigate further though.

Also, I still need to release a new version of this gem to rubygems. I'm referencing this repo's master in my gemfile for my current project. 👎

Thanks for the bug report. I'll try to get to it this week. In the mean time, stick to multipart-post 1.2 if you can.

Thanks!

from docusign_rest.

jondkinney avatar jondkinney commented on June 17, 2024

So it looks like the new multipart-post gem now allows the content-type to be set dynamically via an options hash. YAY! This was the only reason I had to monkey patch it before. Here's the new code in multipart-post 2.0.

def build_part(boundary, name, value, headers = {})
  part = ''
  part << "--#{boundary}\r\n"
  part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\r\n"
  part << "Content-Type: #{headers["Content-Type"]}\r\n" if headers["Content-Type"]
  part << "\r\n"
  part << "#{value}\r\n"
end

Versus my monkey patch which just slams the content-type right in there...also note the lack of the 4th headers param, which is now required in 2.0.

def build_part(boundary, name, value)
  part = ''
  part << "--#{boundary}\r\n"
  part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\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 << "\r\n"
  part << "#{value}\r\n"
end

However, I am as of yet unable to figure out how to actually tap into that headers hash and pass along the content-type header. I did update the monkeypatch to take that additional parameter though, so the gem should now be compatible with multipart-post 2.0.

I'm going to have another look at this soon, and I know right where in the code I need to figure out what is going on, I'm just not quite sure the best way to decipher it.

See here: https://github.com/nicksieger/multipart-post/blob/master/lib/multipartable.rb#L12

So that's looking for a :parts key to a hash in the headers. I was messing with passing in:

parts: {'Content-Type' => 'application/json'}

Since that seems to be the only way to get parts_headers actually populated. But then when it iterates through the params and tries to index into the parts_headers hash based on the key of the param and that's where I get stuck. I need to get the content-type header through to the Part.new constructor but I'm not following that code fully.

If you have any insight let me know. Thanks.

from docusign_rest.

jondkinney avatar jondkinney commented on June 17, 2024

310f179

d183ad1

from docusign_rest.

jondkinney avatar jondkinney commented on June 17, 2024

Turns out I was able to support both multipart-post 1.2 and 2.0 by just adding that optional 4th headers hash argument. So I've left the gemspec capable of upgrading beyond 1.2 to 2.0, but I still need to support 1.2 for my app. We're using another gem that requires multipart-post version 1.2 max, so couldn't abandon 1.2 support for docusign_rest just yet. Luckily there is no need!

I also pushed a new version, 0.1.1, of the gem to rubygems.

from docusign_rest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.