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

Update request headers to match upstream requirements #49

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

robberwick
Copy link
Owner

This pull request includes several changes to the src/pylibrelinkup/pylibrelinkup.py file, focusing on improving the functionality and structure of the PyLibreLinkUp class. The most important changes include the addition of new methods for API calls, the introduction of a new attribute, and updates to the authentication process.

New Methods and Attributes:

  • Added _call_api, _set_token, _set_account_id_hash, _get_graph_data_json, _get_headers, and _get_logbook_json methods to handle API interactions and manage tokens and account IDs. [1] [2]
  • Introduced account_id_hash attribute to store a hashed version of the account ID for API requests. [1] [2]

Authentication Process:

  • Updated the authenticate method to use the new LoginResponse model for validation and to set the token and account ID hash using the new methods.

Imports and Headers:

  • Added imports for hashlib and ValidationError to support new functionality.
  • Updated the _HEADERS dictionary to HEADERS and modified the version number.

Update the version string used in request headers from `4.7.0` to `4
.12.0`, as per the [comment here](https://gist.github.com/khskekec/6c13ba01b10d3018d816706a32ae8ab2?permalink_comment_id=5330276#gistcomment-5330276)

Also add an `Account-Id` header, using a sha256 hashed user id
tidy up method order a little
@robberwick robberwick requested a review from Copilot December 10, 2024 20:28

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no suggestions.

Comments skipped due to low confidence (3)

src/pylibrelinkup/pylibrelinkup.py:70

  • The docstring for the _call_api method should specify the return type as dict instead of object.
def _call_api(self, url: str = None) -> dict:

src/pylibrelinkup/pylibrelinkup.py:33

  • [nitpick] The HEADERS dictionary should be named _HEADERS to maintain consistency with the existing code style.
HEADERS: dict[str, str] = {

src/pylibrelinkup/pylibrelinkup.py:87

  • Ensure that the new account_id_hash attribute is properly validated and tested.
self.account_id_hash = hashlib.sha256(account_id.encode()).hexdigest()
@robberwick robberwick merged commit 06bce45 into main Dec 10, 2024
6 checks passed
@robberwick robberwick deleted the update-llu-version branch December 10, 2024 20:31
@robberwick robberwick linked an issue Dec 10, 2024 that may be closed by this pull request
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.

update request headers to match upstream requirements
1 participant