Skip to content

Commit e53c295

Browse files
authored
Upgrade api version to v2 (#136)
* Upgrade api version to v2 * Bump tap version
1 parent 8064060 commit e53c295

9 files changed

Lines changed: 36 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# Changelog
22

3+
## 4.6.0
4+
* Update the access_check to use the v2 `/branches` endpoint instead of the v1 `/settings/organization` endpoint. [#132](https://github.com/singer-io/tap-mambu/pull/132)
5+
* Replace the v1 `/settings/organization` endpoint with `/setup/organization` to retrieve timezone information.
6+
* Add support for the `timezone` new config property
7+
* The `/setup/organization` endpoint requires admin permissions. If admin credentials are not provided, the timezone config value will be used as a fallback.
8+
39
## 4.5.0
410
* Write `timezone` fetched via API in the config. [#135](https://github.com/singer-io/tap-mambu/pull/135)
11+
* Revert changes of [#133](https://github.com/singer-io/tap-mambu/pull/133)
512

613
## 4.4.1
714
* Replace /users with /branches endpoint [#133](https://github.com/singer-io/tap-mambu/pull/133)

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,15 @@ This tap:
255255
"user_agent": "tap-mambu <api_user_email@your_company.com>",
256256
"page_size": "500",
257257
"apikey_audit": "AUDIT_TRAIL_APIKEY",
258-
"window_size": 7
258+
"window_size": 7,
259+
"timezone": "US/Pacific"
259260
}
260261
```
261262
262263
Note: The `window_size` parameter defaults to 1 day, which may cause slowdowns in historical sync for streams utilizing multi-threaded implementation. Conversely, using a larger `window_size` could lead to potential `out-of-memory` issues. It is advisable to select an optimal `window_size` based on the `start_date` and volume of data to mitigate these concerns.
263264
265+
The `timezone` represents your organization's local timezone. To find the [timezone](https://support.mambu.com/docs/organization-contact-currency-and-timezone) information, go to the main menu and go to Administration > General Setup > Organization Details > Time Zone
266+
264267
Optionally, also create a `state.json` file. `currently_syncing` is an optional attribute used for identifying the last object to be synced in case the job is interrupted mid-stream. The next run would begin where the last job left off.
265268

266269
```json

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup, find_packages
44

55
setup(name='tap-mambu',
6-
version='4.5.0',
6+
version='4.6.0',
77
description='Singer.io tap for extracting data from the Mambu 2.0 API',
88
author='jeff.huth@bytecode.io',
99
classifiers=['Programming Language :: Python :: 3 :: Only'],

tap_mambu/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def main():
4747
elif parsed_args.catalog:
4848
sync_all_streams(client=client,
4949
config=parsed_args.config,
50-
config_path=parsed_args.config_path,
5150
catalog=parsed_args.catalog,
5251
state=state)
5352

tap_mambu/helpers/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ def check_access(self):
168168
headers = {}
169169
# Endpoint: simple API call to return a single record (org settings) to test access
170170
# https://support.mambu.com/docs/organisational-settings-api#get-organisational-settings
171-
endpoint = 'settings/organization'
171+
endpoint = 'branches'
172172
url = '{}/{}'.format(self.base_url, endpoint)
173173
headers['User-Agent'] = self.__user_agent
174-
headers['Accept'] = 'application/vnd.mambu.v1+json'
174+
headers['Accept'] = 'application/vnd.mambu.v2+json'
175175
if use_apikey:
176176
# Api Key API Consumer Authentication: https://support.mambu.com/docs/api-consumers
177177
self.__session.headers['apikey'] = self.__apikey

tap_mambu/helpers/datetime_utils.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import singer
12
from pytz import timezone
23
from datetime import datetime
34
from tap_mambu import MambuClient
5+
from tap_mambu.helpers.client import MambuForbiddenError
46
import dateutil.parser
57

8+
LOGGER = singer.get_logger()
9+
610

711
_timezone = None
812
_datetime_formats = [
@@ -22,11 +26,18 @@
2226
]
2327

2428

25-
def get_timezone_info(client: MambuClient):
29+
def get_timezone_info(client: MambuClient, config_timezone: str = None):
2630
global _timezone
27-
response = client.request(method="GET", path="settings/organization", version="v1")
28-
_timezone = timezone(response.get("timeZoneID"))
29-
return str(_timezone)
31+
try:
32+
response = client.request(method="GET", path="setup/organization", version="v2")
33+
_timezone = timezone(response.get("timeZoneID"))
34+
except MambuForbiddenError:
35+
if config_timezone:
36+
LOGGER.warning("Could not get timezone information from Mambu endpoint, using config timezone")
37+
_timezone = timezone(config_timezone)
38+
else:
39+
raise RuntimeError("Unable to retrieve timezone information from the Mambu endpoint. Please provide administrator credentials or configure valid timezone in the UI(e.g., US/Pacific)." \
40+
" Refer this for more details: https://support.mambu.com/docs/organization-contact-currency-and-timezone")
3041

3142
def localize(dttm: datetime) -> datetime:
3243
if _timezone is None:

tap_mambu/sync.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,12 @@ def sync_endpoint(client, catalog, state,
3030

3131
return processor.process_streams_from_generators()
3232

33-
def _write_config(config, config_path, _timezone):
34-
with open(config_path, encoding='utf-8') as file:
35-
config = json.load(file)
3633

37-
config['timezone'] = _timezone
38-
with open(config_path, 'w', encoding='utf-8') as file:
39-
json.dump(config, file, indent=2)
40-
41-
LOGGER.info("timezone has been updated in config")
42-
43-
def sync_all_streams(client, config, config_path, catalog, state):
34+
def sync_all_streams(client, config, catalog, state):
4435
from .tap_generators.child_generator import ChildGenerator
4536
from .tap_processors.child_processor import ChildProcessor
4637

47-
_timezone = get_timezone_info(client)
48-
_write_config(config, config_path, _timezone)
38+
get_timezone_info(client, config_timezone=config.get("timezone"))
4939

5040
selected_streams = get_selected_streams(catalog)
5141
LOGGER.info('selected_streams: {}'.format(selected_streams))

tests/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def get_properties(self, original_properties=True):
250250
'username': os.environ['TAP_MAMBU_USERNAME'],
251251
'subdomain': os.environ['TAP_MAMBU_SUBDOMAIN'],
252252
'page_size': '90',
253+
'timezone': 'US/Pacific',
253254
'window_size': 30
254255
}
255256

tests/unittests/test_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def test_client_check_access_api_key(mock_requests_session_get):
5353
assert client.base_url == base_url
5454
assert client.page_size == DEFAULT_PAGE_SIZE
5555

56-
mock_requests_session_get.assert_called_once_with(url=f'{base_url}/settings/organization',
57-
headers={'Accept': 'application/vnd.mambu.v1+json',
56+
mock_requests_session_get.assert_called_once_with(url=f'{base_url}/branches',
57+
headers={'Accept': 'application/vnd.mambu.v2+json',
5858
'User-Agent': 'MambuTap-User_Agent_Test'})
5959

6060

@@ -77,8 +77,8 @@ def test_client_check_access_user_pass(mock_requests_session_get):
7777
assert client.base_url == base_url
7878
assert client.page_size == 100
7979

80-
mock_requests_session_get.assert_called_once_with(url=f'{base_url}/settings/organization',
81-
headers={'Accept': 'application/vnd.mambu.v1+json',
80+
mock_requests_session_get.assert_called_once_with(url=f'{base_url}/branches',
81+
headers={'Accept': 'application/vnd.mambu.v2+json',
8282
'User-Agent': 'MambuTap'})
8383

8484

0 commit comments

Comments
 (0)