Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Feb 17, 2024
1 parent f3b5df1 commit f47b987
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 112 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pip install cent

## Usage

First of all, see the description of Centrifugo [server API](https://centrifugal.dev/docs/server/server_api) in the documentation.
First of all, see the description of Centrifugo [server API](https://centrifugal.dev/docs/server/server_api) in the documentation. This library also supports API extensions provided by Centrifugo PRO.

This library contains `Client` and `AsyncClient` to work with Centrifugo HTTP server API. Both clients have the same methods to work with Centrifugo API and raise the same top-level exceptions.
The library contains `Client` and `AsyncClient` to work with Centrifugo HTTP server API. Both clients have the same methods to work with Centrifugo API and raise the same top-level exceptions.

## Sync HTTP client

Expand All @@ -38,13 +38,14 @@ Optional arguments:
Example:

```python
from cent import Client
from cent import Client, PublishRequest

api_url = "http://localhost:8000/api"
api_key = "<CENTRIFUGO_API_KEY>"

client = Client(api_url, api_key)
result = client.publish("channel", {"input": "Hello world!"})
request = PublishRequest(channel="channel", data={"input": "Hello world!"})
result = client.send(request)
print(result)
```

Expand All @@ -68,15 +69,15 @@ Example:

```python
import asyncio
from cent import AsyncClient
from cent import AsyncClient, PublishRequest

api_url = "http://localhost:8000/api"
api_key = "<CENTRIFUGO_API_KEY>"

client = AsyncClient(api_url, api_key)

async def main():
result = await client.publish("channel", {"input": "Hello world!"})
client = AsyncClient(api_url, api_key)
request = PublishRequest(channel="channel", data={"input": "Hello world!"})
result = await client.send(request)
print(result)

if __name__ == "__main__":
Expand Down Expand Up @@ -128,6 +129,7 @@ make bench

Cent v5 contains the following notable changes compared to Cent v4:

* Constructor slightly changed, refer to the examples above.
* Client constructor slightly changed, refer to the examples above.
* To call desired API import and construct a request object (inherited from Pydantic `BaseModel`) and pass it to `send` method of the client.
* Base exception class is now `CentError` instead of `CentException`, exceptions SDK raises were refactored.
* To send multiple commands in one HTTP request SDK provides `batch` method.
60 changes: 60 additions & 0 deletions cent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,36 @@
Node,
Publication,
ClientInfo,
DeviceRegisterRequest,
DeviceRegisterResult,
DeviceUpdateRequest,
DeviceUpdateResult,
DeviceListRequest,
DeviceListResult,
DeviceRemoveRequest,
DeviceRemoveResult,
DeviceTopicListRequest,
DeviceTopicListResult,
UserTopicListRequest,
UserTopicListResult,
SendPushNotificationRequest,
SendPushNotificationResult,
PushNotification,
FcmPushNotification,
HmsPushNotification,
ApnsPushNotification,
Device,
DeviceFilter,
DeviceTopicFilter,
DeviceUserUpdate,
DeviceMetaUpdate,
DeviceTopicsUpdate,
DeviceTopicUpdateRequest,
DeviceTopicUpdateResult,
UpdatePushStatusRequest,
UpdatePushStatusResult,
CancelPushRequest,
CancelPushResult,
)
from cent.exceptions import (
CentError,
Expand All @@ -51,12 +81,15 @@
)

__all__ = (
"ApnsPushNotification",
"AsyncClient",
"BatchRequest",
"BatchResult",
"BoolValue",
"BroadcastRequest",
"BroadcastResult",
"CancelPushRequest",
"CancelPushResult",
"CentApiResponseError",
"CentDecodeError",
"CentError",
Expand All @@ -70,13 +103,33 @@
"ChannelsResult",
"Client",
"ClientInfo",
"Device",
"DeviceFilter",
"DeviceListRequest",
"DeviceListResult",
"DeviceMetaUpdate",
"DeviceRegisterRequest",
"DeviceRegisterResult",
"DeviceRemoveRequest",
"DeviceRemoveResult",
"DeviceTopicFilter",
"DeviceTopicListRequest",
"DeviceTopicListResult",
"DeviceTopicUpdateRequest",
"DeviceTopicUpdateResult",
"DeviceTopicsUpdate",
"DeviceUpdateRequest",
"DeviceUpdateResult",
"DeviceUserUpdate",
"Disconnect",
"DisconnectRequest",
"DisconnectResult",
"FcmPushNotification",
"HistoryRemoveRequest",
"HistoryRemoveResult",
"HistoryRequest",
"HistoryResult",
"HmsPushNotification",
"InfoRequest",
"InfoResult",
"Node",
Expand All @@ -88,12 +141,19 @@
"Publication",
"PublishRequest",
"PublishResult",
"PushNotification",
"RefreshRequest",
"RefreshResult",
"Response",
"SendPushNotificationRequest",
"SendPushNotificationResult",
"StreamPosition",
"SubscribeRequest",
"SubscribeResult",
"UnsubscribeRequest",
"UnsubscribeResult",
"UpdatePushStatusRequest",
"UpdatePushStatusResult",
"UserTopicListRequest",
"UserTopicListResult",
)
Loading

0 comments on commit f47b987

Please sign in to comment.