Ejemplo n.º 1
0
def get_a_client(id):
    base_url = current_app.config["DATABASE_URL"]
    response = requests.get(
        "{}/Clients/{}".format(base_url, id),
        headers={"Authorization": str(os.environ.get("API_KEY"))},
    )
    # Convert to JSON
    response_json = response.json()

    # Validation check
    if (response.status_code // 100) != 2:
        return response_json["error"], response.status_code

    # Get object's parameters
    id_number = response_json["id"]
    name = response_json["fields"].get("Name")
    notes = response_json["fields"].get("Notes")
    email = response_json["fields"].get("Client Email")
    attachments = response_json["fields"].get("Attachments")
    if name is None or email is None:
        return "There is no client with this id. Please try again.", 422

    # Create and return object
    c = Client(
        name=name,
        email=email,
        id_number=id_number,
        notes=notes,
        attachments=attachments,
    )
    return jsonify(c.serialize()), 200
Ejemplo n.º 2
0
def get_all_clients():
    response = requests.get(
        "https://api.airtable.com/v0/appw4RRMDig1g2PFI/Clients",
        headers={"Authorization": str(os.environ.get("API_KEY"))},
    )
    response_json = response.json()

    list_of_clients = []
    for r in response_json["records"]:
        name = r["fields"].get("Name")
        notes = r["fields"].get("Notes")
        attachments = r["fields"].get("Attachments")
        if name is not None:
            m = Client(name=name, notes=notes, attachments=attachments)
            list_of_clients.append(m.serialize())
    return jsonify(list_of_clients)
Ejemplo n.º 3
0
    def getResponse():
        for r in response_json["records"]:
            id_number = r["id"]
            name = r["fields"].get("Name")
            notes = r["fields"].get("Notes")
            email = r["fields"].get("Client Email")
            attachments = r["fields"].get("Attachments")

            if name is not None and email is not None:
                m = Client(
                    name=name,
                    email=email,
                    id_number=id_number,
                    notes=notes,
                    attachments=attachments,
                )
                list_of_clients.append(m.serialize())
Ejemplo n.º 4
0
def get_a_client_from_email(email):
    response = requests.get(
        "https://api.airtable.com/v0/appw4RRMDig1g2PFI/Clients?filterByFormula=SEARCH('{}'"
        .format(email) + ", {Client Email})",
        headers={"Authorization": str(os.environ.get("API_KEY"))},
    )
    response_json = response.json()

    list_of_clients = []
    for r in response_json["records"]:
        name = r["fields"].get("Name")
        notes = r["fields"].get("Notes")
        attachments = r["fields"].get("Attachments")
        if name is not None:
            m = Client(name=name, notes=notes, attachments=attachments)
            list_of_clients.append(m.serialize())
            return jsonify(list_of_clients)
    else:
        return "There is no client with that email, please try again."
Ejemplo n.º 5
0
def get_a_client(id):
    response = requests.get(
        "https://api.airtable.com/v0/appw4RRMDig1g2PFI/Clients/{}".format(id),
        headers={"Authorization": str(os.environ.get("API_KEY"))},
    )
    if response.status_code == 200:
        response_json = response.json()
        client = []
        name = response_json["fields"].get("Name")
        notes = response_json["fields"].get("Notes")
        email = response_json["fields"].get("Client Email")
        attachments = response_json["fields"].get("Attachments")
        if name is not None:
            m = Client(name=name,
                       email=email,
                       notes=notes,
                       attachments=attachments)
            client.append(m.serialize())
            return jsonify(client)
    else:
        return "This client does not exist in the database."
Ejemplo n.º 6
0
def get_a_client_from_email(email):
    base_url = current_app.config["DATABASE_URL"]
    response = requests.get(
        "{}/Clients?filterByFormula=SEARCH('{}'".format(base_url, email)
        + ", {Client Email})",
        headers={"Authorization": str(os.environ.get("API_KEY"))},
    )
    # Convert to JSON
    response_json = response.json()

    # Validation check
    if (response.status_code // 100) != 2:
        return response_json["error"], response.status_code

    error = handleEmailResponse(response_json["records"])
    if error is not None:
        return error, 422

    # Get object's parameters
    id_number = response_json["records"][0]["id"]
    name = response_json["records"][0]["fields"].get("Name")
    email = response_json["records"][0]["fields"].get("Client Email")
    notes = response_json["records"][0]["fields"].get("Notes")
    attachments = response_json["records"][0]["fields"].get("Attachments")
    if name is None or email is None:
        return "There is no client with that email. Please try again.", 422

    # Create and return object
    c = Client(
        name=name,
        email=email,
        id_number=id_number,
        notes=notes,
        attachments=attachments,
    )
    return jsonify(c.serialize()), 200