This repository has been archived by the owner on Jul 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
client.py
55 lines (44 loc) · 1.48 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# coding: utf-8
from django.conf import settings
from cent.core import Client as RawClient
class Client(object):
def __init__(self, address=None, secret=None, timeout=10, json_encoder=None):
self.address = address or settings.CENTRIFUGE_ADDRESS
self.secret = secret or settings.CENTRIFUGE_SECRET
self.timeout = timeout or settings.CENTRIFUGE_TIMEOUT
self.api_address = self.address
self._client = RawClient(
self.api_address, self.secret,
timeout=self.timeout, json_encoder=json_encoder
)
def publish(self, channel, data, client=None):
params = {
"channel": channel,
"data": data
}
if client:
params["client"] = client
self._client.add("publish", params)
def unsubscribe(self, user, channel=None):
params = {"user": user}
if channel:
params["channel"] = channel
self._client.add("unsubscribe", params)
def disconnect(self, user):
self._client.add("disconnect", {
"user": user
})
def presence(self, channel):
self._client.add("presence", {
"channel": channel
})
def history(self, channel):
self._client.add("history", {
"channel": channel
})
def channels(self):
self._client.add("channels", {})
def stats(self):
self._client.add("stats", {})
def send(self):
return self._client.send()