-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy path__init__.py
More file actions
94 lines (78 loc) · 3.42 KB
/
__init__.py
File metadata and controls
94 lines (78 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
'''
Copyright 2012-2019 eBay Inc.
Authored by: Tim Keefer
Licensed under CDDL 1.0
'''
import os
from ebaysdk.finding import Connection as FindingConnection
from ebaysdk.utils import dict2xml
class Connection(FindingConnection):
"""Connection class for the Merchandising service
API documentation:
http://developer.ebay.com/products/merchandising/
Supported calls:
getMostWatchedItems
getSimilarItems
getTopSellingProducts
(all others, see API docs)
Doctests:
>>> s = Connection(config_file=os.environ.get('EBAY_YAML'))
>>> retval = s.execute('getMostWatchedItems', {'maxResults': 3})
>>> print(s.response.reply.ack)
Success
>>> print(s.error())
None
"""
def __init__(self, **kwargs):
"""Merchandising class constructor.
Keyword arguments:
domain -- API endpoint (default: open.api.ebay.com)
config_file -- YAML defaults (default: ebay.yaml)
debug -- debugging enabled (default: False)
warnings -- warnings enabled (default: True)
errors -- errors enabled (default: True)
uri -- API endpoint uri (default: /MerchandisingService)
appid -- eBay application id
siteid -- eBay country site id (default: 0 (US))
version -- version number (default: 799)
https -- execute of https (default: True)
proxy_host -- proxy hostname
proxy_port -- proxy port number
timeout -- HTTP request timeout (default: 20)
parallel -- ebaysdk parallel object
response_encoding -- API encoding (default: XML)
request_encoding -- API encoding (default: XML)
"""
super(Connection, self).__init__(**kwargs)
self.config.set('uri', '/MerchandisingService', force=True)
self.config.set('service', 'MerchandisingService', force=True)
self.config.set(
'doc_url', 'http://developer.ebay.com/Devzone/merchandising/docs/CallRef/index.html')
self.datetime_nodes = ['endtimeto', 'endtimefrom', 'timestamp']
self.base_list_nodes = [
'getdealsresponse.itemrecommendations.item',
'getmostwatcheditemsresponse.itemrecommendations.item',
'getrelatedcategoryitemsresponse.itemrecommendations.item',
'getsimilaritemsresponse.itemrecommendations.item',
'gettopsellingproductsresponse.productrecommendations.product',
'getrelatedcategoryitemsresponse.itemfilter.value',
'getsimilaritemsresponse.itemfilter.value',
]
def build_request_headers(self, verb):
return {
"X-EBAY-API-VERSION": self.config.get('version', ''),
"EBAY-SOA-CONSUMER-ID": self.config.get('appid', ''),
"X-EBAY-SOA-GLOBAL-ID": self.config.get('siteid', ''),
"X-EBAY-SOA-OPERATION-NAME": verb,
"X-EBAY-SOA-REQUEST-DATA-FORMAT": "XML",
"X-EBAY-API-REQUEST-ENCODING": "XML",
"X-EBAY-SOA-SERVICE-NAME": self.config.get('service', ''),
"Content-Type": "text/xml"
}
def build_request_data(self, verb, data, verb_attrs):
xml = "<?xml version='1.0' encoding='utf-8'?>"
xml += "<" + verb + "Request xmlns=\"http://www.ebay.com/marketplace/services\">"
xml += dict2xml(data, self.escape_xml)
xml += "</" + verb + "Request>"
return xml