11'''
2- Created on Jul 6 , 2015
2+ Created on Nov 1 , 2015
33
4- @author: egodolja
4+ @author: krgupta
55'''
66import abc
77import logging
88import os
9+ from os .path import expanduser
10+
911import sys
1012import xml .dom .minidom
1113
1214from pip ._vendor import requests
1315from _pyio import __metaclass__
1416from ConfigParser import SafeConfigParser
17+ import ConfigParser
1518
1619from authorizenet .constants import constants
1720from authorizenet import apicontractsv1
@@ -34,27 +37,27 @@ def getresponseclass(self):
3437 pass
3538
3639 @abc .abstractmethod
37- def getResponse (self ):
40+ def getresponse (self ):
3841 ''' Returns the de-serialized response'''
3942 pass
4043
4144 @abc .abstractmethod
42- def getResultCode (self ):
45+ def getresultcode (self ):
4346 ''' Returns the result code from the response '''
4447 pass
4548
4649 @abc .abstractmethod
47- def getMessageType (self ):
50+ def getmessagetype (self ):
4851 ''' Returns the message type enum from the response '''
4952 pass
5053
5154 @abc .abstractmethod
52- def afterExecute (self ):
53- '''TODO '''
55+ def afterexecute (self ):
56+ '''Returns the message received from binding after processing request '''
5457 pass
5558
5659 @abc .abstractmethod
57- def beforeExecute (self ):
60+ def beforeexecute (self ):
5861 '''TODO'''
5962 pass
6063
@@ -63,16 +66,28 @@ class APIOperationBase(APIOperationBaseInterface):
6366
6467 parser = SafeConfigParser ({"http" :"" ,"https" :"" ,"ftp" :"" })
6568
69+
6670 try :
67- #if #TODO
68- parser .read (os .path .dirname (__file__ ) + "/../properties.ini" )
71+ #if #TODO
72+ home = os .path .expanduser ("~" )
73+ homedirpropertiesfilename = os .path .join (home , "anet_python_sdk_properties.ini" )
74+
75+ currdir = os .getcwd ()
76+ currdirpropertiesfilename = os .path .join (currdir , "anet_python_sdk_properties.ini" )
77+
78+ if (os .path .exists (homedirpropertiesfilename )):
79+ parser .read (homedirpropertiesfilename )
80+ elif (os .path .exists (currdirpropertiesfilename )):
81+ parser .read (currdirpropertiesfilename )
82+ else :
83+ print "you do not have anet_python_sdk_properties.ini file neither in home nor in current working directory"
6984 except IOError , error :
7085 sys .exit ( error )
7186 else :
7287 logFile = parser .get ("properties" , "logfilename" )
7388 #TODO format and level in config file
7489 logging .basicConfig (filename = logFile , level = logging .DEBUG , format = '%(asctime)s %(message)s' )
75- endpoint = parser . get ( "properties" , "sandbox" )
90+ endpoint = constants . SANDBOX_TESTMODE
7691
7792 @abc .abstractmethod
7893 def validaterequest (self ):
@@ -94,10 +109,10 @@ def validate(self):
94109 self .validaterequest ()
95110 return
96111
97- def _getRequest (self ): #protected method
112+ def _getrequest (self ): #protected method
98113 return self ._request
99114
100- def buildRequest (self ):
115+ def buildrequest (self ):
101116 logging .debug ('building request..' )
102117 #TODO requestType = type( self._request)
103118 requestType = self ._requestType
@@ -109,8 +124,8 @@ def buildRequest(self):
109124
110125 return xmlRequest
111126
112- def getPrettyXmlRequest (self ):
113- xmlRequest = self .buildRequest ()
127+ def getprettyxmlrequest (self ):
128+ xmlRequest = self .buildrequest ()
114129 requestDom = xml .dom .minidom .parseString (xmlRequest )
115130 logging .debug ('Request is: %s' % requestDom .toprettyxml ())
116131
@@ -119,26 +134,26 @@ def getPrettyXmlRequest(self):
119134 def execute (self ):
120135 logging .debug ('Executing http post to url: %s' , self .endpoint )
121136
122- self .beforeExecute ()
137+ self .beforeexecute ()
123138
124139 proxyDictionary = {'http' : self .parser .get ("properties" , "http" ),
125140 'https' : self .parser .get ("properties" , "https" ),
126141 'ftp' : self .parser .get ("properties" , "ftp" )}
127142
128143 #requests is http request
129144 try :
130- xmlRequest = self .buildRequest ()
145+ xmlRequest = self .buildrequest ()
131146 self ._httpResponse = requests .post (self .endpoint , data = xmlRequest , headers = constants .headers , proxies = proxyDictionary )
132147 except Exception as httpException :
133- logging .error ( 'Error retrieving http response from: %s for request: %s' , self .endpoint , self .getPrettyXmlRequest ())
148+ logging .error ( 'Error retrieving http response from: %s for request: %s' , self .endpoint , self .getprettyxmlrequest ())
134149 logging .error ( 'Exception: %s, %s' , type (httpException ), httpException .args )
135150
136151
137152 if self ._httpResponse :
138153 #encoding of response should be changed to retrieve text of response
139154 self ._httpResponse .encoding = constants .response_encoding
140155 self ._httpResponse = self ._httpResponse .text [3 :] #strip BOM
141- self .afterExecute ()
156+ self .afterexecute ()
142157 try :
143158 self ._response = apicontractsv1 .CreateFromDocument (self ._httpResponse )
144159 except Exception as createfromdocumentexception :
@@ -156,21 +171,21 @@ def execute(self):
156171 else :
157172 print "Did not receive http response"
158173
159- def getResponse (self ):
174+ def getresponse (self ):
160175 return self ._response
161176
162- def getResultCode (self ):
177+ def getresultcode (self ):
163178 if self ._response :
164179 return self ._response .resultCode
165180
166- def getMessageType (self ):
181+ def getmessagetype (self ):
167182 if self ._response :
168183 return self ._response .message
169184
170- def afterExecute (self ):
185+ def afterexecute (self ):
171186 return
172187
173- def beforeExecute (self ):
188+ def beforeexecute (self ):
174189 return
175190
176191 def __init__ (self , apiRequest , requestType ):
0 commit comments