-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
421ae04
commit 6bcc078
Showing
7 changed files
with
333 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
from .endpoints import AclEndpoints, GwcEndpoints, OwsEndpoints, RestEndpoints | ||
from .restservice import RestService | ||
|
||
__all__ = [ | ||
"RestService", | ||
"AclEndpoints", | ||
"OwsEndpoints", | ||
"GwcEndpoints", | ||
"RestEndpoints", | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from typing import Any | ||
|
||
import requests | ||
|
||
TIMEOUT = 120 | ||
|
||
|
||
class RestClient: | ||
def __init__(self, url: str, auth: tuple[str, str]) -> None: | ||
self.url: str = url | ||
self.auth: tuple[str, str] = auth | ||
|
||
def get( | ||
self, | ||
path: str, | ||
params: dict[str, str] | None = None, | ||
headers: dict[str, str] | None = None, | ||
) -> requests.Response: | ||
response: requests.Response = requests.get( | ||
f"{self.url}{path}", | ||
params=params, | ||
headers=headers, | ||
auth=self.auth, | ||
timeout=TIMEOUT, | ||
) | ||
if response.status_code != 404: | ||
response.raise_for_status() | ||
return response | ||
|
||
def post( | ||
self, | ||
path: str, | ||
params: dict[str, str] | None = None, | ||
headers: dict[str, str] | None = None, | ||
json: dict[str, dict[str, Any]] | None = None, | ||
data: bytes | None = None, | ||
) -> requests.Response: | ||
|
||
response: requests.Response = requests.post( | ||
f"{self.url}{path}", | ||
params=params, | ||
headers=headers, | ||
json=json, | ||
data=data, | ||
auth=self.auth, | ||
timeout=TIMEOUT, | ||
) | ||
if response.status_code != 409: | ||
response.raise_for_status() | ||
return response | ||
|
||
def put( | ||
self, | ||
path: str, | ||
params: dict[str, str] | None = None, | ||
headers: dict[str, str] | None = None, | ||
json: dict[str, dict[str, Any]] | None = None, | ||
data: bytes | None = None, | ||
) -> requests.Response: | ||
response: requests.Response = requests.put( | ||
f"{self.url}{path}", | ||
params=params, | ||
headers=headers, | ||
json=json, | ||
data=data, | ||
auth=self.auth, | ||
timeout=TIMEOUT, | ||
) | ||
response.raise_for_status() | ||
return response | ||
|
||
def delete( | ||
self, | ||
path: str, | ||
params: dict[str, str] | None = None, | ||
headers: dict[str, str] | None = None, | ||
) -> requests.Response: | ||
response: requests.Response = requests.delete( | ||
f"{self.url}{path}", | ||
params=params, | ||
headers=headers, | ||
auth=self.auth, | ||
timeout=TIMEOUT, | ||
) | ||
if response.status_code != 404: | ||
response.raise_for_status() | ||
return response |
Oops, something went wrong.