Reuben (Matatika)
11/23/2022, 11:29 PMclient.py
and streams.py
currently, but wondering if they would fit better in a separate `paginators.py`/`pagination.py` module...aaronsteers
11/23/2022, 11:38 PMpagination.py
probably would make sense. The client.py
file was always intended to handle the 'shared nuances' of a specific API, so that would be a fine place also if it isn't already too crowded there.aaronsteers
11/23/2022, 11:40 PMstreams.py
is probably not the best, as those are generally filled with tons of schema and 'business logic' definitions. So, unless pagination varies wildly per stream, I'd probably not put them there. And if it does vary per stream, that's a pretty good case to move them out to something like paginators.py
(plural).aaronsteers
11/23/2022, 11:40 PMReuben (Matatika)
11/24/2022, 12:11 AMstreams.py
is I ended up having to create a paginator class for a specific stream. As a separate thought, is this a valid approach or more of an anti-pattern?
pagination.py
class Auth0Paginator(HeaderLinkPaginator):
def get_next_url(self, response: Response):
url = super().get_next_url(response)
return url if url and response.json() else None
class LogsPaginator(Auth0Paginator):
def __init__(
self,
log_expired_callback: Callable[[Response], bool],
*args,
**kwargs,
):
super().__init__(*args, **kwargs)
self.log_expired_callback = log_expired_callback
def get_next(self, response: Response):
return (
self.log_expired_callback(response)
or super().get_next(response)
or JSONPathPaginator("$[*].log_id").get_next(response)
)
client.py
class Auth0Stream(RESTStream):
def get_new_paginator(self):
return Auth0Paginator()
streams.py
class LogsStream(Auth0Stream):
def get_new_paginator(self):
def log_expired_callback(response: requests.Response):
self.log_expired = response.status_code == 400
return self.log_expired
return LogsPaginator(log_expired_callback)
(for context, I'm updating tap-auth0
to the newest SDK version, and in the process implementing pagination classes in place of the deprecated get_next_page_token
)Reuben (Matatika)
11/24/2022, 1:24 AMedgar_ramirez_mondragon
11/24/2022, 1:29 AMlog_expired_callback
could be a method of LogsPaginator
tooReuben (Matatika)
11/24/2022, 9:20 AMReuben (Matatika)
11/29/2022, 9:05 PMedgar_ramirez_mondragon
12/01/2022, 7:00 PMLogsStream.log_expired
is no longer used in any condition, so the class even not have a method to and just check the status:
class LogsPaginator(Auth0Paginator):
def get_next(self, response: Response):
return (
response.status_code == 400
or super().get_next(response)
or JSONPathPaginator("$[*].log_id").get_next(response)
)