def parse_shipment_response( response: Element, settings: Settings) -> Tuple[ShipmentDetails, List[Message]]: details = XP.find("ShipmentResults", response, first=True) shipment = _extract_shipment(details, settings) if details is not None else None return shipment, parse_error_response(response, settings)
def parse_rate_response( response: Element, settings: Settings) -> Tuple[List[RateDetails], List[Message]]: rate_reply = XP.find("RatedShipment", response) rates: List[RateDetails] = reduce(_extract_package_rate(settings), rate_reply, []) return rates, parse_error_response(response, settings)
def parse_freight_ship_response( response: Element, settings: Settings) -> Tuple[ShipmentDetails, List[Message]]: details = response.xpath(".//*[local-name() = $name]", name="FreightShipResponse") shipment = _extract_shipment(details[0], settings) if len(details) > 0 else None return shipment, parse_error_response(response, settings)
def parse_shipment_response( response: Element, settings: Settings ) -> Tuple[ShipmentDetails, List[Message]]: details = next( iter(response.xpath(".//*[local-name() = $name]", name="ShipmentResults")), None ) shipment = _extract_shipment(details, settings) if details is not None else None return shipment, parse_error_response(response, settings)
def parse_rate_response( response: Element, settings: Settings) -> Tuple[List[RateDetails], List[Message]]: rate_reply = response.xpath(".//*[local-name() = $name]", name="RatedShipment") rates: List[RateDetails] = reduce(_extract_package_rate(settings), rate_reply, []) return rates, parse_error_response(response, settings)
def parse_tracking_response( response: Element, settings: Settings) -> Tuple[List[TrackingDetails], List[Message]]: track_details = response.xpath(".//*[local-name() = $name]", name="Shipment") tracking: List[TrackingDetails] = [ _extract_details(node, settings) for node in track_details ] return tracking, parse_error_response(response, settings)
def parse_freight_rate_response( response: Element, settings: Settings) -> Tuple[List[RateDetails], List[Message]]: rate_reply = response.xpath(".//*[local-name() = $name]", name="FreightRateResponse") rates: List[RateDetails] = [ _extract_freight_rate(detail_node, settings) for detail_node in rate_reply ] return rates, parse_error_response(response, settings)
def parse_pickup_response( response: Element, settings: Settings ) -> Tuple[PickupDetails, List[Message]]: reply = XP.find( "PickupCreationResponse", response, PickupCreationResponse, first=True ) pickup = ( _extract_pickup_details(response, settings) if reply is not None and reply.PRN is not None else None ) return pickup, parse_error_response(response, settings)
def parse_address_validation_response( response: Element, settings: Settings) -> Tuple[AddressValidationDetails, List[Message]]: status = XP.to_object( Response, next( iter(response.xpath(".//*[local-name() = $name]", name="Response")), None, ), ) success = status is not None and status.ResponseStatusCode == "1" validation_details = AddressValidationDetails( carrier_id=settings.carrier_id, carrier_name=settings.carrier_name, success=success) if success else None return validation_details, parse_error_response(response, settings)
def parse_pickup_response( response: Element, settings: Settings ) -> Tuple[PickupDetails, List[Message]]: reply = XP.build( PickupCreationResponse, next( iter( response.xpath( ".//*[local-name() = $name]", name="PickupCreationResponse" ) ), None, ), ) pickup = ( _extract_pickup_details(response, settings) if reply is not None and reply.PRN is not None else None ) return pickup, parse_error_response(response, settings)
def parse_pickup_cancel_response( response: Element, settings: Settings) -> Tuple[ConfirmationDetails, List[Message]]: status = XP.build( CodeDescriptionType, next( iter( response.xpath(".//*[local-name() = $name]", name="ResponseStatus")), None, ), ) success = status is not None and status.Code == "1" cancellation = (ConfirmationDetails( carrier_id=settings.carrier_id, carrier_name=settings.carrier_name, success=success, operation="Cancel Pickup", ) if success else None) return cancellation, parse_error_response(response, settings)