|
13 | 13 |
|
14 | 14 | from example_config import CONFIG_OBJ |
15 | 15 | from fedex.services.rate_service import FedexRateServiceRequest |
| 16 | +from fedex.tools.conversion import sobject_to_dict |
16 | 17 |
|
17 | | -# Set this to the INFO level to see the response from Fedex printed in stdout. |
| 18 | +# Un-comment to see the response from Fedex printed in stdout. |
18 | 19 | logging.basicConfig(stream=sys.stdout, level=logging.INFO) |
19 | 20 |
|
20 | 21 | # This is the object that will be handling our request. |
|
98 | 99 | # good to un-comment to see the variables returned by the FedEx reply. |
99 | 100 | # print(rate_request.response) |
100 | 101 |
|
| 102 | +# This will convert the response to a python dict object. To |
| 103 | +# make it easier to work with. |
| 104 | +# from fedex.tools.conversion import basic_sobject_to_dict |
| 105 | +# print(basic_sobject_to_dict(rate_request.response)) |
| 106 | + |
| 107 | +# This will dump the response data dict to json. |
| 108 | +# from fedex.tools.conversion import sobject_to_json |
| 109 | +# print(sobject_to_json(rate_request.response)) |
| 110 | + |
101 | 111 | # Here is the overall end result of the query. |
102 | | -print("HighestSeverity:", rate_request.response.HighestSeverity) |
| 112 | +print("HighestSeverity: {}".format(rate_request.response.HighestSeverity)) |
103 | 113 |
|
104 | 114 | # RateReplyDetails can contain rates for multiple ServiceTypes if ServiceType was set to None |
105 | 115 | for service in rate_request.response.RateReplyDetails: |
106 | 116 | for detail in service.RatedShipmentDetails: |
107 | 117 | for surcharge in detail.ShipmentRateDetail.Surcharges: |
108 | 118 | if surcharge.SurchargeType == 'OUT_OF_DELIVERY_AREA': |
109 | | - print("%s: ODA rate_request charge %s" % (service.ServiceType, surcharge.Amount.Amount)) |
| 119 | + print("{}: ODA rate_request charge {}".format(service.ServiceType, surcharge.Amount.Amount)) |
110 | 120 |
|
111 | 121 | for rate_detail in service.RatedShipmentDetails: |
112 | | - print("%s: Net FedEx Charge %s %s" % (service.ServiceType, |
113 | | - rate_detail.ShipmentRateDetail.TotalNetFedExCharge.Currency, |
114 | | - rate_detail.ShipmentRateDetail.TotalNetFedExCharge.Amount)) |
| 122 | + print("{}: Net FedEx Charge {} {}".format(service.ServiceType, |
| 123 | + rate_detail.ShipmentRateDetail.TotalNetFedExCharge.Currency, |
| 124 | + rate_detail.ShipmentRateDetail.TotalNetFedExCharge.Amount)) |
| 125 | + |
| 126 | +# Not sure if 'NOTE' checking should be put in base class. |
| 127 | +# For now can check notifications manually. |
| 128 | +# if notification.Severity == 'NOTE': |
| 129 | +# self.logger.warning(FedexFailure(notification.Code, |
| 130 | +# notification.Message)) |
| 131 | +if rate_request.response.HighestSeverity == 'NOTE': |
| 132 | + for notification in rate_request.response.Notifications: |
| 133 | + if notification.Severity == 'NOTE': |
| 134 | + print(sobject_to_dict(notification)) |
0 commit comments