Exemplo n.º 1
0
def parse_address_validation_response(
        response: Element,
        settings: Settings) -> Tuple[AddressValidationDetails, List[Message]]:
    errors = parse_error_response(response, settings)
    address_node = next(
        iter(response.xpath(".//*[local-name() = $name]", name="address")),
        None)
    address = XP.to_object(CanparAddress, address_node)
    success = len(errors) == 0
    validation_details = AddressValidationDetails(
        carrier_id=settings.carrier_id,
        carrier_name=settings.carrier_name,
        success=success,
        complete_address=Address(postal_code=address.postal_code,
                                 city=address.city,
                                 company_name=address.name,
                                 country_code=address.country,
                                 email=address.email,
                                 state_code=address.province,
                                 residential=address.residential,
                                 address_line1=address.address_line_1,
                                 address_line2=SF.concat_str(
                                     address.address_line_2,
                                     address.address_line_3,
                                     join=True))) if success else None

    return validation_details, errors
Exemplo n.º 2
0
def parse_shipment_response(response: Element, settings: Settings) -> Tuple[ShipmentDetails, List[Message]]:
    shipment = XP.to_object(
        Shipment, next(iter(response.xpath(".//*[local-name() = $name]", name="shipment")), None)
    )
    success = (shipment is not None and shipment.id is not None)
    shipment_details = _extract_details(response, settings) if success else None

    return shipment_details, parse_error_response(response, settings)
Exemplo n.º 3
0
def parse_rate_response(
        response: Element,
        settings: Settings) -> Tuple[List[RateDetails], List[Message]]:
    shipment_nodes = XP.find("shipment", response)
    rates: List[RateDetails] = [
        _extract_rate_details(node, settings) for node in shipment_nodes
    ]
    return rates, parse_error_response(response, settings)
Exemplo n.º 4
0
def _create_pickup(cancel_response: str, payload: PickupUpdateRequest,
                   settings: Settings) -> Job:
    errors = parse_error_response(XP.to_xml(cancel_response), settings)
    canceled = len(errors) == 0
    data: Optional[PickupRequest] = (pickup_request(payload, settings)
                                     if canceled else None)
    fallback: Optional[str] = None if canceled else ''

    return Job(id='schedule', data=data, fallback=fallback)
Exemplo n.º 5
0
def parse_tracking_response(
        response: Element,
        settings: Settings) -> Tuple[List[TrackingDetails], List[Message]]:
    results = response.xpath(".//*[local-name() = $name]", name="result")
    details: List[TrackingDetails] = [
        _extract_tracking_details(result, settings) for result in results
    ]

    return details, parse_error_response(response, settings)
Exemplo n.º 6
0
def parse_rate_response(
        response: Element,
        settings: Settings) -> Tuple[List[RateDetails], List[Message]]:
    shipment_nodes = response.xpath(".//*[local-name() = $name]",
                                    name="shipment")
    rates: List[RateDetails] = [
        _extract_rate_details(node, settings) for node in shipment_nodes
    ]
    return rates, parse_error_response(response, settings)
Exemplo n.º 7
0
def parse_pickup_response(response: Element, settings: Settings) -> Tuple[PickupDetails, List[Message]]:
    pickup_node = next(iter(response.xpath(".//*[local-name() = $name]", name="pickup")), None)
    pickup = XP.build(PickupV2, pickup_node)
    details: PickupDetails = PickupDetails(
        carrier_id=settings.carrier_id,
        carrier_name=settings.carrier_name,
        confirmation_number=str(pickup.id),
        pickup_date=DF.fdatetime(pickup.pickup_date, '%Y-%m-%dT%H:%M:%S')
    )

    return details, parse_error_response(response, settings)
Exemplo n.º 8
0
def parse_pickup_cancel_response(response: Element, settings: Settings) -> Tuple[ConfirmationDetails, List[Message]]:
    errors = parse_error_response(response, settings)
    success = len(errors) == 0
    confirmation: ConfirmationDetails = ConfirmationDetails(
        carrier_id=settings.carrier_id,
        carrier_name=settings.carrier_name,
        success=success,
        operation="Cancel Pickup",
    ) if success else None

    return confirmation, errors