From 9217c4f7fdfb36cc67121d1ab173a1e2305c7a35 Mon Sep 17 00:00:00 2001 From: Devendra Date: Tue, 24 Jun 2014 10:57:35 +0530 Subject: [#73754750 develop] adding examples for grant, revoke, audit --- python-tornado/README.md | 32 ++++++++++++++++++++++++ python-tornado/examples/audit.py | 31 +++++++++++++++++++++++ python-tornado/examples/grant.py | 31 +++++++++++++++++++++++ python-tornado/examples/revoke.py | 31 +++++++++++++++++++++++ python-twisted/README.md | 32 ++++++++++++++++++++++++ python-twisted/examples/audit.py | 31 +++++++++++++++++++++++ python-twisted/examples/grant.py | 31 +++++++++++++++++++++++ python-twisted/examples/revoke.py | 31 +++++++++++++++++++++++ python/README.md | 52 +++++++++++++++++++++++++++++++++++++++ python/examples/audit.py | 35 ++++++++++++++++++++++++++ python/examples/grant.py | 35 ++++++++++++++++++++++++++ python/examples/revoke.py | 35 ++++++++++++++++++++++++++ 12 files changed, 407 insertions(+) create mode 100644 python-tornado/examples/audit.py create mode 100644 python-tornado/examples/grant.py create mode 100644 python-tornado/examples/revoke.py create mode 100644 python-twisted/examples/audit.py create mode 100644 python-twisted/examples/grant.py create mode 100644 python-twisted/examples/revoke.py create mode 100644 python/examples/audit.py create mode 100644 python/examples/grant.py create mode 100644 python/examples/revoke.py diff --git a/python-tornado/README.md b/python-tornado/README.md index 53aad32..59e79b7 100644 --- a/python-tornado/README.md +++ b/python-tornado/README.md @@ -97,6 +97,38 @@ pubnub.presence(channel, callback=callback, error=callback) pubnub.unsubscribe(channel='hello_world') ``` +#### Grant Example +``` +authkey = "abcd" + +def callback(message): + print(message) + +pubnub.grant(channel, authkey, True, True, callback=callback, error=callback) + +``` + +#### Audit Example +``` +authkey = "abcd" + +def callback(message): + print(message) + +pubnub.audit(channel, authkey, callback=callback, error=callback) +``` + +#### Revoke Example +``` +authkey = "abcd" + +def callback(message): + print(message) + +pubnub.revoke(channel, authkey, callback=callback, error=callback) +``` + + #### IO Event Loop start ``` pubnub.start() diff --git a/python-tornado/examples/audit.py b/python-tornado/examples/audit.py new file mode 100644 index 0000000..77d189b --- /dev/null +++ b/python-tornado/examples/audit.py @@ -0,0 +1,31 @@ +## 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 'pam' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'pam' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'pam' +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' +authkey = "abcd" + +def callback(message): + print(message) + +pubnub.audit(channel, authkey, callback=callback, error=callback) + +pubnub.start() diff --git a/python-tornado/examples/grant.py b/python-tornado/examples/grant.py new file mode 100644 index 0000000..daf7434 --- /dev/null +++ b/python-tornado/examples/grant.py @@ -0,0 +1,31 @@ +## 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 'pam' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'pam' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'pam' +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' +authkey = "abcd" + +def callback(message): + print(message) + +pubnub.grant(channel, authkey, True, True, callback=callback, error=callback) + +pubnub.start() diff --git a/python-tornado/examples/revoke.py b/python-tornado/examples/revoke.py new file mode 100644 index 0000000..1e4487e --- /dev/null +++ b/python-tornado/examples/revoke.py @@ -0,0 +1,31 @@ +## 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 'pam' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'pam' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'pam' +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' +authkey = "abcd" + +def callback(message): + print(message) + +pubnub.revoke(channel, authkey, callback=callback, error=callback) + +pubnub.start() diff --git a/python-twisted/README.md b/python-twisted/README.md index ea4173c..c74fb0d 100644 --- a/python-twisted/README.md +++ b/python-twisted/README.md @@ -97,6 +97,38 @@ pubnub.presence(channel, callback=callback, error=callback) pubnub.unsubscribe(channel='hello_world') ``` +#### Grant Example +``` +authkey = "abcd" + +def callback(message): + print(message) + +pubnub.grant(channel, authkey, True, True, callback=callback, error=callback) + +``` + +#### Audit Example +``` +authkey = "abcd" + +def callback(message): + print(message) + +pubnub.audit(channel, authkey, callback=callback, error=callback) +``` + +#### Revoke Example +``` +authkey = "abcd" + +def callback(message): + print(message) + +pubnub.revoke(channel, authkey, callback=callback, error=callback) +``` + + #### IO Event Loop start ``` pubnub.start() diff --git a/python-twisted/examples/audit.py b/python-twisted/examples/audit.py new file mode 100644 index 0000000..b99a8a9 --- /dev/null +++ b/python-twisted/examples/audit.py @@ -0,0 +1,31 @@ +## 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 'pam' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'pam' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'pam' +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' +authkey = "abcd" + +def callback(message): + print(message) + +pubnub.audit(channel, authkey, callback=callback, error=callback) + +pubnub.start() diff --git a/python-twisted/examples/grant.py b/python-twisted/examples/grant.py new file mode 100644 index 0000000..053c1f9 --- /dev/null +++ b/python-twisted/examples/grant.py @@ -0,0 +1,31 @@ +## 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 'pam' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'pam' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'pam' +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' +authkey = "abcd" + +def callback(message): + print(message) + +pubnub.grant(channel, authkey, True, True, callback=callback, error=callback) + +pubnub.start() diff --git a/python-twisted/examples/revoke.py b/python-twisted/examples/revoke.py new file mode 100644 index 0000000..fab0497 --- /dev/null +++ b/python-twisted/examples/revoke.py @@ -0,0 +1,31 @@ +## 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 'pam' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'pam' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'pam' +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' +authkey = "abcd" + +def callback(message): + print(message) + +pubnub.revoke(channel, authkey, callback=callback, error=callback) + +pubnub.start() diff --git a/python/README.md b/python/README.md index 0877535..63548ad 100644 --- a/python/README.md +++ b/python/README.md @@ -140,4 +140,56 @@ def callback(message): pubnub.history(channel, count=2, callback=callback, error=callback) ``` + +#### GRANT + +``` +authkey = "abcd" + +# Synchronous usage +print pubnub.grant(channel, authkey, True, True) + +# Asynchronous usage + + +def callback(message): + print(message) + +pubnub.grant(channel, authkey, True, True, callback=callback, error=callback) +``` + +#### AUDIT + +``` +authkey = "abcd" + +# Synchronous usage +print pubnub.audit(channel, authkey) + +# Asynchronous usage + + +def callback(message): + print(message) + +pubnub.audit(channel, authkey, callback=callback, error=callback) +``` + +#### REVOKE + +``` +authkey = "abcd" + +# Synchronous usage +print pubnub.revoke(channel, authkey) + +# Asynchronous usage + + +def callback(message): + print(message) + +pubnub.revoke(channel, authkey, callback=callback, error=callback) +``` + ## Contact support@pubnub.com for all questions diff --git a/python/examples/audit.py b/python/examples/audit.py new file mode 100644 index 0000000..ebf31af --- /dev/null +++ b/python/examples/audit.py @@ -0,0 +1,35 @@ +## 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 Pubnub + +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'pam' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'pam' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'pam' +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' +authkey = "abcd" + +# Synchronous usage +print pubnub.audit(channel, authkey) + +# Asynchronous usage + + +def callback(message): + print(message) + +pubnub.audit(channel, authkey, callback=callback, error=callback) diff --git a/python/examples/grant.py b/python/examples/grant.py new file mode 100644 index 0000000..af9352e --- /dev/null +++ b/python/examples/grant.py @@ -0,0 +1,35 @@ +## 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 Pubnub + +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'pam' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'pam' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'pam' +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' +authkey = "abcd" + +# Synchronous usage +print pubnub.grant(channel, authkey, True, True) + +# Asynchronous usage + + +def callback(message): + print(message) + +pubnub.grant(channel, authkey, True, True, callback=callback, error=callback) diff --git a/python/examples/revoke.py b/python/examples/revoke.py new file mode 100644 index 0000000..437e5b5 --- /dev/null +++ b/python/examples/revoke.py @@ -0,0 +1,35 @@ +## 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 Pubnub + +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'pam' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'pam' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'pam' +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' +authkey = "abcd" + +# Synchronous usage +print pubnub.revoke(channel, authkey) + +# Asynchronous usage + + +def callback(message): + print(message) + +pubnub.revoke(channel, authkey, callback=callback, error=callback) -- cgit v1.2.3