Exemplo n.º 1
0
def new(phone_number):
    item = {
        'phone_number': {'S': sanitize_phone_number(phone_number)},
        'consumptions': {'N': str(Config.FREE_CONSUMPTIONS)}
    }
    put(TABLE_NAME, item)
    return item
Exemplo n.º 2
0
def get(phone_number):
    response = dynamo_client.get_item(
        TableName=TABLE_NAME,
        Key={'phone_number': {'S': sanitize_phone_number(phone_number)}}
    )
    if 'Item' in response:
        return response['Item']
    else:
        return None
Exemplo n.º 3
0
def new(pile_id, recipient_phone_number, sender_name,
        pile_name, timestamp):
    item = {
        'pile_id': {'S': pile_id},
        'phone_number': {'S': sanitize_phone_number(recipient_phone_number)},
        'sender_name': {'S': sender_name},
        'pile_name': {'S': pile_name},
        'timestamp': {'S': timestamp.strftime('%Y-%m-%d %H:%M:%S')},
    }
    put(TABLE_NAME, item)
    return item
Exemplo n.º 4
0
def add_metadata(phone_number, key, value):
    dynamo_client.update_item(
        TableName=TABLE_NAME,
        Key={
            'phone_number': {"S": sanitize_phone_number(phone_number)}
        },
        AttributeUpdates={
            key: {
                "Action": "PUT",
                "Value": {"S": str(value)}
            }
        }
    )
Exemplo n.º 5
0
def modify_consumptions(phone_number, consumptions=1):
    dynamo_client.update_item(
        TableName=TABLE_NAME,
        Key={
            'phone_number': {"S": sanitize_phone_number(phone_number)}
        },
        AttributeUpdates={
            "consumptions": {
                "Action": "ADD",
                "Value": {"N": str(consumptions * -1)}
            },
            "message_count": {
                "Action": "ADD",
                "Value": {"N": str(consumptions * 1)}
            }
        }
        )