如何在面向对象编程中使用更好的编码实现同样的功能?也许通过创建一个类并重用相同的代码?现在我所拥有的更像是一个脚本,不可恢复的代码
import requests
import json
url = "https://sandbox.esignlive.com/api/packages"
payload = json.dumps({"documents":[{"id":"sample-contract","name":"Test Document"}],"status":"SENT","type":"PACKAGE","roles":[{"type":"SIGNER","id":"Signer1","signers":[{"email":"signer@example.com","firstName":"John","lastName":"Smith","id":"Signer1"}],"name":"Signer1"}],"name":"Example Package"})
file = open('doc1.pdf', 'rb')
files = {
'payload': payload,
'file': file
}
headers = {
'authorization': "Basic **********",
'accept': "application/json"
}
response = requests.post(url, files=files, headers=headers)
# create a new approval
url = "https://sandbox.esignlive.com/api/packages/" + str(response.text[1]) + "/documents/sample-contract/approvals"
requests.post(url, headers=headers)
# Create a new field with an auto-generated name
url = "https://sandbox.e-signlive.com/api/user/customfields"
requests.post(url, headers=headers)
# get and display signing url
url = "https://sandbox.e-signlive.com/api/packages/"+response.text+"/roles/Signer1/signingUrl"
response = requests.get(url, headers=headers)
print(response.text)
如果您希望您的代码是可重用的,您只需要使用一些函数。你是否把这些函数放在一个类中完全是个人品味的问题。下面是你将如何做到这一点。你知道吗
这门课可能有一些缺陷,但如果有什么不好的地方,请在评论中告诉我。我不知道esign是怎么工作的,但这应该给你一个好的开始。你知道吗
相关问题 更多 >
编程相关推荐