From 17b573ade3c6f2d45452850d0adea8c76c07bd20 Mon Sep 17 00:00:00 2001 From: tdstein Date: Wed, 21 Feb 2024 13:21:35 -0500 Subject: [PATCH] fix: url path resolution --- src/posit/connect/urls.py | 2 ++ src/posit/connect/users.py | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/posit/connect/urls.py b/src/posit/connect/urls.py index e6004a7d..b2227c96 100644 --- a/src/posit/connect/urls.py +++ b/src/posit/connect/urls.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import posixpath from urllib.parse import urlsplit, urlunsplit diff --git a/src/posit/connect/users.py b/src/posit/connect/users.py index 30b56aaf..e58641a6 100644 --- a/src/posit/connect/users.py +++ b/src/posit/connect/users.py @@ -51,9 +51,8 @@ def __init__( f"page_size must be less than or equal to {_MAX_PAGE_SIZE}" ) - url = urls.append_path(config.url, "v1/users") - super().__init__(url) - self.url = url + super().__init__(config.url) + self.config = config self.session = session self.page_size = page_size @@ -68,8 +67,10 @@ def fetch(self, index) -> tuple[Iterator[User] | None, bool]: page_number = int(index / self.page_size) + 1 # Define query parameters for pagination. params = {"page_number": page_number, "page_size": self.page_size} + # Create the URL for the endpoint. + url = urls.append_path(self.config.url, "v1/users") # Send a GET request to the endpoint with the specified parameters. - response = self.session.get(self.url, params=params) + response = self.session.get(url, params=params) # Convert response to dict json: dict = dict(response.json()) # Parse the JSON response and extract the results. @@ -81,6 +82,6 @@ def fetch(self, index) -> tuple[Iterator[User] | None, bool]: return (users, exhausted) def get(self, id: str) -> User: - url = urls.append_path(self.url, id) + url = urls.append_path(self.config.url, f"v1/users/{id}") response = self.session.get(url) return User(**response.json())