README.md in docusign_rest-0.2.0 vs README.md in docusign_rest-0.3.0
- old
+ new
@@ -1,8 +1,8 @@
# DocusignRest
-This 'wrapper gem' hooks a Ruby app (currently only tested with Rails) up to the [DocuSign](http://www.docusign.com/) [REST API](http://www.docusign.com/developer-center) to allow for embedded signing.
+This 'wrapper gem' hooks a Ruby app (currently only tested with Rails) up to the [DocuSign](http://www.docusign.com/) REST API ([docs](https://docs.docusign.com/esign/), [API explorer](https://apiexplorer.docusign.com/#/esign/restapi)) to allow for embedded signing.
## Installation
Add this line to your application's Gemfile:
@@ -63,60 +63,110 @@
There are several other configuration options available but the two most likely to be needed are:
```ruby
config.endpoint = 'https://docusign.net/restapi'
-config.api_version = 'v1'
+config.api_version = 'v2'
```
-The above options allow you to change the endpoint (to be able to hit the production DocuSign API, for instance) and to modify the API version you wish to use. If there is a big change in the API it's likely that this gem will need to be updated to leverage changes on the DocuSign side. However, it doesn't hurt to provide the option in case there are several minor updates that do not break functionality but would otherwise require a new gem release. These config options have existed since the gem was created, but in v0.0.3 and above, the options are auto-generated in the config file as comments to make them easier to discover.
+The above options allow you to change the endpoint (to be able to hit the production DocuSign API, for instance) and to modify the API version you wish to use.
-
## Usage
-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).
+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.
* Unless noted otherwise, these requests return the JSON parsed body of the response so you can index the returned hash directly. For example: `template_response["templateId"]`.
+#### Situations
+
+** In the context of a Rails app **
+
+This is how most people are using this gem - they've got a Rails app that's doing things with the Docusign API. In that case, these examples assume you have already set up a docusign account, have 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.
+
+** In the context of this gem as a standalone project **
+
+Ideally this gem will be independent of Rails. If that's your situation, there won't be a Rails initializer so your code will need to load the API authentication credentials. You will want to do something like:
+
+```ruby
+load 'test/docusign_login_config.rb'
+client = DocusignRest::Client.new
+client.get_account_id
+document_envelope_response = client.create_envelope_from_document( # etc etc
+```
+
+#### Example code
+
**Getting account_id:**
```ruby
client = DocusignRest::Client.new
puts client.get_account_id
```
-
**Creating an envelope from a document:**
-Note: In the example below there are two sign here tabs for the user with a role of 'Attorney'. There are also two documents attached to the envelope, however, this exact configuration would only allow for signature on the first document. If you need signature for a second document, you'll need to add further options, namely: `document_id: 2` in one of the sign_here_tabs so that DocuSign knows where to embed that signature tab.
+Here's how to create an envelope from a local PDF file and open a browser to the URL for the recipient:
```ruby
client = DocusignRest::Client.new
document_envelope_response = client.create_envelope_from_document(
email: {
subject: "test email subject",
body: "this is the email body and it's large!"
},
+ # If embedded is set to true in the signers array below, emails
+ # don't go out to the signers and you can embed the signature page in an
+ # iframe by using the client.get_recipient_view method
+ signers: [
+ {
+ embedded: true,
+ name: 'Joe Dimaggio',
+ email: 'joe.dimaggio@example.org',
+ role_name: 'Issuer',
+ sign_here_tabs: [
+ {
+ anchor_string: 'sign here',
+ anchor_x_offset: '-30',
+ anchor_y_offset: '35'
+ }
+ ]
+ },
+ ],
+ files: [
+ {path: '/Absolute/path/to/test.pdf', name: 'test.pdf'},
+ ],
+ status: 'sent'
+)
+url = client.get_recipient_view(envelope_id: document_envelope_response['envelopeId'], name: "Joe Dimaggio", email: "joe.dimaggio@example.org", return_url: 'http://google.com')['url']
+`open #{url}`
+```
+
+Note: In the example below there are two sign here tabs for the user with a role of 'Attorney'. There are also two documents attached to the envelope, however, this exact configuration would only allow for signature on the first document. If you need signature for a second document, you'll need to add further options, namely: `document_id: 2` in one of the `sign_here_tabs` so that DocuSign knows where to embed that signature tab.
+
+```ruby
+client = DocusignRest::Client.new
+document_envelope_response = client.create_envelope_from_document(
+ email: {
+ subject: "test email subject",
+ body: "this is the email body and it's large!"
+ },
# If embedded is set to true in the signers array below, emails
# don't go out to the signers and you can embed the signature page in an
- # iFrame by using the client.get_recipient_view method
+ # iframe by using the client.get_recipient_view method
signers: [
{
embedded: true,
name: 'Test Guy',
email: 'someone@gmail.com',
role_name: 'Issuer',
sign_here_tabs: [
{
- anchor_string: 'sign_here_1',
- anchor_x_offset: '140',
- anchor_y_offset: '8'
+ anchor_string: 'sign here',
+ anchor_x_offset: '-30',
+ anchor_y_offset: '35'
}
]
},
{
embedded: true,
@@ -216,12 +266,10 @@
)
```
**Creating an envelope from a template using custom tabs:**
-Note: This feature is not supported in 'v1' of the REST API
-
```ruby
client = DocusignRest::Client.new
@envelope_response = client.create_envelope_from_template(
status: 'sent',
email: {
@@ -294,18 +342,18 @@
document_id: 1,
local_save_path: "#{Rails.root.join('docusign_docs/file_name.pdf')}"
)
```
-## Breaking out of the iFrame after signing
+## Breaking out of the iframe after signing
-In order to return to your application after the signing process is complete it's important to have a way to evaluate whether or not the signing was successful and then do something about each case. The way I set this up was to render the embedded signing iframe for a controller action called 'embedded_signing' and specify the return_url of the `client.get_recipient_view` API call to be something like: http://myapp.com/docusign_response. Then in the same controller as the embedded_signing method, define the docusign_response method. This is where the signing process will redirect to after the user is done interacting with the DocuSign iframe. DocuSign passes a query string parameter in the return_url named 'event' and you can check like so: `if params[:event] == "signing_complete"` then you'll want to redirect to another spot in your app, not in the iframe. To do so, we need to use JavaScript to access the iframe's parent and set it's location to the path of our choosing. To do this, instanciate the DocusignRest::Utility class and call the breakout_path method like this:
+In order to return to your application after the signing process is complete it's important to have a way to evaluate whether or not the signing was successful and then do something about each case. The way I set this up was to render the embedded signing iframe for a controller action called 'embedded_signing' and specify the return_url of the `client.get_recipient_view` API call to be something like: http://myapp.com/docusign_response. Then in the same controller as the embedded_signing method, define the docusign_response method. This is where the signing process will redirect to after the user is done interacting with the DocuSign iframe. DocuSign passes a query string parameter in the return_url named 'event' and you can check like so: `if params[:event] == "signing_complete"` then you'll want to redirect to another spot in your app, not in the iframe. To do so, we need to use JavaScript to access the iframe's parent and set it's location to the path of our choosing. To do this, instantiate the `DocusignRest::Utility` class and call the breakout_path method like this:
```ruby
class SomeController < ApplicationController
- # the view corresponding to this action has the iFrame in it with the
+ # the view corresponding to this action has the iframe in it with the
# @url as it's src. @envelope_response is populated from either:
# @envelope_response = client.create_envelope_from_document
# or
# @envelope_response = client.create_envelope_from_template
def embedded_signing
@@ -346,13 +394,9 @@
In order to run the tests you'll need to register for a (free) DocuSign developer account. After doing so you'll have a username, password, and integrator key. Armed with that information execute the following ruby file:
$ bundle exec ruby lib/tasks/docusign_task.rb
This calls a rake task which adds a non-version controlled file in the test folder called `docusign_login_config.rb` which holds your account specific credentials and is required in order to hit the test API through the test suite.
-
-**Guard**
-
-Simply run 'guard' from the root directory of the repository to have the test suite executed automatically as you make changes.
**VCR**
The test suite uses VCR and is configured to record all requests by using the 'all' configuration option surrounding each API request. If you want to speed up the test suite locally for new feature development, you may want to change the VCR config record setting to 'once' temporarily which will not write a new YAML file for each request each time you hit the API and significantly speed up the tests. However, this can lead to false passing tests as the gem changes so it's recommended that you ensure all tests pass by actually hitting the API before submitting a pull request.