Skip to content

Commit e4ddf78

Browse files
authored
refactor: add url class in place of urls module functions (#244)
1 parent 21f1d1b commit e4ddf78

File tree

16 files changed

+121
-91
lines changed

16 files changed

+121
-91
lines changed

src/posit/connect/bundles.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def metadata(self) -> BundleMetadata:
142142
def delete(self) -> None:
143143
"""Delete the bundle."""
144144
path = f"v1/content/{self.content_guid}/bundles/{self.id}"
145-
url = urls.append(self.config.url, path)
145+
url = self.config.url + path
146146
self.session.delete(url)
147147

148148
def deploy(self) -> tasks.Task:
@@ -162,7 +162,7 @@ def deploy(self) -> tasks.Task:
162162
None
163163
"""
164164
path = f"v1/content/{self.content_guid}/deploy"
165-
url = urls.append(self.config.url, path)
165+
url = self.config.url + path
166166
response = self.session.post(url, json={"bundle_id": self.id})
167167
result = response.json()
168168
ts = tasks.Tasks(self.config, self.session)
@@ -200,7 +200,7 @@ def download(self, output: io.BufferedWriter | str) -> None:
200200
)
201201

202202
path = f"v1/content/{self.content_guid}/bundles/{self.id}/download"
203-
url = urls.append(self.config.url, path)
203+
url = self.config.url + path
204204
response = self.session.get(url, stream=True)
205205
if isinstance(output, io.BufferedWriter):
206206
for chunk in response.iter_content():
@@ -287,7 +287,7 @@ def create(self, input: io.BufferedReader | bytes | str) -> Bundle:
287287
)
288288

289289
path = f"v1/content/{self.content_guid}/bundles"
290-
url = urls.append(self.config.url, path)
290+
url = self.config.url + path
291291
response = self.session.post(url, data=data)
292292
result = response.json()
293293
return Bundle(self.config, self.session, **result)
@@ -301,7 +301,7 @@ def find(self) -> List[Bundle]:
301301
List of all found bundles.
302302
"""
303303
path = f"v1/content/{self.content_guid}/bundles"
304-
url = urls.append(self.config.url, path)
304+
url = self.config.url + path
305305
response = self.session.get(url)
306306
results = response.json()
307307
return [
@@ -333,7 +333,7 @@ def get(self, id: str) -> Bundle:
333333
The bundle with the specified ID.
334334
"""
335335
path = f"v1/content/{self.content_guid}/bundles/{id}"
336-
url = urls.append(self.config.url, path)
336+
url = self.config.url + path
337337
response = self.session.get(url)
338338
result = response.json()
339339
return Bundle(self.config, self.session, **result)

src/posit/connect/client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def request(self, method: str, path: str, **kwargs) -> Response:
318318
Response
319319
A [](`requests.Response`) object.
320320
"""
321-
url = urls.append(self.config.url, path)
321+
url = self.config.url + path
322322
return self.session.request(method, url, **kwargs)
323323

324324
def get(self, path: str, **kwargs) -> Response:
@@ -339,7 +339,7 @@ def get(self, path: str, **kwargs) -> Response:
339339
Response
340340
A [](`requests.Response`) object.
341341
"""
342-
url = urls.append(self.config.url, path)
342+
url = self.config.url + path
343343
return self.session.get(url, **kwargs)
344344

345345
def post(self, path: str, **kwargs) -> Response:
@@ -360,7 +360,7 @@ def post(self, path: str, **kwargs) -> Response:
360360
Response
361361
A [](`requests.Response`) object.
362362
"""
363-
url = urls.append(self.config.url, path)
363+
url = self.config.url + path
364364
return self.session.post(url, **kwargs)
365365

366366
def put(self, path: str, **kwargs) -> Response:
@@ -381,7 +381,7 @@ def put(self, path: str, **kwargs) -> Response:
381381
Response
382382
A [](`requests.Response`) object.
383383
"""
384-
url = urls.append(self.config.url, path)
384+
url = self.config.url + path
385385
return self.session.put(url, **kwargs)
386386

387387
def patch(self, path: str, **kwargs) -> Response:
@@ -402,7 +402,7 @@ def patch(self, path: str, **kwargs) -> Response:
402402
Response
403403
A [](`requests.Response`) object.
404404
"""
405-
url = urls.append(self.config.url, path)
405+
url = self.config.url + path
406406
return self.session.patch(url, **kwargs)
407407

408408
def delete(self, path: str, **kwargs) -> Response:
@@ -423,5 +423,5 @@ def delete(self, path: str, **kwargs) -> Response:
423423
Response
424424
A [](`requests.Response`) object.
425425
"""
426-
url = urls.append(self.config.url, path)
426+
url = self.config.url + path
427427
return self.session.delete(url, **kwargs)

src/posit/connect/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ def __init__(
5656
self, api_key: Optional[str] = None, url: Optional[str] = None
5757
) -> None:
5858
self.api_key = api_key or _get_api_key()
59-
self.url = urls.create(url or _get_url())
59+
self.url = urls.Url(url or _get_url())

src/posit/connect/content.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class ContentItem(Resource):
144144
def delete(self) -> None:
145145
"""Delete the content item."""
146146
path = f"v1/content/{self.guid}"
147-
url = urls.append(self.config.url, path)
147+
url = self.config.url + path
148148
self.session.delete(url)
149149

150150
def deploy(self) -> tasks.Task:
@@ -164,7 +164,7 @@ def deploy(self) -> tasks.Task:
164164
None
165165
"""
166166
path = f"v1/content/{self.guid}/deploy"
167-
url = urls.append(self.config.url, path)
167+
url = self.config.url + path
168168
response = self.session.post(url, json={"bundle_id": None})
169169
result = response.json()
170170
ts = tasks.Tasks(self.config, self.session)
@@ -237,7 +237,7 @@ def restart(self) -> None:
237237
self.environment_variables.create(key, random_hash)
238238
self.environment_variables.delete(key)
239239
# GET via the base Connect URL to force create a new worker thread.
240-
url = urls.append(dirname(self.config.url), f"content/{self.guid}")
240+
url = dirname(self.config.url) + f"/content/{self.guid}"
241241
self.session.get(url)
242242
return None
243243
else:
@@ -314,7 +314,7 @@ def update(self, *args, **kwargs) -> None:
314314
def update(self, *args, **kwargs) -> None:
315315
"""Update the content item."""
316316
body = dict(*args, **kwargs)
317-
url = urls.append(self.config.url, f"v1/content/{self.guid}")
317+
url = self.config.url + f"v1/content/{self.guid}"
318318
response = self.session.patch(url, json=body)
319319
super().update(**response.json())
320320

@@ -548,7 +548,7 @@ def __init__(
548548
*,
549549
owner_guid: str | None = None,
550550
) -> None:
551-
self.url = urls.append(config.url, "v1/content")
551+
self.url = config.url + "v1/content"
552552
self.config = config
553553
self.session = session
554554
self.owner_guid = owner_guid
@@ -656,7 +656,7 @@ def create(self, *args, **kwargs) -> ContentItem:
656656
"""
657657
body = dict(*args, **kwargs)
658658
path = "v1/content"
659-
url = urls.append(self.config.url, path)
659+
url = self.config.url + path
660660
response = self.session.post(url, json=body)
661661
return ContentItem(self.config, self.session, **response.json())
662662

@@ -798,6 +798,6 @@ def get(self, guid: str) -> ContentItem:
798798
-------
799799
ContentItem
800800
"""
801-
url = urls.append(self.url, guid)
801+
url = self.url + guid
802802
response = self.session.get(url)
803803
return ContentItem(self.config, self.session, **response.json())

src/posit/connect/env.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def clear(self) -> None:
7171
>>> clear()
7272
"""
7373
path = f"v1/content/{self.content_guid}/environment"
74-
url = urls.append(self.config.url, path)
74+
url = self.config.url + path
7575
self.session.put(url, json=[])
7676

7777
def create(self, key: str, value: str, /) -> None:
@@ -129,7 +129,7 @@ def find(self) -> List[str]:
129129
['DATABASE_URL']
130130
"""
131131
path = f"v1/content/{self.content_guid}/environment"
132-
url = urls.append(self.config.url, path)
132+
url = self.config.url + path
133133
response = self.session.get(url)
134134
return response.json()
135135

@@ -204,5 +204,5 @@ def update(self, other=(), /, **kwargs: Optional[str]):
204204

205205
body = [{"name": key, "value": value} for key, value in d.items()]
206206
path = f"v1/content/{self.content_guid}/environment"
207-
url = urls.append(self.config.url, path)
207+
url = self.config.url + path
208208
self.session.patch(url, json=body)

src/posit/connect/groups.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def owner_guid(self) -> str:
3939
def delete(self) -> None:
4040
"""Delete the group."""
4141
path = f"v1/groups/{self.guid}"
42-
url = urls.append(self.config.url, path)
42+
url = self.config.url + path
4343
self.session.delete(url)
4444

4545

@@ -90,7 +90,7 @@ def create(self, *args, **kwargs) -> Group:
9090
...
9191
body = dict(*args, **kwargs)
9292
path = "v1/groups"
93-
url = urls.append(self.config.url, path)
93+
url = self.config.url + path
9494
response = self.session.post(url, json=body)
9595
return Group(self.config, self.session, **response.json())
9696

@@ -117,7 +117,7 @@ def find(self, *args, **kwargs):
117117
"""
118118
params = dict(*args, **kwargs)
119119
path = "v1/groups"
120-
url = urls.append(self.config.url, path)
120+
url = self.config.url + path
121121
paginator = Paginator(self.session, url, params=params)
122122
results = paginator.fetch_results()
123123
return [
@@ -152,7 +152,7 @@ def find_one(self, *args, **kwargs) -> Group | None:
152152
"""
153153
params = dict(*args, **kwargs)
154154
path = "v1/groups"
155-
url = urls.append(self.config.url, path)
155+
url = self.config.url + path
156156
paginator = Paginator(self.session, url, params=params)
157157
pages = paginator.fetch_pages()
158158
results = (result for page in pages for result in page.results)
@@ -177,7 +177,7 @@ def get(self, guid: str) -> Group:
177177
-------
178178
Group
179179
"""
180-
url = urls.append(self.config.url, f"v1/groups/{guid}")
180+
url = self.config.url + f"v1/groups/{guid}"
181181
response = self.session.get(url)
182182
return Group(
183183
config=self.config,
@@ -193,7 +193,7 @@ def count(self) -> int:
193193
int
194194
"""
195195
path = "v1/groups"
196-
url = urls.append(self.config.url, path)
196+
url = self.config.url + path
197197
response: requests.Response = self.session.get(
198198
url, params={"page_size": 1}
199199
)

src/posit/connect/me.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ def get(config: Config, session: requests.Session) -> User:
1818
-------
1919
User: The current user.
2020
"""
21-
url = urls.append(config.url, "v1/user")
21+
url = config.url + "v1/user"
2222
response = session.get(url)
2323
return User(config, session, **response.json())

src/posit/connect/metrics/shiny_usage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def find(self, *args, **kwargs) -> List[ShinyUsageEvent]:
109109
params = rename_params(params)
110110

111111
path = "/v1/instrumentation/shiny/usage"
112-
url = urls.append(self.config.url, path)
112+
url = self.config.url + path
113113
paginator = CursorPaginator(self.session, url, params=params)
114114
results = paginator.fetch_results()
115115
return [
@@ -168,7 +168,7 @@ def find_one(self, *args, **kwargs) -> ShinyUsageEvent | None:
168168
params = dict(*args, **kwargs)
169169
params = rename_params(params)
170170
path = "/v1/instrumentation/shiny/usage"
171-
url = urls.append(self.config.url, path)
171+
url = self.config.url + path
172172
paginator = CursorPaginator(self.session, url, params=params)
173173
pages = paginator.fetch_pages()
174174
results = (result for page in pages for result in page.results)

src/posit/connect/metrics/visits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def find(self, *args, **kwargs) -> List[VisitEvent]:
141141
params = rename_params(params)
142142

143143
path = "/v1/instrumentation/content/visits"
144-
url = urls.append(self.config.url, path)
144+
url = self.config.url + path
145145
paginator = CursorPaginator(self.session, url, params=params)
146146
results = paginator.fetch_results()
147147
return [
@@ -200,7 +200,7 @@ def find_one(self, *args, **kwargs) -> VisitEvent | None:
200200
params = dict(*args, **kwargs)
201201
params = rename_params(params)
202202
path = "/v1/instrumentation/content/visits"
203-
url = urls.append(self.config.url, path)
203+
url = self.config.url + path
204204
paginator = CursorPaginator(self.session, url, params=params)
205205
pages = paginator.fetch_pages()
206206
results = (result for page in pages for result in page.results)

src/posit/connect/oauth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Credentials(TypedDict, total=False):
1515

1616
class OAuthIntegration:
1717
def __init__(self, config: Config, session: Session) -> None:
18-
self.url = urls.append(config.url, "v1/oauth/integrations/credentials")
18+
self.url = config.url + "v1/oauth/integrations/credentials"
1919
self.config = config
2020
self.session = session
2121

0 commit comments

Comments
 (0)