diff options
22 files changed, 344 insertions, 544 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 diff --git a/python-twisted/examples/here-now-example.py b/python-twisted/examples/here-now.py index 4b2965b..38b79f8 100644 --- a/python-twisted/examples/here-now-example.py +++ b/python-twisted/examples/here-now.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 PubnubTwisted as Pubnub @@ -21,22 +18,16 @@ 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) +channel = 'hello_world' -## ----------------------------------------------------------------------- -## History Example -## ----------------------------------------------------------------------- +# Asynchronous usage -def here_now_complete(messages): -    print(messages) -    pubnub.stop() +def callback(message): +    print(message) -pubnub.here_now( -    channel=crazy, callback=here_now_complete, error=here_now_complete) +pubnub.here_now(channel, callback=callback, error=callback) -## ----------------------------------------------------------------------- -## IO Event Loop -## -----------------------------------------------------------------------  pubnub.start() diff --git a/python-twisted/examples/history-example.py b/python-twisted/examples/history-example.py deleted file mode 100644 index f867a36..0000000 --- a/python-twisted/examples/history-example.py +++ /dev/null @@ -1,46 +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 twisted.internet import reactor -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' - -## ----------------------------------------------------------------------- -## History Example -## ----------------------------------------------------------------------- - - -def history_complete(messages): -    print(messages) -    reactor.stop() - -pubnub.history({ -    'channel': crazy, -    'limit': 10, -    'callback': history_complete -}) - -## ----------------------------------------------------------------------- -## IO Event Loop -## ----------------------------------------------------------------------- -reactor.run() diff --git a/python-twisted/examples/history.py b/python-twisted/examples/history.py new file mode 100644 index 0000000..10e86b3 --- /dev/null +++ b/python-twisted/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 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=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-twisted/examples/publish-example.py b/python-twisted/examples/publish-example.py deleted file mode 100644 index d5af6a5..0000000 --- a/python-twisted/examples/publish-example.py +++ /dev/null @@ -1,75 +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 twisted.internet import reactor -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 ''  # (Cipher key is Optional) -auth_key = len( -    sys.argv) > 5 and sys.argv[5] or 'abcd'  # (Cipher key is Optional) -ssl_on = len(sys.argv) > 6 and bool(sys.argv[5]) or False - -## ----------------------------------------------------------------------- -## Initiate Pubnub State -## ----------------------------------------------------------------------- -pubnub = Pubnub( -    publish_key, subscribe_key, secret_key, cipher_key, auth_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-twisted/examples/publish.py b/python-twisted/examples/publish.py new file mode 100644 index 0000000..f7b746f --- /dev/null +++ b/python-twisted/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 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=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-twisted/examples/subscribe-example.py b/python-twisted/examples/subscribe-example.py deleted file mode 100644 index 3bca615..0000000 --- a/python-twisted/examples/subscribe-example.py +++ /dev/null @@ -1,50 +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 twisted.internet import reactor -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 None -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 ) -pubnub = Pubnub(publish_key, subscribe_key, secret_key, ssl_on) -crazy = 'hello_world' - -## ----------------------------------------------------------------------- -## Subscribe Example -## ----------------------------------------------------------------------- - - -def message_received(message): -    print(message) - - -def connected(): -    print 'Connected' - -pubnub.subscribe({ -    'channel': crazy, -    'connect': connected, -    'callback': message_received -}) - -## ----------------------------------------------------------------------- -## IO Event Loop -## ----------------------------------------------------------------------- -reactor.run() diff --git a/python-twisted/examples/subscribe.py b/python-twisted/examples/subscribe.py new file mode 100644 index 0000000..1462a69 --- /dev/null +++ b/python-twisted/examples/subscribe.py @@ -0,0 +1,48 @@ +## 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 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=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, 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) + +pubnub.start() diff --git a/python-twisted/examples/uuid-example.py b/python-twisted/examples/uuid-example.py deleted file mode 100644 index a745088..0000000 --- a/python-twisted/examples/uuid-example.py +++ /dev/null @@ -1,27 +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 twisted.internet import reactor -from Pubnub import PubnubTwisted as Pubnub - -## ----------------------------------------------------------------------- -## Initiate Pubnub State -## ----------------------------------------------------------------------- -pubnub = Pubnub("", "", "", False) - -## ----------------------------------------------------------------------- -## UUID Example -## ----------------------------------------------------------------------- - -uuid = pubnub.uuid() -print "UUID: " -print uuid diff --git a/python/examples/here-now-example.py b/python/examples/here-now.py index 0bc3015..f573389 100644 --- a/python/examples/here-now-example.py +++ b/python/examples/here-now.py @@ -20,13 +20,17 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False  ## -----------------------------------------------------------------------  pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,                  secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) -crazy = 'hello_world' +channel = 'hello_world' -def print_cb(message): + +# Synchronous usage + +print pubnub.here_now(channel) + +# Asynchronous usage + +def callback(message):      print(message) -pubnub.here_now({ -    'channel': crazy, -    'callback': print_cb -}) +pubnub.here_now(channel, callback=callback, error=callback) diff --git a/python/examples/history-example.py b/python/examples/history-example.py deleted file mode 100755 index 793c612..0000000 --- a/python/examples/history-example.py +++ /dev/null @@ -1,12 +0,0 @@ -import sys -from Pubnub import PubnubAsync as Pubnub - -## Initiat Class -pubnub = Pubnub('demo', 'demo', None, False) - -## History Example -history = pubnub.history({ -    'channel': 'hello_world', -    'limit': 1 -}) -print(history) diff --git a/python/examples/history.py b/python/examples/history.py new file mode 100644 index 0000000..3d6addf --- /dev/null +++ b/python/examples/history.py @@ -0,0 +1,34 @@ +## 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 PubnubAsync 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' + +# Synchronous usage + +print pubnub.history(channel, count=2) + +# Asynchronous usage + +def callback(message): +    print(message) + +pubnub.history(channel, count=2 , callback=callback, error=callback) diff --git a/python/examples/publish-example.py b/python/examples/publish-example.py deleted file mode 100755 index 78b7f36..0000000 --- a/python/examples/publish-example.py +++ /dev/null @@ -1,44 +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/ - -import sys -from Pubnub import PubnubAsync 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 ''  # (Cipher key is Optional) -auth_key = len( -    sys.argv) > 5 and sys.argv[4] or 'abcd'  # (Cipher key is Optional) -ssl_on = len(sys.argv) > 6 and bool(sys.argv[5]) or False - -## ----------------------------------------------------------------------- -## Initiate Pubnub State -## ----------------------------------------------------------------------- -pubnub = Pubnub( -    publish_key, subscribe_key, secret_key, cipher_key, auth_key, ssl_on, pooling=True) -crazy = 'hello_world' - -## ----------------------------------------------------------------------- -## Publish Example -## ----------------------------------------------------------------------- - - -def publish_complete(info): -    print(info) - - -def publish_error(info): -    print('ERROR : ' + str(info)) - -import time -start = time.time() -for i in range(1,100): -    print pubnub.publish(crazy, 'hello world-' + str(i)) -end = time.time() -print(end - start); diff --git a/python/examples/publish.py b/python/examples/publish.py new file mode 100644 index 0000000..029c17a --- /dev/null +++ b/python/examples/publish.py @@ -0,0 +1,37 @@ +## 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 PubnubAsync 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 !!!' + + + +# Synchronous usage + +print pubnub.publish(channel, message) + +# Asynchronous usage + +def callback(message): +    print(message) + +pubnub.publish(channel, message, callback=callback, error=callback) diff --git a/python/examples/subscribe-example.py b/python/examples/subscribe-example.py deleted file mode 100755 index 9c16bbe..0000000 --- a/python/examples/subscribe-example.py +++ /dev/null @@ -1,70 +0,0 @@ -import sys -import threading -import time -import random -import string -from Pubnub import PubnubAsync as Pubnub - -## Initiate Class -pubnub = Pubnub('demo', 'demo', None, False) - -print("My UUID is: " + pubnub.uuid) - -channel = ''.join( -    random.choice(string.ascii_letters + string.digits) for x in range(20)) - -## Subscribe Example - - -def receive(message): -    print(message) -    return False - - -def pres_event(message): -    print(message) -    return False - - -def subscribe(): -    print("Listening for messages on '%s' channel..." % channel) -    pubnub.subscribe({ -        'channel': channel, -        'callback': receive -    }) - - -def presence(): -    print("Listening for presence events on '%s' channel..." % channel) -    pubnub.presence({ -        'channel': channel, -        'callback': pres_event -    }) - - -def publish(): -    print("Publishing a test message on '%s' channel..." % channel) -    pubnub.publish({ -        'channel': channel, -        'message': {'text': 'foo bar'} -    }) - -pres_thread = threading.Thread(target=presence) -pres_thread.daemon = True -pres_thread.start() - -sub_thread = threading.Thread(target=subscribe) -sub_thread.daemon = True -sub_thread.start() - -time.sleep(3) - -publish() - - -print("waiting for subscribes and presence") -pres_thread.join() - -print(pubnub.here_now({'channel': channel})) - -sub_thread.join() diff --git a/python/examples/subscribe.py b/python/examples/subscribe.py new file mode 100644 index 0000000..a410297 --- /dev/null +++ b/python/examples/subscribe.py @@ -0,0 +1,46 @@ +## 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 PubnubAsync 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, 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) | 
