Example #1
0
 def test_push(self):
     c = Client(self.endpoint, "localhost", "public", host="t.nextalk.im")
     message = {
         'to': 'uid2',
         'from': 'uid3',
         'nick': 'user3',
         'body': 'hahaha',
         'timestamp': time.time()*1000,
         'type': 'chat',
         'style': '' 
     }
     c.message(message) 
Example #2
0
 def test_push(self):
     c = Client(self.endpoint, "localhost", "public", host="t.nextalk.im")
     message = {
         'to': 'uid2',
         'from': 'uid3',
         'nick': 'user3',
         'body': 'hahaha',
         'timestamp': time.time() * 1000,
         'type': 'chat',
         'style': ''
     }
     c.message(message)
Example #3
0
    def setUp(self):
        self.endpoint = {
            'id': 'uid1',
            'nick': 'user1',
            'show': 'available',
            'status': ''
        }
        self.client = Client(self.endpoint,
                             "localhost",
                             "public",
                             host="t.nextalk.im")

        self.buddies = ['uid1', 'uid2', 'uid3']
        self.rooms = ['room1', 'room2', 'room3']
        self.client.online(self.buddies, self.rooms)
Example #4
0
    def setUp(self):
        self.endpoint = {
                'id': 'uid1', 
                'nick': 'user1', 
                'show': 'available', 
                'status': ''}
        self.client = Client(self.endpoint, "localhost", "public", host="t.nextalk.im")

        self.buddies = ['uid1', 'uid2', 'uid3']
        self.rooms = ['room1', 'room2', 'room3']
        self.client.online(self.buddies, self.rooms)
Example #5
0
class TestWebimMethods(unittest.TestCase):

    def setUp(self):
        self.endpoint = {
                'id': 'uid1', 
                'nick': 'user1', 
                'show': 'available', 
                'status': ''}
        self.client = Client(self.endpoint, "localhost", "public", host="t.nextalk.im")

        self.buddies = ['uid1', 'uid2', 'uid3']
        self.rooms = ['room1', 'room2', 'room3']
        self.client.online(self.buddies, self.rooms)
    
    def test_online(self):
        resp = self.client.online(self.buddies, self.rooms)
        self.assertTrue(resp['success'])

    def test_presence(self):
        self.client.presence('away', 'Away')

    def test_message(self):
        message = {
            'to': 'uid2',
            'nick': 'user1',
            'body': 'hahaha',
            'timestamp': time.time()*1000,
            'type': 'chat',
            'style': '' 
                }
        self.client.message(message)

    def test_push(self):
        c = Client(self.endpoint, "localhost", "public", host="t.nextalk.im")
        message = {
            'to': 'uid2',
            'from': 'uid3',
            'nick': 'user3',
            'body': 'hahaha',
            'timestamp': time.time()*1000,
            'type': 'chat',
            'style': '' 
        }
        c.message(message) 
    
    def test_status(self):
        status = {
            'to': 'uid2',
            'show': 'typeing',
            'status': 'user1 is typing' 
        }
        self.client.status(status)

    def test_presences(self):
        self.client.presences(['uid1', 'uid2'])

    def test_members(self):
        self.client.members("gid1")

    def test_join(self):
        self.client.join("gid4")

    def test_leave(self):
        self.client.leave("gid4")
Example #6
0
def prepare():
    print '========================================'
    print 'BEGIN prepare(%s) [%s]' % (request.endpoint, str(datetime.now()))

    if request.endpoint in UNSUPPORTED_ENDPOINTS:
        abort(403)

    data = request.cookies.get('auth', None)

    if request.endpoint not in (None, 'static'):
        print '<<< %s >>>' % request.endpoint
        print '<< request.values:: %r >>' % request.values
        print '<< cookie_data:: %r >>' % str(
            SecureCookie.unserialize(data, app.secret_key
                                     ) if data is not None else 'None')
        print '--------------------'

    # For guest user
    if request.endpoint == 'init':
        if not data:
            vid = save_visitor(request.environ)
            g.uid = str(vid)
            g.is_login = False
        else:
            cookie = SecureCookie.unserialize(data, app.secret_key)
            g.uid = cookie.get('uid', None)

            if g.uid is None:
                vid = save_visitor(request.environ)
                g.uid = str(vid)
                g.is_login = False
            else:
                g.is_login = True

    elif request.endpoint in LOGIN_REQUIRED_ENDPOINTS:
        if data:
            # Get uid & ticket from cookie then new Client
            cookie = SecureCookie.unserialize(data, app.secret_key)
            print '[...].cookie: ', cookie
            g.cookie = cookie
            g.uid = cookie.get('uid', None)
            g.is_login = True
            g.is_guest = cookie.get('is_guest', None)
            show = cookie.get('show', 'available')

            record, nick, pic_url = None, None, None
            if g.is_guest:
                record = db.load_visitor(g.uid)
                nick = '%s(%s)' % (record['nick'], record['location'])
                pic_url = gravatar_default(g.uid)
            else:
                record = db.load_user(g.uid)
                nick = record['nick']
                pic_url = gravatar_url(record['email'])

            g.record = record
            print 'g.record:', g.record

            user = {
                'id': g.uid,
                'nick': nick,
                'show': show,
                'status': '',
                'pic_url': pic_url,
                'default_pic_url': gravatar_default(g.uid)
            }
            ticket = request.values.get('ticket', None)
            g.client = Client(user,
                              CONFIG['domain'],
                              CONFIG['apikey'],
                              ticket=ticket,
                              host=CONFIG['host'],
                              port=CONFIG['port'])
        else:
            print '403.request.endpoint:', request.endpoint
            abort(403)

    print 'END prepare(%s) [%s]' % (request.endpoint, str(datetime.now()))
Example #7
0
class TestWebimMethods(unittest.TestCase):
    def setUp(self):
        self.endpoint = {
            'id': 'uid1',
            'nick': 'user1',
            'show': 'available',
            'status': ''
        }
        self.client = Client(self.endpoint,
                             "localhost",
                             "public",
                             host="t.nextalk.im")

        self.buddies = ['uid1', 'uid2', 'uid3']
        self.rooms = ['room1', 'room2', 'room3']
        self.client.online(self.buddies, self.rooms)

    def test_online(self):
        resp = self.client.online(self.buddies, self.rooms)
        self.assertTrue(resp['success'])

    def test_presence(self):
        self.client.presence('away', 'Away')

    def test_message(self):
        message = {
            'to': 'uid2',
            'nick': 'user1',
            'body': 'hahaha',
            'timestamp': time.time() * 1000,
            'type': 'chat',
            'style': ''
        }
        self.client.message(message)

    def test_push(self):
        c = Client(self.endpoint, "localhost", "public", host="t.nextalk.im")
        message = {
            'to': 'uid2',
            'from': 'uid3',
            'nick': 'user3',
            'body': 'hahaha',
            'timestamp': time.time() * 1000,
            'type': 'chat',
            'style': ''
        }
        c.message(message)

    def test_status(self):
        status = {'to': 'uid2', 'show': 'typeing', 'status': 'user1 is typing'}
        self.client.status(status)

    def test_presences(self):
        self.client.presences(['uid1', 'uid2'])

    def test_members(self):
        self.client.members("gid1")

    def test_join(self):
        self.client.join("gid4")

    def test_leave(self):
        self.client.leave("gid4")
#!/usr/bin/env python
#coding: utf-8

from webim import Client

user = {
    'id': 'uid1', 
    'nick': 'user1', 
    'show': 'available', 
    'status': ''
}

client = Client(user, "localhost", "public", timeout=30)

content = client.online(['uid1', 'uid2', 'uid3'], ['room1'])

print "Response: "

print content

while(True): print client.poll()