@@ -112,6 +112,30 @@ def __set_requested_shipment(self):
112112 # looks like.
113113 self .logger .info (self .RequestedShipment )
114114
115+ def send_validation_request (self ):
116+ """
117+ This is very similar to just sending the shipment via the typical
118+ send_request() function, but this doesn't create a shipment. It is
119+ used to make sure "good" values are given by the user or the
120+ application using the library.
121+ """
122+ self .send_request (send_function = self ._assemble_and_send_validation_request )
123+
124+ def _assemble_and_send_validation_request (self ):
125+ """
126+ Fires off the Fedex request.
127+
128+ @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES
129+ ON FedexBaseService AND IS INHERITED.
130+ """
131+ # Fire off the query.
132+ response = self .client .service .processShipment (WebAuthenticationDetail = self .WebAuthenticationDetail ,
133+ ClientDetail = self .ClientDetail ,
134+ TransactionDetail = self .TransactionDetail ,
135+ Version = self .VersionId ,
136+ RequestedShipment = self .RequestedShipment )
137+ return response
138+
115139 def _assemble_and_send_request (self ):
116140 """
117141 Fires off the Fedex request.
@@ -140,4 +164,89 @@ def add_package(self, package_item):
140164 self .RequestedShipment .RequestedPackageLineItems .append (package_item )
141165 package_weight = package_item .Weight .Value
142166 self .RequestedShipment .TotalWeight .Value += package_weight
143- self .RequestedShipment .PackageCount += 1
167+ self .RequestedShipment .PackageCount += 1
168+
169+ class FedexDeleteShipmentRequest (FedexBaseService ):
170+ """
171+ This class allows you to delete a shipment, given a tracking number.
172+ """
173+ def __init__ (self , config_obj , tracking_value ,
174+ package_identifier = 'TRACKING_NUMBER_OR_DOORTAG' ,
175+ * args , ** kwargs ):
176+ """
177+ Sends a shipment tracking request. The optional keyword args
178+ detailed on L{FedexBaseService} apply here as well.
179+
180+ @type config_obj: L{FedexConfig}
181+ @param config_obj: A valid FedexConfig object.
182+ @type tracking_value: L{str}
183+ @param tracking_value: Based on the value of package_identifier,
184+ this will be anything from a tracking number to a purchase order
185+ number.
186+ @type package_identifier: L{str}
187+ @keyword package_identifier: Determines what you are using to query for
188+ the shipment. The default assumes that tracking_value will be a Fedex
189+ tracking number.
190+ """
191+ self ._config_obj = config_obj
192+
193+ # Holds version info for the VersionId SOAP object.
194+ self ._version_info = {'service_id' : 'trck' , 'major' : '4' ,
195+ 'intermediate' : '0' , 'minor' : '0' }
196+ # Call the parent FedexBaseService class for basic setup work.
197+ super (FedexTrackRequest , self ).__init__ (self ._config_obj ,
198+ 'TrackService_v4.wsdl' ,
199+ * args , ** kwargs )
200+
201+ # Important request-specific instance variables.
202+ self .package_identifier = package_identifier
203+ """@ivar: Determines what L{tracking_value} is, be it a tracking number,
204+ purchase order, or other things."""
205+ self .tracking_value = tracking_value
206+ """@ivar: This is typically a Fedex tracking number, but setting
207+ L{package_identifier} to other values makes this change."""
208+
209+ def __set_track_package_identifier (self ):
210+ """
211+ This sets the package identifier information. This may be a tracking
212+ number or a few different things as per the Fedex spec.
213+ """
214+ TrackPackageIdentifier = self .client .factory .create ('TrackPackageIdentifier' )
215+ TrackPackageIdentifier .Type = self .package_identifier
216+ TrackPackageIdentifier .Value = self .tracking_value
217+ self .logger .debug (TrackPackageIdentifier )
218+ self .TrackPackageIdentifier = TrackPackageIdentifier
219+
220+ def _check_response_for_request_errors (self ):
221+ """
222+ Checks the response to see if there were any errors specific to
223+ this WSDL.
224+ """
225+ if self .response .HighestSeverity == "ERROR" :
226+ for notification in self .response .Notifications :
227+ if notification .Severity == "ERROR" :
228+ if "Invalid tracking number" in notification .Message :
229+ raise FedexInvalidTrackingNumber (notification .Code ,
230+ notification .Message )
231+ else :
232+ raise FedexError (notification .Code ,
233+ notification .Message )
234+
235+ def _assemble_and_send_request (self ):
236+ """
237+ Fires off the Fedex request.
238+
239+ @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES
240+ ON FedexBaseService AND IS INHERITED.
241+ """
242+ self .__set_track_package_identifier ()
243+ client = self .client
244+ # Fire off the query.
245+ response = client .service .track (WebAuthenticationDetail = self .WebAuthenticationDetail ,
246+ ClientDetail = self .ClientDetail ,
247+ TransactionDetail = self .TransactionDetail ,
248+ Version = self .VersionId ,
249+ CarrierCodeType = self .CarrierCodeType ,
250+ PackageIdentifier = self .TrackPackageIdentifier )
251+
252+ return response
0 commit comments