|
| 1 | +""" |
| 2 | +Service Availability and Commitment Module |
| 3 | +================================= |
| 4 | +This package contains the shipping methods defined by Fedex's |
| 5 | +ValidationAvailabilityAndCommitmentService 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 FedexAvailabilityCommitmentRequest(FedexBaseService): |
| 15 | + """ |
| 16 | + This class allows you validate service availability |
| 17 | + """ |
| 18 | + |
| 19 | + def __init__(self, config_obj, *args, **kwargs): |
| 20 | + """ |
| 21 | + @type config_obj: L{FedexConfig} |
| 22 | + @param config_obj: A valid FedexConfig object. |
| 23 | + """ |
| 24 | + |
| 25 | + self._config_obj = config_obj |
| 26 | + # Holds version info for the VersionId SOAP object. |
| 27 | + self._version_info = { |
| 28 | + 'service_id': 'vacs', |
| 29 | + 'major': '4', |
| 30 | + 'intermediate': '0', |
| 31 | + 'minor': '0' |
| 32 | + } |
| 33 | + |
| 34 | + """ivar: Carrier Code Default to Fedex (FDXE), or can bbe FDXG.""" |
| 35 | + self.CarrierCode = None |
| 36 | + |
| 37 | + """@ivar: Holds Addresses, Ship Date, Service and Packaging objects.""" |
| 38 | + self.Origin = self.Destination = None |
| 39 | + self.ShipDate = None |
| 40 | + self.Service = None |
| 41 | + self.Packaging = None |
| 42 | + |
| 43 | + """@ivar: Holds the ValidationAvailabilityAndCommitmentService WSDL object.""" |
| 44 | + # Call the parent FedexBaseService class for basic setup work. |
| 45 | + # Shortened the name of the wsdl, otherwise suds did not load it properly. |
| 46 | + # Suds throws the following error when using the long file name from FedEx: |
| 47 | + # |
| 48 | + # File "/Library/Python/2.7/site-packages/suds/wsdl.py", line 878, in resolve |
| 49 | + # raise Exception("binding '%s', not-found" % p.binding) |
| 50 | + # Exception: binding 'ns:ValidationAvailabilityAndCommitmentServiceSoapBinding', not-found |
| 51 | + |
| 52 | + super(FedexAvailabilityCommitmentRequest, self).__init__( |
| 53 | + self._config_obj, 'AvailabilityAndCommitmentService_v4.wsdl', *args, **kwargs) |
| 54 | + |
| 55 | + def _prepare_wsdl_objects(self): |
| 56 | + """ |
| 57 | + Create the data structure and get it ready for the WSDL request. |
| 58 | + """ |
| 59 | + self.CarrierCode = 'FDXE' |
| 60 | + self.Origin = self.Destination = self.client.factory.create('Address') |
| 61 | + self.ShipDate = datetime.date.today().isoformat() |
| 62 | + self.Service = None |
| 63 | + self.Packaging = 'YOUR_PACKAGING' |
| 64 | + |
| 65 | + def _assemble_and_send_request(self): |
| 66 | + """ |
| 67 | + Fires off the Fedex request. |
| 68 | + |
| 69 | + @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), |
| 70 | + WHICH RESIDES ON FedexBaseService AND IS INHERITED. |
| 71 | + """ |
| 72 | + |
| 73 | + # We get an exception like this when specifying an IntegratorId: |
| 74 | + # suds.TypeNotFound: Type not found: 'IntegratorId' |
| 75 | + # Setting it to None does not seem to appease it. |
| 76 | + del self.ClientDetail.IntegratorId |
| 77 | + self.logger.debug(self.WebAuthenticationDetail) |
| 78 | + self.logger.debug(self.ClientDetail) |
| 79 | + self.logger.debug(self.TransactionDetail) |
| 80 | + self.logger.debug(self.VersionId) |
| 81 | + # Fire off the query. |
| 82 | + return self.client.service.serviceAvailability( |
| 83 | + WebAuthenticationDetail=self.WebAuthenticationDetail, |
| 84 | + ClientDetail=self.ClientDetail, |
| 85 | + TransactionDetail=self.TransactionDetail, |
| 86 | + Version=self.VersionId, |
| 87 | + Origin=self.Origin, |
| 88 | + Destination=self.Destination, |
| 89 | + ShipDate=self.ShipDate, |
| 90 | + CarrierCode=self.CarrierCode, |
| 91 | + Service=self.Service, |
| 92 | + Packaging=self.Packaging) |
0 commit comments