Exemple #1
0
from pubnub import PubnubTwisted as Pubnub

# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Configuration
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
publish_key = 'pub-c-f6a20151-db8d-45af-ba42-def0edaa459f'
subscribe_key = 'sub-c-b5ff3208-7f64-11e4-b601-02ee2ddab7fe'
server_channel = 'echo-server'
client_channel = 'echo-channel'

# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Create PubNub Instance
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
pubnub = Pubnub(
    publish_key=publish_key,
    subscribe_key=subscribe_key,
    ssl_on=True
)


# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Error Log
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def error_log(data):
    print(data)


# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Access Log
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def access_log(data):
Exemple #2
0
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'
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
origin = len(sys.argv) > 6 and sys.argv[6] or 'pubsub.pubnub.com'

## -----------------------------------------------------------------------
## Initiat Class
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key,
                subscribe_key,
                secret_key=secret_key,
                cipher_key=cipher_key,
                ssl_on=ssl_on,
                origin=origin)
crazy = ' ~`!@#$%^&*( 顶顅 Ȓ)+=[]\\{}|;\':",./<>?abcd'


## -----------------------------------------------------------------------
## BENCHMARK
## -----------------------------------------------------------------------
def connected():
    pubnub.publish({'channel': crazy, 'message': {'Info': 'Connected!'}})


trips = {'last': None, 'current': None, 'max': 0, 'avg': 0}


from pubnub import PubnubTwisted as Pubnub
import time

pubnub = Pubnub("demo","demo")
pubnub_enc = Pubnub("demo", "demo", cipher_key="enigma")
pubnub_pam = Pubnub("pub-c-c077418d-f83c-4860-b213-2f6c77bde29a", 
	"sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe", "sec-c-OGU3Y2Q4ZWUtNDQwMC00NTI1LThjNWYtNWJmY2M4OGIwNjEy")



# Publish and receive string
def test_1():

	channel = "test_1-" + str(time.time())
	message = "I am a string"

	def _cb(resp, ch=None):
		assert resp == message
		pubnub.unsubscribe(channel)

	def _connect(resp):
		def _cb1(resp,ch=None):
			assert resp[0] == 1
		def _err1(resp):
			assert False
		pubnub.publish(channel,message, callback=_cb1, error=_err1)

	def _error(resp):
		assert False
Exemple #4
0
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()
trips = {
    'last': None,
    'current': None,
    'max': 0,
    'avg': 0
}

## -----------------------------------------------------------------------
## Initiat Class
## -----------------------------------------------------------------------
channel = 'deliverability-' + str(time.time())
pubnub = Pubnub(
    publish_key,
    subscribe_key,
    secret_key=secret_key,
    cipher_key=cipher_key,
    ssl_on=ssl_on,
    origin=origin
)

## -----------------------------------------------------------------------
## BENCHMARK
## -----------------------------------------------------------------------


def publish_sent(info=None):
    if info and info[0]:
        analytics['successful_publishes'] += 1
    else:
        analytics['failed_publishes'] += 1
Exemple #6
0
from pubnub import PubnubTwisted as Pubnub

## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Configuration
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
publish_key = 'pub-c-f6a20151-db8d-45af-ba42-def0edaa459f'
subscribe_key = 'sub-c-b5ff3208-7f64-11e4-b601-02ee2ddab7fe'
secret_key = 'demo'
server_channel = 'echo-server'
client_channel = 'echo-channel'

## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Create PubNub Instance
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
pubnub = Pubnub(publish_key=publish_key,
                subscribe_key=subscribe_key,
                secret_key=secret_key,
                ssl_on=True)


## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Error Log
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def error_log(data):
    print(data)


## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Access Log
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def access_log(data):
    print(data)
import sys
import datetime
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 "demo"
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False

## -----------------------------------------------------------------------
## Initiat Class
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on)
crazy = " ~`!@#$%^&*( 顶顅 Ȓ)+=[]\\{}|;':\",./<>?abcd"

## -----------------------------------------------------------------------
## BENCHMARK
## -----------------------------------------------------------------------
def connected():
    pubnub.publish({"channel": crazy, "message": {"Info": "Connected!"}})


trips = {"last": None, "current": None, "max": 0, "avg": 0}


def received(message):
    current_trip = trips["current"] = str(datetime.datetime.now())[0:19]
    last_trip = trips["last"] = str(datetime.datetime.now() - datetime.timedelta(seconds=1))[0:19]
import time

from pubnub import PubnubTwisted as Pubnub

subkey = "sub-c-9aeec0d4-cdf4-11e5-bcee-0619f8945a4f"
pubkey = "pub-c-b3fdf8fc-4516-4ab2-8836-6fb22ba7870d"
secretkey = "sec-c-ZDQwNTUwMDctZDViYi00MzhlLTg2NTctYjViZDcwNTA5Zjhj"
pubnub = Pubnub(pubkey, subkey)
pubnub_pam = Pubnub(pubkey, subkey, secretkey)


# Grant permission read true, write true, on channel ( Async Mode )
def test_1():
    def _callback(resp, ch=None):
        assert resp == {
            'message': u'Success',
            'payload': {
                u'auths': {
                    u'abcd': {
                        u'r': 1,
                        u'w': 1
                    }
                },
                u'subscribe_key': subkey,
                u'level': u'user',
                u'channel': u'abcd',
                u'ttl': 1
            }
        }

    def _error(response):
Exemple #9
0
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'
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
origin = len(sys.argv) > 6 and sys.argv[6] or 'pubsub.pubnub.com'

# -----------------------------------------------------------------------
# Initiat Class
# -----------------------------------------------------------------------
pubnub = Pubnub(publish_key,
                subscribe_key,
                secret_key=secret_key,
                cipher_key=cipher_key,
                ssl_on=ssl_on,
                origin=origin)
crazy = ' ~`!@#$%^&*( 顶顅 Ȓ)+=[]\\{}|;\':",./<>?abcd'


# -----------------------------------------------------------------------
# BENCHMARK
# -----------------------------------------------------------------------
def success(msg):
    print(msg)


def connected(msg):
    pubnub.publish(crazy, {'Info': 'Connected!'},
                   error=error,
import sys
from pubnub import PubnubTwisted as Pubnub
from functools import partial
from threading import current_thread
import threading
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'

current = -1

errors = 0
received = 0

## -----------------------------------------------------------------------
## Subscribe Example
## -----------------------------------------------------------------------


def message_received(message):
    print(message)
Exemple #11
0
## 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")
Exemple #12
0
# 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.stop()


pubnub.audit(channel, auth_key=authkey, callback=callback, error=callback)

pubnub.start()
Exemple #13
0
## -----------------------------------------------------------------------
## High Security PubNub
## -----------------------------------------------------------------------
pubnub_high_security = Pubnub(
    ## Publish Key
    'pub-c-a30c030e-9f9c-408d-be89-d70b336ca7a0',

    ## Subscribe Key
    'sub-c-387c90f3-c018-11e1-98c9-a5220e0555fd',

    ## Secret Key
    'sec-c-MTliNDE0NTAtYjY4Ni00MDRkLTllYTItNDhiZGE0N2JlYzBl',

    ## Cipher Key
    'YWxzamRmbVjFaa05HVnGFqZHM3NXRBS73jxmhVMkjiwVVXV1d5UrXR1JLSkZFRr' +
    'WVd4emFtUm1iR0TFpUZvbiBoYXMgYmVlbxWkhNaF3uUi8kM0YkJTEVlZYVFjBYi' +
    'jFkWFIxSkxTa1pGUjd874hjklaTFpUwRVuIFNob3VsZCB5UwRkxUR1J6YVhlQWa' +
    'V1ZkNGVH32mDkdho3pqtRnRVbTFpUjBaeGUgYXNrZWQtZFoKjda40ZWlyYWl1eX' +
    'U4RkNtdmNub2l1dHE2TTA1jd84jkdJTbFJXYkZwWlZtRnKkWVrSRhhWbFpZVmFz' +
    'c2RkZmTFpUpGa1dGSXhTa3hUYTFwR1Vpkm9yIGluZm9ybWFNfdsWQdSiiYXNWVX' +
    'RSblJWYlRGcFVqQmFlRmRyYUU0MFpXbHlZV2wxZVhVNFJrTnR51YjJsMWRIRTJU' +
    'W91ciBpbmZvcm1hdGliBzdWJtaXR0ZWQb3UZSBhIHJlc3BvbnNlLCB3ZWxsIHJl' +
    'VEExWdHVybiB0am0aW9uIb24gYXMgd2UgcG9zc2libHkgY2FuLuhcFe24ldWVns' +
    'dSaTFpU3hVUjFKNllWaFdhRmxZUWpCaQo34gcmVxdWlGFzIHNveqQl83snBfVl3',

    ## 2048bit SSL ON - ENABLED TRUE
    True
)

## -----------------------------------------------------------------------
## Channel | Message Test Data (UTF-8)
Exemple #14
0
# 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'


# Asynchronous usage
def callback(message):
    print(message)
    pubnub.stop()


pubnub.here_now(channel, callback=callback, error=callback)

pubnub.start()
import datetime
from pubnub import PubnubTwisted as Pubnub
from functools import partial
from threading import current_thread
import threading
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'

current = -1

errors = 0
received = 0

## -----------------------------------------------------------------------
## Subscribe Example
## -----------------------------------------------------------------------


def message_received(message):
    print(message)
Exemple #16
0
## 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()
Exemple #17
0
# 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.stop()


pubnub.grant(channel, authkey, True, True, callback=callback, error=callback)

pubnub.start()
Exemple #18
0
## 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()
Exemple #19
0
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.stop()


pubnub.revoke(channel, authkey, callback=callback, error=callback)

pubnub.start()
Exemple #20
0
## 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()
Exemple #21
0
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'
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
origin = len(sys.argv) > 6 and sys.argv[6] or 'pubsub.pubnub.com'

# -----------------------------------------------------------------------
# Initiat Class
# -----------------------------------------------------------------------
pubnub = Pubnub(
    publish_key,
    subscribe_key,
    secret_key=secret_key,
    cipher_key=cipher_key,
    ssl_on=ssl_on,
    origin=origin
)
crazy = ' ~`!@#$%^&*( 顶顅 Ȓ)+=[]\\{}|;\':",./<>?abcd'


# -----------------------------------------------------------------------
# BENCHMARK
# -----------------------------------------------------------------------
def success(msg):
    print(msg)


def connected(msg):
    pubnub.publish(crazy, {'Info': 'Connected!'}, error=error, callback=success)
Exemple #22
0
# Import Libs
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
from pubnub import PubnubTwisted as Pubnub

# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Configuration
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
publish_key = 'pub-c-f6a20151-db8d-45af-ba42-def0edaa459f'
subscribe_key = 'sub-c-b5ff3208-7f64-11e4-b601-02ee2ddab7fe'
server_channel = 'echo-server'

# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Create PubNub Instance
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
pubnub = Pubnub(publish_key=publish_key,
                subscribe_key=subscribe_key,
                ssl_on=True)


# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Error Log
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def error_log(data):
    print(data)


# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Access Log
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def access_log(data):
    print(data)
from pubnub import PubnubTwisted as Pubnub
import time

pubnub = Pubnub("demo", "demo")
pubnub_enc = Pubnub("demo", "demo", cipher_key="enigma")
pubnub_pam = Pubnub("pub-c-c077418d-f83c-4860-b213-2f6c77bde29a",
                    "sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe",
                    "sec-c-OGU3Y2Q4ZWUtNDQwMC00NTI1LThjNWYtNWJmY2M4OGIwNjEy")


# Publish and receive string
def test_1():

    channel = "test_1-" + str(time.time())
    message = "I am a string"

    def _cb(resp, ch=None):
        assert resp == message
        pubnub.unsubscribe(channel)

    def _connect(resp):
        def _cb1(resp, ch=None):
            assert resp[0] == 1

        def _err1(resp):
            assert False

        pubnub.publish(channel, message, callback=_cb1, error=_err1)

    def _error(resp):
        assert False
Exemple #24
0
import time

from pubnub import PubnubTwisted as Pubnub

subkey = "sub-c-9aeec0d4-cdf4-11e5-bcee-0619f8945a4f"
pubkey = "pub-c-b3fdf8fc-4516-4ab2-8836-6fb22ba7870d"
secretkey = "sec-c-ZDQwNTUwMDctZDViYi00MzhlLTg2NTctYjViZDcwNTA5Zjhj"
pubnub = Pubnub(pubkey, subkey)
pubnub_pam = Pubnub(pubkey, subkey, secretkey)


# Grant permission read true, write true, on channel ( Async Mode )
def test_1():
    def _callback(resp, ch=None):
        assert resp == {
            'message': u'Success',
            'payload': {u'auths': {u'abcd': {u'r': 1, u'w': 1}},
                        u'subscribe_key': subkey,
                        u'level': u'user', u'channel': u'abcd', u'ttl': 1}
        }

    def _error(response):
        assert False

    pubnub_pam.grant(channel="abcd", auth_key="abcd", read=True, write=True, ttl=1, callback=_callback, error=_error)


# Grant permission read false, write false, on channel ( Async Mode )
def test_2():
    def _callback(resp, ch=None):
        assert resp == {
## Import Libs
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
from pubnub import PubnubTwisted as Pubnub

## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Configuration
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
publish_key = "pub-c-f6a20151-db8d-45af-ba42-def0edaa459f"
subscribe_key = "sub-c-b5ff3208-7f64-11e4-b601-02ee2ddab7fe"
secret_key = "demo"
server_channel = "echo-server"

## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Create PubNub Instance
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, secret_key=secret_key, ssl_on=True)

## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Error Log
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def error_log(data):
    print(data)


## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Access Log
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def access_log(data):
    print(data)

Exemple #26
0
# 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.stop()


pubnub.revoke(channel, authkey, callback=callback, error=callback)

pubnub.start()
## 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'


# Asynchronous usage

def callback(message):
    print(message)

pubnub.here_now(channel, callback=callback, error=callback)

pubnub.start()
## 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()