By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,010 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

eBay.py - Has anyone looked at this???

P: n/a
I'm somewhat of a newbie was confused by the following code that I
downloaded from eBay's developer site:

One of the classes in the file is called "Call". What I don't get is
that in "MakeCall" function, there's a use of self.Session.Server.
Where is this property coming from?


============================================

class Call:
RequestData = "<xml />" # just a stub
DetailLevel = "0"
SiteID = "0"

def MakeCall(self, CallName):
# specify the connection to the eBay Sandbox environment
# TODO: Make this configurable in eBay.ini (sandbox/production)
conn = httplib.HTTPSConnection(self.Session.Server)

# specify a POST with the results of generateHeaders and
generateRequest
conn.request("POST", self.Session.Command, self.RequestData,
self.GenerateHeaders(self.Session, CallName))
response = conn.getresponse()

# TODO: When you add logging to this, change the
# following to log statements
# print "Response status:", response.status
# print "Response reason:", response.reason

# store the response data and close the connection
data = response.read()
conn.close()

responseDOM = parseString(data)

# check for any <Error> tags and print
# TODO: Return a real exception and log when this happens
tag = responseDOM.getElementsByTagName('Error')
if (tag.count!=0):
for error in tag:
print "\n",error.toprettyxml(" ")

return responseDOM

def GenerateHeaders(self, Session, CallName):
headers = {"X-EBAY-API-COMPATIBILITY-LEVEL": "349",
"X-EBAY-API-SESSION-CERTIFICATE": Session.Developer
+ ";" + Session.Application + ";" + Session.Certificate,
"X-EBAY-API-DEV-NAME": Session.Developer,
"X-EBAY-API-APP-NAME": Session.Application,
"X-EBAY-API-CERT-NAME": Session.Certificate,
"X-EBAY-API-CALL-NAME": CallName,
"X-EBAY-API-SITEID": self.SiteID,
"X-EBAY-API-DETAIL-LEVEL": self.DetailLevel,
"Content-Type": "text/xml"}
return headers

Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"provato" <pr*****@gmail.com> wrote
I'm somewhat of a newbie was confused by the following code that I
downloaded from eBay's developer site:

One of the classes in the file is called "Call". What I don't get is
that in "MakeCall" function, there's a use of self.Session.Server.
Where is this property coming from?

[snipped]


Typically, instance attributes should be bound in the constructor (__init__), but strangely Call has
no constructor. I checked out the ebay.py file and it turns out that other classes bind Session (and
other attributes) directly, e.g.

class SellerList:
def Get(self, SellerUserName):
api = Call()
api.Session = self.Session
api.DetailLevel = "2"
# etc

This is lousy OO design and you saw why; you can't tell where on earth is Session and the other
attributes coming from. From a brief look, the api seems like a quick & dirty solution that would
benefit from refactoring, so you'd rather not try to learn python from it.

George
Jul 21 '05 #2

P: n/a
Thanks. That helps.

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.