From c1f366829375593bf3946d5d2a761af57d521783 Mon Sep 17 00:00:00 2001 From: Devendra Date: Tue, 17 Jun 2014 03:15:19 +0530 Subject: adding migration files --- python-tornado/migration.md | 97 +++++++++++++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 29 deletions(-) (limited to 'python-tornado') 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() +``` -- cgit v1.2.3