aboutsummaryrefslogtreecommitdiffstats
path: root/common/PubnubCore.py
diff options
context:
space:
mode:
authorDevendra2014-06-18 01:02:15 +0530
committerDevendra2014-06-18 01:02:15 +0530
commita1ee7f8bd90b463318bfa75f7ee4f58d458d2a24 (patch)
tree9e260902f960f792a93fa25e3b619c42ecb5f4d4 /common/PubnubCore.py
parentbfd5c64bdf7ed45f21207cb53c653e7220e39eff (diff)
parent083127cde127dd78fc88ffe2b3b82144b2c07038 (diff)
downloadpubnub-python-a1ee7f8bd90b463318bfa75f7ee4f58d458d2a24.tar.bz2
Merge branch 'master' into develop
Diffstat (limited to 'common/PubnubCore.py')
-rw-r--r--common/PubnubCore.py115
1 files changed, 0 insertions, 115 deletions
diff --git a/common/PubnubCore.py b/common/PubnubCore.py
deleted file mode 100644
index dcfd319..0000000
--- a/common/PubnubCore.py
+++ /dev/null
@@ -1,115 +0,0 @@
-class PubnubCore(PubnubBase):
- def __init__(
- self,
- publish_key,
- subscribe_key,
- secret_key = False,
- cipher_key = False,
- ssl_on = False,
- origin = 'pubsub.pubnub.com',
- uuid = None
- ) :
- """
- #**
- #* Pubnub
- #*
- #* Init the Pubnub Client API
- #*
- #* @param string publish_key required key to send messages.
- #* @param string subscribe_key required key to receive messages.
- #* @param string secret_key optional key to sign messages.
- #* @param boolean ssl required for 2048 bit encrypted messages.
- #* @param string origin PUBNUB Server Origin.
- #* @param string pres_uuid optional identifier for presence (auto-generated if not supplied)
- #**
-
- ## Initiat Class
- pubnub = Pubnub( 'PUBLISH-KEY', 'SUBSCRIBE-KEY', 'SECRET-KEY', False )
-
- """
- super(PubnubCore, self).__init__(
- publish_key=publish_key,
- subscribe_key=subscribe_key,
- secret_key=secret_key,
- cipher_key=cipher_key,
- ssl_on=ssl_on,
- origin=origin,
- UUID=uuid
- )
-
- self.subscriptions = {}
- self.timetoken = 0
- self.version = '3.4'
- self.accept_encoding = 'gzip'
-
-
-
- def subscribe( self, args ) :
- """
- #**
- #* Subscribe
- #*
- #* This is BLOCKING.
- #* Listen for a message on a channel.
- #*
- #* @param array args with channel and callback.
- #* @return false on fail, array on success.
- #**
-
- ## Subscribe Example
- def receive(message) :
- print(message)
- return True
-
- pubnub.subscribe({
- 'channel' : 'hello_world',
- 'callback' : receive
- })
-
- """
-
- ## Fail if missing channel
- if not 'channel' in args :
- raise Exception('Missing Channel.')
- return False
-
- ## Fail if missing callback
- if not 'callback' in args :
- raise Exception('Missing Callback.')
- return False
-
- ## Capture User Input
- channel = str(args['channel'])
- callback = args['callback']
- subscribe_key = args.get('subscribe_key') or self.subscribe_key
-
- ## Begin Subscribe
- while True :
-
- timetoken = 'timetoken' in args and args['timetoken'] or 0
- try :
- ## Wait for Message
- response = self._request({"urlcomponents" : [
- 'subscribe',
- subscribe_key,
- channel,
- '0',
- str(timetoken)
- ],"urlparams" : {"uuid" : self.uuid }})
-
- messages = response[0]
- args['timetoken'] = response[1]
-
- ## If it was a timeout
- if not len(messages) :
- continue
-
- ## Run user Callback and Reconnect if user permits.
- for message in messages :
- if not callback(self.decrypt(message)) :
- return
-
- except Exception:
- time.sleep(1)
-
- return True