Пример #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
def login(name, password):
    path = "/api/login"

    request = LoginRequest(name, password)

    # send register credentials
    response = requests.post(host + path, data=request.to_json())

    # create register data
    result = api_response(response)
    return AccessRefreshToken(result.data)
Пример #3
0
def register(name, password, repeat_password):
    path = "api/register"

    request = RegisterRequest(name, password, repeat_password)

    # send register credentials
    response = requests.post(host + path, data=request.to_json())

    # create register data
    result = api_response(response)
    return AccessRefreshToken(result.data)
Пример #4
0
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)
Пример #5
0
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
Пример #6
0
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