Skip to content

Commit 63a8f2f

Browse files
authored
Merge pull request #93 from kbussell/77-edit-recipients
Support the add/update/delete recipient APIs
2 parents 90b9d80 + be9df34 commit 63a8f2f

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

pydocusign/client.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,66 @@ def get_connect_failures(self):
498498
url = '/accounts/{accountId}/connect/failures' \
499499
.format(accountId=self.account_id)
500500
return self.get(url)['failures']
501+
502+
def add_envelope_recipients(self, envelopeId, recipients,
503+
resend_envelope=False):
504+
"""Add one or more recipients to an envelope
505+
506+
DocuSign reference:
507+
https://docs.docusign.com/esign/restapi/Envelopes/EnvelopeRecipients/create/
508+
"""
509+
if not self.account_url:
510+
self.login_information()
511+
url = '/accounts/{accountId}/envelopes/{envelopeId}/recipients' \
512+
.format(accountId=self.account_id,
513+
envelopeId=envelopeId)
514+
if resend_envelope:
515+
url += '?resend_envelope=true'
516+
data = {'signers': [recipient.to_dict() for recipient in recipients]}
517+
return self.post(url, data=data)
518+
519+
def update_envelope_recipients(self, envelopeId, recipients,
520+
resend_envelope=False):
521+
"""Modify recipients in a draft envelope or correct recipient information
522+
for an in process envelope
523+
524+
DocuSign reference:
525+
https://docs.docusign.com/esign/restapi/Envelopes/EnvelopeRecipients/update/
526+
"""
527+
if not self.account_url:
528+
self.login_information()
529+
url = '/accounts/{accountId}/envelopes/{envelopeId}/recipients' \
530+
.format(accountId=self.account_id,
531+
envelopeId=envelopeId)
532+
if resend_envelope:
533+
url += '?resend_envelope=true'
534+
data = {'signers': [recipient.to_dict() for recipient in recipients]}
535+
return self.put(url, data=data)
536+
537+
def delete_envelope_recipient(self, envelopeId, recipientId):
538+
"""Deletes one or more recipients from a draft or sent envelope.
539+
540+
DocuSign reference:
541+
https://docs.docusign.com/esign/restapi/Envelopes/EnvelopeRecipients/delete/
542+
"""
543+
if not self.account_url:
544+
self.login_information()
545+
url = '/accounts/{accountId}/envelopes/{envelopeId}/recipients/' \
546+
'{recipientId}'.format(accountId=self.account_id,
547+
envelopeId=envelopeId,
548+
recipientId=recipientId)
549+
return self.delete(url)
550+
551+
def delete_envelope_recipients(self, envelopeId, recipientIds):
552+
"""Deletes one or more recipients from a draft or sent envelope.
553+
554+
DocuSign reference:
555+
https://docs.docusign.com/esign/restapi/Envelopes/EnvelopeRecipients/deleteList/
556+
"""
557+
if not self.account_url:
558+
self.login_information()
559+
url = '/accounts/{accountId}/envelopes/{envelopeId}/recipients' \
560+
.format(accountId=self.account_id,
561+
envelopeId=envelopeId)
562+
data = {'signers': [{'recipientId': id_} for id_ in recipientIds]}
563+
return self.delete(url, data=data)

tests/test_client.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import unittest
2+
try:
3+
from unittest import mock
4+
except ImportError: # Python 2 fallback.
5+
import mock
6+
7+
from pydocusign import DocuSignClient, Signer
8+
9+
10+
class DocuSignTestClient(DocuSignClient):
11+
def login_information(self):
12+
self.account_id = 'test'
13+
self.account_url = '{root}/accounts/test'.format(root=self.root_url)
14+
15+
16+
class ClientRequestTest(unittest.TestCase):
17+
def test_create_envelope_recipients(self):
18+
client = DocuSignTestClient()
19+
20+
with mock.patch.object(client, 'post') as post_mock:
21+
signers = [
22+
Signer(clientUserId='userid_2', email='signer1@example.com',
23+
name='Signer 2'),
24+
Signer(clientUserId='userid_2', email='signer2@example.com',
25+
name='Signer 2'),
26+
]
27+
client.add_envelope_recipients('ABC123', signers)
28+
29+
url = '/accounts/{account_id}/envelopes/ABC123/recipients'.format(
30+
account_id=client.account_id)
31+
32+
post_mock.assert_called_once_with(
33+
url, data={'signers': [signers[0].to_dict(), signers[1].to_dict()]}
34+
)
35+
36+
with mock.patch.object(client, 'post') as post_mock:
37+
client.add_envelope_recipients('ABC123', [], resend_envelope=True)
38+
39+
post_mock.assert_called_once_with(
40+
'/accounts/{}/envelopes/ABC123/recipients'
41+
'?resend_envelope=true'.format(client.account_id),
42+
data={'signers': []}
43+
)
44+
45+
def test_update_envelope_recipients(self):
46+
client = DocuSignTestClient()
47+
48+
with mock.patch.object(client, 'put') as put_mock:
49+
signers = [
50+
Signer(clientUserId='userid_2', email='signer1@example.com',
51+
name='Signer 2'),
52+
Signer(clientUserId='userid_2', email='signer2@example.com',
53+
name='Signer 2'),
54+
]
55+
client.update_envelope_recipients('ABC123', signers)
56+
57+
url = '/accounts/{account_id}/envelopes/ABC123/recipients'.format(
58+
account_id=client.account_id)
59+
60+
put_mock.assert_called_once_with(
61+
url, data={'signers': [signers[0].to_dict(), signers[1].to_dict()]}
62+
)
63+
64+
with mock.patch.object(client, 'put') as put_mock:
65+
client.update_envelope_recipients('ABC123', [], resend_envelope=True)
66+
67+
put_mock.assert_called_once_with(
68+
'/accounts/{}/envelopes/ABC123/recipients'
69+
'?resend_envelope=true'.format(client.account_id),
70+
data={'signers': []}
71+
)
72+
73+
def test_delete_envelope_recipient(self):
74+
client = DocuSignTestClient()
75+
76+
with mock.patch.object(client, 'delete') as delete_mock:
77+
client.delete_envelope_recipient('ABC123', '1')
78+
79+
url = '/accounts/{account_id}/envelopes/ABC123/recipients/1'.format(
80+
account_id=client.account_id)
81+
82+
delete_mock.assert_called_once_with(url)
83+
84+
def test_delete_envelope_recipients(self):
85+
client = DocuSignTestClient()
86+
87+
with mock.patch.object(client, 'delete') as delete_mock:
88+
client.delete_envelope_recipients('ABC123', ['1', '2'])
89+
90+
url = '/accounts/{account_id}/envelopes/ABC123/recipients'.format(
91+
account_id=client.account_id)
92+
93+
delete_mock.assert_called_once_with(
94+
url, data={'signers': [{'recipientId': '1'}, {'recipientId': '2'}]}
95+
)

0 commit comments

Comments
 (0)