Exemplo n.º 1
0
def create(uuid, **kwargs):
    data = { "uuid": uuid, "token": crocodoc.api_token } 

    # validate session parameters
    boolean_parameters = ("editable", "admin", "downloadable", "copyprotected", "demo")  
    for key in kwargs.keys():
        if key in boolean_parameters:
            data[key] = "true" if bool(kwargs[key]) else "false"
            del kwargs[key]
    
    if "user" in kwargs and "id" in kwargs["user"] and "name" in kwargs["user"]:
        data["user"] = str(kwargs["user"]["id"]) + ',' + kwargs["user"]["name"]
        del kwargs["user"]
            
    if "filter" in kwargs:
        data["filter"] = kwargs["filter"]
        del kwargs["filter"]
        
    if "sidebar" in kwargs:
        data["sidebar"] = kwargs["sidebar"]
        del kwargs["sidebar"]
    
    r = requests.post(crocodoc.base_url + "session/create", data)
    
    crocodoc.check_response(r)
    
    if "session" not in r.json():
        raise crocodoc.CrocodocError("missing_session_key", r)

    return r.json()["session"]
Exemplo n.º 2
0
def text(uuid):
    querystring = "uuid=%s&token=%s" % (uuid, crocodoc.api_token)
    url = crocodoc.base_url + "download/text?" + querystring
    r = requests.get(url)

    crocodoc.check_response(r, True)

    return r.content
Exemplo n.º 3
0
def delete(uuid):
    data = {"uuid": uuid, "token": crocodoc.api_token}
    url = crocodoc.base_url + "document/delete"
    r = requests.post(url, data)

    crocodoc.check_response(r)

    return True
Exemplo n.º 4
0
def text(uuid):
    querystring = "uuid=%s&token=%s" % (uuid, crocodoc.api_token)
    url = crocodoc.base_url + "download/text?" + querystring
    r = requests.get(url)
    
    crocodoc.check_response(r, True)
    
    return r.content
Exemplo n.º 5
0
def delete(uuid):
    data = { "uuid": uuid, "token": crocodoc.api_token }
    url = crocodoc.base_url + "document/delete"
    r = requests.post(url, data)
    
    crocodoc.check_response(r)

    return True
Exemplo n.º 6
0
def thumbnail(uuid, width=None, height=None):
    querystring = "uuid=%s&token=%s" % (uuid, crocodoc.api_token)
    if width is not None and height is not None:
        querystring += "&size=%dx%d" % (width, height)

    url = crocodoc.base_url + "download/thumbnail?" + querystring
    r = requests.get(url)

    crocodoc.check_response(r, True)

    return r.content
Exemplo n.º 7
0
def thumbnail(uuid, width=None, height=None):
    querystring = "uuid=%s&token=%s" % (uuid, crocodoc.api_token)
    if width is not None and height is not None:
        querystring += "&size=%dx%d" % (width, height)

    url = crocodoc.base_url + "download/thumbnail?" + querystring
    r = requests.get(url)
    
    crocodoc.check_response(r, True)
    
    return r.content
Exemplo n.º 8
0
def status(uuids):
    single_uuid = isinstance(uuids, basestring)
    if single_uuid:
        uuids = [uuids]

    querystring = "uuids=%s&token=%s" % (",".join(uuids), crocodoc.api_token)
    url = crocodoc.base_url + "document/status?" + querystring
    r = requests.get(url)

    crocodoc.check_response(r)

    return r.json()[0] if single_uuid else r.json()
Exemplo n.º 9
0
def status(uuids):
    single_uuid = isinstance(uuids, basestring)
    if single_uuid:
        uuids = [uuids]
    
    querystring = "uuids=%s&token=%s" % (",".join(uuids), crocodoc.api_token)
    url = crocodoc.base_url + "document/status?" + querystring
    r = requests.get(url)
    
    crocodoc.check_response(r)
    
    return r.json()[0] if single_uuid else r.json()
Exemplo n.º 10
0
def document(uuid, pdf=False, annotated=False, user_filter=None):
    querystring = "uuid=%s&token=%s" % (uuid, crocodoc.api_token)
    if pdf:
        querystring += "&pdf=true"
    if annotated:
        querystring += "&annotated=true"
    if filter:
        querystring += "&filter=%s" % (user_filter, )

    url = crocodoc.base_url + "download/document?" + querystring
    r = requests.get(url)

    crocodoc.check_response(r, True)

    return r.content
Exemplo n.º 11
0
def document(uuid, pdf=False, annotated=False, user_filter=None):
    querystring = "uuid=%s&token=%s" % (uuid, crocodoc.api_token)
    if pdf:
        querystring += "&pdf=true"
    if annotated:
        querystring += "&annotated=true"
    if filter:
        querystring += "&filter=%s" % (user_filter,)

    url = crocodoc.base_url + "download/document?" + querystring
    r = requests.get(url)
    
    crocodoc.check_response(r, True)
    
    return r.content
Exemplo n.º 12
0
def upload(url=None, file=None):
    data = { "token": crocodoc.api_token }
    files = {}

    if file:
        files["file"] = file 
    elif url:
        data["url"] = url
    else:
        raise crocodoc.CrocodocError("invalid_url_or_file_param")

    r = requests.post(crocodoc.base_url + "document/upload", data=data, files=files)
    
    crocodoc.check_response(r)
    
    if "uuid" not in r.json():
        raise crocodoc.CrocodocError("missing_uuid", r)

    return r.json()["uuid"]
Exemplo n.º 13
0
def upload(url=None, file=None):
    data = {"token": crocodoc.api_token}
    files = {}

    if file:
        files["file"] = file
    elif url:
        data["url"] = url
    else:
        raise crocodoc.CrocodocError("invalid_url_or_file_param")

    r = requests.post(crocodoc.base_url + "document/upload",
                      data=data,
                      files=files)

    crocodoc.check_response(r)

    if "uuid" not in r.json():
        raise crocodoc.CrocodocError("missing_uuid", r)

    return r.json()["uuid"]