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