Skip to content

Commit

Permalink
Bulk commit to force https and for fixes to the code samples. see Cha…
Browse files Browse the repository at this point in the history
…nges file more details
  • Loading branch information
timotheus committed Apr 20, 2020
1 parent a713f28 commit 988704c
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 77 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Changes for ebaysdk

2.2.0 Mon Apr 20 15:23:53 PDT 2020
- Forced HTTPS for finding, shopping, and trading calls
- fixed sample code so that it uses the appropriate domain
- added py38 to tox testing

2.1.6
- Update Copyright

Expand Down
2 changes: 0 additions & 2 deletions ebay.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ api.ebay.com:
# Finding API - https://www.x.com/developers/ebay/products/finding-api
svcs.ebay.com:
appid: ENTER_YOUR_APPID_HERE
version: 1.0.0

# Shopping API - https://www.x.com/developers/ebay/products/shopping-api
open.api.ebay.com:
appid: ENTER_YOUR_APPID_HERE
version: 671
2 changes: 1 addition & 1 deletion ebaysdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import platform
import logging

__version__ = '2.1.5'
__version__ = '2.2.0'
Version = __version__ # for backward compatibility

try:
Expand Down
2 changes: 1 addition & 1 deletion ebaysdk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def build_request_data(self, verb, data, verb_attrs):

def build_request_url(self, verb):
url = "%s://%s%s" % (
HTTP_SSL[self.config.get('https', False)],
HTTP_SSL[self.config.get('https', True)],
self.config.get('domain'),
self.config.get('uri')
)
Expand Down
3 changes: 3 additions & 0 deletions ebaysdk/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ def __init__(self, obj, verb=None, list_nodes=[], datetime_nodes=[], parse_respo
datetime_nodes=copy.copy(datetime_nodes))
except XMLSyntaxError as e:
log.debug('response parse failed: %s' % e)
self._dom = self._parse_xml("<%sResponse>parse error <![CDATA[%s]]></%sResponse>" % (verb, e, verb))
self._dict = self._etree_to_dict(self._dom)
self.reply = ResponseDataObject({}, [])

else:
self.reply = ResponseDataObject({}, [])

Expand Down
6 changes: 2 additions & 4 deletions ebaysdk/shopping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, **kwargs):
self.config.set('uri', '/shopping')
self.config.set('warnings', True)
self.config.set('errors', True)
self.config.set('https', False)
self.config.set('https', True, force=True)
self.config.set('siteid', '0')
self.config.set('response_encoding', 'XML')
self.config.set('request_encoding', 'XML')
Expand All @@ -85,15 +85,13 @@ def __init__(self, **kwargs):
self.config.set(
'doc_url', 'http://developer.ebay.com/DevZone/Shopping/docs/CallRef/index.html')

if self.config.get('https') and self.debug:
print("HTTPS is not supported on the Shopping API.")

self.datetime_nodes = ['timestamp', 'registrationdate', 'creationtime',
'commenttime', 'updatetime', 'estimateddeliverymintime',
'estimateddeliverymaxtime', 'creationtime', 'estimateddeliverymintime',
'estimateddeliverymaxtime', 'endtime', 'starttime']

self.base_list_nodes = [
'getcategoryinforesponse.categoryarray.category',
'findhalfproductsresponse.halfcatalogproduct.productid',
'findhalfproductsresponse.halfproducts.product',
'getshippingcostsresponse.internationalshippingserviceoption.shipsto',
Expand Down
2 changes: 1 addition & 1 deletion ebaysdk/trading/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, **kwargs):
self.config.set('uri', '/ws/api.dll')
self.config.set('warnings', True)
self.config.set('errors', True)
self.config.set('https', True)
self.config.set('https', True, force=True)
self.config.set('siteid', '0')
self.config.set('response_encoding', 'XML')
self.config.set('request_encoding', 'XML')
Expand Down
15 changes: 14 additions & 1 deletion samples/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
Licensed under CDDL 1.0
'''

from ebaysdk.finding import Connection as finding

def get_one_item(opts):
api = finding(debug=opts.debug, appid=opts.appid,
config_file=opts.yaml, warnings=True)

api_request = {
'keywords': u'GRAMMY Foundation®',
}

response = api.execute('findItemsAdvanced', api_request)
return response.reply.searchResult.item[0].itemId


def dump(api, full=False):

Expand All @@ -17,7 +30,7 @@ def dump(api, full=False):
print("Call Success: %s in length" % len(api.response.content))

print("Response code: %s" % api.response_code())
print("Response DOM1: %s" % api.response_dom()) # deprecated
print("Response DOM1: %s" % api.response.dom()) # deprecated
print("Response ETREE: %s" % api.response.dom())

if full:
Expand Down
87 changes: 23 additions & 64 deletions samples/shopping.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

sys.path.insert(0, '%s/../' % os.path.dirname(__file__))

from common import dump
from common import dump, get_one_item

import ebaysdk
from ebaysdk.exception import ConnectionError
Expand All @@ -37,8 +37,8 @@ def init_options():
dest="appid", default=None,
help="Specifies the eBay application id to use.")
parser.add_option("-n", "--domain",
dest="domain", default='svcs.ebay.com',
help="Specifies the eBay domain to use (e.g. svcs.sandbox.ebay.com).")
dest="domain", default='open.api.ebay.com',
help="Specifies the eBay domain to use (e.g. open.api.ebay.com).")

(opts, args) = parser.parse_args()
return opts, args
Expand All @@ -51,13 +51,12 @@ def run(opts):
print("Shopping samples for SDK version %s" % ebaysdk.get_version())

try:
response = api.execute('FindPopularItems', {'QueryKeywords': 'Python'})
ItemID = get_one_item(opts)

dump(api)
response = api.execute('GetSingleItem', {'ItemID': ItemID})
print("EndTime: %s" % response.reply.Item.EndTime)

print("Matching Titles:")
for item in response.reply.ItemArray.Item:
print(item.Title)
dump(api)

except ConnectionError as e:
print(e)
Expand All @@ -69,45 +68,22 @@ def popularSearches(opts):
api = Shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml, domain=opts.domain,
warnings=True)

choice = True

while choice:

choice = input('Search: ')

if choice == 'quit':
break

mySearch = {
"MaxKeywords": 10,
"QueryKeywords": choice,
}

try:
response = api.execute('FindPopularSearches', mySearch)
mySearch = {
"MaxKeywords": 10,
"QueryKeywords": 'shirt',
}

dump(api, full=False)

print("Related: %s" %
response.reply.PopularSearchResult.RelatedSearches)

for term in response.reply.PopularSearchResult.AlternativeSearches.split(';')[:3]:
api.execute('FindPopularItems', {
'QueryKeywords': term, 'MaxEntries': 3})
try:
response = api.execute('FindPopularSearches', mySearch)

print("Term: %s" % term)
try:
for item in response.reply.ItemArray.Item:
print(item.Title)
except AttributeError:
pass
dump(api, full=False)

dump(api)
print("\n")
print("Related: %s" %
response.reply.PopularSearchResult.RelatedSearches)

except ConnectionError as e:
print(e)
print(e.response.dict())
except ConnectionError as e:
print(e)
print(e.response.dict())


def categoryInfo(opts):
Expand All @@ -116,28 +92,12 @@ def categoryInfo(opts):
api = Shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml, domain=opts.domain,
warnings=True)

response = api.execute('GetCategoryInfo', {"CategoryID": 3410})

dump(api, full=False)

except ConnectionError as e:
print(e)
print(e.response.dict())


def with_affiliate_info(opts):
try:
api = Shopping(debug=opts.debug, appid=opts.appid,
config_file=opts.yaml, warnings=True,
trackingid=1234, trackingpartnercode=9)
response = api.execute('GetCategoryInfo', {"CategoryID": 11450})

mySearch = {
"MaxKeywords": 10,
"QueryKeywords": 'shirt',
}
print("Category Name: %s" %
response.reply.CategoryArray.Category[0].CategoryName)

response = api.execute('FindPopularSearches', mySearch)
dump(api, full=False)
dump(api)

except ConnectionError as e:
print(e)
Expand Down Expand Up @@ -165,5 +125,4 @@ def using_attributes(opts):
run(opts)
popularSearches(opts)
categoryInfo(opts)
with_affiliate_info(opts)
using_attributes(opts)
4 changes: 2 additions & 2 deletions samples/trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def init_options():
dest="certid", default=None,
help="Specifies the eBay cert id to use.")
parser.add_option("-n", "--domain",
dest="domain", default='svcs.ebay.com',
help="Specifies the eBay domain to use (e.g. svcs.sandbox.ebay.com).")
dest="domain", default='api.ebay.com',
help="Specifies the eBay domain to use (e.g. api.sandbox.ebay.com).")

(opts, args) = parser.parse_args()
return opts, args
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py37
envlist = py27,py37,py38

[testenv]
setenv =
Expand Down

0 comments on commit 988704c

Please sign in to comment.