aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/PubnubBase.py6
-rw-r--r--python/Pubnub.py6
-rwxr-xr-xpython/examples/dev-console.py65
3 files changed, 64 insertions, 13 deletions
diff --git a/common/PubnubBase.py b/common/PubnubBase.py
index 075327d..aa71577 100644
--- a/common/PubnubBase.py
+++ b/common/PubnubBase.py
@@ -147,14 +147,14 @@ class PubnubBase(object):
"ttl" : ttl
}, callback=callback)
- def revoke( self, channel, authkey=False, read=False, write=False, ttl=1, callback=None):
+ def revoke( self, channel, authkey=False, ttl=1, callback=None):
"""Revoke Access on a Channel."""
return self._pam_auth({
"channel" : channel,
"auth" : authkey,
- "r" : read and 1 or 0,
- "w" : write and 1 or 0,
+ "r" : 0,
+ "w" : 0,
"ttl" : ttl
}, callback=callback)
diff --git a/python/Pubnub.py b/python/Pubnub.py
index 169bd54..64bc14b 100644
--- a/python/Pubnub.py
+++ b/python/Pubnub.py
@@ -318,14 +318,14 @@ class PubnubBase(object):
"ttl" : ttl
}, callback=callback)
- def revoke( self, channel, authkey=False, read=False, write=False, ttl=1, callback=None):
+ def revoke( self, channel, authkey=False, ttl=1, callback=None):
"""Revoke Access on a Channel."""
return self._pam_auth({
"channel" : channel,
"auth" : authkey,
- "r" : read and 1 or 0,
- "w" : write and 1 or 0,
+ "r" : 0,
+ "w" : 0,
"ttl" : ttl
}, callback=callback)
diff --git a/python/examples/dev-console.py b/python/examples/dev-console.py
index 372599a..33ec39f 100755
--- a/python/examples/dev-console.py
+++ b/python/examples/dev-console.py
@@ -78,10 +78,16 @@ def get_input(message, t=None):
while True:
try:
command = raw_input(message)
+ if t is not None and t == bool:
+ if command in ["True", "true", "1", 1, "y", "Y", "yes", "Yes", "YES"]:
+ return True
+ else:
+ return False
if t is not None:
command = t(command)
else:
command = eval("'" + command + "'")
+
return command
except ValueError:
print_error("Invalid input : " + command)
@@ -120,19 +126,65 @@ def _subscribe_command_handler():
})
def _grant_command_handler():
- pass
+ def _callback(r):
+ print_ok(r)
+ def _error(r):
+ print_error(r)
+ channel = get_input("[GRANT] Enter Channel Name ", str)
+ auth_key = get_input("[GRANT] Enter Auth Key ", str)
+ ttl = get_input("[GRANT] Enter ttl ", int)
+ read = get_input("[GRANT] Read ? ", bool)
+ write = get_input("[GRANT] Write ? ", bool)
+ pubnub.grant(channel, auth_key,read,write,ttl, _callback)
def _revoke_command_handler():
- pass
+ def _callback(r):
+ print_ok(r)
+ def _error(r):
+ print_error(r)
+ channel = get_input("[REVOKE] Enter Channel Name ", str)
+ auth_key = get_input("[REVOKE] Enter Auth Key ", str)
+ ttl = get_input("[REVOKE] Enter ttl ", int)
+
+ pubnub.revoke(channel, auth_key, ttl, _callback)
def _audit_command_handler():
- pass
+ def _callback(r):
+ print_ok(r)
+ def _error(r):
+ print_error(r)
+ channel = get_input("[AUDIT] Enter Channel Name ", str)
+ auth_key = get_input("[AUDIT] Enter Auth Key ", str)
+ pubnub.audit(channel, auth_key, _callback)
def _history_command_handler():
- pass
+ def _callback(r):
+ print_ok(r)
+ def _error(r):
+ print_error(r)
+ channel = get_input("[HISTORY] Enter Channel Name ", str)
+ count = get_input("[HISTORY] Enter Count ", int)
+
+ pubnub.history({
+ 'channel' : channel,
+ 'count' : count,
+ 'callback' : _callback,
+ 'error' : _error
+ })
+
def _here_now_command_handler():
- pass
+ def _callback(r):
+ print_ok(r)
+ def _error(r):
+ print_error(r)
+ channel = get_input("[HERE NOW] Enter Channel Name ", str)
+
+ pubnub.here_now({
+ 'channel' : channel,
+ 'callback' : _callback,
+ 'error' : _error
+ })
@@ -150,13 +202,12 @@ def kill_all_threads():
commands = []
commands.append({"command" : "publish", "handler" : _publish_command_handler})
commands.append({"command" : "subscribe", "handler" : _subscribe_command_handler})
-'''
commands.append({"command" : "here_now", "handler" : _here_now_command_handler})
commands.append({"command" : "history", "handler" : _history_command_handler})
commands.append({"command" : "grant", "handler" : _grant_command_handler})
commands.append({"command" : "revoke", "handler" : _revoke_command_handler})
commands.append({"command" : "audit", "handler" : _audit_command_handler})
-'''
+
# last command is quit. add new commands before this line
commands.append({"command" : "QUIT"})