def _get_shipment_label(create_response: str, payload: ShipmentRequest, settings: Settings) -> Job: errors = parse_error_response(to_xml(create_response), settings) valid = len(errors) == 0 shipment_pin = None if valid: node = next( iter( 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).serialize() if valid else None ), fallback="", )
def _get_shipment_label(shipement_response: str) -> Job: links = to_xml(shipement_response).xpath(".//*[local-name() = $name]", name="link") label_url = next( (link.get("href") for link in links if link.get("rel") == "label"), None, ) return Job(id="shipment_label", data=label_url, fallback="")
def _create_shipment(validate_response: str, payload: ShipmentRequest, settings: Settings) -> Job: errors = parse_error_response(to_xml(validate_response), settings) valid = len(errors) == 0 return Job( id="create", data=create_shipping_request(payload, settings).serialize() if valid else None, fallback=(validate_response if not valid else None), )