1+ import os
2+ import logging
3+ from suds .client import Client
4+
5+ class FedexBaseService (object ):
6+ def __init__ (self , config_obj , wsdl_name , * args , ** kwargs ):
7+ self .config_obj = config_obj
8+ self .wsdl_path = os .path .join (config_obj .wsdl_path , wsdl_name )
9+ self .client = Client ('file://%s' % self .wsdl_path )
10+ self .logger = logging .getLogger ('fedex' )
11+
12+ self .logger .debug (self .client )
13+ self .set_web_authentication_detail ()
14+ self .set_client_detail ()
15+ self .set_version_id ()
16+ self .set_carrier_code_type (* args , ** kwargs )
17+ self .set_transaction_detail (* args , ** kwargs )
18+
19+ def set_web_authentication_detail (self ):
20+ """
21+ Sets up the WebAuthenticationDetail node. This is required for all
22+ requests.
23+ """
24+ # Start of the authentication stuff.
25+ WebAuthenticationCredential = self .client .factory .create ('WebAuthenticationCredential' )
26+ WebAuthenticationCredential .Key = self .config_obj .key
27+ WebAuthenticationCredential .Password = self .config_obj .password
28+
29+ # Encapsulates the auth credentials.
30+ WebAuthenticationDetail = self .client .factory .create ('WebAuthenticationDetail' )
31+ WebAuthenticationDetail .UserCredential = WebAuthenticationCredential
32+ self .logger .debug (WebAuthenticationDetail )
33+ self .WebAuthenticationDetail = WebAuthenticationDetail
34+
35+ def set_client_detail (self ):
36+ """
37+ Sets up the ClientDetail node, which is required for all shipping
38+ related requests.
39+ """
40+ ClientDetail = self .client .factory .create ('ClientDetail' )
41+ ClientDetail .AccountNumber = self .config_obj .account_number
42+ ClientDetail .MeterNumber = self .config_obj .meter_number
43+ ClientDetail .IntegratorId = self .config_obj .integrator_id
44+ self .logger .debug (ClientDetail )
45+ self .ClientDetail = ClientDetail
46+
47+ def set_transaction_detail (self , * args , ** kwargs ):
48+ """
49+ Checks kwargs for 'customer_transaction_id' and sets it if present.
50+ """
51+ customer_transaction_id = kwargs .get ('customer_transaction_id' , False )
52+ if customer_transaction_id :
53+ TransactionDetail = client .factory .create ('TransactionDetail' )
54+ TransactionDetail .CustomerTransactionId = customer_transaction_id
55+ self .logger .debug (TransactionDetail )
56+ self .TransactionDetail = TransactionDetail
57+ else :
58+ self .TransactionDetail = None
59+
60+ def set_carrier_code_type (self , * args , ** kwargs ):
61+ """
62+ Checks kwargs for 'carrier_code' and sets it if present.
63+ """
64+ carrier_code = kwargs .get ('carrier_code' , False )
65+ if carrier_code :
66+ CarrierCodeType = self .client .factory .create ('CarrierCodeType' )
67+ CarrierCodeType .Type = carrier_code
68+ self .logger .debug (CarrierCodeType )
69+ self .CarrierCodeType = CarrierCodeType
70+ else :
71+ self .CarrierCodeType = None
72+
73+ def set_version_id (self ):
74+ """
75+ Pulles the versioning info for the request from the child request.
76+ """
77+ VersionId = self .client .factory .create ('VersionId' )
78+ VersionId .ServiceId = self .version_info ['service_id' ]
79+ VersionId .Major = self .version_info ['major' ]
80+ VersionId .Intermediate = self .version_info ['intermediate' ]
81+ VersionId .Minor = self .version_info ['minor' ]
82+ self .logger .debug (VersionId )
83+ self .VersionId = VersionId
84+
85+ def send_request (self ):
86+ """
87+ Sends the assembled request on the child object.
88+ """
89+ self .response = self .assemble_and_send_request ()
90+ self .logger .info ("== FEDEX QUERY RESULT ==" )
91+ self .logger .info (self .response )
0 commit comments