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

Source Code for Module fedex.services.package_movement

  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 warnings 
  8   
  9  from ..base_service import FedexBaseService, FedexError 
 10   
 11   
12 -class FedexPostalCodeNotFound(FedexError):
13 """ 14 Exception: Sent when the postalcode is missing. 15 """ 16 pass
17 18
19 -class FedexInvalidPostalCodeFormat(FedexError):
20 """ 21 Exception: Sent when the postal code is invalid 22 """ 23 pass
24 25
26 -class PostalCodeInquiryRequest(FedexBaseService):
27 """ 28 The postal code inquiry enables customers to validate postal codes 29 and service commitments. 30 """ 31
32 - def __init__(self, config_obj, postal_code=None, country_code=None, *args, **kwargs):
33 """ 34 Sets up an inquiry request. The optional keyword args 35 detailed on L{FedexBaseService} apply here as well. 36 37 @type config_obj: L{FedexConfig} 38 @param config_obj: A valid FedexConfig object 39 @param postal_code: a valid postal code 40 @param country_code: ISO country code to which the postal code belongs to. 41 """ 42 self._config_obj = config_obj 43 44 # Holds version info for the VersionId SOAP object. 45 self._version_info = {'service_id': 'pmis', 46 'major': '4', 47 'intermediate': '0', 48 'minor': '0'} 49 50 self.PostalCode = postal_code 51 self.CountryCode = country_code 52 53 warnings.warn( 54 "Package Movement Service has been deprecated; " 55 "please use Country Service for postal code validation requests or " 56 "Availability and Commitment Service for service availability " 57 "requests instead.", 58 DeprecationWarning 59 ) 60 61 # Call the parent FedexBaseService class for basic setup work. 62 super(PostalCodeInquiryRequest, self).__init__(self._config_obj, 63 'PackageMovementInformationService_v4.wsdl', 64 *args, **kwargs)
65
67 """ 68 Checks the response to see if there were any errors specific to 69 this WSDL. 70 """ 71 if self.response.HighestSeverity == "ERROR": 72 for notification in self.response.Notifications: # pragma: no cover 73 if notification.Severity == "ERROR": 74 if "Postal Code Not Found" in notification.Message: 75 raise FedexPostalCodeNotFound(notification.Code, 76 notification.Message) 77 78 elif "Invalid Postal Code Format" in self.response.Notifications: 79 raise FedexInvalidPostalCodeFormat(notification.Code, 80 notification.Message) 81 else: 82 raise FedexError(notification.Code, 83 notification.Message)
84
85 - def _prepare_wsdl_objects(self):
86 """ 87 Preps the WSDL data structures for the user. 88 """ 89 90 self.CarrierCode = 'FDXE'
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 # We get an exception like this when specifying an IntegratorId: 103 # suds.TypeNotFound: Type not found: 'IntegratorId' 104 # Setting it to None does not seem to appease it. 105 106 del self.ClientDetail.IntegratorId 107 108 # Fire off the query. 109 response = client.service.postalCodeInquiry(WebAuthenticationDetail=self.WebAuthenticationDetail, 110 ClientDetail=self.ClientDetail, 111 TransactionDetail=self.TransactionDetail, 112 Version=self.VersionId, 113 PostalCode=self.PostalCode, 114 CountryCode=self.CountryCode, 115 CarrierCode=self.CarrierCode) 116 117 return response
118