def parse_pickup_update_response( response, settings: Settings) -> Tuple[PickupDetails, List[Message]]: successful = (len( response.xpath(".//*[local-name() = $name]", name="ConfirmationNumber")) > 0) pickup = _extract_pickup(response, settings) if successful else None return pickup, parse_error_response(response, settings)
def parse_shipment_response( response: Element, settings: Settings) -> Tuple[ShipmentDetails, List[Message]]: air_way_bill = XP.find("AirwayBillNumber", response, first=True) return ( _extract_shipment(response, settings) if air_way_bill is not None else None, parse_error_response(response, settings), )
def parse_rate_response( response: Element, settings: Settings) -> Tuple[List[RateDetails], List[Message]]: qtdshp_list = response.xpath(".//*[local-name() = $name]", name="QtdShp") quotes: List[RateDetails] = [ _extract_quote(qtdshp_node, settings) for qtdshp_node in qtdshp_list ] return ( [quote for quote in quotes if quote is not None], parse_error_response(response, settings), )
def parse_shipment_response( response: Element, settings: Settings ) -> Tuple[ShipmentDetails, List[Message]]: air_way_bill = next( iter(response.xpath(".//*[local-name() = $name]", name="AirwayBillNumber")), None, ) return ( _extract_shipment(response, settings) if air_way_bill is not None else None, parse_error_response(response, settings), )
def parse_rate_response( response: Element, settings: Settings) -> Tuple[List[RateDetails], List[Message]]: quotes = XP.find("QtdShp", response, ResponseQtdShpType) rates: List[RateDetails] = [ _extract_quote(quote, settings) for quote in quotes if (quote.ShippingCharge is not None) or ( quote.ShippingCharge is not None) ] return rates, parse_error_response(response, settings)
def parse_pickup_cancel_response( response, settings) -> Tuple[ConfirmationDetails, List[Message]]: successful = (len( response.xpath(".//*[local-name() = $name]", name="ConfirmationNumber")) > 0) cancellation = (ConfirmationDetails( carrier_name=settings.carrier_name, carrier_id=settings.carrier_id, success=successful, operation="Cancel Pickup", ) if successful else None) return cancellation, parse_error_response(response, settings)
def parse_address_validation_response( response: Element, settings: Settings) -> Tuple[AddressValidationDetails, List[Message]]: notes = response.xpath(".//*[local-name() = $name]", name="Note") success = next((True for note in notes if XP.to_object(Note, note).ActionNote == "Success"), False) validation_details = AddressValidationDetails( carrier_id=settings.carrier_id, carrier_name=settings.carrier_name, success=success) return validation_details, parse_error_response(response, settings)