Skip to content

Commit

Permalink
Headers fixed in case of multiple accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
geertmeersman committed Apr 12, 2023
1 parent 496d4db commit 937852d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
- [ ] **Breaking change** (fix or feature that would cause existing functionality to change)
- [ ] **Enhancement** (changes that improvement of current feature or performance)
- [ ] **Refactoring** (changes that neither fixes a bug nor adds a feature)
- [ ] **Test Case** (changes that add missing tests or correct existing tests)
- [ ] **Code style optimization** (changes that do not affect the meaning of the code)
- [ ] **Docs** (changes that only update documentation)
- [ ] **Chore** (changes that don't modify src or test files)
Expand Down
6 changes: 0 additions & 6 deletions .github/labels.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
- name: fix
description: A bug correction
color: d3fc03
- name: bug
description: Something isn't working
color: d73a4a
- name: feature
description: A new feature or request
color: a2eeef
- name: enhancement
description: A new feature or request
color: a2eeef
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ repos:
entry: flake8
language: system
types: [python]
args: ["-j8", "--ignore=E501,W503"]
require_serial: true
- id: reorder-python-imports
name: Reorder python imports
Expand Down
19 changes: 14 additions & 5 deletions custom_components/nexxtmove/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def __init__(
environment: NexxtmoveEnvironment = DEFAULT_NEXXTMOVE_ENVIRONMENT,
) -> None:
"""Initialize NexxtmoveClient."""
self.session = session if session else Session()
self.session = Session()
self.username = username
self.password = password
self.environment = environment
self.session.headers = headers
self._headers = headers
self.profile = {}
self.request_error = {}
self.token = None
Expand All @@ -54,10 +54,19 @@ def request(
"""Send a request to Nexxtmove."""
if data is None:
log_debug(f"{caller} Calling GET {url}")
response = self.session.get(url, timeout=REQUEST_TIMEOUT)
response = self.session.get(
url,
timeout=REQUEST_TIMEOUT,
headers=self._headers | {"Authorize": f"Token {self.token}"},
)
else:
log_debug(f"{caller} Calling POST {url} with {data}")
response = self.session.post(url, json=data, timeout=REQUEST_TIMEOUT)
response = self.session.post(
url,
json=data,
timeout=REQUEST_TIMEOUT,
headers=self._headers | {"Authorize": f"Token {self.token}"},
)
log_debug(
f"{caller} http status code = {response.status_code} (expecting {expected})"
)
Expand Down Expand Up @@ -102,7 +111,7 @@ def login(self) -> dict:
result = response.json()
try:
self.token = result.get("authToken")
self.session.headers |= {"Authorize": f"Token {self.token}"}
log_debug(f"Setting Token {self.token}")
self.profile = result.get("profile")
except Exception as exception:
raise BadCredentialsException(
Expand Down

0 comments on commit 937852d

Please sign in to comment.