def shipment_cancel_request(payload: ShipmentCancelRequest, _) -> Serializable[Pipeline]: identifier = Serializable(payload.shipment_identifier) def _refund_if_submitted(shipment_details: str): shipment = XP.build(ShipmentInfoType, XP.to_xml(shipment_details)) transmitted = shipment.shipment_status == 'transmitted' data = dict( id=payload.shipment_identifier, payload=Serializable( ShipmentRefundRequestType( email=payload.options.get('email')), lambda request: XP. export(request, name_='shipment-refund-request', namespacedef_= 'xmlns="http://www.canadapost.ca/ws/shipment-v8"')) ) if transmitted else None return Job(id="refund", data=data, fallback=shipment_details) def _cancel_other_wise(previous_job_response: str): response: Element = XP.to_xml(previous_job_response) refunded = (response.tag == 'shipment-refund-request-info') data = identifier if not refunded else None return Job(id="cancel", data=data) request: Pipeline = Pipeline( info=lambda *_: Job(id="info", data=identifier), refund=_refund_if_submitted, cancel=_cancel_other_wise) return Serializable(request)
def pickup_update_request(payload: PickupUpdateRequest, settings: Settings) -> Serializable[Pipeline]: request: Pipeline = Pipeline( update_pickup=lambda *_: _update_pickup(payload, settings), get_pickup=partial(_get_pickup, payload=payload, settings=settings), ) return Serializable(request)
def pickup_request( payload: PickupRequest, settings: Settings ) -> Serializable[Pipeline]: request: Pipeline = Pipeline( get_availability=lambda *_: _get_pickup_availability(payload), create_pickup=partial(_create_pickup, payload=payload, settings=settings), ) return Serializable(request)
def shipment_request(payload: ShipmentRequest, settings: Settings) -> Serializable[Pipeline]: request: Pipeline = Pipeline( process=lambda *_: _process_shipment(payload, settings), get_label=partial(_get_label, settings=settings) ) return Serializable(request)
def pickup_request(payload: PickupRequest, settings: Settings) -> Serializable: request: Pipeline = Pipeline( create_pickup=lambda *_: _create_pickup(payload), retrieve_pickup=partial(_retrieve_pickup, payload=payload, settings=settings)) return Serializable(request)
def shipment_request(payload: ShipmentRequest, settings: Settings) -> Serializable[Pipeline]: requests: Pipeline = Pipeline( create=lambda *_: partial( _create_shipment, payload=payload, settings=settings)(), document=partial(_get_shipment_label, payload=payload, settings=settings), ) return Serializable(requests)
def pickup_update_request(payload: PickupUpdateRequest, settings: Settings) -> Serializable[Pipeline]: request: Pipeline = Pipeline( delete_pickup=lambda *_: _delete_pickup(payload, settings), create_pickup=partial(_create_pickup, payload=payload, settings=settings), retrieve_pickup=partial(_retrieve_pickup, payload=payload, settings=settings)) return Serializable(request)
def pickup_update_request(payload: PickupUpdateRequest, settings: Settings) -> Serializable[Pipeline]: """ Modify a pickup request Steps 1 - cancel former pickup 2 - create a new one :param payload: PickupUpdateRequest :param settings: Settings :return: Serializable[Pipeline] """ request: Pipeline = Pipeline( cancel=lambda *_: _cancel_pickup(payload, settings), schedule=partial(_create_pickup, payload=payload, settings=settings)) return Serializable(request)
def pickup_update_request( payload: PickupUpdateRequest, settings: Settings ) -> Serializable[Pipeline]: """ Create a pickup request Steps 1 - create pickup 2 - cancel old pickup :param payload: PickupUpdateRequest :param settings: Settings :return: Serializable[Pipeline] """ request: Pipeline = Pipeline( rate=lambda *_: pickup_request(payload=payload, settings=settings), cancel=partial(_cancel_pickup_request, payload=payload, settings=settings), ) return Serializable(request)
def pickup_request( payload: PickupRequest, settings: Settings ) -> Serializable[Pipeline]: """ Create a pickup request Steps 1 - rate pickup 2 - create pickup :param payload: PickupRequest :param settings: Settings :return: Serializable[Pipeline] """ request: Pipeline = Pipeline( rate=lambda *_: _rate_pickup(payload=payload, settings=settings), create=partial(_create_pickup, payload=payload, settings=settings), ) return Serializable(request)
def pickup_update_request( payload: PickupUpdateRequest, settings: Settings ) -> Serializable[Pipeline]: """ Modify a pickup request Steps 1 - validate 2 - modify pickup :param payload: PickupUpdateRequest :param settings: Settings :return: Serializable[Pipeline] """ request: Pipeline = Pipeline( validate=lambda *_: _validate_pickup(payload=payload, settings=settings), modify=partial(_modify_pickup, payload=payload, settings=settings), ) return Serializable(request)
def shipment_request(payload: ShipmentRequest, settings: Settings) -> Serializable[Pipeline]: def _create_shipment_request(_) -> Job: return Job(id='create', data=create_shipment_request(payload, settings)) def _create_label_request(shipment_response: str) -> Job: activity = XP.build(document, XP.to_xml(shipment_response)) fallback = shipment_response if activity is None else None data = (create_label_request(activity, payload, settings) if activity is None else None) return Job(id='create', data=data, fallback=fallback) request: Pipeline = Pipeline(create=_create_shipment_request, get_label=_create_label_request) return Serializable(request)
def pickup_request(payload: PickupRequest, settings: Settings) -> Serializable[Pipeline]: """ Create a pickup request Steps 1 - get availability 2 - create pickup :param payload: PickupRequest :param settings: Settings :return: Serializable[Pipeline] """ request: Pipeline = Pipeline( get_availability=lambda *_: _get_availability(payload=payload, settings=settings), create_pickup=partial(_create_pickup, payload=payload, settings=settings), ) return Serializable(request)