diff options
Diffstat (limited to 'python-twisted/examples')
| -rw-r--r-- | python-twisted/examples/here-now.py (renamed from python-twisted/examples/here-now-example.py) | 23 | ||||
| -rw-r--r-- | python-twisted/examples/history-example.py | 46 | ||||
| -rw-r--r-- | python-twisted/examples/history.py | 32 | ||||
| -rw-r--r-- | python-twisted/examples/publish-example.py | 75 | ||||
| -rw-r--r-- | python-twisted/examples/publish.py | 33 | ||||
| -rw-r--r-- | python-twisted/examples/subscribe-example.py | 50 | ||||
| -rw-r--r-- | python-twisted/examples/subscribe.py | 48 | ||||
| -rw-r--r-- | python-twisted/examples/uuid-example.py | 27 | 
8 files changed, 120 insertions, 214 deletions
| 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 | 
