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  from datetime import datetime 
10  from .. base_service import FedexBaseService 
11   
12 -class FedexAddressValidationRequest(FedexBaseService):
13 """ 14 This class allows you validate anywhere from one to a hundred addresses 15 in one go. Create AddressToValidate WSDL objects and add them to each 16 instance of this request using add_address(). 17 """
18 - def __init__(self, config_obj, *args, **kwargs):
19 """ 20 @type config_obj: L{FedexConfig} 21 @param config_obj: A valid FedexConfig object. 22 """ 23 self._config_obj = config_obj 24 25 # Holds version info for the VersionId SOAP object. 26 self._version_info = {'service_id': 'aval', 'major': '2', 27 'intermediate': '0', 'minor': '0'} 28 29 self.AddressValidationOptions = None 30 """@ivar: Holds the AddressValidationOptions WSDL object.""" 31 self.addresses_to_validate = [] 32 """@ivar: Holds the AddressToValidate WSDL object.""" 33 # Call the parent FedexBaseService class for basic setup work. 34 super(FedexAddressValidationRequest, self).__init__(self._config_obj, 35 'AddressValidationService_v2.wsdl', 36 *args, **kwargs)
37
38 - def _prepare_wsdl_objects(self):
39 """ 40 Create the data structure and get it ready for the WSDL request. 41 """ 42 # This holds some optional options for the request.. 43 self.AddressValidationOptions = self.client.factory.create('AddressValidationOptions') 44 45 # This is good to review if you'd like to see what the data structure 46 # looks like. 47 self.logger.debug(self.AddressValidationOptions)
48
50 """ 51 Fires off the Fedex request. 52 53 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), 54 WHICH RESIDES ON FedexBaseService AND IS INHERITED. 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 response = self.client.service.addressValidation(WebAuthenticationDetail=self.WebAuthenticationDetail, 66 ClientDetail=self.ClientDetail, 67 TransactionDetail=self.TransactionDetail, 68 Version=self.VersionId, 69 RequestTimestamp=datetime.now(), 70 Options=self.AddressValidationOptions, 71 AddressesToValidate=self.addresses_to_validate) 72 return response
73
74 - def add_address(self, address_item):
75 """ 76 Adds an address to self.addresses_to_validate. 77 78 @type address_item: WSDL object, type of AddressToValidate WSDL object. 79 @keyword address_item: A AddressToValidate, created by 80 calling create_wsdl_object_of_type('AddressToValidate') on 81 this FedexAddressValidationRequest object. 82 See examples/create_shipment.py for more details. 83 """ 84 self.addresses_to_validate.append(address_item)
85