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

Source Code for Module fedex.services.address_validation_service

 1  """ 
 2  Address Validation Service Module 
 3   
 4  This package contains the shipping methods defined by Fedex's  
 5  AddressValidationService WSDL file. Each is encapsulated in a class for  
 6  easy access. For more details on each, refer to the respective class's  
 7  documentation. 
 8  """ 
 9   
10  import datetime 
11  from ..base_service import FedexBaseService 
12   
13   
14 -class FedexAddressValidationRequest(FedexBaseService):
15 """ 16 This class allows you validate anywhere from one to a hundred addresses 17 in one go. Create AddressToValidate WSDL objects and add them to each 18 instance of this request using add_address(). 19 """ 20
21 - def __init__(self, config_obj, *args, **kwargs):
22 """ 23 @type config_obj: L{FedexConfig} 24 @param config_obj: A valid FedexConfig object. 25 """ 26 27 self._config_obj = config_obj 28 # Holds version info for the VersionId SOAP object. 29 self._version_info = { 30 'service_id': 'aval', 31 'major': '4', 32 'intermediate': '0', 33 'minor': '0' 34 } 35 36 self.AddressesToValidate = [] 37 """@ivar: Holds the AddressToValidate WSDL object.""" 38 # Call the parent FedexBaseService class for basic setup work. 39 super(FedexAddressValidationRequest, self).__init__( 40 self._config_obj, 'AddressValidationService_v4.wsdl', *args, **kwargs)
41
42 - def _prepare_wsdl_objects(self):
43 """ 44 Create the data structure and get it ready for the WSDL request. 45 """ 46 pass
47
49 """ 50 Fires off the Fedex request. 51 52 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), 53 WHICH RESIDES ON FedexBaseService AND IS INHERITED. 54 """ 55 56 # We get an exception like this when specifying an IntegratorId: 57 # suds.TypeNotFound: Type not found: 'IntegratorId' 58 # Setting it to None does not seem to appease it. 59 del self.ClientDetail.IntegratorId 60 self.logger.debug(self.WebAuthenticationDetail) 61 self.logger.debug(self.ClientDetail) 62 self.logger.debug(self.TransactionDetail) 63 self.logger.debug(self.VersionId) 64 # Fire off the query. 65 return self.client.service.addressValidation( 66 WebAuthenticationDetail=self.WebAuthenticationDetail, 67 ClientDetail=self.ClientDetail, 68 TransactionDetail=self.TransactionDetail, 69 Version=self.VersionId, 70 InEffectAsOfTimestamp=datetime.datetime.now(), 71 AddressesToValidate=self.AddressesToValidate)
72
73 - def add_address(self, address_item):
74 """ 75 Adds an address to self.AddressesToValidate. 76 77 @type address_item: WSDL object, type of AddressToValidate WSDL object. 78 @keyword address_item: A AddressToValidate, created by 79 calling create_wsdl_object_of_type('AddressToValidate') on 80 this FedexAddressValidationRequest object. 81 See examples/create_shipment.py for more details. 82 """ 83 84 self.AddressesToValidate.append(address_item)
85