diff options
| author | Devendra | 2014-06-17 00:58:40 +0530 |
|---|---|---|
| committer | Devendra | 2014-06-17 00:58:40 +0530 |
| commit | 30202de8be4ba24f4fba8dda4b3f28f6ee6600aa (patch) | |
| tree | 1a7933ad65111c1f19f99c716f9cdd0dfa379f2d /python/README.md | |
| parent | 819dbedf0904b81e866ea6d27219608167d8b8ca (diff) | |
| download | pubnub-python-30202de8be4ba24f4fba8dda4b3f28f6ee6600aa.tar.bz2 | |
readme changes
Diffstat (limited to 'python/README.md')
| -rw-r--r-- | python/README.md | 119 |
1 files changed, 69 insertions, 50 deletions
diff --git a/python/README.md b/python/README.md index 7232756..14d767f 100644 --- a/python/README.md +++ b/python/README.md @@ -6,55 +6,78 @@ #### Init ``` -pubnub = Pubnub( - "demo", ## PUBLISH_KEY - "demo", ## SUBSCRIBE_KEY - None, ## SECRET_KEY - False ## SSL_ON? -) +pubnub = Pubnub(publish_key="demo", subscribe_key="demo", ssl_on=False) + ``` #### PUBLISH ``` -info = pubnub.publish({ - 'channel' : 'hello_world', - 'message' : { - 'some_text' : 'Hello my World' - } -}) -print(info) +channel = 'hello_world' +message = 'Hello World !!!' + +# Synchronous usage +print pubnub.publish(channel='hello_world', message='Hello World !!!') + +# Asynchronous usage + +def callback(message): + print(message) + +pubnub.publish(channel, message, callback=callback, error=callback) + ``` #### SUBSCRIBE ``` -# Listen for Messages *BLOCKING* -def receive(message) : +# Listen for Messages + +channel = 'hello_world' + +def callback(message, channel): print(message) - return True -pubnub.subscribe({ - 'channel' : 'hello_world', - 'callback' : receive -}) + +def error(message): + print("ERROR : " + str(message)) + + +def connect(message): + print("CONNECTED") + + +def reconnect(message): + print("RECONNECTED") + + +def disconnect(message): + print("DISCONNECTED") + + +pubnub.subscribe(channel, callback=callback, error=callback, + connect=connect, reconnect=reconnect, disconnect=disconnect) ``` #### PRESENCE ``` -# Listen for Presence Event Messages *BLOCKING* +# Listen for Presence Event Messages + +channel = 'hello_world' -def pres_event(message) : +def callback(message, channel): print(message) - return True -pubnub.presence({ - 'channel' : 'hello_world', - 'callback' : receive -}) + +def error(message): + print("ERROR : " + str(message)) + + + +pubnub.presence(channel, callback=callback, error=callback) ``` #### HERE_NOW @@ -62,36 +85,32 @@ pubnub.presence({ ``` # Get info on who is here right now! -here_now = pubnub.here_now({ - 'channel' : 'hello_world', -}) +channel = 'hello_world' -print(here_now['occupancy']) -print(here_now['uuids']) -``` +# Synchronous usage +print pubnub.here_now(channel) -#### Channel Analytics -``` -analytics = pubnub.analytics({ - 'channel' : 'channel-name-here', ## Leave blank for all channels - 'limit' : 100, ## aggregation range - 'ago' : 0, ## minutes ago to look backward - 'duration' : 100 ## minutes offset -}) -print(analytics) +# Asynchronous usage +def callback(message): + print(message) + +pubnub.here_now(channel, callback=callback, error=callback) ``` #### HISTORY ``` -# Load Previously Published Messages -history = pubnub.detailedHistory({ - 'channel' : 'my_channel', - 'end' : my_end_time_token, # Optional - 'start' : my_start_time_token, # Optional - 'count' : num_of_msgs_to_return # Optional, default is 100 -}) -print(history) +# Synchronous usage + +print pubnub.history(channel, count=2) + +# Asynchronous usage + + +def callback(message): + print(message) + +pubnub.history(channel, count=2, callback=callback, error=callback) ``` |
