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

Discussion in 'Python' started by provato, Jul 14, 2005.

  1. provato

    provato Guest

    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
    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()

    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",
    + ";" + 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
    provato, Jul 14, 2005
    1. Advertisements

  2. 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 Sakkis, Jul 15, 2005
    1. Advertisements

  3. provato

    provato Guest

    Thanks. That helps.
    provato, Jul 15, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.