Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ApiToken and pass api_key as a string #48

Merged
merged 6 commits into from
Jul 15, 2024

Conversation

mnbf9rca
Copy link
Owner

@mnbf9rca mnbf9rca commented Jul 15, 2024

Summary by Sourcery

This pull request refactors the API token handling by removing the ApiToken class and passing the API key directly as a string. It includes updates to the documentation and tests to reflect this change.

  • Enhancements:
    • Refactored the API token handling by removing the ApiToken class and passing the API key directly as a string.
  • Documentation:
    • Updated README.md to reflect the new method of passing the API key directly as a string.
  • Tests:
    • Modified tests to accommodate the change from using ApiToken to passing the API key directly as a string.

Copy link

sourcery-ai bot commented Jul 15, 2024

Reviewer's Guide by Sourcery

This pull request removes the ApiToken class and refactors the codebase to pass the api_key as a string. Significant changes include updating the Client and RestClient classes, modifying tests, and updating documentation and examples to reflect this change.

File-Level Changes

Files Changes
tests/test_basic_tests.py
tests/test_client.py
Updated tests to use a string for api_key instead of ApiToken.
pydantic_tfl_api/rest_client.py
pydantic_tfl_api/client.py
pydantic_tfl_api/__init__.py
Refactored client and rest client to use a string for api_key instead of ApiToken.
README.md
example.py
Updated documentation and examples to use a string for api_key instead of ApiToken.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mnbf9rca - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 1 issue found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

pydantic_tfl_api/rest_client.py Outdated Show resolved Hide resolved
pydantic_tfl_api/rest_client.py Show resolved Hide resolved
@@ -38,10 +37,10 @@
class Client:
"""Client

:param ApiToken api_token: API token to access TfL unified API
:param str api_token: API token to access TfL unified API
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Update docstring to reflect new parameter name.

The docstring should be updated to reflect the new parameter name 'api_token' instead of 'api_token' to avoid confusion.

tests/test_basic_tests.py Show resolved Hide resolved
@@ -109,7 +108,7 @@ def test_create_model_with_expiry(
"api_token, expected_client_type, expected_models",
[
(None, RestClient, {"test_model"}),
(ApiToken("valid_token", "valid_key"), RestClient, {"test_model"}),
( "valid_key", RestClient, {"test_model"}),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Add test for invalid API key in parameterized test

Consider adding an additional parameterized test case for an invalid API key to ensure that the client handles invalid keys correctly.

Suggested change
( "valid_key", RestClient, {"test_model"}),
("valid_key", RestClient, {"test_model"}),
("invalid_key", RestClient, {"test_model"}),

README.md Outdated

app_id = 'APPLICATION ID'
app_key = 'APPLICATION KEY'

token = ApiToken(app_id, app_key)
token = "your_secret_token"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (documentation): Consider adding a note explaining the change from ApiToken to a direct token string.

To avoid confusion for users familiar with the previous method, consider adding a note or comment explaining the change from ApiToken(app_id, app_key) to token = "your_secret_token".

Suggested change
token = "your_secret_token"
# Note: Changed from ApiToken(app_id, app_key) to a direct token string for simplicity
token = "your_secret_token"

if self.api_token is not None:
request_headers.update(self.api_token)
if self.app_key is not None:
request_headers.update(self.app_key)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Merge dictionary updates via the union operator (dict-assign-update-to-union)

Suggested change
request_headers.update(self.app_key)
request_headers |= self.app_key

mnbf9rca and others added 5 commits July 15, 2024 14:55
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@mnbf9rca mnbf9rca merged commit de50def into main Jul 15, 2024
3 checks passed
@mnbf9rca mnbf9rca deleted the feat/remove-api_id-from-ApiToken branch July 15, 2024 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant