From 22e0d8cbca6070b968905ff0f9db5e231410a9d1 Mon Sep 17 00:00:00 2001 From: Yarovoy Nikolay Date: Wed, 21 Jan 2015 23:56:46 +0100 Subject: [PATCH] Business Polices API was added --- .DS_Store | Bin 0 -> 6148 bytes ebaysdk/.DS_Store | Bin 0 -> 6148 bytes ebaysdk/polices/__init__.py | 224 ++++++++++++++++++++++++++++++++++++ samples/.DS_Store | Bin 0 -> 6148 bytes 4 files changed, 224 insertions(+) create mode 100644 .DS_Store create mode 100644 ebaysdk/.DS_Store create mode 100644 ebaysdk/polices/__init__.py create mode 100644 samples/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..df8237a12ada71bde97ac19e9857d9abcdc51b3f GIT binary patch literal 6148 zcmeHK%}yIJ5FUq6HgMUhMMC1@Yo#1WDk6^ClpZTZ3IZXh!n(UstZvs)ydgqSq&@dB z=O7zD}sD)_nc!~_r-mO3i0%ACWJNu_H+)^CUIPe(;kYSJ(V?7X=5;$@r z2AR~w*48zvELE4Etpv5zHG0D5s~@_3HSQL1G1BdLcw~AqNrkgJanYaIdrD<MGiZ|*dwbv|jm-l_BLMr%3^uYzFn)%KhBhlA;t^RM5&|M>aq_l4aiMz2ru z!opl%qV<3l`;S){#VkWXOrh2@_iU#56yER*cm_NJkIaBOmx8rN{vCdK&wyv(=`ld( z1II=fIV>%jqXU&G0TAgk(g@mAOHdAX7&$C0;s^?}sfad}xe|lfbo6r<7db2~+H_#9 z_+V~j<|-6sR>%3d2?rKg^x8Av8Mx2DlI@0c|G)ct{eM5n_dElhf&YpDR^9FHw(*tR z-Ma8{bk}lhC)h|RuCzE$LBm|d7)w|21~wz;=VTy84oi#ZLGd2~h6b-Z1OJqPTb~AT A?*IS* literal 0 HcmV?d00001 diff --git a/ebaysdk/.DS_Store b/ebaysdk/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c62aa420042249fa9c64134d699f218824d5cbd4 GIT binary patch literal 6148 zcmeHKUyBnl5TD%j>|PIHMTG-j@+$PUM}&(aP+2mk>pVWWlSH$vm2YqI5g zb`XV~LqP#AQZvpIy%xjGV^I;WNGt-Z! zPi#x2S>pXcTum`DY(5HaJ=mXC;vzd$MkOj&)$3rFzEQZpSoAvGw(K5tmuN8XlimM&k6g2)hwhleT`>0lMOp=2bd8{2` Q4+{Sgur#n?1~$sTPd!e@MF0Q* literal 0 HcmV?d00001 diff --git a/ebaysdk/polices/__init__.py b/ebaysdk/polices/__init__.py new file mode 100644 index 0000000..fdd3d85 --- /dev/null +++ b/ebaysdk/polices/__init__.py @@ -0,0 +1,224 @@ +# -*- coding: utf-8 -*- + +''' +© 2012-2013 eBay Software Foundation +Authored by: Tim Keefer +Licensed under CDDL 1.0 +''' + +import os + +from ebaysdk import log +from ebaysdk.connection import BaseConnection +from ebaysdk.exception import RequestPaginationError, PaginationLimit +from ebaysdk.config import Config +from ebaysdk.utils import dict2xml + +class Connection(BaseConnection): + """Connection class for the Business Polices service + + API documentation: + http://developer.ebay.com/Devzone/business-policies + + Supported calls: + addSellerProfile + getSellerProfiles + (all others, see API docs) + + """ + + def __init__(self, **kwargs): + """Finding class constructor. + + Keyword arguments: + domain -- API endpoint (default: svcs.ebay.com) + config_file -- YAML defaults (default: ebay.yaml) + debug -- debugging enabled (default: False) + warnings -- warnings enabled (default: False) + uri -- API endpoint uri (default: /services/selling/v1/SellerProfilesManagementService) + appid -- eBay application id + siteid -- eBay country site id (default: EBAY-US) + version -- version number (default: 1.0.0) + https -- execute of https (default: False) + 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__(method='POST', **kwargs) + + self.config=Config(domain=kwargs.get('domain', 'svcs.ebay.com'), + connection_kwargs=kwargs, + config_file=kwargs.get('config_file', 'ebay.yaml')) + + # override yaml defaults with args sent to the constructor + self.config.set('domain', kwargs.get('domain', 'svcs.ebay.com')) + self.config.set('uri', '/services/selling/v1/SellerProfilesManagementService') + self.config.set('https', True) + self.config.set('warnings', True) + self.config.set('errors', True) + self.config.set('siteid', 'EBAY-US') + self.config.set('response_encoding', 'XML') + self.config.set('request_encoding', 'XML') + self.config.set('proxy_host', None) + self.config.set('proxy_port', None) + self.config.set('token', None) + self.config.set('iaf_token', None) + self.config.set('appid', None) + self.config.set('version', '1.0.0') + self.config.set('service', 'SellerProfilesManagementService') + self.config.set('doc_url', 'http://developer.ebay.com/Devzone/business-policies/CallRef/index.html') + + self.datetime_nodes = ['deleteddate', 'timestamp', 'maxdeliverydate', + 'mindeliverydate'] + self.base_list_nodes = [ + 'setsellerprofileresponse.paymentprofile.categorygroups.categorygroup', + 'addsellerprofileresponse.paymentprofile.categorygroups.categorygroup', + 'getsellerprofilesresponse.paymentprofilelist.paymentprofile.categorygroups.categorygroup', + 'addsellerprofileresponse.returnpolicyprofile.categorygroups.categorygroup', + 'setsellerprofileresponse.returnpolicyprofile.categorygroups.categorygroup', + 'getsellerprofilesresponse.returnpolicyprofilelist.returnpolicyprofile.categorygroups.categorygroup', + 'addsellerprofileresponse.shippingpolicyprofile.categorygroups.categorygroup', + 'setsellerprofileresponse.shippingpolicyprofile.categorygroups.categorygroup', + 'getsellerprofilesresponse.shippingpolicyprofilelist.shippingpolicyprofile.categorygroups.categorygroup', + 'consolidateshippingprofilesresponse.consolidationjob', + 'getconsolidationjobstatusresponse.consolidationjob', + 'addsellerprofileresponse.paymentprofile.paymentinfo.depositdetails', + 'setsellerprofileresponse.paymentprofile.paymentinfo.depositdetails', + 'getsellerprofilesresponse.paymentprofilelist.paymentprofile.paymentinfo.depositdetails', + 'addsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.freightshipping', + 'setsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.freightshipping', + 'getsellerprofilesresponse.shippingpolicyprofilelist.shippingpolicyprofile.shippingpolicyinfo.freightshipping', + 'addsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.insurance', + 'setsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.insurance', + 'getsellerprofilesresponse.shippingpolicyprofilelist.shippingpolicyprofile.shippingpolicyinfo.insurance', + 'addsellerprofileresponse.paymentprofile.paymentinfo', + 'setsellerprofileresponse.paymentprofile.paymentinfo', + 'getsellerprofilesresponse.paymentprofilelist.paymentprofile.paymentinfo', + 'addsellerprofileresponse.returnpolicyprofile.returnpolicyinfo', + 'setsellerprofileresponse.returnpolicyprofile.returnpolicyinfo', + 'getsellerprofilesresponse.returnpolicyprofilelist.returnpolicyprofile.returnpolicyinfo', + 'addsellerprofileresponse.sellerprofile', + 'setsellerprofileresponse.sellerprofile', + 'getsellerprofilesresponse.paymentprofilelist.sellerprofile', + 'getsellerprofilesresponse.returnpolicyprofilelist.sellerprofile', + 'getsellerprofilesresponse.shippingpolicyprofilelist.sellerprofile', + 'addsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.shippingpolicyinfoservice', + 'setsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.shippingpolicyinfoservice', + 'getsellerprofilesresponse.shippingpolicyprofilelist.shippingpolicyprofile.shippingpolicyinfo.shippingpolicyinfoservice', + 'addsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.shippingprofilediscountinfo', + 'setsellerprofileresponse.shippingpolicyprofile.shippingpolicyinfo.shippingprofilediscountinfo', + 'getsellerprofilesresponse.shippingpolicyprofilelist.shippingpolicyprofile.shippingpolicyinfo.shippingprofilediscountinfo' + ] + + def build_request_headers(self, verb): + return { + "X-EBAY-SOA-SERVICE-NAME": self.config.get('service', ''), + "X-EBAY-SOA-SERVICE-VERSION": self.config.get('version', ''), + "X-EBAY-SOA-SECURITY-TOKEN": self.config.get('token', ''), + "X-EBAY-SOA-GLOBAL-ID": self.config.get('siteid', ''), + "X-EBAY-SOA-OPERATION-NAME": verb, + "X-EBAY-SOA-REQUEST-DATA-FORMAT": self.config.get('request_encoding', ''), + "X-EBAY-SOA-RESPONSE-DATA-FORMAT": self.config.get('response_encoding', ''), + "Content-Type": "text/xml" + } + + def build_request_data(self, verb, data, verb_attrs): + xml = "" + xml += "<" + verb + "Request xmlns=\"http://www.ebay.com/marketplace/search/v1/services\">" + xml += dict2xml(data) + xml += "" + + return xml + + def warnings(self): + warning_string = "" + + if len(self._resp_body_warnings) > 0: + warning_string = "%s: %s" \ + % (self.verb, ", ".join(self._resp_body_warnings)) + + return warning_string + + def _get_resp_body_errors(self): + """Parses the response content to pull errors. + + Child classes should override this method based on what the errors in the + XML response body look like. They can choose to look at the 'ack', + 'Errors', 'errorMessage' or whatever other fields the service returns. + the implementation below is the original code that was part of error() + """ + + if self._resp_body_errors and len(self._resp_body_errors) > 0: + return self._resp_body_errors + + errors = [] + warnings = [] + resp_codes = [] + + if self.verb is None: + return errors + + dom = self.response.dom() + if dom is None: + return errors + + for e in dom.findall("error"): + eSeverity = None + eDomain = None + eMsg = None + eId = None + + try: + eSeverity = e.findall('severity')[0].text + except IndexError: + pass + + try: + eDomain = e.findall('domain')[0].text + except IndexError: + pass + + try: + eId = e.findall('errorId')[0].text + if int(eId) not in resp_codes: + resp_codes.append(int(eId)) + except IndexError: + pass + + try: + eMsg = e.findall('message')[0].text + except IndexError: + pass + + msg = "Domain: %s, Severity: %s, errorId: %s, %s" \ + % (eDomain, eSeverity, eId, eMsg) + + if eSeverity == 'Warning': + warnings.append(msg) + else: + errors.append(msg) + + self._resp_body_warnings = warnings + self._resp_body_errors = errors + self._resp_codes = resp_codes + + if self.config.get('warnings') and len(warnings) > 0: + log.warn("%s: %s\n\n" % (self.verb, "\n".join(warnings))) + + try: + if self.response.reply.ack == 'Success' and len(errors) > 0 and self.config.get('errors'): + log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) + + elif len(errors) > 0: + if self.config.get('errors'): + log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) + + return errors + except AttributeError as e: + return errors + + return [] diff --git a/samples/.DS_Store b/samples/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0