Skip to content

Commit 3640624

Browse files
author
Greg Taylor
committed
This has been done pretty much blindly, as I'm running into authentication errors. Address validation -might- work, but I need someone whose account isn't acting strange to test this.
Also more comment fixes on ship_service.py.
1 parent c8ff959 commit 3640624

File tree

5 files changed

+120
-9
lines changed

5 files changed

+120
-9
lines changed

examples/__init__.py

100644100755
File mode changed.

examples/address_validation.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
"""
3+
This example shows how to validate addresses. Note that the validation
4+
class can handle up to 100 addresses for validation.
5+
"""
6+
import logging
7+
import binascii
8+
from example_config import CONFIG_OBJ
9+
from fedex.services.address_validation_service import FedexAddressValidationRequest
10+
11+
# Set this to the INFO level to see the response from Fedex printed in stdout.
12+
logging.basicConfig(level=logging.INFO)
13+
14+
# This is the object that will be handling our tracking request.
15+
# We're using the FedexConfig object from example_config.py in this dir.
16+
address = FedexAddressValidationRequest(CONFIG_OBJ)
17+
18+
address1 = address.create_wsdl_object_of_type('AddressToValidate')
19+
address1.CompanyName = 'International Paper'
20+
address1.Address.StreetLines = ['155 Old Greenville Hwy', 'Suite 103']
21+
address1.Address.City = 'Clemson'
22+
address1.Address.StateOrProvinceCode = 'SC'
23+
address1.Address.PostalCode = 29631
24+
address1.Address.CountryCode = 'US'
25+
address1.Address.Residential = False
26+
27+
address.add_address(address1)
28+
address.send_request()
29+
print address.response

fedex/base_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(self, config_obj, wsdl_name, *args, **kwargs):
8181

8282
self.client = Client('file://%s' % self.wsdl_path)
8383

84-
print self.client
84+
#print self.client
8585

8686
self.VersionId = None
8787
"""@ivar: Holds details on the version numbers of the WSDL."""
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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': 'ship', '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+
49+
def _assemble_and_send_request(self):
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+
AddressToValidate=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)

fedex/services/ship_service.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010

1111
class FedexProcessShipmentRequest(FedexBaseService):
1212
"""
13-
This class allows you to track shipments by providing a tracking
14-
number or other identifying features. By default, you
15-
can simply pass a tracking number to the constructor. If you would like
16-
to query shipments based on something other than tracking number, you will
17-
want to read the documentation for the L{__init__} method.
18-
Particularly, the tracking_value and package_identifier arguments.
13+
This class allows you to process (create) a new FedEx shipment. You will
14+
need to populate the data structures in self.RequestedShipment, then
15+
send the request. Label printing is supported and very configurable,
16+
returning an ASCII representation with the response as well.
1917
"""
2018
def __init__(self, config_obj, *args, **kwargs):
2119
"""
22-
Sends a shipment tracking request. The optional keyword args
23-
detailed on L{FedexBaseService} apply here as well.
20+
The optional keyword args detailed on L{FedexBaseService}
21+
apply here as well.
2422
2523
@type config_obj: L{FedexConfig}
2624
@param config_obj: A valid FedexConfig object.

0 commit comments

Comments
 (0)