From eb7c97c601fcf63ac75e8bf213f929d2e3ddd666 Mon Sep 17 00:00:00 2001 From: Michel Romero Date: Wed, 16 Jul 2025 14:46:43 -0300 Subject: [PATCH 1/5] Fix URL path handling --- src/vqueue/queues.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vqueue/queues.py b/src/vqueue/queues.py index 996e115..630d303 100644 --- a/src/vqueue/queues.py +++ b/src/vqueue/queues.py @@ -1,4 +1,4 @@ -from pathlib import Path +from urllib.parse import urljoin import requests @@ -7,8 +7,8 @@ from .types import VerificationResult, VerificationResultData from .utils import validate_uuidv4 -QUEUES_API_URL = Path(API_BASE_PATH).joinpath("queue/") -VERIFY_API_URL = QUEUES_API_URL.joinpath("verify") +QUEUES_API_URL = urljoin(API_BASE_PATH, "queue/") +VERIFY_API_URL = urljoin(QUEUES_API_URL, "verify") class TokenVerifier: From be1f6471ca2ceb3ea824c263139081cfc652593d Mon Sep 17 00:00:00 2001 From: Michel Romero Date: Wed, 16 Jul 2025 14:49:05 -0300 Subject: [PATCH 2/5] Modify `verify_token` to safely get data --- src/vqueue/queues.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vqueue/queues.py b/src/vqueue/queues.py index 630d303..459ddcc 100644 --- a/src/vqueue/queues.py +++ b/src/vqueue/queues.py @@ -75,7 +75,7 @@ def verify_token(self, token: str) -> VerificationResult: raise VQueueApiError( response.status_code, - response_data["message"], - response_data["error_code"], - response_data["data"], + response_data.get("message"), + response_data.get("error_code"), + response_data.get("data"), ) From 110e65014c18f631a9651aadb99bcf39358059b4 Mon Sep 17 00:00:00 2001 From: Michel Romero Date: Wed, 16 Jul 2025 15:06:23 -0300 Subject: [PATCH 3/5] Add examples --- examples/verify-token.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/verify-token.py diff --git a/examples/verify-token.py b/examples/verify-token.py new file mode 100644 index 0000000..3ba77fb --- /dev/null +++ b/examples/verify-token.py @@ -0,0 +1,32 @@ +from uuid import uuid4 + +from vqueue import TokenVerifier +from vqueue.exceptions import VQueueApiError, VQueueError, VQueueNetworkError + + +def your_function_or_handler(): + # Get the token from the request in your system + token = str(uuid4()) # This is an example UUIDv4 + + # This handles the connections with a session and can be reused + # for better performance + verifier = TokenVerifier() + + try: + # Handle the happy path + verified_result = verifier.verify_token(token) + print("The token was successfuly verified:", verified_result) + except ValueError as ve: + # Then handle the possible errors + # Of course, you should handle the exceptions with more grace than this + print("The token is not valir UUID", ve) + except VQueueNetworkError as ne: + print("Network error", ne) + except VQueueApiError as ae: + print("The API returned an error status", ae) + except VQueueError as vqe: + print("A generic error with the Virtual Queue system or this SDK", vqe) + + +if __name__ == "__main__": + your_function_or_handler() From 8a96ad2ffabae55a3895d8f9f920f71dd9f5abfe Mon Sep 17 00:00:00 2001 From: Michel Romero Date: Wed, 16 Jul 2025 15:06:28 -0300 Subject: [PATCH 4/5] Update README with usage example --- CONTRIBUTE.md | 25 ++++++++++++++++ README.md | 80 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 80 insertions(+), 25 deletions(-) create mode 100644 CONTRIBUTE.md diff --git a/CONTRIBUTE.md b/CONTRIBUTE.md new file mode 100644 index 0000000..86ce19e --- /dev/null +++ b/CONTRIBUTE.md @@ -0,0 +1,25 @@ +## Development + +Some development notes + +### Coding style guidelines + +The configurations in [.editorconfig](./.editorconfig) and some in [pyproject.toml](./pyptoject.toml) are put in place in order to format and check compliance with [PEP 8](https://pep8.org) (with some exceptions). + +[.pre-commit-config.yaml](./.pre-commit-config.yaml) defines a set of hooks to be executed right before each commit so that [ruff](https://docs.astral.sh/ruff/) (a blazingly fast linter and formatter) is called on the changes made. + +This project uses [`uv`](https://docs.astral.sh/uv/) as package and project manager. To set it up: + +1. Create a virtual environment and install the packages: + ```shell + uv sync + ``` +2. Install the hooks running: + ```shell + uvx pre-commit install + ``` +3. Now on every `git commit` the `pre-commit` hook (inside `.git/hooks/`) will be run. + +#### Configuring your editor + +To configure your code editor [read `ruff`'s documentation about it](https://docs.astral.sh/ruff/editors/). diff --git a/README.md b/README.md index c9843a6..e249a54 100644 --- a/README.md +++ b/README.md @@ -2,28 +2,58 @@ SDK to communicate with Virtual Queue's API in Python projects. -## Development - -Some development notes - -### Coding style guidelines - -The configurations in [.editorconfig](./.editorconfig) and some in [pyproject.toml](./pyptoject.toml) are put in place in order to format and check compliance with [PEP 8](https://pep8.org) (with some exceptions). - -[.pre-commit-config.yaml](./.pre-commit-config.yaml) defines a set of hooks to be executed right before each commit so that [ruff](https://docs.astral.sh/ruff/) (a blazingly fast linter and formatter) is called on the changes made. - -This project uses [`uv`](https://docs.astral.sh/uv/) as package and project manager. To set it up: - -1. Create a virtual environment and install the packages: - ```shell - uv sync - ``` -2. Install the hooks running: - ```shell - uvx pre-commit install - ``` -3. Now on every `git commit` the `pre-commit` hook (inside `.git/hooks/`) will be run. - -#### Configuring your editor - -To configure your code editor [read `ruff`'s documentation about it](https://docs.astral.sh/ruff/editors/). +## How to use + +> [!NOTE] +> See (`examples/`)[./examples/] for more + +You can verify the token with `TokenVerifier` like this: + +```python +from vqueue import TokenVerifier +from vqueue.exceptions import VQueueApiError, VQueueError, VQueueNetworkError + + +def your_function_or_handler(): + # Get the token from the request in your system + token = str(uuid4()) # This is an example UUIDv4 + + # This handles the connections with a session and can be reused + # for better performance + verifier = TokenVerifier() + + try: + # Handle the happy path + verified_result = verifier.verify_token(token) + print("The token was successfuly verified:", verified_result) + except ValueError as ve: + # Then handle the possible errors + # Of course, you should handle the exceptions with more grace than this + print("The token is not valir UUID", ve) + except VQueueNetworkError as ne: + print("Network error", ne) + except VQueueApiError as ae: + print("The API returned an error status", ae) + except VQueueError as vqe: + print("A generic error with the Virtual Queue system or this SDK", vqe) +``` + +You can also wrap your code in a context managed `with` block: + +```python + with TokenVerifier() as verfifier: + try: + # Handle the happy path + verified_result = verifier.verify_token(token) + print("The token was successfuly verified:", verified_result) + except ValueError as ve: + # Then handle the possible errors + # Of course, you should handle the exceptions with more grace than this + print("The token is not valir UUID", ve) + except VQueueNetworkError as ne: + print("Network error", ne) + except VQueueApiError as ae: + print("The API returned an error status", ae) + except VQueueError as vqe: + print("A generic error with the Virtual Queue system or this SDK", vqe) +``` From 6a9c3889b1c3b93feda7d65ad4fc5506cd0e210d Mon Sep 17 00:00:00 2001 From: Michel Romero Date: Wed, 16 Jul 2025 15:08:25 -0300 Subject: [PATCH 5/5] Fix README md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e249a54..14a285b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ SDK to communicate with Virtual Queue's API in Python projects. ## How to use > [!NOTE] -> See (`examples/`)[./examples/] for more +> See [`examples/`](./examples/) for more You can verify the token with `TokenVerifier` like this: