diff options
Diffstat (limited to 'python-tornado/examples')
| -rw-r--r-- | python-tornado/examples/here-now.py (renamed from python-tornado/examples/history-example.py) | 18 | ||||
| -rw-r--r-- | python-tornado/examples/history.py | 32 | ||||
| -rw-r--r-- | python-tornado/examples/publish-example.py | 70 | ||||
| -rw-r--r-- | python-tornado/examples/publish.py | 33 | ||||
| -rw-r--r-- | python-tornado/examples/subscribe-example.py | 77 | ||||
| -rw-r--r-- | python-tornado/examples/subscribe.py (renamed from python-tornado/examples/here-now-example.py) | 39 | ||||
| -rw-r--r-- | python-tornado/examples/uuid-example.py | 26 | 
7 files changed, 97 insertions, 198 deletions
| diff --git a/python-tornado/examples/history-example.py b/python-tornado/examples/here-now.py index 3a5fd88..5c195f1 100644 --- a/python-tornado/examples/history-example.py +++ b/python-tornado/examples/here-now.py @@ -5,9 +5,6 @@  ## Copyright (c) 2010 Stephen Blum  ## http://www.pubnub.com/ -## ----------------------------------- -## PubNub 3.0 Real-time Push Cloud API -## -----------------------------------  import sys  from Pubnub import PubnubTornado as Pubnub @@ -18,14 +15,19 @@ secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo'  cipher_key = len(sys.argv) > 4 and sys.argv[4] or ''  ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False -pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on) +## ----------------------------------------------------------------------- +## Initiate Pubnub State +## ----------------------------------------------------------------------- +pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, +                secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)  channel = 'hello_world' -def history_complete(messages): -    print(messages) -    pubnub.stop() +# Asynchronous usage -pubnub.history(channel=channel, count=10, callback=history_complete) +def callback(message): +    print(message) + +pubnub.here_now(channel, callback=callback, error=callback)  pubnub.start() diff --git a/python-tornado/examples/history.py b/python-tornado/examples/history.py new file mode 100644 index 0000000..da3d6a5 --- /dev/null +++ b/python-tornado/examples/history.py @@ -0,0 +1,32 @@ +## www.pubnub.com - PubNub Real-time push service in the cloud. +# coding=utf8 + +## PubNub Real-time Push APIs and Notifications Framework +## Copyright (c) 2010 Stephen Blum +## http://www.pubnub.com/ + + +import sys +from Pubnub import PubnubTornado as Pubnub + +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' +cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False + +## ----------------------------------------------------------------------- +## Initiate Pubnub State +## ----------------------------------------------------------------------- +pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, +                secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) +channel  = 'a' + +# Asynchronous usage + +def callback(message): +    print(message) + +pubnub.history(channel, count=2 , callback=callback, error=callback) + +pubnub.start() diff --git a/python-tornado/examples/publish-example.py b/python-tornado/examples/publish-example.py deleted file mode 100644 index 456dbf9..0000000 --- a/python-tornado/examples/publish-example.py +++ /dev/null @@ -1,70 +0,0 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. -# coding=utf8 - -## PubNub Real-time Push APIs and Notifications Framework -## Copyright (c) 2010 Stephen Blum -## http://www.pubnub.com/ - -## ----------------------------------- -## PubNub 3.1 Real-time Push Cloud API -## ----------------------------------- - -import sys -from Pubnub import PubnubTwisted as Pubnub - -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' -subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' -secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False - -## ----------------------------------------------------------------------- -## Initiate Pubnub State -## ----------------------------------------------------------------------- -pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on) -crazy = 'hello_world' - -## ----------------------------------------------------------------------- -## Publish Example -## ----------------------------------------------------------------------- - - -def publish_complete(info): -    print(info) - - -def publish_error(info): -    print('ERROR : ' + str(info)) - -## Publish string -pubnub.publish({ -    'channel': crazy, -    'message': 'Hello World!', -    'callback': publish_complete, -    'error': publish_error -}) - -## Publish list -li = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', -      'Saturday'] - -pubnub.publish({ -    'channel': crazy, -    'message': li, -    'callback': publish_complete, -    'error': publish_error -}) - - -def done_cb(info): -    publish_complete(info) - -pubnub.publish({ -    'channel': crazy, -    'message': {'some_key': 'some_val'}, -    'callback': done_cb, -    'error': publish_error -}) - - -pubnub.start() diff --git a/python-tornado/examples/publish.py b/python-tornado/examples/publish.py new file mode 100644 index 0000000..4e662fd --- /dev/null +++ b/python-tornado/examples/publish.py @@ -0,0 +1,33 @@ +## www.pubnub.com - PubNub Real-time push service in the cloud. +# coding=utf8 + +## PubNub Real-time Push APIs and Notifications Framework +## Copyright (c) 2010 Stephen Blum +## http://www.pubnub.com/ + + +import sys +from Pubnub import PubnubTornado as Pubnub + +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' +cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False + +## ----------------------------------------------------------------------- +## Initiate Pubnub State +## ----------------------------------------------------------------------- +pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, +                secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) +channel  = 'hello_world' +message  = 'Hello World !!!' + +# Asynchronous usage + +def callback(message): +    print(message) + +pubnub.publish(channel, message, callback=callback, error=callback) + +pubnub.start() diff --git a/python-tornado/examples/subscribe-example.py b/python-tornado/examples/subscribe-example.py deleted file mode 100644 index 26be1fd..0000000 --- a/python-tornado/examples/subscribe-example.py +++ /dev/null @@ -1,77 +0,0 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. -# coding=utf8 - -## PubNub Real-time Push APIs and Notifications Framework -## Copyright (c) 2010 Stephen Blum -## http://www.pubnub.com/ - -## ----------------------------------- -## PubNub 3.1 Real-time Push Cloud API -## ----------------------------------- - -import sys -import tornado -from Pubnub import PubnubTwisted as Pubnub - -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' -subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' -secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len( -    sys.argv) > 4 and sys.argv[4] or 'demo'  # (Cipher key is Optional) -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False - -## ----------------------------------------------------------------------- -## Initiate Pubnub State -## ----------------------------------------------------------------------- -pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, -                secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) -#pubnub = Pubnub( publish_key, subscribe_key, secret_key, ssl_on ) -crazy = 'hello_world' - - -def connect_cb(): -    print 'Connect' - - -def subscribe_result(response): -    print response - -pubnub.subscribe({ -    'channel': crazy, -    'callback': subscribe_result, -    'connect': connect_cb -}) -## ----------------------------------------------------------------------- -## Publish Example -## ----------------------------------------------------------------------- -''' -def publish_complete(info): -    print(info) - -## Publish string -pubnub.publish({ -    'channel' : crazy, -    'message' : 'Hello World!', -    'callback' : publish_complete -}) - -## Publish list -li = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', -    'Saturday'] -pubnub.publish({ -    'channel' : crazy, -    'message' : li, -    'callback' : publish_complete -}) - -## Publish Dictionary Object -pubnub.publish({ -    'channel' : crazy, -    'message' : { 'some_key' : 'some_val' }, -    'callback' : publish_complete -}) -''' -## ----------------------------------------------------------------------- -## IO Event Loop -## ----------------------------------------------------------------------- -tornado.ioloop.IOLoop.instance().start() diff --git a/python-tornado/examples/here-now-example.py b/python-tornado/examples/subscribe.py index c701daf..9288836 100644 --- a/python-tornado/examples/here-now-example.py +++ b/python-tornado/examples/subscribe.py @@ -5,9 +5,6 @@  ## Copyright (c) 2010 Stephen Blum  ## http://www.pubnub.com/ -## ----------------------------------- -## PubNub 3.1 Real-time Push Cloud API -## -----------------------------------  import sys  from Pubnub import PubnubTornado as Pubnub @@ -21,23 +18,31 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False  ## -----------------------------------------------------------------------  ## Initiate Pubnub State  ## ----------------------------------------------------------------------- -pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on) -crazy = 'hello_world' +pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, +                secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) -## ----------------------------------------------------------------------- -## History Example -## ----------------------------------------------------------------------- +channel  = 'a' -def here_now_complete(messages): -    print(messages) -    print(type(messages)) -    pubnub.stop() -pubnub.here_now( -    channel=crazy, callback=here_now_complete, error=here_now_complete) +# Asynchronous usage + +def callback(message, channel): +    print(message) + +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) -## ----------------------------------------------------------------------- -## IO Event Loop -## -----------------------------------------------------------------------  pubnub.start() diff --git a/python-tornado/examples/uuid-example.py b/python-tornado/examples/uuid-example.py deleted file mode 100644 index e5521ab..0000000 --- a/python-tornado/examples/uuid-example.py +++ /dev/null @@ -1,26 +0,0 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. -# coding=utf8 - -## PubNub Real-time Push APIs and Notifications Framework -## Copyright (c) 2010 Stephen Blum -## http://www.pubnub.com/ - -## ----------------------------------- -## PubNub 3.1 Real-time Push Cloud API -## ----------------------------------- - -import sys -import tornado -from Pubnub import PubnubTwisted as Pubnub - -## ----------------------------------------------------------------------- -## Initiate Pubnub State -## ----------------------------------------------------------------------- -pubnub = Pubnub("", "", "", False) - -## ----------------------------------------------------------------------- -## UUID Example -## ----------------------------------------------------------------------- -uuid = pubnub.uuid() -print "UUID: " -print uuid | 
