Example #1
0
def _modify_pickup(
    validation_response: str, payload: PickupUpdateRequest, settings: Settings
):
    errors = parse_error_response(XP.to_xml(validation_response), settings)
    data = _modify_pickup_request(payload, settings) if len(errors) == 0 else None

    return Job(id="modify", data=data, fallback="")
Example #2
0
def parse_tracking_response(
        response: Element,
        settings: Settings) -> Tuple[List[TrackingDetails], List[Message]]:
    track_infos = response.xpath(".//*[local-name() = $name]",
                                 name="TrackingInformation")
    return (
        [_extract_tracking(node, settings) for node in track_infos],
        parse_error_response(response, settings),
    )
Example #3
0
def parse_rate_response(
        response: Element,
        settings: Settings) -> Tuple[List[RateDetails], List[Message]]:
    estimates = response.xpath(".//*[local-name() = $name]",
                               name="ShipmentEstimate")
    return (
        [_extract_rate(node, settings) for node in estimates],
        parse_error_response(response, settings),
    )
Example #4
0
def _create_shipment(validate_response: str, payload: ShipmentRequest,
                     settings: Settings) -> Job:
    errors = parse_error_response(XP.to_xml(validate_response), settings)
    valid = len(errors) == 0
    return Job(
        id="create",
        data=_shipment_request(payload, settings) if valid else None,
        fallback=(validate_response if not valid else None),
    )
Example #5
0
def parse_pickup_cancel_response(
        response: Element,
        settings: Settings) -> Tuple[ConfirmationDetails, List[Message]]:
    errors = parse_error_response(response, settings)
    cancellation = (ConfirmationDetails(
        carrier_id=settings.carrier_id,
        carrier_name=settings.carrier_name,
        success=True,
        operation="Cancel Pickup",
    ) if not any(errors) else None)

    return cancellation, errors
Example #6
0
def parse_shipment_response(
        response: Element,
        settings: Settings) -> Tuple[ShipmentDetails, List[Message]]:
    details = next(
        iter(
            response.xpath(".//*[local-name() = $name]",
                           name="CreateShipmentResponse")),
        None,
    )
    shipment = _extract_shipment(response,
                                 settings) if details is not None else None
    return shipment, parse_error_response(response, settings)
Example #7
0
def parse_shipment_cancel_response(
        response: Element,
        settings: Settings) -> Tuple[ConfirmationDetails, List[Message]]:
    void_response = XP.build(
        VoidShipmentResponse,
        next(
            iter(
                response.xpath(".//*[local-name() = $name]",
                               name="VoidShipmentResponse")), None))
    voided = void_response is not None and void_response.ShipmentVoided
    cancellation = ConfirmationDetails(
        carrier_id=settings.carrier_id,
        carrier_name=settings.carrier_name,
        success=True,
        operation="Cancel Shipment",
    ) if voided else None

    return cancellation, parse_error_response(response, settings)
Example #8
0
def parse_pickup_update_response(
    response: Element, settings: Settings
) -> Tuple[PickupDetails, List[Message]]:
    reply = XP.build(
        ModifyPickUpResponse,
        next(
            iter(
                response.xpath(
                    ".//*[local-name() = $name]", name="ModifyPickUpResponse"
                )
            ),
            None,
        ),
    )
    pickup = (
        _extract_pickup_details(reply, settings)
        if reply is not None and reply.PickUpConfirmationNumber is not None
        else None
    )

    return pickup, parse_error_response(response, settings)
Example #9
0
def _get_shipment_label(create_response: str, payload: ShipmentRequest,
                        settings: Settings) -> Job:
    errors = parse_error_response(XP.to_xml(create_response), settings)
    valid = len(errors) == 0
    shipment_pin = None

    if valid:
        node = next(
            iter(
                XP.to_xml(create_response).xpath(".//*[local-name() = $name]",
                                                 name="ShipmentPIN")),
            None,
        )
        pin = PIN()
        pin.build(node)
        shipment_pin = pin.Value

    return Job(
        id="document",
        data=(get_shipping_documents_request(shipment_pin, payload, settings)
              if valid else None),
        fallback="",
    )