Skip to content

Commit

Permalink
chore: renames classes to CursorPaginator and CursorPage
Browse files Browse the repository at this point in the history
  • Loading branch information
tdstein committed Apr 11, 2024
1 parent 41b2f12 commit 420b418
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/posit/connect/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@


@dataclass
class Page:
class CursorPage:
paging: dict
results: List[dict]


class Paginator:
class CursorPaginator:
def __init__(self, session: requests.Session, url: str, params: dict = {}) -> None:
self.session = session
self.url = url
Expand All @@ -36,7 +36,7 @@ def fetch_results(self) -> List[dict]:
results.extend(page.results)
return results

def fetch_pages(self) -> Generator[Page, None, None]:
def fetch_pages(self) -> Generator[CursorPage, None, None]:
"""Fetch pages.
Yields
Expand All @@ -54,7 +54,7 @@ def fetch_pages(self) -> Generator[Page, None, None]:
# stop if a next page is not defined
return

def fetch_page(self, next: str | None = None) -> Page:
def fetch_page(self, next: str | None = None) -> CursorPage:
"""Fetch a page.
Parameters
Expand All @@ -72,4 +72,4 @@ def fetch_page(self, next: str | None = None) -> Page:
"limit": _MAX_PAGE_SIZE,
}
response = self.session.get(self.url, params=params)
return Page(**response.json())
return CursorPage(**response.json())
6 changes: 3 additions & 3 deletions src/posit/connect/visits.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from . import urls

from .cursors import Paginator
from .cursors import CursorPaginator
from .resources import Resource, Resources


Expand Down Expand Up @@ -142,7 +142,7 @@ def find(self, *args, **kwargs) -> List[Visit]:

path = "/v1/instrumentation/content/visits"
url = urls.append_path(self.config.url, path)
paginator = Paginator(self.session, url, params=params)
paginator = CursorPaginator(self.session, url, params=params)
results = paginator.fetch_results()
return [
Visit(
Expand Down Expand Up @@ -202,7 +202,7 @@ def find_one(self, *args, **kwargs) -> Visit | None:
params = rename_params(params)
path = "/v1/instrumentation/content/visits"
url = urls.append_path(self.config.url, path)
paginator = Paginator(self.session, url, params=params)
paginator = CursorPaginator(self.session, url, params=params)
pages = paginator.fetch_pages()
results = (result for page in pages for result in page.results)
visits = (
Expand Down

0 comments on commit 420b418

Please sign in to comment.