You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Internal: user session class
Problem: we often pass 2-3 objects to each function that represent
information on how to connect to the Aleph network:
* the user account
* the API server URL
* the aiohttp session.
This can be simplified to improve the user experience and reduce
the complexity of the SDK.
Solution: introduce a new state class: `UserSession`. This object
is now passed as the first parameter of every public function.
It is initialized with the user account and the API server URL.
It is in charge of configuring and managing the aiohttp session object.
The typical usage of the library now looks like this:
```
account = load_my_account()
api_server = "https://aleph.cloud" # example
async with UserSession(account=account, api_server=api_server) as session:
message, status = await create_post(
session=session,
...
)
```
This enables the following improvements:
* Less clutter in function signatures: all public SDK functions now
have 1 or 2 fewer arguments.
* The API server URL is now managed when initializing the aiohttp
session inside the user session object. Implementations can
simply specify the endpoint URL. Ex:
`f"{api_server}/api/v0/messages.json` can now be expressed
as `"/api/v0/messages.json"`.
Breaking changes:
* The signatures of all public functions of the SDK have been
modified. The user must now initialize the user session object
and pass it as parameter.
* UserSession + AuthenticatedUserSession
* Feature: full API refactoring
The session classes now provide all the SDK functionalities.
The `synchronous` and `asynchronous` modules are removed in
favor of the `UserSession` and `AuthenticatedUserSession` classes.
`UserSession` is intended as a read-only session to access public
API endpoints, while `AuthenticatedUserSession` requires a chain
account and allows the user to post messages to the Aleph network.
Example usage:
```
from aleph_client import AuthenticatedUserSession
async def post_message():
async with AuthenticatedUserSession(
account=fixture_account, api_server=emitter_node
) as session:
post_message, message_status = await session.create_post(
post_content={"Hello": "World"},
)
```
Both classes provide a synchronous context manager and an equivalent
sync class for non-async code.
Breaking changes:
- Everything: the SDK API is entirely modified.
0 commit comments