Package fedex :: Package services :: Module track_service
[hide private]
[frames] | no frames]

Source Code for Module fedex.services.track_service

 1  """ 
 2  Tracking Service Module 
 3  ======================= 
 4  This package contains the shipment tracking methods defined by Fedex's  
 5  TrackService WSDL file. Each is encapsulated in a class for easy access.  
 6  For more details on each, refer to the respective class's documentation. 
 7  """ 
 8  import logging 
 9  from .. base_service import FedexBaseService, FedexError 
10   
11 -class FedexInvalidTrackingNumber(FedexError):
12 """ 13 Sent when a bad tracking number is provided. 14 """ 15 pass
16
17 -class FedexTrackRequest(FedexBaseService):
18 """ 19 This class allows you to track shipments by providing a tracking 20 number or other identifying features. By default, you 21 can simply pass a tracking number to the constructor. If you would like 22 to query shipments based on something other than tracking number, you will 23 want to read the documentation for the L{__init__} method. 24 Particularly, the tracking_value and package_identifier arguments. 25 """
26 - def __init__(self, config_obj, *args, **kwargs):
27 """ 28 Sends a shipment tracking request. The optional keyword args 29 detailed on L{FedexBaseService} apply here as well. 30 31 @type config_obj: L{FedexConfig} 32 @param config_obj: A valid FedexConfig object. 33 """ 34 self._config_obj = config_obj 35 36 # Holds version info for the VersionId SOAP object. 37 self._version_info = {'service_id': 'trck', 'major': '4', 38 'intermediate': '0', 'minor': '0'} 39 self.TrackPackageIdentifier = None 40 """@ivar: Holds the TrackPackageIdentifier WSDL object.""" 41 # Call the parent FedexBaseService class for basic setup work. 42 super(FedexTrackRequest, self).__init__(self._config_obj, 43 'TrackService_v4.wsdl', 44 *args, **kwargs)
45
46 - def _prepare_wsdl_objects(self):
47 """ 48 This sets the package identifier information. This may be a tracking 49 number or a few different things as per the Fedex spec. 50 """ 51 self.TrackPackageIdentifier = self.client.factory.create('TrackPackageIdentifier') 52 # Default to tracking number. 53 self.TrackPackageIdentifier.Type = 'TRACKING_NUMBER_OR_DOORTAG'
54
56 """ 57 Checks the response to see if there were any errors specific to 58 this WSDL. 59 """ 60 if self.response.HighestSeverity == "ERROR": 61 for notification in self.response.Notifications: 62 if notification.Severity == "ERROR": 63 if "Invalid tracking number" in notification.Message: 64 raise FedexInvalidTrackingNumber(notification.Code, 65 notification.Message) 66 else: 67 raise FedexError(notification.Code, 68 notification.Message)
69
71 """ 72 Fires off the Fedex request. 73 74 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES 75 ON FedexBaseService AND IS INHERITED. 76 """ 77 client = self.client 78 # Fire off the query. 79 response = client.service.track(WebAuthenticationDetail=self.WebAuthenticationDetail, 80 ClientDetail=self.ClientDetail, 81 TransactionDetail=self.TransactionDetail, 82 Version=self.VersionId, 83 PackageIdentifier=self.TrackPackageIdentifier) 84 85 return response
86