Esempio n. 1
0
def update_customer(connection, customer_id, customer):
    """
    Update a given customer with supplied customer info

    :param customer_id:
    :param customer:
    :return:
    """
    connection.command_path = "customer/{0}".format(customer_id)
    extra_headers = {
        connection.header_key: connection.token,
        'Content-Type': 'text/xml'
    }
    url = connection.build_url()
    verify_ssl = connection.verify_ssl
    customer_data = _build_customer_payload(customer)
    res = requests.put(url,
                       headers=extra_headers,
                       data=customer_data,
                       verify=verify_ssl)
    if res.status_code == 400 and res.content == b'The Customer name must be unique.':
        raise DuplicateCustomerException(res.content)
    elif res.status_code == 400 and b'not a valid country code' in res.content:
        raise InvalidCountryCodeException(res.content)
    elif res.status_code == 200:
        return customers.parse_customer(res.content)
    else:
        raise UnExpectedCustomerException(res.content)
Esempio n. 2
0
def create_customer(connection, customer):
    """
    Creates a customer

    The customer param should be a dict like:
    {
        'name': 123456,
        'country': 'US',
        'postal_code': 78232
    }

    :param connection:
    :param customer:
    :return:
    """
    connection.command_path = "customer"
    extra_headers = {
        connection.header_key: connection.token,
        'Content-Type': 'text/xml'
    }
    url = connection.build_url()
    verify_ssl = connection.verify_ssl
    customer_data = _build_customer_payload(customer)
    res = requests.post(url,
                        headers=extra_headers,
                        data=customer_data,
                        verify=verify_ssl)
    if res.status_code == 400 and res.content == b'The Customer name must be unique.':
        raise DuplicateCustomerException(res.content)
    elif res.status_code == 400 and b'not a valid country code' in res.content:
        raise InvalidCountryCodeException(res.content)
    elif res.status_code == 201:
        return customers.parse_customer(res.content)
    else:
        raise UnExpectedCustomerException(res.content)
Esempio n. 3
0
def update_customer(connection, customer_id, customer):
    """
    Update a given customer with supplied customer info

    :param customer_id:
    :param customer:
    :return:
    """
    connection.command_path = "customer/{0}".format(customer_id)
    extra_headers = {
        connection.header_key: connection.token,
        'Content-Type': 'text/xml'
    }
    url = connection.build_url()
    verify_ssl = connection.verify_ssl
    customer_data = _build_customer_payload(customer)
    res = requests.put(url, headers=extra_headers,
                       data=customer_data,
                       verify=verify_ssl)
    if res.status_code == 400 and res.content == b'The Customer name must be unique.':
        raise DuplicateCustomerException(res.content)
    elif res.status_code == 400 and b'not a valid country code' in res.content:
        raise InvalidCountryCodeException(res.content)
    elif res.status_code == 200:
        return customers.parse_customer(res.content)
    else:
        raise UnExpectedCustomerException(res.content)
Esempio n. 4
0
def create_customer(connection, customer):
    """
    Creates a customer

    The customer param should be a dict like:
    {
        'name': 123456,
        'country': 'US',
        'postal_code': 78232
    }

    :param connection:
    :param customer:
    :return:
    """
    connection.command_path = "customer"
    extra_headers = {
        connection.header_key: connection.token,
        'Content-Type': 'text/xml'
    }
    url = connection.build_url()
    verify_ssl = connection.verify_ssl
    customer_data = _build_customer_payload(customer)
    res = requests.post(url, headers=extra_headers,
                        data=customer_data,
                        verify=verify_ssl)
    if res.status_code == 400 and res.content == b'The Customer name must be unique.':
        raise DuplicateCustomerException(res.content)
    elif res.status_code == 400 and b'not a valid country code' in res.content:
        raise InvalidCountryCodeException(res.content)
    elif res.status_code == 201:
        return customers.parse_customer(res.content)
    else:
        raise UnExpectedCustomerException(res.content)
Esempio n. 5
0
def get_customer(connection, customer_id):
    """
    Returns a single customer given a customer id

    :param customer_id:
    :return:
    """
    connection.command_path = "customer/{0}".format(customer_id)
    extra_headers = {connection.header_key: connection.token}
    url = connection.build_url()
    verify_ssl = connection.verify_ssl
    res = requests.get(url=url, headers=extra_headers, verify=verify_ssl)
    body = res.content
    if res.status_code > 210:
        return
    return customers.parse_customer(body)
Esempio n. 6
0
def get_customer(connection, customer_id):
    """
    Returns a single customer given a customer id

    :param customer_id:
    :return:
    """
    connection.command_path = "customer/{0}".format(customer_id)
    extra_headers = {connection.header_key: connection.token}
    url = connection.build_url()
    verify_ssl = connection.verify_ssl
    res = requests.get(url=url, headers=extra_headers, verify=verify_ssl)
    body = res.content
    if res.status_code > 210:
        return
    return customers.parse_customer(body)