コード例 #1
0
def api_kz_hook():
    with app.test_request_context('/kazoo', method='POST'):
        """
        now you can do something with the request until the
        end of the with block, such as basic assertions:
        """

        assert request.path == '/kazoo'
        assert request.method == 'POST'
        print('assertions passed')

    # if request.headers['Content-Type'] == 'x-www-form-urlencoded':
    item_id = request.form.get('id')
    item_type = request.form.get('type')
    account_id = request.form.get('account_id')

    print('this are the items: ', item_type, item_id, account_id)

    response = get_items(item_type, account_id, item_id, get_auth_token())

    print('this is my response', response)

    user_name = response['data']['caller_id']['internal']['name']
    print(user_name)
    # response = json.loads(response)

    var = db.insert_user(user_name, response, item_id)
    print('this is var', var)

    print(request.form)
    return 'ok'
コード例 #2
0
 def create_account():
     item_account = kp.get_items(item_type=item_type,
                                 account_id=account_id,
                                 item_id=item_id,
                                 auth=auth)
     print(item_account)
     data = item_account['data']
     account_name = data.get('name')
     account = Account(item_id, account_name, date(2015, 4, 2))
     session.add(account)
コード例 #3
0
 def create_user():
     item_user = kp.get_items(item_type=item_type,
                              account_id=account_id,
                              item_id=item_id,
                              auth=auth)
     print(item_user)
     data = item_user['data']
     user_name = data['caller_id']['internal']['name']
     email = data.get('email')
     account = session.query(Account).get(account_id)
     user = User(item_id, user_name, date(2015, 4, 2), 3, email, account)
     session.add(user)
コード例 #4
0
    def create_device():
        item_device = kp.get_items(item_type=item_type,
                                   account_id=account_id,
                                   item_id=item_id,
                                   auth=auth)
        print(item_device)
        data = item_device['data']
        device_type = data.get('device_type')
        owner_id = data.get('owner_id')
        name = data.get('name')

        device = Device(item_id, name, device_type)
        user = session.query(User).get(owner_id)
        device.user = [user]
        session.add(device)
コード例 #5
0
async def consumer(event):
    """
    consumer code that prints the notifications from messages sent by the websocket connection
    - does something with the messages sent by server

    """
    event = j.loads(event)
    data = event['data']
    item_type = data.get('type')
    item_id = data.get('id')
    account_id = data.get('account_id')
    print(item_type, item_id, account_id)
    print()
    item = kp.get_items(item_type, account_id, item_id, auth=auth_token)
    print(item)
コード例 #6
0
    def create_user():
        item_user = kp.get_items(item_type=item_type,
                                 account_id=account_id,
                                 item_id=item_id,
                                 auth=auth)
        print('in data_alchemy', item_user)

        data = item_user['data']
        if data.get('priv_level') == 'admin':
            user_name = 'admin'
            email = '*****@*****.**'
        else:
            user_name = data['caller_id']['internal']['name']
            email = data.get('email')
        account = session.query(Account).get(account_id)
        user = User(item_id, user_name, datetime.now(), 1, email, account)
        session.add(user)