mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-05 00:42:19 +00:00
rename hub_manager, for consistency with other services
This commit is contained in:
10
openbb_sdk/sdk/core/README.md
vendored
10
openbb_sdk/sdk/core/README.md
vendored
@@ -150,13 +150,13 @@ app = CommandRunnerSession()
|
||||
```python
|
||||
|
||||
# Create Hub manager
|
||||
hm = HubManager()
|
||||
hs = HubService()
|
||||
|
||||
# Connect with email, password or SDK token
|
||||
hm.connect(email="your_email", password="your_password") # pragma: allowlist secret
|
||||
hs.connect(email="your_email", password="your_password") # pragma: allowlist secret
|
||||
|
||||
# Pull your settings
|
||||
user_settings = hm.pull()
|
||||
user_settings = hs.pull()
|
||||
|
||||
# Make the app aware
|
||||
app = CommandRunnerSession(user_settings=user_settings)
|
||||
@@ -165,10 +165,10 @@ app = CommandRunnerSession(user_settings=user_settings)
|
||||
user_settings.credentials.polygon_api_key = "new_key" # pragma: allowlist secret
|
||||
|
||||
# Send change back to Hub
|
||||
hm.push(user_settings)
|
||||
hs.push(user_settings)
|
||||
|
||||
# Disconnect
|
||||
hm.disconnect()
|
||||
hs.disconnect()
|
||||
```
|
||||
|
||||
### 5.3. Define the Command parameters
|
||||
|
||||
@@ -12,8 +12,8 @@ from openbb_core.api.dependency.user import (
|
||||
get_user_service,
|
||||
)
|
||||
from openbb_core.api.model.token_response import TokenResponse
|
||||
from openbb_core.app.hub_manager import HubManager
|
||||
from openbb_core.app.model.user_settings import UserSettings
|
||||
from openbb_core.app.service.hub_service import HubService
|
||||
|
||||
router = APIRouter(prefix="/account", tags=["Account"])
|
||||
|
||||
@@ -30,9 +30,9 @@ async def login_for_access_token(
|
||||
username=form_data.username,
|
||||
)
|
||||
if not user_settings and openbb_hub:
|
||||
hm = HubManager()
|
||||
hm.connect(email=form_data.username, password=form_data.password)
|
||||
user_settings = hm.pull()
|
||||
hs = HubService()
|
||||
hs.connect(email=form_data.username, password=form_data.password)
|
||||
user_settings = hs.pull()
|
||||
if user_settings:
|
||||
user_settings.profile.username = form_data.username
|
||||
user_settings.profile.password_hash = get_password_hash(form_data.password)
|
||||
@@ -57,8 +57,8 @@ async def push_user_settings_to_hub(
|
||||
user_settings: Annotated[UserSettings, Depends(get_user)]
|
||||
) -> UserSettings:
|
||||
if user_settings.profile.hub_session:
|
||||
hm = HubManager(user_settings.profile.hub_session)
|
||||
hm.push(user_settings)
|
||||
hs = HubService(user_settings.profile.hub_session)
|
||||
hs.push(user_settings)
|
||||
return user_settings
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
@@ -73,8 +73,8 @@ async def pull_user_settings_from_hub(
|
||||
user_service: Annotated[UserService, Depends(get_user_service)],
|
||||
) -> UserSettings:
|
||||
if user_settings.profile.hub_session:
|
||||
hm = HubManager(user_settings.profile.hub_session)
|
||||
incoming = hm.pull()
|
||||
hs = HubService(user_settings.profile.hub_session)
|
||||
incoming = hs.pull()
|
||||
incoming.id = user_settings.id
|
||||
d = incoming.dict(exclude_none=True)
|
||||
filtered_incoming = UserSettings.parse_obj(d)
|
||||
@@ -92,8 +92,8 @@ async def disconnect_from_hub(
|
||||
user_settings: Annotated[UserSettings, Depends(get_user)],
|
||||
) -> bool:
|
||||
if user_settings.profile.hub_session:
|
||||
hm = HubManager(user_settings.profile.hub_session)
|
||||
result = hm.disconnect()
|
||||
hs = HubService(user_settings.profile.hub_session)
|
||||
result = hs.disconnect()
|
||||
user_settings.profile.hub_session = None
|
||||
return result
|
||||
raise HTTPException(
|
||||
|
||||
@@ -2,7 +2,6 @@ from typing import Optional
|
||||
|
||||
import requests
|
||||
from fastapi import HTTPException
|
||||
|
||||
from openbb_core.app.model.credentials import Credentials
|
||||
from openbb_core.app.model.hub.features_keys import FeaturesKeys
|
||||
from openbb_core.app.model.hub.hub_session import HubSession
|
||||
@@ -15,7 +14,7 @@ class OpenBBError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class HubManager:
|
||||
class HubService:
|
||||
"""Hub manager class"""
|
||||
|
||||
BASE_URL = "https://payments.openbb.dev"
|
||||
@@ -4,9 +4,9 @@ from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from openbb_core.app.command_runner import CommandRunnerSession
|
||||
from openbb_core.app.hub_manager import HubManager
|
||||
from openbb_core.app.model.hub.hub_session import HubSession
|
||||
from openbb_core.app.model.user_settings import UserSettings
|
||||
from openbb_core.app.service.hub_service import HubService
|
||||
from openbb_core.app.service.user_service import UserService
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -21,12 +21,12 @@ class Account:
|
||||
def __init__(self, app: "App"):
|
||||
self._app = app
|
||||
|
||||
def create_hub_manager(
|
||||
def create_hub_service(
|
||||
self,
|
||||
email: Optional[str] = None,
|
||||
password: Optional[str] = None,
|
||||
sdk_token: Optional[str] = None,
|
||||
) -> HubManager:
|
||||
) -> HubService:
|
||||
if email is None and password is None and sdk_token is None:
|
||||
session_file = Path(
|
||||
self._app.system.openbb_directory, ".sdk_hub_session.json"
|
||||
@@ -38,11 +38,11 @@ class Account:
|
||||
session_dict = json.load(f)
|
||||
|
||||
hub_session = HubSession(**session_dict)
|
||||
hm = HubManager(hub_session)
|
||||
hs = HubService(hub_session)
|
||||
else:
|
||||
hm = HubManager()
|
||||
hm.connect(email, password, sdk_token)
|
||||
return hm
|
||||
hs = HubService()
|
||||
hs.connect(email, password, sdk_token)
|
||||
return hs
|
||||
|
||||
def login(
|
||||
self,
|
||||
@@ -69,8 +69,8 @@ class Account:
|
||||
UserSettings
|
||||
User settings: profile, credentials, preferences
|
||||
"""
|
||||
hm = self.create_hub_manager(email, password, sdk_token)
|
||||
incoming = hm.pull()
|
||||
hs = self.create_hub_service(email, password, sdk_token)
|
||||
incoming = hs.pull()
|
||||
updated = UserService.update_default(incoming)
|
||||
self._app._command_runner_session = CommandRunnerSession(user_settings=updated)
|
||||
if remember_me:
|
||||
@@ -79,10 +79,10 @@ class Account:
|
||||
self._app.system.openbb_directory, ".sdk_hub_session.json"
|
||||
)
|
||||
with open(session_file, "w") as f:
|
||||
if not hm.session:
|
||||
if not hs.session:
|
||||
raise OpenBBError("Not connected to hub.")
|
||||
|
||||
json.dump(hm.session.dict(), f, indent=4)
|
||||
json.dump(hs.session.dict(), f, indent=4)
|
||||
|
||||
return self._app._command_runner_session.user_settings
|
||||
|
||||
@@ -102,8 +102,8 @@ class Account:
|
||||
self._app._command_runner_session.user_settings
|
||||
)
|
||||
else:
|
||||
hm = HubManager(hub_session)
|
||||
hm.push(self._app._command_runner_session.user_settings)
|
||||
hs = HubService(hub_session)
|
||||
hs.push(self._app._command_runner_session.user_settings)
|
||||
return self._app._command_runner_session.user_settings
|
||||
|
||||
def refresh(self) -> UserSettings:
|
||||
@@ -120,8 +120,8 @@ class Account:
|
||||
if not hub_session:
|
||||
self._app._command_runner_session = CommandRunnerSession()
|
||||
else:
|
||||
hm = HubManager(hub_session)
|
||||
incoming = hm.pull()
|
||||
hs = HubService(hub_session)
|
||||
incoming = hs.pull()
|
||||
updated = UserService.update_default(incoming)
|
||||
updated.id = self._app._command_runner_session.user_settings.id
|
||||
self._app._command_runner_session = CommandRunnerSession(
|
||||
@@ -143,8 +143,8 @@ class Account:
|
||||
if not hub_session:
|
||||
raise OpenBBError("Not connected to hub.")
|
||||
|
||||
hm = HubManager(hub_session)
|
||||
hm.disconnect()
|
||||
hs = HubService(hub_session)
|
||||
hs.disconnect()
|
||||
|
||||
session_file = Path(self._app.system.openbb_directory, ".sdk_hub_session.json")
|
||||
if session_file.exists():
|
||||
|
||||
Reference in New Issue
Block a user