Skip to content

Commit 22e0d8c

Browse files
committed
Business Polices API was added
1 parent 3156c07 commit 22e0d8c

File tree

4 files changed

+224
-0
lines changed

4 files changed

+224
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

ebaysdk/.DS_Store

6 KB
Binary file not shown.

ebaysdk/polices/__init__.py

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
# -*- coding: utf-8 -*-
2+
3+
'''
4+
© 2012-2013 eBay Software Foundation
5+
Authored by: Tim Keefer
6+
Licensed under CDDL 1.0
7+
'''
8+
9+
import os
10+
11+
from ebaysdk import log
12+
from ebaysdk.connection import BaseConnection
13+
from ebaysdk.exception import RequestPaginationError, PaginationLimit
14+
from ebaysdk.config import Config
15+
from ebaysdk.utils import dict2xml
16+
17+
class Connection(BaseConnection):
18+
"""Connection class for the Business Polices service
19+
20+
API documentation:
21+
http://developer.ebay.com/Devzone/business-policies
22+
23+
Supported calls:
24+
addSellerProfile
25+
getSellerProfiles
26+
(all others, see API docs)
27+
28+
"""
29+
30+
def __init__(self, **kwargs):
31+
"""Finding class constructor.
32+
33+
Keyword arguments:
34+
domain -- API endpoint (default: svcs.ebay.com)
35+
config_file -- YAML defaults (default: ebay.yaml)
36+
debug -- debugging enabled (default: False)
37+
warnings -- warnings enabled (default: False)
38+
uri -- API endpoint uri (default: /services/selling/v1/SellerProfilesManagementService)
39+
appid -- eBay application id
40+
siteid -- eBay country site id (default: EBAY-US)
41+
version -- version number (default: 1.0.0)
42+
https -- execute of https (default: False)
43+
proxy_host -- proxy hostname
44+
proxy_port -- proxy port number
45+
timeout -- HTTP request timeout (default: 20)
46+
parallel -- ebaysdk parallel object
47+
response_encoding -- API encoding (default: XML)
48+
request_encoding -- API encoding (default: XML)
49+
"""
50+
51+
super(Connection, self).__init__(method='POST', **kwargs)
52+
53+
self.config=Config(domain=kwargs.get('domain', 'svcs.ebay.com'),
54+
connection_kwargs=kwargs,
55+
config_file=kwargs.get('config_file', 'ebay.yaml'))
56+
57+
# override yaml defaults with args sent to the constructor
58+
self.config.set('domain', kwargs.get('domain', 'svcs.ebay.com'))
59+
self.config.set('uri', '/services/selling/v1/SellerProfilesManagementService')
60+
self.config.set('https', True)
61+
self.config.set('warnings', True)
62+
self.config.set('errors', True)
63+
self.config.set('siteid', 'EBAY-US')
64+
self.config.set('response_encoding', 'XML')
65+
self.config.set('request_encoding', 'XML')
66+
self.config.set('proxy_host', None)
67+
self.config.set('proxy_port', None)
68+
self.config.set('token', None)
69+
self.config.set('iaf_token', None)
70+
self.config.set('appid', None)
71+
self.config.set('version', '1.0.0')
72+
self.config.set('service', 'SellerProfilesManagementService')
73+
self.config.set('doc_url', 'http://developer.ebay.com/Devzone/business-policies/CallRef/index.html')
74+
75+
self.datetime_nodes = ['deleteddate', 'timestamp', 'maxdeliverydate',
76+
'mindeliverydate']
77+
self.base_list_nodes = [
78+
'setsellerprofileresponse.paymentprofile.categorygroups.categorygroup',
79+
'addsellerprofileresponse.paymentprofile.categorygroups.categorygroup',
80+
'getsellerprofilesresponse.paymentprofilelist.paymentprofile.categorygroups.categorygroup',
81+
'addsellerprofileresponse.returnpolicyprofile.categorygroups.categorygroup',
82+
'setsellerprofileresponse.returnpolicyprofile.categorygroups.categorygroup',
83+
'getsellerprofilesresponse.returnpolicyprofilelist.returnpolicyprofile.categorygroups.categorygroup',
84+
'addsellerprofileresponse.shippingpolicyprofile.categorygroups.categorygroup',
85+
'setsellerprofileresponse.shippingpolicyprofile.categorygroups.categorygroup',
86+
'getsellerprofilesresponse.shippingpolicyprofilelist.shippingpolicyprofile.categorygroups.categorygroup',
87+
'consolidateshippingprofilesresponse.consolidationjob',
88+
'getconsolidationjobstatusresponse.consolidationjob',
89+
'addsellerprofileresponse.paymentprofile.paymentinfo.depositdetails',
90+
'setsellerprofileresponse.paymentprofile.paymentinfo.depositdetails',
91+
'getsellerprofilesresponse.paymentprofilelist.paymentprofile.paymentinfo.depositdetails',
92+
'addsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.freightshipping',
93+
'setsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.freightshipping',
94+
'getsellerprofilesresponse.shippingpolicyprofilelist.shippingpolicyprofile.shippingpolicyinfo.freightshipping',
95+
'addsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.insurance',
96+
'setsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.insurance',
97+
'getsellerprofilesresponse.shippingpolicyprofilelist.shippingpolicyprofile.shippingpolicyinfo.insurance',
98+
'addsellerprofileresponse.paymentprofile.paymentinfo',
99+
'setsellerprofileresponse.paymentprofile.paymentinfo',
100+
'getsellerprofilesresponse.paymentprofilelist.paymentprofile.paymentinfo',
101+
'addsellerprofileresponse.returnpolicyprofile.returnpolicyinfo',
102+
'setsellerprofileresponse.returnpolicyprofile.returnpolicyinfo',
103+
'getsellerprofilesresponse.returnpolicyprofilelist.returnpolicyprofile.returnpolicyinfo',
104+
'addsellerprofileresponse.sellerprofile',
105+
'setsellerprofileresponse.sellerprofile',
106+
'getsellerprofilesresponse.paymentprofilelist.sellerprofile',
107+
'getsellerprofilesresponse.returnpolicyprofilelist.sellerprofile',
108+
'getsellerprofilesresponse.shippingpolicyprofilelist.sellerprofile',
109+
'addsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.shippingpolicyinfoservice',
110+
'setsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.shippingpolicyinfoservice',
111+
'getsellerprofilesresponse.shippingpolicyprofilelist.shippingpolicyprofile.shippingpolicyinfo.shippingpolicyinfoservice',
112+
'addsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.shippingprofilediscountinfo',
113+
'setsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.shippingprofilediscountinfo',
114+
'getsellerprofilesresponse.shippingpolicyprofilelist.shippingpolicyprofile.shippingpolicyinfo.shippingprofilediscountinfo'
115+
]
116+
117+
def build_request_headers(self, verb):
118+
return {
119+
"X-EBAY-SOA-SERVICE-NAME": self.config.get('service', ''),
120+
"X-EBAY-SOA-SERVICE-VERSION": self.config.get('version', ''),
121+
"X-EBAY-SOA-SECURITY-TOKEN": self.config.get('token', ''),
122+
"X-EBAY-SOA-GLOBAL-ID": self.config.get('siteid', ''),
123+
"X-EBAY-SOA-OPERATION-NAME": verb,
124+
"X-EBAY-SOA-REQUEST-DATA-FORMAT": self.config.get('request_encoding', ''),
125+
"X-EBAY-SOA-RESPONSE-DATA-FORMAT": self.config.get('response_encoding', ''),
126+
"Content-Type": "text/xml"
127+
}
128+
129+
def build_request_data(self, verb, data, verb_attrs):
130+
xml = "<?xml version='1.0' encoding='utf-8'?>"
131+
xml += "<" + verb + "Request xmlns=\"http://www.ebay.com/marketplace/search/v1/services\">"
132+
xml += dict2xml(data)
133+
xml += "</" + verb + "Request>"
134+
135+
return xml
136+
137+
def warnings(self):
138+
warning_string = ""
139+
140+
if len(self._resp_body_warnings) > 0:
141+
warning_string = "%s: %s" \
142+
% (self.verb, ", ".join(self._resp_body_warnings))
143+
144+
return warning_string
145+
146+
def _get_resp_body_errors(self):
147+
"""Parses the response content to pull errors.
148+
149+
Child classes should override this method based on what the errors in the
150+
XML response body look like. They can choose to look at the 'ack',
151+
'Errors', 'errorMessage' or whatever other fields the service returns.
152+
the implementation below is the original code that was part of error()
153+
"""
154+
155+
if self._resp_body_errors and len(self._resp_body_errors) > 0:
156+
return self._resp_body_errors
157+
158+
errors = []
159+
warnings = []
160+
resp_codes = []
161+
162+
if self.verb is None:
163+
return errors
164+
165+
dom = self.response.dom()
166+
if dom is None:
167+
return errors
168+
169+
for e in dom.findall("error"):
170+
eSeverity = None
171+
eDomain = None
172+
eMsg = None
173+
eId = None
174+
175+
try:
176+
eSeverity = e.findall('severity')[0].text
177+
except IndexError:
178+
pass
179+
180+
try:
181+
eDomain = e.findall('domain')[0].text
182+
except IndexError:
183+
pass
184+
185+
try:
186+
eId = e.findall('errorId')[0].text
187+
if int(eId) not in resp_codes:
188+
resp_codes.append(int(eId))
189+
except IndexError:
190+
pass
191+
192+
try:
193+
eMsg = e.findall('message')[0].text
194+
except IndexError:
195+
pass
196+
197+
msg = "Domain: %s, Severity: %s, errorId: %s, %s" \
198+
% (eDomain, eSeverity, eId, eMsg)
199+
200+
if eSeverity == 'Warning':
201+
warnings.append(msg)
202+
else:
203+
errors.append(msg)
204+
205+
self._resp_body_warnings = warnings
206+
self._resp_body_errors = errors
207+
self._resp_codes = resp_codes
208+
209+
if self.config.get('warnings') and len(warnings) > 0:
210+
log.warn("%s: %s\n\n" % (self.verb, "\n".join(warnings)))
211+
212+
try:
213+
if self.response.reply.ack == 'Success' and len(errors) > 0 and self.config.get('errors'):
214+
log.error("%s: %s\n\n" % (self.verb, "\n".join(errors)))
215+
216+
elif len(errors) > 0:
217+
if self.config.get('errors'):
218+
log.error("%s: %s\n\n" % (self.verb, "\n".join(errors)))
219+
220+
return errors
221+
except AttributeError as e:
222+
return errors
223+
224+
return []

samples/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)