Skip to content

Commit

Permalink
hub service rename it as _request_session
Browse files Browse the repository at this point in the history
  • Loading branch information
deeleeramone committed Dec 5, 2024
1 parent dec94bc commit 46362fa
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions openbb_platform/core/openbb_core/app/service/hub_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
self._base_url = base_url or Env().HUB_BACKEND
self._session = session
self._hub_user_settings: Optional[HubUserSettings] = None
self._session = get_requests_session()
self._request_session = get_requests_session()

@property
def base_url(self) -> str:
Expand Down Expand Up @@ -73,13 +73,10 @@ def connect(

def disconnect(self) -> bool:
"""Disconnect from Hub."""
old_verify = self._get_certificates()
if self._session:
result = self._post_logout(self._session)
self._session = None
self._restore_certs(old_verify)
return result
self._restore_certs(old_verify)
raise OpenBBError(
"No session found. Login or provide a 'HubSession' on initialization."
)
Expand Down Expand Up @@ -118,7 +115,7 @@ def _get_session_from_email_password(self, email: str, password: str) -> HubSess
if not password:
raise OpenBBError("Password not found.")

response = self._session.post(
response = self._request_session.post(
url=self._base_url + "/login",
json={
"email": email,
Expand Down Expand Up @@ -150,7 +147,7 @@ def _get_session_from_platform_token(self, token: str) -> HubSession:

self._check_token_expiration(token)

response = self._session.post(
response = self._request_session.post(
url=self._base_url + "/sdk/login",
json={
"token": token,
Expand Down Expand Up @@ -179,7 +176,7 @@ def _post_logout(self, session: HubSession) -> bool:
token_type = session.token_type
authorization = f"{token_type.title()} {access_token}"

response = self._session.get(
response = self._request_session.get(
url=self._base_url + "/logout",
headers={"Authorization": authorization},
json={"token": access_token},
Expand All @@ -199,7 +196,7 @@ def _get_user_settings(self, session: HubSession) -> HubUserSettings:
access_token = session.access_token.get_secret_value()
token_type = session.token_type
authorization = f"{token_type.title()} {access_token}"
response = self._session.get(
response = self._request_session.get(
url=self._base_url + "/terminal/user",
headers={"Authorization": authorization},
timeout=self.TIMEOUT,
Expand All @@ -220,7 +217,7 @@ def _put_user_settings(
access_token = session.access_token.get_secret_value()
token_type = session.token_type
authorization = f"{token_type.title()} {access_token}"
response = self._session.put(
response = self._request_session.put(
url=self._base_url + "/user",
headers={"Authorization": authorization},
json=settings.model_dump(exclude_defaults=True),
Expand Down

0 comments on commit 46362fa

Please sign in to comment.