Skip to content

Commit

Permalink
Merge branch 'release/v0.0.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
genaromadrid committed Jun 23, 2020
2 parents 8fa5c66 + 306737b commit 74df725
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## v0.0.8 - 22.Jun.2020
### Features
- Ability to use the timeout parameter of the requests

## v0.0.7 - 17.Jan.2020
### Bug fixes
- Allow empty responses from server (status codes 204 and 205) - [PR#8](https://github.com/Mifiel/python-api-client/pull/8)
Expand Down
28 changes: 18 additions & 10 deletions mifiel/base.py
Expand Up @@ -26,24 +26,32 @@ def execute_request(self, method, url=None, data=None, json=None, files=None):
if not url:
url = self.url()

kwargs = dict(
url=url,
auth=self.client.auth,
json=json,
)
if self.client.timeout:
kwargs.update({
'timeout': self.client.timeout
})

if method == 'post':
response = requests.post(
url=url,
auth=self.client.auth,
data=data,
json=json,
files=files
)
kwargs.update({
'data': data,
'files': files
})
response = requests.post(**kwargs)
if files:
for file_name in files:
file = files[file_name]
if file: file[1].close()
elif method == 'put':
response = requests.put(url, auth=self.client.auth, json=data)
response = requests.put(**kwargs)
elif method == 'get':
response = requests.get(url, auth=self.client.auth, json=data)
response = requests.get(**kwargs)
elif method == 'delete':
response = requests.delete(url, auth=self.client.auth, json=data)
response = requests.delete(**kwargs)

return response

Expand Down
5 changes: 5 additions & 0 deletions mifiel/client.py
Expand Up @@ -5,6 +5,7 @@ def __init__(self, app_id, secret_key):
self.sandbox = False
self.auth = RequestsApiAuth(app_id, secret_key)
self.base_url = 'https://www.mifiel.com'
self.timeout = None

def use_sandbox(self):
self.sandbox = True
Expand All @@ -15,3 +16,7 @@ def set_base_url(self, base_url):

def url(self):
return self.base_url + '/api/v1/{path}'

def set_timeout(self, timeout):
assert type(timeout) == int
self.timeout = timeout
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -7,11 +7,11 @@

setup(
name='mifiel',
version='0.0.7',
version='0.0.8',
description='Python API Client library for Mifiel.com',
long_description=long_description,
url='http://github.com/mifiel/python-api-client',
download_url='https://github.com/Mifiel/python-api-client/tarball/v0.0.7',
download_url='https://github.com/Mifiel/python-api-client/tarball/v0.0.8',
author='Genaro Madrid',
author_email='genmadrid@gmail.com',
license='MIT',
Expand Down
4 changes: 4 additions & 0 deletions test/mifiellib/test_client.py
Expand Up @@ -15,3 +15,7 @@ def test_sandbox(self):
def test_base_url(self):
self.client.set_base_url('http://example.com')
self.assertRegex(self.client.url(), 'example.com')

def test_timeout(self):
self.client.set_timeout(timeout=4)
self.assertEqual(self.client.timeout, 4)
17 changes: 17 additions & 0 deletions test/mifiellib/test_document.py
Expand Up @@ -132,6 +132,23 @@ def test_create(self):
self.assertEqual(doc.callback_url, 'some')
assert req.headers['Authorization'] is not None

@responses.activate
def test_create_with_timeout(self):
self.client.set_timeout(timeout=2)
doc_id = 'some-doc-id'
url = self.client.url().format(path='documents')
self.mock_doc_response(responses.POST, url, doc_id)

signatories = [{'email': 'some@email.com'}]
doc = Document.create(self.client, signatories, dhash='some-sha256-hash', name='some.pdf')

req = self.get_last_request()
self.assertEqual(req.method, 'POST')
self.assertEqual(req.url, url)
self.assertEqual(doc.id, doc_id)
self.assertEqual(doc.callback_url, 'some')
assert req.headers['Authorization'] is not None

@responses.activate
def test_create_with_file(self):
doc_id = 'some-doc-id'
Expand Down

0 comments on commit 74df725

Please sign in to comment.