Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid monkey patching the multipart-post gem to specify Content-Type headers #35

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Expand Up @@ -75,8 +75,6 @@ The above options allow you to change the endpoint (to be able to hit the produc

The docusign\_rest gem makes creating multipart POST (aka file upload) requests to the DocuSign REST API dead simple. It's built on top of Net:HTTP and utilizes the [multipart-post](https://github.com/nicksieger/multipart-post) gem to assist with formatting the multipart requests. The DocuSign REST API requires that all files be embedded as JSON directly in the request body (not the body\_stream like multipart-post does by default) so the docusign\_rest gem takes care of [setting that up for you](https://github.com/j2fly/docusign_rest/blob/master/lib/docusign_rest/client.rb#L397).

This gem also monkey patches one small part of multipart-post to inject some header values and formatting that DocuSign requires. If you would like to see the monkey patched code please take a look at [lib/multipart-post/parts.rb](https://github.com/j2fly/docusign_rest/blob/master/lib/multipart_post/parts.rb). It's only re-opening one method, but feel free to make sure you understand that code if it concerns you.

### Examples

* These examples assume you have already run the `docusign_rest:generate_config` rake task and have the configure block properly setup in an initializer with your username, password, integrator\_key, and account\_id.
Expand Down
1 change: 0 additions & 1 deletion lib/docusign_rest.rb
Expand Up @@ -4,7 +4,6 @@
require_relative 'docusign_rest/utility'
require 'multipart_post' #require the multipart-post gem itself
require 'net/http/post/multipart' #require the multipart-post net/http/post/multipart monkey patch
require_relative 'multipart_post/parts' #require my monkey patched parts.rb which adjusts the build_part method
require 'net/http'
require 'json'

Expand Down
3 changes: 3 additions & 0 deletions lib/docusign_rest/client.rb
Expand Up @@ -547,6 +547,9 @@ def initialize_net_http_multipart_post_request(uri, post_body, file_params, head
# headers={} - The fully merged, final request headers
# boundary - Optional: you can give the request a custom boundary
#

headers = headers.dup.merge(parts: {post_body: {'Content-Type' => 'application/json'}})

request = Net::HTTP::Post::Multipart.new(
uri.request_uri,
{ post_body: post_body }.merge(file_params),
Expand Down
20 changes: 0 additions & 20 deletions lib/multipart_post/parts.rb

This file was deleted.