-
Notifications
You must be signed in to change notification settings - Fork 326
Migrating from v1 to v2
Sadly version 2 of this SDK has come to contain a few changes that break backward compatibility. These changes were necessary to optimize this project and help keep it moving forward. Below I’ll highlight the differences and point out code changes that you may need to make.
- Import: Modified package structure
- execute(): Modified return value
- Switched to lxml.etree
- Added a new response class (response.reply, response.dom(), response.dict(), response.json())
- Added ebaysdk exception classes
- Modified utils.py (dict2xml, xml2dict)
-
The new response class (response.py)
-
methods - response.reply, response.dom(), response.dict(), response.json()
-
benefits of using response.reply
- object representation of the response content (perfect for introspection in iPython)
- forces list context on appropriate nodes
- converts date values to datetime object on relevant nodes
import datetime from ebaysdk.finding import Connection api = Connection(config_file='/etc/ebay.yaml') response = api.execute('findItemsAdvanced', {'keywords': 'legos'}) print(response.reply) assert(response.reply.ack=='Success') assert(type(response.reply.searchResult.item)==list) item = response.reply.searchResult.item[0] assert(type(item.listingInfo.endTime)==datetime.datetime)
-
-
The exception classes now contain the response class
except ConnectionError as e: print(e) print(e.response.dict())
-
Module Imports
- Previous imports
from ebaysdk import finding
- New imports
from ebaysdk.finding import Connection as finding
-
execute() method returns a response object instead of self.
api = Finding() response = api.execute(…)
-
Accessing response data
- Previous
* Newapi.response_dict() api.response_dom() api.response_obj()
api.response.reply api.response.dict() * api.response.json()
* api.response.dict() will now return a dictionary instead of a dictionary like object.
- Previous
* Newapi.response_dict().Ack
api.response.dict()[‘Ack’] api.response.reply.Ack
-
lxml.etree is the new default XML parser instead of ElementTree. lxml (http://lxml.de/api.html) has a slightly different interface. Any code that leverages the ElementTree DOM will need to change.
- Previous
dom = api.response_dom() dom.getElementsByTagName(‘tagname’)
- New
dom = api.response.dom() dom.findall(‘tagname’) dom.xpath(‘//tagname’)
-
Deprecated methods - use the methods in the new response class, e.g. api.response.dict()
api.response_dict() api.response_dom() api.response_obj()