Skip to content

Commit 0ee1c28

Browse files
committed
update and refactor
1 parent 4e42403 commit 0ee1c28

13 files changed

+77
-47
lines changed

examples/address_validation.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class can handle up to 100 addresses for validation.
1313
# Set this to the INFO level to see the response from Fedex printed in stdout.
1414
logging.basicConfig(level=logging.INFO)
1515

16-
# This is the object that will be handling our tracking request.
16+
# This is the object that will be handling our avs request.
1717
# We're using the FedexConfig object from example_config.py in this dir.
1818
customer_transaction_id = "*** AddressValidation Request v4 using Python ***" # Optional transaction_id
1919
# Optional locale & language client data
@@ -68,27 +68,35 @@ class can handle up to 100 addresses for validation.
6868
# Overall end result of the query
6969
for i in range(len(avs_request.response.AddressResults)):
7070

71-
print("Details for Address", i + 1)
72-
print("The validated street is:", avs_request.response.AddressResults[i].EffectiveAddress.StreetLines)
73-
print("The validated city is:", avs_request.response.AddressResults[i].EffectiveAddress.City)
74-
print("The validated state code is:", avs_request.response.AddressResults[i].EffectiveAddress.StateOrProvinceCode)
75-
print("The validated postal code is:", avs_request.response.AddressResults[i].EffectiveAddress.PostalCode)
76-
print("The validated country code is:", avs_request.response.AddressResults[i].EffectiveAddress.CountryCode)
71+
print("Details for Address {}".format(i + 1))
72+
print("The validated street is: {}"
73+
"".format(avs_request.response.AddressResults[i].EffectiveAddress.StreetLines))
74+
print("The validated city is: {}"
75+
"".format(avs_request.response.AddressResults[i].EffectiveAddress.City))
76+
print("The validated state code is: {}"
77+
"".format(avs_request.response.AddressResults[i].EffectiveAddress.StateOrProvinceCode))
78+
print("The validated postal code is: {}"
79+
"".format(avs_request.response.AddressResults[i].EffectiveAddress.PostalCode))
80+
print("The validated country code is: {}"
81+
"".format(avs_request.response.AddressResults[i].EffectiveAddress.CountryCode))
7782

7883
# Can be used to determine the address classification to figure out if Residential fee should apply.
7984
# MIXED, RESIDENTIAL, UNKNOWN, BUSINESS
80-
print("The validated address is residential:", avs_request.response.AddressResults[i].Classification != 'BUSINESS')
85+
print("The validated address is residential: {}"
86+
"".format(avs_request.response.AddressResults[i].Classification != 'BUSINESS'))
8187

8288
# Getting the optional attributes if available
8389
for j in range(len(avs_request.response.AddressResults[i].Attributes)):
8490
cur_attribute = avs_request.response.AddressResults[i].Attributes[j]
8591
if cur_attribute.Name == "CountrySupported":
86-
print("Supported Country:", cur_attribute.Value == 'true')
92+
print("Supported Country: {}".format(cur_attribute.Value == 'true'))
8793
if cur_attribute.Name == "SuiteRequiredButMissing":
88-
print("Missing Suite:", cur_attribute.Value == 'true')
94+
print("Missing Suite: {}".format(cur_attribute.Value == 'true'))
8995
if cur_attribute.Name == "CountrySupported":
90-
print("Invalid Suite:", cur_attribute.Value == 'true')
96+
print("Invalid Suite: {}".format(cur_attribute.Value == 'true'))
9197
if cur_attribute.Name == "MultipleMatches":
92-
print("Multiple Matches:", cur_attribute.Value == 'true')
98+
print("Multiple Matches: {}".format(cur_attribute.Value == 'true'))
9399
if cur_attribute.Name == "POBox":
94-
print("Is POBox:", cur_attribute.Value == 'true')
100+
print("Is POBox: {}".format(cur_attribute.Value == 'true'))
101+
print("")
102+

examples/create_freight_shipment.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# NOTE: A VALID 'freight_account_number' REQUIRED IN YOUR 'CONFIB_OBJ' FOR THIS SERVICE TO WORK.
2525
# OTHERWISE YOU WILL GET FEDEX FREIGHT OR ASSOCIATED ADDRESS IS REQUIRED, ERROR 3619.
2626

27-
# This is the object that will be handling our tracking request.
27+
# This is the object that will be handling our freight shipment request.
2828
# We're using the FedexConfig object from example_config.py in this dir.
2929
shipment = FedexProcessShipmentRequest(CONFIG_OBJ)
3030
shipment.RequestedShipment.DropoffType = 'REGULAR_PICKUP'
@@ -148,12 +148,17 @@
148148
# attributes through the response attribute on the request object. This is
149149
# good to un-comment to see the variables returned by the Fedex reply.
150150
print(shipment.response)
151+
151152
# Here is the overall end result of the query.
152-
# print("HighestSeverity:", shipment.response.HighestSeverity)
153-
# # Getting the tracking number from the new shipment.
154-
# print("Tracking #:", shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].TrackingIds[0].TrackingNumber)
155-
# # Net shipping costs.
156-
# print("Net Shipping Cost (US$):", shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].PackageRating.PackageRateDetails[0].NetCharge.Amount)
153+
print("HighestSeverity: {}".format(shipment.response.HighestSeverity))
154+
155+
# Getting the tracking number from the new shipment.
156+
print("Tracking #: {}"
157+
"".format(shipment.response.CompletedShipmentDetail.MasterTrackingId.TrackingNumber))
158+
159+
# Net shipping costs.
160+
amount = shipment.response.CompletedShipmentDetail.ShipmentRating.ShipmentRateDetails[0].TotalNetCharge.Amount
161+
print("Net Shipping Cost (US$): {}".format(amount))
157162

158163

159164
# # Get the label image in ASCII format from the reply. Note the list indices
@@ -170,7 +175,7 @@
170175
"""
171176
# This will be the file we write the label out to.
172177
out_path = 'example_freight_shipment_label.%s' % GENERATE_IMAGE_TYPE.lower()
173-
print("Writing to file", out_path)
178+
print("Writing to file {}".format(out_path))
174179
out_file = open(out_path, 'wb')
175180
out_file.write(label_binary_data)
176181
out_file.close()

examples/create_shipment.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# Set this to the INFO level to see the response from Fedex printed in stdout.
2323
logging.basicConfig(level=logging.INFO)
2424

25-
# This is the object that will be handling our tracking request.
25+
# This is the object that will be handling our shipment request.
2626
# We're using the FedexConfig object from example_config.py in this dir.
2727
customer_transaction_id = "*** ShipService Request v17 using Python ***" # Optional transaction_id
2828
shipment = FedexProcessShipmentRequest(CONFIG_OBJ, customer_transaction_id=customer_transaction_id)
@@ -143,17 +143,19 @@
143143
print(shipment.response)
144144

145145
# Here is the overall end result of the query.
146-
print("HighestSeverity:", shipment.response.HighestSeverity)
146+
print("HighestSeverity: {}".format(shipment.response.HighestSeverity))
147147

148148
# Getting the tracking number from the new shipment.
149-
print("Tracking #:", shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].TrackingIds[0].TrackingNumber)
149+
print("Tracking #: {}"
150+
"".format(shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].TrackingIds[0].TrackingNumber))
150151

151152
# Net shipping costs. Only show if available. Sometimes sandbox will not include this in the response.
152153
CompletedPackageDetails = shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0]
153154
if hasattr(CompletedPackageDetails, 'PackageRating'):
154-
print("Net Shipping Cost (US$):", CompletedPackageDetails.PackageRating.PackageRateDetails[0].NetCharge.Amount)
155+
print("Net Shipping Cost (US$): {}"
156+
"".format(CompletedPackageDetails.PackageRating.PackageRateDetails[0].NetCharge.Amount))
155157
else:
156-
print('WARNING: Unable to get rate.')
158+
print('WARNING: Unable to get shipping rate.')
157159

158160
# Get the label image in ASCII format from the reply. Note the list indices
159161
# we're using. You'll need to adjust or iterate through these if your shipment
@@ -169,7 +171,7 @@
169171
"""
170172
# This will be the file we write the label out to.
171173
out_path = 'example_shipment_label.%s' % GENERATE_IMAGE_TYPE.lower()
172-
print("Writing to file", out_path)
174+
print("Writing to file {}".format(out_path))
173175
out_file = open(out_path, 'wb')
174176
out_file.write(label_binary_data)
175177
out_file.close()

examples/delete_shipment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Set this to the INFO level to see the response from Fedex printed in stdout.
1010
logging.basicConfig(level=logging.INFO)
1111

12-
# This is the object that will be handling our tracking request.
12+
# This is the object that will be handling our request.
1313
# We're using the FedexConfig object from example_config.py in this dir.
1414
del_request = FedexDeleteShipmentRequest(CONFIG_OBJ)
1515

examples/freight_rate_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Set this to the INFO level to see the response from Fedex printed in stdout.
1616
logging.basicConfig(level=logging.INFO)
1717

18-
# This is the object that will be handling our tracking request.
18+
# This is the object that will be handling our request.
1919
# We're using the FedexConfig object from example_config.py in this dir.
2020
rate_request = FedexRateServiceRequest(CONFIG_OBJ)
2121

examples/rate_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
logging.basicConfig(level=logging.INFO)
1717

1818

19-
# This is the object that will be handling our tracking request.
19+
# This is the object that will be handling our request.
2020
# We're using the FedexConfig object from example_config.py in this dir.
2121
customer_transaction_id = "*** RateService Request v18 using Python ***" # Optional transaction_id
2222
rate_request = FedexRateServiceRequest(CONFIG_OBJ, customer_transaction_id=customer_transaction_id)

examples/service_availability_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# This will show the reply to your avc_request being sent. You can access the
5656
# attributes through the response attribute on the request object. This is
5757
# good to un-comment to see the variables returned by the FedEx reply.
58-
#print(avc_request.response)
58+
print(avc_request.response)
5959

6060
# Here is the overall end result of the query.
6161
print("HighestSeverity: {}".format(avc_request.response.HighestSeverity))

examples/track_shipment.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,31 @@
4343
# Fires off the request, sets the 'response' attribute on the object.
4444
track.send_request()
4545

46-
# See the response printed out.
46+
# This will show the reply to your track 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.
4749
print(track.response)
4850

4951
# Look through the matches (there should only be one for a tracking number
5052
# query), and show a few details about each shipment.
5153
print("== Results ==")
52-
#print(track.response)
5354
for match in track.response.CompletedTrackDetails[0].TrackDetails:
54-
print("Tracking #:", match.TrackingNumber)
55-
print("Tracking # UniqueID:", match.TrackingNumberUniqueIdentifier)
56-
print("Status:", match.StatusDetail.Description)
57-
print("Status AncillaryDetails Reason:", match.StatusDetail.AncillaryDetails[-1].Reason)
58-
print("Status AncillaryDetails Description:", match.StatusDetail.AncillaryDetails[-1].ReasonDescription)
59-
print("Commit Message:", match.ServiceCommitMessage)
55+
print("Tracking #: {}".format(match.TrackingNumber))
56+
print("Tracking # UniqueID: {}".format(match.TrackingNumberUniqueIdentifier))
57+
print("Status: {}".format(match.StatusDetail.Description))
58+
print("Status AncillaryDetails Reason: {}".format(match.StatusDetail.AncillaryDetails[-1].Reason))
59+
print("Status AncillaryDetails Description:{}".format(match.StatusDetail.AncillaryDetails[-1].ReasonDescription))
60+
print("Commit Message:{}".format(match.ServiceCommitMessage))
61+
print("")
62+
63+
event_details = []
64+
if hasattr(match, 'Events'):
65+
for j in range(len(match.Events)):
66+
event_match = match.Events[j]
67+
event_details.append({'created': event_match.Timestamp, 'type': event_match.EventType,
68+
'description': event_match.EventDescription})
69+
70+
if hasattr(event_match, 'StatusExceptionDescription'):
71+
event_details[j]['exception_description'] = event_match.StatusExceptionDescription
72+
73+
print("Event {}: {}".format(j+1, event_details[j]))

fedex/services/address_validation_service.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
documentation.
88
"""
99

10-
from datetime import datetime
10+
import datetime
1111
from .. base_service import FedexBaseService
1212

1313

@@ -33,7 +33,6 @@ def __init__(self, config_obj, *args, **kwargs):
3333
'minor': '0'
3434
}
3535

36-
# self.AddressValidationOptions = None
3736
"""@ivar: Holds the AddressValidationOptions WSDL object."""
3837
self.AddressesToValidate = []
3938
"""@ivar: Holds the AddressToValidate WSDL object."""
@@ -69,7 +68,7 @@ def _assemble_and_send_request(self):
6968
ClientDetail=self.ClientDetail,
7069
TransactionDetail=self.TransactionDetail,
7170
Version=self.VersionId,
72-
InEffectAsOfTimestamp=datetime.now(),
71+
InEffectAsOfTimestamp=datetime.datetime.now(),
7372
AddressesToValidate=self.AddressesToValidate)
7473

7574
def add_address(self, address_item):

fedex/services/availability_commitment_service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ def __init__(self, config_obj, *args, **kwargs):
3434
"""ivar: Carrier Code Default to Fedex (FDXE), or can bbe FDXG."""
3535
self.CarrierCode = None
3636

37-
"""@ivar: Holds Addresses and Ship Date objects."""
37+
"""@ivar: Holds Addresses, Ship Date, Service and Packaging objects."""
3838
self.Origin = self.Destination = None
3939
self.ShipDate = None
40+
self.Service = None
41+
self.Packaging = None
4042

4143
"""@ivar: Holds the ValidationAvailabilityAndCommitmentService WSDL object."""
4244
# Call the parent FedexBaseService class for basic setup work.

0 commit comments

Comments
 (0)