コード例 #1
0
def profile(business_ID, company, first_name, last_name, tokens):
    path = "/api/user/profile"

    # create request
    request = ProfileRequest(business_ID=business_ID,
                             company=company,
                             first_name=first_name,
                             last_name=last_name)

    # first we try the access token
    headers = auth_header(tokens.access_token)
    response = requests.put(host + path,
                            headers=headers,
                            data=request.to_json())

    # if access token is expired, we send the request token to fetch another access token
    if response.status_code == 401:
        access_token = access_for_refresh_token(tokens.refresh_token)
        headers = auth_header(access_token)
        response = requests.put(host + path,
                                headers=headers,
                                data=request.to_json())

    # map to response model
    result = api_response(response)
    return result.status
コード例 #2
0
ファイル: client.py プロジェクト: finux-ai/pythonClient
def handle_expired_access_token(request, tokens, path):
    access_token = access_for_refresh_token(tokens.refresh_token)
    headers = auth_header(access_token)
    data = None
    if request is not None:
        data = request.to_json()
    return requests.put(host + path, headers=headers, data=data)
コード例 #3
0
ファイル: client.py プロジェクト: finux-ai/pythonClient
def fetch_data(tokens):
    path = "/api/user/profile"

    # first we try the access token
    headers = auth_header(tokens.access_token)
    response = requests.get(host + path, headers=headers)

    # if access token is expired, we send the request token to fetch another access token
    if response.status_code == 401:
        response = handle_expired_access_token(request=None,
                                               tokens=tokens,
                                               path=path)

    # map to response model
    result = api_response(response)
    return FetchData(result.data)
コード例 #4
0
ファイル: client.py プロジェクト: finux-ai/pythonClient
def feedback(message, reply, tokens):
    path = "/api/user/feedback"

    # create request
    request = FeedbackRequest(message=message, reply=reply)

    # first we try the access token
    headers = auth_header(tokens.access_token)
    response = requests.put(host + path,
                            headers=headers,
                            data=request.to_json())

    # if access token is expired, we send the request token to fetch another access token
    if response.status_code == 401:
        response = handle_expired_access_token(request=request,
                                               tokens=tokens,
                                               path=path)

    # map to response model
    result = api_response(response)
    return result.status
コード例 #5
0
ファイル: client.py プロジェクト: finux-ai/pythonClient
def change_password(new_password, repeat_password, old_password, tokens):
    path = "/api/user/changepw"

    # create request
    request = ChangePasswordRequest(new_password=new_password,
                                    old_password=old_password,
                                    repeat_password=repeat_password)

    # first we try the access token
    headers = auth_header(tokens.access_token)
    response = requests.put(host + path,
                            headers=headers,
                            data=request.to_json())

    # if access token is expired, we send the request token to fetch another access token
    if response.status_code == 401:
        response = handle_expired_access_token(request=request,
                                               tokens=tokens,
                                               path=path)

    # map to response model
    result = api_response(response)
    return result.status