Skip to content

Commit a739ffe

Browse files
committed
add location serivce wsdl, base, test and example
1 parent 4981150 commit a739ffe

File tree

5 files changed

+2116
-0
lines changed

5 files changed

+2116
-0
lines changed

examples/location_request.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python
2+
"""
3+
This example shows how to use the FedEx Location service.
4+
The variables populated below represents the minimum required values.
5+
You will need to fill all of these, or risk seeing a SchemaValidationError
6+
exception thrown by suds.
7+
8+
"""
9+
import logging
10+
from example_config import CONFIG_OBJ
11+
from fedex.services.location_service import FedexSearchLocationRequest
12+
13+
# Set this to the INFO level to see the response from Fedex printed in stdout.
14+
logging.basicConfig(level=logging.INFO)
15+
16+
17+
# This is the object that will be handling our request.
18+
# We're using the FedexConfig object from example_config.py in this dir.
19+
customer_transaction_id = "*** LocationService Request v3 using Python ***" # Optional transaction_id
20+
location_request = FedexSearchLocationRequest(CONFIG_OBJ, customer_transaction_id=customer_transaction_id)
21+
22+
# Specify the type of search and search criteria.
23+
location_request.LocationsSearchCriterion = 'PHONE_NUMBER'
24+
location_request.PhoneNumber = '4169297819'
25+
location_request.MultipleMatchesAction = 'RETURN_ALL'
26+
27+
# Set constraints, see SearchLocationConstraints definition.
28+
location_request.Constraints.LocationTypesToInclude = ['FEDEX_SELF_SERVICE_LOCATION',
29+
'FEDEX_AUTHORIZED_SHIP_CENTER']
30+
31+
location_request.Address.PostalCode = '38119'
32+
location_request.Address.CountryCode = 'US'
33+
34+
# If you'd like to see some documentation on the ship service WSDL, un-comment
35+
# this line. (Spammy).
36+
# print(rate_request.client)
37+
38+
# Un-comment this to see your complete, ready-to-send request as it stands
39+
# before it is actually sent. This is useful for seeing what values you can
40+
# change.
41+
# print(location_request.LocationsSearchCriterion)
42+
43+
# Fires off the request, sets the 'response' attribute on the object.
44+
location_request.send_request()
45+
46+
# This will show the reply to your request being sent. You can access the
47+
# attributes through the response attribute on the request object. This is
48+
# good to un-comment to see the variables returned by the FedEx reply.
49+
# print(location_request.response)
50+
51+
# Here is the overall end result of the query.
52+
print("HighestSeverity:", location_request.response.HighestSeverity)
53+

fedex/services/location_service.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""
2+
Location Service Module
3+
=================================
4+
This package contains the shipping methods defined by Fedex's
5+
LocationService 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+
from ..base_service import FedexBaseService
11+
12+
13+
class FedexSearchLocationRequest(FedexBaseService):
14+
"""
15+
This class allows you validate service availability
16+
"""
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+
24+
self._config_obj = config_obj
25+
# Holds version info for the VersionId SOAP object.
26+
self._version_info = {
27+
'service_id': 'locs',
28+
'major': '3',
29+
'intermediate': '0',
30+
'minor': '0'
31+
}
32+
33+
"""@ivar: set default objects."""
34+
self.Address = None
35+
self.PhoneNumber = None
36+
self.MultipleMatchesAction = None
37+
self.Constraints = []
38+
self.LocationsSearchCriterion = None
39+
40+
"""@ivar: Holds the WSDL object."""
41+
42+
super(FedexSearchLocationRequest, self).__init__(
43+
self._config_obj, 'LocationsService_v3.wsdl', *args, **kwargs)
44+
45+
def _prepare_wsdl_objects(self):
46+
"""
47+
Create the data structure and get it ready for the WSDL request.
48+
"""
49+
self.MultipleMatchesAction = 'RETURN_ALL'
50+
self.Constraints = self.create_wsdl_object_of_type('SearchLocationConstraints')
51+
self.Address = self.create_wsdl_object_of_type('Address')
52+
53+
def _assemble_and_send_request(self):
54+
"""
55+
Fires off the Fedex request.
56+
57+
@warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(),
58+
WHICH RESIDES ON FedexBaseService AND IS INHERITED.
59+
"""
60+
61+
# We get an exception like this when specifying an IntegratorId:
62+
# suds.TypeNotFound: Type not found: 'IntegratorId'
63+
# Setting it to None does not seem to appease it.
64+
del self.ClientDetail.IntegratorId
65+
self.logger.debug(self.WebAuthenticationDetail)
66+
self.logger.debug(self.ClientDetail)
67+
self.logger.debug(self.TransactionDetail)
68+
self.logger.debug(self.VersionId)
69+
# Fire off the query.
70+
return self.client.service.searchLocations(
71+
WebAuthenticationDetail=self.WebAuthenticationDetail,
72+
ClientDetail=self.ClientDetail,
73+
TransactionDetail=self.TransactionDetail,
74+
Version=self.VersionId,
75+
LocationsSearchCriterion=self.LocationsSearchCriterion,
76+
PhoneNumber=self.PhoneNumber,
77+
MultipleMatchesAction=self.MultipleMatchesAction,
78+
Constraints=self.Constraints,
79+
Address=self.Address)

0 commit comments

Comments
 (0)