def parse_address_validation_response( response: Element, settings: Settings) -> Tuple[AddressValidationDetails, List[Message]]: reply = XP.build( AddressValidationReply, next( iter( response.xpath(".//*[local-name() = $name]", name="AddressValidationReply")), None)) address: FedexAddress = next( (result.EffectiveAddress for result in reply.AddressResults), None) success = reply.HighestSeverity == NotificationSeverityType.SUCCESS.value _, lines = (address.StreetLines if address is not None and len(address.StreetLines) > 1 else ["", ""]) validation_details = AddressValidationDetails( carrier_id=settings.carrier_id, carrier_name=settings.carrier_name, success=success, complete_address=Address(city=address.City, state_code=address.StateOrProvinceCode, country_code=address.CountryCode, residential=address.Residential, address_line1=next(iter(address.StreetLines), None), address_line2=SF.concat_str(lines, join=True)) if address is not None else None) if success else None return validation_details, parse_error_response(response, settings)
def parse_shipment_response( response: Element, settings: Settings ) -> Tuple[ShipmentDetails, List[Message]]: detail = XP.find("CompletedShipmentDetail", response, first=True) shipment = ( _extract_shipment(detail, settings) if detail 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]]: replys = XP.find("RateReplyDetails", response) rates: List[RateDetails] = [ _extract_rate(detail_node, settings) for detail_node in replys ] return rates, parse_error_response(response, settings)
def parse_shipment_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 Shipment", ) if success else None return confirmation, errors
def parse_shipment_response( response: Element, settings: Settings) -> Tuple[ShipmentDetails, List[Message]]: detail = next( iter( response.xpath(".//*[local-name() = $name]", name="CompletedShipmentDetail")), None, ) shipment: ShipmentDetails = (_extract_shipment(detail, settings) if detail is not None else None) return shipment, 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="TrackDetails") tracking_details = [ _extract_tracking(track_detail_node, settings) for track_detail_node in track_details ] return ( [details for details in tracking_details if details is not None], 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="RateReplyDetails") rate_details: List[RateDetails] = [ _extract_rate(detail_node, settings) for detail_node in rate_reply ] return ( [details for details in rate_details if details is not None], parse_error_response(response, settings), )
def parse_pickup_response( response: Element, settings: Settings) -> Tuple[PickupDetails, List[Message]]: reply = XP.build( CreatePickupReply, next( iter( response.xpath(".//*[local-name() = $name]", name="CreatePickupReply")), None, ), ) pickup = (_extract_pickup_details(reply, settings) if reply.HighestSeverity == NotificationSeverityType.SUCCESS.value else None) return pickup, parse_error_response(response, settings)
def parse_pickup_cancel_response( response: Element, settings: Settings ) -> Tuple[ConfirmationDetails, List[Message]]: reply = XP.to_object( CancelPickupReply, next( iter( response.xpath(".//*[local-name() = $name]", name="CancelPickupReply") ), None, ), ) cancellation = ConfirmationDetails( carrier_id=settings.carrier_id, carrier_name=settings.carrier_name, success=reply.HighestSeverity == NotificationSeverityType.SUCCESS.value, operation="Cancel Pickup", ) return cancellation, parse_error_response(response, settings)