Skip to content

Commit

Permalink
update page logic
Browse files Browse the repository at this point in the history
  • Loading branch information
phani-yadla committed Jan 11, 2023
1 parent 627b849 commit 05fdb9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
4 changes: 2 additions & 2 deletions tap_api_diabolocom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def sync(config, state, catalog):

singer.write_schema(
stream_name=stream.tap_stream_id,
schema=stream.schema,
schema={},
key_properties=stream.key_properties,
)

diabolocom_client = DiabolocomApi(config["api_key"])

max_bookmark = None
if stream.tap_stream_id == "users":
for record in diabolocom_client.get_sync_endpoints(stream.tap_stream_id):
for record in diabolocom_client.get_sync_endpoints(stream.tap_stream_id, config["api_key"], config["path"]):
# write one or more rows to the stream:
singer.write_records(stream.tap_stream_id, record)
if bookmark_column:
Expand Down
25 changes: 10 additions & 15 deletions tap_api_diabolocom/diabolocom_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,18 @@ def __init__(
self.retry = retry


def get_sync_endpoints(self, stream, path, parameters={}):
def get_sync_endpoints(self, stream, api_key, path, parameters={}):
current_retry = 0
page=0
page=1
headers = {
"accept": "application/json",
"authorization": f"Basic {self.api_key}",
"Content-Type": "application/json",
"Private-Token": f"{api_key}",
}

if stream == "users":
url = f"https://public-fr6.engage.diabolocom.com/api/v1{path}?page="

next_pages = True
try:
while next_pages:
url=f"{url}{page}"
if stream == "users":
url = f"https://public-fr6.engage.diabolocom.com/api/v1{path}?page={page}"
response = requests.get(url, headers=headers, timeout=60)

if response.status_code != 200:
Expand All @@ -59,14 +56,12 @@ def get_sync_endpoints(self, stream, path, parameters={}):
)
else:
records = json.loads(response.content.decode("utf-8"))
if not [records["next"]]:
next_pages = False
if stream == "users":
records = [records["users"]]
for record in records:
page+=1
for record in [records["users"]]:
LOGGER.info(f"the record to be sent - {record}")
yield record
page+=1
if not records["next"]:
next_pages = False


except Exception as e:
Expand Down

0 comments on commit 05fdb9c

Please sign in to comment.