From 786da3b9d067ee9303b3b9cabfc61c669aaac2ca Mon Sep 17 00:00:00 2001 From: Kevin Hill Date: Wed, 21 Jun 2017 13:22:51 -0600 Subject: [PATCH 1/3] moved data encoding to json at advice of api docs --- pipedrive/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipedrive/__init__.py b/pipedrive/__init__.py index 87ab977..ac8b4ce 100644 --- a/pipedrive/__init__.py +++ b/pipedrive/__init__.py @@ -35,7 +35,7 @@ def _request(self, endpoint, data, method='POST'): response, data = self.http.request(uri, method=method, headers={'Content-Type': 'application/x-www-form-urlencoded'}) else: uri = PIPEDRIVE_API_URL + endpoint + '?api_token=' + str(self.api_token) - response, data = self.http.request(uri, method=method, body=urlencode(data), headers={'Content-Type': 'application/x-www-form-urlencoded'}) + response, data = self.http.request(uri, method=method, body=json.dumps(data), headers={'Content-Type': 'application/json'}) logger.debug('sending {method} request to {uri}'.format( method=method, From dbbf06b9c41a161747721ff71bfbcec74b1366eb Mon Sep 17 00:00:00 2001 From: Kevin Hill Date: Mon, 26 Jun 2017 09:04:48 -0600 Subject: [PATCH 2/3] refactored to generator scheme --- .gitignore | 4 +++- pipedrive/__init__.py | 20 +++++++++++++++++++- setup.py | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6d254ba..ff7c604 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,6 @@ pip-log.txt #Mr Developer .mr.developer.cfg -pipedrive/ve/ \ No newline at end of file +pipedrive/ve/ + +__pycache__ diff --git a/pipedrive/__init__.py b/pipedrive/__init__.py index ac8b4ce..679a1cc 100644 --- a/pipedrive/__init__.py +++ b/pipedrive/__init__.py @@ -64,8 +64,26 @@ def __init__(self, email, password=None): def __getattr__(self, name): def wrapper(data={}, method='GET'): + response = self._request(name.replace('_', '/'), data, method) if 'error' in response: raise PipedriveError(response) - return response + + additional_data = response.get('additional_data', {}) + pagination_info = additional_data.get('pagination', {}) + + logger.debug('pagination_info: {}'.format(pagination_info)) + if isinstance(response['data'], dict): + yield response['data'] + else: + yield from response['data'] + + if pagination_info.get('more_items_in_collection', False): + + data.update({ + 'start': pagination_info['next_start'] + }) + + yield from wrapper(data, method) + return wrapper diff --git a/setup.py b/setup.py index 078c85c..55d9e25 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='python-pipedrive', - version="0.4.0", + version="0.5.0", license="MIT", install_requires=[ From 211f1108de01135b66af85b555e236b36bb44726 Mon Sep 17 00:00:00 2001 From: Kevin Hill Date: Wed, 19 Jul 2017 14:08:38 -0600 Subject: [PATCH 3/3] now PUTs, POSTs, etc should work without needing to try and access the first element --- pipedrive/__init__.py | 32 ++++++++++++++++++-------------- setup.py | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pipedrive/__init__.py b/pipedrive/__init__.py index 679a1cc..e528ba5 100644 --- a/pipedrive/__init__.py +++ b/pipedrive/__init__.py @@ -66,24 +66,28 @@ def __getattr__(self, name): def wrapper(data={}, method='GET'): response = self._request(name.replace('_', '/'), data, method) - if 'error' in response: - raise PipedriveError(response) - additional_data = response.get('additional_data', {}) - pagination_info = additional_data.get('pagination', {}) + def _generator(): + if 'error' in response: + raise PipedriveError(response) + + additional_data = response.get('additional_data', {}) + pagination_info = additional_data.get('pagination', {}) + + logger.debug('pagination_info: {}'.format(pagination_info)) + if isinstance(response['data'], dict): + yield response['data'] + else: + yield from response['data'] - logger.debug('pagination_info: {}'.format(pagination_info)) - if isinstance(response['data'], dict): - yield response['data'] - else: - yield from response['data'] + if pagination_info.get('more_items_in_collection', False): - if pagination_info.get('more_items_in_collection', False): + data.update({ + 'start': pagination_info['next_start'] + }) - data.update({ - 'start': pagination_info['next_start'] - }) + yield from wrapper(data, method) - yield from wrapper(data, method) + return _generator() return wrapper diff --git a/setup.py b/setup.py index 55d9e25..fb2f669 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='python-pipedrive', - version="0.5.0", + version="0.5.1", license="MIT", install_requires=[