Skip to content

Commit

Permalink
Merge pull request #1 from krriyo/feature/fixes
Browse files Browse the repository at this point in the history
Updating support for Python 2.7
  • Loading branch information
genaromadrid authored Jun 14, 2016
2 parents 2f0f91e + 7fa3abf commit 468f829
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions mifiel/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from mifiel import Response
import requests
from os.path import basename

class Base(object):
def __init__(self, client, path):
Expand All @@ -22,12 +23,11 @@ def url(self, path=None):

return self.client.url().format(path=p)

def process_request(self, method, url=None, data=None, file=None):
def process_request(self, method, url=None, data=None, files=None):
if not url:
url = self.url()

if method == 'post':
response = requests.post(url, auth=self.client.auth, json=data)
response = requests.post(url, auth=self.client.auth, data=data, files=files)
elif method == 'put':
response = requests.put(url, auth=self.client.auth, json=data)
elif method == 'get':
Expand Down
14 changes: 11 additions & 3 deletions mifiel/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ def create(client, signatories, file=None, dhash=None, callback_url=None):
if file and dhash:
raise ValueError('Only one of file or hash must be provided')

data = { 'signatories': signatories }
sig_numbers = {}

for index, item in enumerate(signatories):
for key, val in item.iteritems():
sig_numbers.update({'signatories['+str(index)+']['+str(key)+']':val})

data = sig_numbers

if callback_url:
data['callback_url'] = callback_url
if file:
data['file'] = open(file)
_file = open(file, 'rb')
file = {'file':(basename(_file.name), _file, 'application/pdf')}
if dhash:
data['original_hash'] = dhash

doc = Document(client)
doc.process_request('post', data=data)
doc.process_request('post', data=data, files=file)
return doc

0 comments on commit 468f829

Please sign in to comment.