Skip to content

Commit 8064060

Browse files
authored
Revert "Upgrade api version to v2 (#132)" (#135)
* Revert "Upgrade api version to v2 (#132)" This reverts commit 5e51412. * Write timezone in config * Bump tap version
1 parent 00918bb commit 8064060

9 files changed

Lines changed: 30 additions & 30 deletions

File tree

CHANGELOG.md

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

3+
## 4.5.0
4+
* Write `timezone` fetched via API in the config. [#135](https://github.com/singer-io/tap-mambu/pull/135)
5+
36
## 4.4.1
47
* Replace /users with /branches endpoint [#133](https://github.com/singer-io/tap-mambu/pull/133)
58

@@ -8,6 +11,7 @@
811
* Replace the v1 `/settings/organization` endpoint with `/setup/organization` to retrieve timezone information.
912
* Add support for the `timezone` new config property
1013
* The `/setup/organization` endpoint requires admin permissions. If admin credentials are not provided, the timezone config value will be used as a fallback.
14+
1115
## 4.3.1
1216
* Bump dependency versions for twistlock compliance [#124](https://github.com/singer-io/tap-mambu/pull/123)
1317

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,12 @@ 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,
259-
"timezone": "US/Pacific"
258+
"window_size": 7
260259
}
261260
```
262261
263262
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.
264263
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-
267264
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.
268265
269266
```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.4.1',
6+
version='4.5.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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ 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,
5051
catalog=parsed_args.catalog,
5152
state=state)
5253

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 = 'branches'
171+
endpoint = 'settings/organization'
172172
url = '{}/{}'.format(self.base_url, endpoint)
173173
headers['User-Agent'] = self.__user_agent
174-
headers['Accept'] = 'application/vnd.mambu.v2+json'
174+
headers['Accept'] = 'application/vnd.mambu.v1+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: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import singer
21
from pytz import timezone
32
from datetime import datetime
43
from tap_mambu import MambuClient
5-
from tap_mambu.helpers.client import MambuForbiddenError
64
import dateutil.parser
75

8-
LOGGER = singer.get_logger()
9-
106

117
_timezone = None
128
_datetime_formats = [
@@ -26,18 +22,11 @@
2622
]
2723

2824

29-
def get_timezone_info(client: MambuClient, config_timezone: str = None):
25+
def get_timezone_info(client: MambuClient):
3026
global _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")
27+
response = client.request(method="GET", path="settings/organization", version="v1")
28+
_timezone = timezone(response.get("timeZoneID"))
29+
return str(_timezone)
4130

4231
def localize(dttm: datetime) -> datetime:
4332
if _timezone is None:

tap_mambu/sync.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import singer
2-
2+
import json
33
from .helpers.constants import DEFAULT_PAGE_SIZE
44
from .helpers import get_selected_streams, should_sync_stream, update_currently_syncing
55
from .helpers.datetime_utils import get_timezone_info
@@ -30,12 +30,22 @@ 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)
36+
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")
3342

34-
def sync_all_streams(client, config, catalog, state):
43+
def sync_all_streams(client, config, config_path, catalog, state):
3544
from .tap_generators.child_generator import ChildGenerator
3645
from .tap_processors.child_processor import ChildProcessor
3746

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

4050
selected_streams = get_selected_streams(catalog)
4151
LOGGER.info('selected_streams: {}'.format(selected_streams))

tests/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ 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',
254253
'window_size': 30
255254
}
256255

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}/branches',
57-
headers={'Accept': 'application/vnd.mambu.v2+json',
56+
mock_requests_session_get.assert_called_once_with(url=f'{base_url}/settings/organization',
57+
headers={'Accept': 'application/vnd.mambu.v1+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}/branches',
81-
headers={'Accept': 'application/vnd.mambu.v2+json',
80+
mock_requests_session_get.assert_called_once_with(url=f'{base_url}/settings/organization',
81+
headers={'Accept': 'application/vnd.mambu.v1+json',
8282
'User-Agent': 'MambuTap'})
8383

8484

0 commit comments

Comments
 (0)