Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Johannes Nussbaum <39048939+jnussbaum@users.noreply.github.com>
- Loading branch information
1 parent
863c631
commit 87c1e18
Showing
32 changed files
with
217 additions
and
185 deletions.
There are no files selected for viewing
Empty file.
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,94 @@ | ||
from typing import Any, Protocol | ||
|
||
|
||
class Connection(Protocol): | ||
""" | ||
Protocol class/interface for the connection object. | ||
Exposes: | ||
- get | ||
- put | ||
- post | ||
- delete | ||
""" | ||
|
||
def get( | ||
self, | ||
route: str, | ||
headers: dict[str, str] | None = None, | ||
) -> dict[str, Any]: | ||
""" | ||
Make a HTTP GET request to the server to which this connection has been established. | ||
Args: | ||
route: route that will be called on the server | ||
headers: headers for the HTTP request | ||
""" | ||
|
||
def put( | ||
self, | ||
route: str, | ||
jsondata: str | None = None, | ||
content_type: str = "application/json", | ||
) -> dict[str, Any]: | ||
""" | ||
Make a HTTP GET request to the server to which this connection has been established. | ||
Args: | ||
route: route that will be called on the server | ||
jsondata: Valid JSON as string | ||
content_type: HTTP Content-Type [default: 'application/json'] | ||
""" | ||
|
||
def post( | ||
self, | ||
route: str, | ||
jsondata: str | None = None, | ||
content_type: str = "application/json", | ||
) -> dict[str, Any]: | ||
""" | ||
Make a HTTP POST request to the server to which this connection has been established. | ||
Args: | ||
route: route that will be called on the server | ||
jsondata: Valid JSON as string | ||
content_type: HTTP Content-Type [default: 'application/json'] | ||
""" | ||
|
||
def delete( | ||
self, | ||
route: str, | ||
params: dict[str, Any] | None = None, | ||
) -> dict[str, Any]: | ||
""" | ||
Make a HTTP GET request to the server to which this connection has been established. | ||
Args: | ||
route: route that will be called on the server | ||
params: additional parameters for the HTTP request | ||
""" | ||
|
||
def get_token(self) -> str: | ||
""" | ||
Return the token of this connection. | ||
Raises: | ||
BaseError: if no token is available | ||
""" | ||
|
||
def login(self, email: str, password: str) -> None: | ||
""" | ||
Retrieve a session token and store it as class attribute. | ||
Args: | ||
email: email address of the user | ||
password: password of the user | ||
Raises: | ||
BaseError: if DSP-API returns no token with the provided user credentials | ||
""" | ||
|
||
def logout(self) -> None: | ||
""" | ||
Delete the token on the server and in this class. | ||
""" |
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
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
Oops, something went wrong.