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
9 from ..base_service import FedexBaseService, FedexError
10
11
13 """
14 Exception: Sent when a bad tracking number is provided.
15 """
16
17 pass
18
19
21 """
22 This class allows you to track shipments by providing a tracking
23 number or other identifying features. By default, you
24 can simply pass a tracking number to the constructor. If you would like
25 to query shipments based on something other than tracking number, you will
26 want to read the documentation for the L{__init__} method.
27 Particularly, the tracking_value and package_identifier arguments.
28 """
29
31 """
32 Sends a shipment tracking request. The optional keyword args
33 detailed on L{FedexBaseService} apply here as well.
34
35 @type config_obj: L{FedexConfig}
36 @param config_obj: A valid FedexConfig object.
37 """
38
39 self._config_obj = config_obj
40
41
42 self._version_info = {
43 'service_id': 'trck',
44 'major': '10',
45 'intermediate': '0',
46 'minor': '0'
47 }
48 self.SelectionDetails = None
49 """@ivar: Holds the SelectionDetails WSDL object that includes tracking type and value."""
50
51
52 self.ProcessingOptions = None
53 """@ivar: Holds the TrackRequestProcessingOptionType WSDL object that defaults no None."""
54
55
56 super(FedexTrackRequest, self).__init__(
57 self._config_obj, 'TrackService_v10.wsdl', *args, **kwargs)
58 self.IncludeDetailedScans = False
59
61 """
62 This sets the package identifier information. This may be a tracking
63 number or a few different things as per the Fedex spec.
64 """
65
66 self.SelectionDetails = self.client.factory.create('TrackSelectionDetail')
67
68
69 self.SelectionDetails.CarrierCode = 'FDXE'
70
71 track_package_id = self.client.factory.create('TrackPackageIdentifier')
72
73
74 track_package_id.Type = 'TRACKING_NUMBER_OR_DOORTAG'
75
76 self.SelectionDetails.PackageIdentifier = track_package_id
77
79 """
80 Checks the response to see if there were any errors specific to
81 this WSDL.
82 """
83 if self.response.HighestSeverity == "ERROR":
84 for notification in self.response.Notifications:
85 if notification.Severity == "ERROR":
86 if "Invalid tracking number" in notification.Message:
87 raise FedexInvalidTrackingNumber(
88 notification.Code, notification.Message)
89 else:
90 raise FedexError(notification.Code, notification.Message)
91
93 """
94 Fires off the Fedex request.
95
96 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES
97 ON FedexBaseService AND IS INHERITED.
98 """
99
100 client = self.client
101
102 return client.service.track(
103 WebAuthenticationDetail=self.WebAuthenticationDetail,
104 ClientDetail=self.ClientDetail,
105 TransactionDetail=self.TransactionDetail,
106 Version=self.VersionId,
107 SelectionDetails=self.SelectionDetails,
108 ProcessingOptions=self.ProcessingOptions)
109