diff options
| author | Devendra | 2014-06-17 03:15:19 +0530 |
|---|---|---|
| committer | Devendra | 2014-06-17 03:15:19 +0530 |
| commit | c1f366829375593bf3946d5d2a761af57d521783 (patch) | |
| tree | 888786f1bbf436d65aa2e4b8314e07a99b6fc716 | |
| parent | eed03469559dfca83a3ae320a674f2784b93ffc4 (diff) | |
| download | pubnub-python-c1f366829375593bf3946d5d2a761af57d521783.tar.bz2 | |
adding migration files
| -rw-r--r-- | python-tornado/migration.md | 97 | ||||
| -rw-r--r-- | python/migration.md | 61 |
2 files changed, 118 insertions, 40 deletions
diff --git a/python-tornado/migration.md b/python-tornado/migration.md index 10d03ae..5ce15b5 100644 --- a/python-tornado/migration.md +++ b/python-tornado/migration.md @@ -2,15 +2,28 @@ #### www.pubnub.com - PubNub Web Data Push Service in the Cloud. #### http://github.com/pubnub/python +#### Import -#### Init +``` +# Pre 3.5: +from Pubnub import Pubnub +# New in 3.5+ +from Pubnub import PubnubTornado as Pubnub + +``` +#### Init + ``` # Pre 3.5: -# +pubnub = Pubnub( + "demo", ## PUBLISH_KEY + "demo", ## SUBSCRIBE_KEY + False ## SSL_ON? +) # New in 3.5+ pubnub = Pubnub(publish_key="demo", subscribe_key="demo", ssl_on=False) @@ -24,14 +37,16 @@ channel = 'hello_world' message = 'Hello World !!!' # Pre 3.5: -# - -# New in 3.5+ +def callback(messages): + print(messages) -# Synchronous usage -print pubnub.publish(channel='hello_world', message='Hello World !!!') +pubnub.history( { + 'channel' : channel, + 'message' : message, + 'callback' : callback +}) -# Asynchronous usage +# New in 3.5+ def callback(message): print(message) @@ -42,7 +57,6 @@ pubnub.publish(channel, message, callback=callback, error=callback) #### SUBSCRIBE -Pre 3.5.x, subscribe was blocking and would only be terminated via a false return from the callback. In our latest version of the SDK, subscribe is asyncronous, and because of this, usage is a bit different, but the experience is more like our other async SDKs. ``` @@ -51,7 +65,17 @@ Pre 3.5.x, subscribe was blocking and would only be terminated via a false retur channel = 'hello_world' # Pre 3.5: -# +def connected() : + print('CONNECTED') + +def message_received(message): + print(message) + +pubnub.subscribe({ + 'channel' : channel, + 'connect' : connected, + 'callback' : message_received +}) # New in 3.5+ @@ -84,11 +108,13 @@ Once subscribed, you can easily, gracefully, unsubscribe: ``` # Pre 3.5: -# +pubnub.unsubscribe({ + 'channel' : 'hello_world' +}) # New in 3.5+ -Unsub example +pubnub.unsubscribe(channel='hello_world') ``` #### PRESENCE @@ -111,8 +137,6 @@ def callback(message, channel): def error(message): print("ERROR : " + str(message)) - - pubnub.presence(channel, callback=callback, error=callback) ``` @@ -120,20 +144,22 @@ pubnub.presence(channel, callback=callback, error=callback) ``` -# Pre 3.5: -# +channel = 'hello_world' -# New in 3.5+ +# Pre 3.5: +def callback(messages): + print(messages) -# Get info on who is here right now! +pubnub.here_now( { + 'channel' : channel, + 'callback' : callback +}) -channel = 'hello_world' -# Synchronous usage -print pubnub.here_now(channel) +# New in 3.5+ +# Get info on who is here right now! -# Asynchronous usage def callback(message): print(message) @@ -144,21 +170,34 @@ pubnub.here_now(channel, callback=callback, error=callback) #### HISTORY ``` +channel = 'hello_world' # Pre 3.5: -# - -# New in 3.5+ +def history_complete(messages): + print(messages) -# Synchronous usage +pubnub.history( { + 'channel' : channel, + 'limit' : 2, + 'callback' : history_complete +}) -print pubnub.history(channel, count=2) - -# Asynchronous usage +# New in 3.5+ def callback(message): print(message) pubnub.history(channel, count=2, callback=callback, error=callback) ``` + +#### IO Event Loop + +``` + +# Pre 3.5: +tornado.ioloop.IOLoop.instance().start() + +# New in 3.5+ +pubnub.start() +``` diff --git a/python/migration.md b/python/migration.md index 10d03ae..4567a7f 100644 --- a/python/migration.md +++ b/python/migration.md @@ -5,12 +5,14 @@ #### Init - - ``` # Pre 3.5: -# +pubnub = Pubnub( + "demo", ## PUBLISH_KEY + "demo", ## SUBSCRIBE_KEY + False ## SSL_ON? +) # New in 3.5+ pubnub = Pubnub(publish_key="demo", subscribe_key="demo", ssl_on=False) @@ -24,7 +26,11 @@ channel = 'hello_world' message = 'Hello World !!!' # Pre 3.5: -# +info = pubnub.publish({ + 'channel' : channel, + 'message' : message +}) +print(info) # New in 3.5+ @@ -51,7 +57,16 @@ Pre 3.5.x, subscribe was blocking and would only be terminated via a false retur channel = 'hello_world' # Pre 3.5: -# +# Listen for Messages *BLOCKING* +def receive(message) : + print(message) + return True + +pubnub.subscribe({ + 'channel' : channel, + 'callback' : receive +}) + # New in 3.5+ @@ -88,22 +103,31 @@ Once subscribed, you can easily, gracefully, unsubscribe: # New in 3.5+ -Unsub example +pubnub.unsubscribe(channel='hello_world') ``` #### PRESENCE ``` + +channel = 'hello_world' + # Pre 3.5: -# +def pres_event(message) : + print(message) + return True + +pubnub.presence({ + 'channel' : channel, + 'callback' : receive +}) + # New in 3.5+ # Listen for Presence Event Messages -channel = 'hello_world' - def callback(message, channel): print(message) @@ -121,7 +145,15 @@ pubnub.presence(channel, callback=callback, error=callback) ``` # Pre 3.5: -# +# Get info on who is here right now! + +here_now = pubnub.here_now({ + 'channel' : 'hello_world', +}) + +print(here_now['occupancy']) +print(here_now['uuids']) + # New in 3.5+ @@ -146,7 +178,14 @@ pubnub.here_now(channel, callback=callback, error=callback) ``` # Pre 3.5: -# +# 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) # New in 3.5+ |
