1 """
2 Package Movement Information Service
3 ====================================
4 This package contains classes to check service availability, route, and postal
5 codes. Defined by the PackageMovementInformationService WSDL file.
6 """
7 import logging
8 from .. base_service import FedexBaseService, FedexError
9
11 """
12 Exception: Sent when the postalcode is missing.
13 """
14 pass
15
17 """
18 Exception: Sent when the postal code is invalid
19 """
20 pass
21
22 -class PostalCodeInquiryRequest(FedexBaseService):
23 """
24 The postal code inquiry enables customers to validate postal codes
25 and service commitments.
26 """
27 - def __init__(self, config_obj, postal_code=None, country_code=None, *args, **kwargs):
28 """
29 Sets up an inquiry request. The optional keyword args
30 detailed on L{FedexBaseService} apply here as well.
31
32 @type config_obj: L{FedexConfig}
33 @param config_obj: A valid FedexConfig object
34 @param postal_code: a valid postal code
35 @param country_code: ISO country code to which the postal code belongs to.
36 """
37 self._config_obj = config_obj
38
39
40 self._version_info = {'service_id': 'pmis', 'major': '4',
41 'intermediate': '0', 'minor': '0'}
42 self.PostalCode = postal_code
43 self.CountryCode = country_code
44
45
46
47 super(PostalCodeInquiryRequest, self).__init__(self._config_obj,
48 'PackageMovementInformationService_v4.wsdl',
49 *args, **kwargs)
50
51
53 """
54 Checks the response to see if there were any errors specific to
55 this WSDL.
56 """
57 if self.response.HighestSeverity == "ERROR":
58 for notification in self.response.Notifications:
59 if notification.Severity == "ERROR":
60 if "Postal Code Not Found" in notification.Message:
61 raise FedexPostalCodeNotFound(notification.Code,
62 notification.Message)
63
64 elif "Invalid Postal Code Format" in self.response.Notifications:
65 raise FedexInvalidPostalCodeFormat(notification.Code,
66 notification.Message)
67 else:
68 raise FedexError(notification.Code,
69 notification.Message)
70
73
74
76 """
77 Fires off the Fedex request.
78
79 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES
80 ON FedexBaseService AND IS INHERITED.
81 """
82 client = self.client
83
84
85
86
87
88
89 del self.ClientDetail.IntegratorId
90
91
92 response = client.service.postalCodeInquiry(WebAuthenticationDetail=self.WebAuthenticationDetail,
93 ClientDetail=self.ClientDetail,
94 TransactionDetail=self.TransactionDetail,
95 Version=self.VersionId,
96 PostalCode = self.PostalCode,
97 CountryCode = self.CountryCode)
98
99 return response
100