Ejemplo n.º 1
0
def craftar_api(f, api_key):
    collection = "53d73dec8c984038a391970b19bf3074"
    # token_list = craftar.get_token_list(api_key, limit=1, offset=0, collection=collection)
    token = "3856d9807c1d44a6"
    name = "my name"
    url = "http://www.jeffreymaxim.com"
    item = craftar.create_item(api_key, collection, name, url)
    filename = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/media/" + f.docfile.name
    image = craftar.create_image(api_key, item["uuid"], filename)
    result_list = craftar.search(token, filename)
    print result_list
Ejemplo n.º 2
0
def run_management(api_key, filename, items_per_page=5, hostname=None):
    """
    Basic example of listing, creating, updating and finally deleting
    each type of object, using CraftAR's Management API.
    """

    if hostname:
        craftar.settings.MANAGEMENT_HOSTNAME = hostname

    print("\n- Retrieving first %s collections..." % items_per_page)
    collection_list = craftar.get_collection_list(
        api_key,
        limit=items_per_page,
        offset=0,
    )
    for collection in collection_list:
        print("%s: %s" % (collection["uuid"], collection["name"]))

    print("\n- Creating collection...")
    collection = craftar.create_collection(
        api_key,
        name="My API collection",
    )
    collection_uuid = collection["uuid"]
    pprint(collection)

    print("\n- Retrieving collection...")
    collection = craftar.get_collection(
        api_key,
        uuid=collection_uuid,
    )
    pprint(collection)

    print("\n- Updating collection...")
    new_name = "My edited API collection"
    success = craftar.update_collection(
        api_key,
        uuid=collection_uuid,
        name=new_name,
    )
    print("Updated: %s, name: '%s'" % (success, new_name))

    print("\n- Retrieving collection...")
    collection = craftar.get_collection(
        api_key,
        uuid=collection_uuid,
    )
    pprint(collection)

    print("\n- Retrieving first %s tokens..." % items_per_page)
    token_list = craftar.get_token_list(
        api_key,
        limit=items_per_page,
        offset=0,
        collection=collection_uuid,
    )
    for t in token_list:
        print("Collection: %s Token: %s" % (t["collection"], t["token"]))

    print("\n- Creating token...")
    token = craftar.create_token(
        api_key,
        collection=collection_uuid,
    )
    token_id = token["token"]
    pprint(token)

    print("\n- Deleting token...")
    success = craftar.delete_token(
        api_key,
        token=token_id,
    )
    print("Deleted: %s" % success)

    print("\n- Retrieving first %s items..." % items_per_page)
    item_list = craftar.get_item_list(
        api_key,
        limit=items_per_page,
        offset=0,
        collection=collection_uuid,
    )
    for i in item_list:
        print("%s: %s" % (i["uuid"], i["name"]))

    print("\n- Creating item...")
    item = craftar.create_item(
        api_key,
        name="My API item",
        collection=collection_uuid,
        url="http://example.com",
        custom="Lorem Ipsum",
    )
    item_uuid = item["uuid"]
    pprint(item)

    print("\n- Retrieving first %s items..." % items_per_page)
    item_list = craftar.get_item_list(
        api_key,
        limit=items_per_page,
        offset=0,
        collection=collection_uuid,
    )
    for i in item_list:
        print("%s: %s" % (i["uuid"], i["name"]))

    print("\n- Retrieving item...")
    item = craftar.get_item(
        api_key,
        uuid=item_uuid,
    )
    pprint(item)

    print("\n- Updating item...")
    new_name = "My edited API item"
    success = craftar.update_item(
        api_key,
        uuid=item_uuid,
        name=new_name,
        custom="New Lorem Ipsum",
    )
    print("Updated: %s, name: '%s'" % (success, new_name))

    print("\n- Retrieving item...")
    item = craftar.get_item(
        api_key,
        uuid=item_uuid,
    )
    pprint(item)

    print("\n- Retrieving first %s images..." % items_per_page)
    image_list = craftar.get_image_list(
        api_key,
        limit=items_per_page,
        offset=0,
        item=item_uuid,
    )
    for i in image_list:
        print("%s: %s" % (i["uuid"], i["name"]))

    print("\n- Uploading image...")
    image = craftar.create_image(
        api_key,
        item=item_uuid,
        filename=filename,
    )
    image_uuid = image["uuid"]
    pprint(image)

    print("\n- Retrieving image...")
    image = craftar.get_image(
        api_key,
        uuid=image_uuid,
    )
    print("uuid: %s" % image["uuid"])
    pprint(image)

    print("\n- Deleting image...")
    success = craftar.delete_image(
        api_key,
        uuid=image_uuid,
    )
    print("Deleted: %s" % success)

    print("\n- Deleting item...")
    success = craftar.delete_item(
        api_key,
        uuid=item_uuid,
    )
    print("Deleted: %s" % success)

    print("\n- Deleting collection...")
    success = craftar.delete_collection(
        api_key,
        uuid=collection_uuid,
    )
    print("Deleted: %s" % success)