Ejemplo n.º 1
0
class Connection(BaseConnection):
    """Trading API class

    API documentation:
    https://www.x.com/developers/ebay/products/trading-api

    Supported calls:
    AddItem
    ReviseItem
    GetUser
    (all others, see API docs)

    Doctests:
    >>> import datetime
    >>> t = Connection(config_file=os.environ.get('EBAY_YAML'))
    >>> response = t.execute(u'GetCharities', {'CharityID': 3897})
    >>> charity_name = ''
    >>> if len( t.response.dom().xpath('//Name') ) > 0:
    ...   charity_name = t.response.dom().xpath('//Name')[0].text
    >>> print(charity_name)
    Sunshine Kids Foundation
    >>> isinstance(response.reply.Timestamp, datetime.datetime)
    True
    >>> print(t.error())
    None
    >>> t2 = Connection(errors=False, debug=False, config_file=os.environ.get('EBAY_YAML'))
    >>> response = t2.execute(u'VerifyAddItem', {})
    >>> print(t2.response_codes())
    [10009]

    Proof that utf8 errors work (calling .error() was triggering UTF8 Errors
    >>> t3 = Connection(token="WRONG_TOKEN", errors=False, debug=False, config_file=os.environ.get('EBAY_YAML'))
    >>> response = t3.execute(u'VerifyAddItem', {u'ErrorLanguage': u'de_DE'})
    >>> error = t3.error()
    >>> error.startswith('VerifyAddItem: Class: RequestError, Severity:')
    True
    """

    def __init__(self, **kwargs):
        """Trading class constructor.

        Keyword arguments:
        domain        -- API endpoint (default: api.ebay.com)
        config_file   -- YAML defaults (default: ebay.yaml)
        debug         -- debugging enabled (default: False)
        warnings      -- warnings enabled (default: False)
        uri           -- API endpoint uri (default: /ws/api.dll)
        appid         -- eBay application id
        devid         -- eBay developer id
        certid        -- eBay cert id
        token         -- eBay application/user token
        siteid        -- eBay country site id (default: 0 (US))
        compatibility -- version number (default: 648)
        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__(method='POST', **kwargs)

        self.config = Config(domain=kwargs.get('domain', 'api.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', 'api.ebay.com'))
        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('siteid', '0')
        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('devid', None)
        self.config.set('certid', None)
        self.config.set('compatibility', '837')
        self.config.set(
            'doc_url', 'http://developer.ebay.com/devzone/xml/docs/reference/ebay/index.html')

        self.datetime_nodes = [
            'shippingtime',
            'starttime',
            'endtime',
            'scheduletime',
            'createdtime',
            'hardexpirationtime',
            'invoicedate',
            'begindate',
            'enddate',
            'startcreationtime',
            'endcreationtime',
            'endtimefrom',
            'endtimeto',
            'updatetime',
            'lastupdatetime',
            'lastmodifiedtime',
            'modtimefrom',
            'modtimeto',
            'createtimefrom',
            'createtimeto',
            'starttimefrom',
            'starttimeto',
            'timeto',
            'paymenttimefrom',
            'paymenttimeto',
            'inventorycountlastcalculateddate',
            'registrationdate',
            'timefrom',
            'timestamp',
            'messagecreationtime',
            'resolutiontime',
            'date',
            'bankmodifydate',
            'creditcardexpiration',
            'creditcardmodifydate',
            'lastpaymentdate',
            'submittedtime',
            'announcementstarttime',
            'eventtime',
            'periodicstartdate',
            'modtime',
            'expirationtime',
            'creationtime',
            'lastusedtime',
            'disputecreatedtime',
            'disputemodifiedtime',
            'externaltransactiontime',
            'commenttime',
            'lastbidtime',
            'time',
            'creationdate',
            'lastmodifieddate',
            'receivedate',
            'expirationdate',
            'resolutiondate',
            'lastreaddate',
            'userforwarddate',
            'itemendtime',
            'userresponsedate',
            'nextretrytime',
            'deliverytime',
            'timebid',
            'paidtime',
            'shippedtime',
            'expectedreleasedate',
            'paymenttime',
            'promotionalsalestarttime',
            'promotionalsaleendtime',
            'refundtime',
            'refundrequestedtime',
            'refundcompletiontime',
            'estimatedrefundcompletiontime',
            'lastemailsenttime',
            'sellerinvoicetime',
            'estimateddeliverydate',
            'printedtime',
            'deliverydate',
            'refundgrantedtime',
            'scheduleddeliverytimemin',
            'scheduleddeliverytimemax',
            'actualdeliverytime',
            'usebydate',
            'lastopenedtime',
            'returndate',
            'revocationtime',
            'lasttimemodified',
            'createddate',
            'invoicesenttime',
            'acceptedtime',
            'sellerebaypaymentprocessenabletime',
            'useridlastchanged',
            'actionrequiredby',
        ]

        self.base_list_nodes = [
            'getmymessagesresponse.abstractrequest.detaillevel',
            'getaccountresponse.abstractrequest.outputselector',
            'getadformatleadsresponse.abstractrequest.outputselector',
            'getallbiddersresponse.abstractrequest.outputselector',
            'getbestoffersresponse.abstractrequest.outputselector',
            'getbidderlistresponse.abstractrequest.outputselector',
            'getcategoriesresponse.abstractrequest.outputselector',
            'getcategoryfeaturesresponse.abstractrequest.outputselector',
            'getcategorylistingsresponse.abstractrequest.outputselector',
            'getcrosspromotionsresponse.abstractrequest.outputselector',
            'getfeedbackresponse.abstractrequest.outputselector',
            'gethighbiddersresponse.abstractrequest.outputselector',
            'getitemresponse.abstractrequest.outputselector',
            'getitemsawaitingfeedbackresponse.abstractrequest.outputselector',
            'getitemshippingresponse.abstractrequest.outputselector',
            'getitemtransactionsresponse.abstractrequest.outputselector',
            'getmembermessagesresponse.abstractrequest.outputselector',
            'getmyebaybuyingresponse.abstractrequest.outputselector',
            'getmyebaysellingresponse.abstractrequest.outputselector',
            'getmymessagesresponse.abstractrequest.outputselector',
            'getnotificationpreferencesresponse.abstractrequest.outputselector',
            'getordersresponse.abstractrequest.outputselector',
            'getordertransactionsresponse.abstractrequest.outputselector',
            'getproductsresponse.abstractrequest.outputselector',
            'getsearchresultsresponse.abstractrequest.outputselector',
            'getsellereventsresponse.abstractrequest.outputselector',
            'getsellerlistresponse.abstractrequest.outputselector',
            'getsellerpaymentsresponse.abstractrequest.outputselector',
            'getsellertransactionsresponse.abstractrequest.outputselector',
            'getmessagepreferencesresponse.asqpreferences.subject',
            'getaccountresponse.accountentries.accountentry',
            'getaccountresponse.accountsummary.additionalaccount',
            'additemresponse.additemresponsecontainer.discountreason',
            'additemsresponse.additemresponsecontainer.discountreason',
            'setnotificationpreferencesresponse.applicationdeliverypreferences.deliveryurldetails',
            'additemresponse.attributearray.attribute',
            'additemsresponse.attributearray.attribute',
            'verifyadditemresponse.attributearray.attribute',
            'additemresponse.attribute.value',
            'additemsresponse.attribute.value',
            'addsellingmanagertemplateresponse.attribute.value',
            'addliveauctionitemresponse.attribute.value',
            'getitemrecommendationsresponse.attribute.value',
            'verifyadditemresponse.attribute.value',
            'addfixedpriceitemresponse.attribute.value',
            'relistfixedpriceitemresponse.attribute.value',
            'revisefixedpriceitemresponse.attribute.value',
            'getfeedbackresponse.averageratingdetailarray.averageratingdetails',
            'getfeedbackresponse.averageratingsummary.averageratingdetails',
            'respondtobestofferresponse.bestofferarray.bestoffer',
            'getliveauctionbiddersresponse.bidderdetailarray.bidderdetail',
            'getallbiddersresponse.biddingsummary.itembiddetails',
            'getsellerdashboardresponse.buyersatisfactiondashboard.alert',
            'getshippingdiscountprofilesresponse.calculatedshippingdiscount.discountprofile',
            'getcategoriesresponse.categoryarray.category',
            'getcategoryfeaturesresponse.categoryfeature.listingduration',
            'getcategoryfeaturesresponse.categoryfeature.paymentmethod',
            'getcategoriesresponse.category.categoryparentid',
            'getsuggestedcategoriesresponse.category.categoryparentname',
            'getcategory2csresponse.category.productfinderids',
            'getcategory2csresponse.category.characteristicssets',
            'getproductfamilymembersresponse.characteristicsset.characteristics',
            'getproductsearchpageresponse.characteristicsset.characteristics',
            'getproductsearchresultsresponse.characteristicsset.characteristics',
            'getuserresponse.charityaffiliationdetails.charityaffiliationdetail',
            'getbidderlistresponse.charityaffiliations.charityid',
            'setcharitiesresponse.charityinfo.nonprofitaddress',
            'setcharitiesresponse.charityinfo.nonprofitsocialaddress',
            'getcategoryfeaturesresponse.conditionvalues.condition',
            'getbidderlistresponse.crosspromotions.promoteditem',
            'getuserdisputesresponse.disputearray.dispute',
            'getuserdisputesresponse.dispute.disputeresolution',
            'getdisputeresponse.dispute.disputemessage',
            'setsellingmanagerfeedbackoptionsresponse.feedbackcommentarray.storedcommenttext',
            'getfeedbackresponse.feedbackdetailarray.feedbackdetail',
            'getfeedbackresponse.feedbackperiodarray.feedbackperiod',
            'addfixedpriceitemresponse.fees.fee',
            'additemresponse.fees.fee',
            'additemsresponse.fees.fee',
            'addliveauctionitemresponse.fees.fee',
            'relistfixedpriceitemresponse.fees.fee',
            'relistitemresponse.fees.fee',
            'revisefixedpriceitemresponse.fees.fee',
            'reviseitemresponse.fees.fee',
            'reviseliveauctionitemresponse.fees.fee',
            'verifyaddfixedpriceitemresponse.fees.fee',
            'verifyadditemresponse.fees.fee',
            'reviseinventorystatusresponse.fees.fee',
            'verifyrelistitemresponse.fees.fee',
            'getshippingdiscountprofilesresponse.flatshippingdiscount.discountprofile',
            'getitemrecommendationsresponse.getrecommendationsrequestcontainer.recommendationengine',
            'getitemrecommendationsresponse.getrecommendationsrequestcontainer.deletedfield',
            'getuserresponse.integratedmerchantcreditcardinfo.supportedsite',
            'sendinvoiceresponse.internationalshippingserviceoptions.shiptolocation',
            'reviseinventorystatusresponse.inventoryfees.fee',
            'getbidderlistresponse.itemarray.item',
            'getbestoffersresponse.itembestoffersarray.itembestoffers',
            'addfixedpriceitemresponse.itemcompatibilitylist.compatibility',
            'additemresponse.itemcompatibilitylist.compatibility',
            'additemfromsellingmanagertemplateresponse.itemcompatibilitylist.compatibility',
            'additemsresponse.itemcompatibilitylist.compatibility',
            'addsellingmanagertemplateresponse.itemcompatibilitylist.compatibility',
            'relistfixedpriceitemresponse.itemcompatibilitylist.compatibility',
            'relistitemresponse.itemcompatibilitylist.compatibility',
            'revisefixedpriceitemresponse.itemcompatibilitylist.compatibility',
            'reviseitemresponse.itemcompatibilitylist.compatibility',
            'revisesellingmanagertemplateresponse.itemcompatibilitylist.compatibility',
            'verifyaddfixedpriceitemresponse.itemcompatibilitylist.compatibility',
            'verifyadditemresponse.itemcompatibilitylist.compatibility',
            'verifyrelistitemresponse.itemcompatibilitylist.compatibility',
            'addfixedpriceitemresponse.itemcompatibility.namevaluelist',
            'additemresponse.itemcompatibility.namevaluelist',
            'additemfromsellingmanagertemplateresponse.itemcompatibility.namevaluelist',
            'additemsresponse.itemcompatibility.namevaluelist',
            'addsellingmanagertemplateresponse.itemcompatibility.namevaluelist',
            'relistfixedpriceitemresponse.itemcompatibility.namevaluelist',
            'relistitemresponse.itemcompatibility.namevaluelist',
            'revisefixedpriceitemresponse.itemcompatibility.namevaluelist',
            'reviseitemresponse.itemcompatibility.namevaluelist',
            'revisesellingmanagertemplateresponse.itemcompatibility.namevaluelist',
            'verifyadditemresponse.itemcompatibility.namevaluelist',
            'verifyrelistitemresponse.itemcompatibility.namevaluelist',
            'getpromotionalsaledetailsresponse.itemidarray.itemid',
            'leavefeedbackresponse.itemratingdetailarray.itemratingdetails',
            'getordertransactionsresponse.itemtransactionidarray.itemtransactionid',
            'addfixedpriceitemresponse.item.giftservices',
            'additemresponse.item.giftservices',
            'additemsresponse.item.giftservices',
            'addsellingmanagertemplateresponse.item.giftservices',
            'getitemrecommendationsresponse.item.giftservices',
            'relistfixedpriceitemresponse.item.giftservices',
            'relistitemresponse.item.giftservices',
            'revisefixedpriceitemresponse.item.giftservices',
            'reviseitemresponse.item.giftservices',
            'revisesellingmanagertemplateresponse.item.giftservices',
            'verifyadditemresponse.item.giftservices',
            'verifyrelistitemresponse.item.giftservices',
            'addfixedpriceitemresponse.item.listingenhancement',
            'additemresponse.item.listingenhancement',
            'additemsresponse.item.listingenhancement',
            'addsellingmanagertemplateresponse.item.listingenhancement',
            'getitemrecommendationsresponse.item.listingenhancement',
            'relistfixedpriceitemresponse.item.listingenhancement',
            'relistitemresponse.item.listingenhancement',
            'revisefixedpriceitemresponse.item.listingenhancement',
            'reviseitemresponse.item.listingenhancement',
            'revisesellingmanagertemplateresponse.item.listingenhancement',
            'verifyadditemresponse.item.listingenhancement',
            'verifyrelistitemresponse.item.listingenhancement',
            'addfixedpriceitemresponse.item.paymentmethods',
            'additemresponse.item.paymentmethods',
            'additemfromsellingmanagertemplateresponse.item.paymentmethods',
            'additemsresponse.item.paymentmethods',
            'addsellingmanagertemplateresponse.item.paymentmethods',
            'relistfixedpriceitemresponse.item.paymentmethods',
            'relistitemresponse.item.paymentmethods',
            'revisefixedpriceitemresponse.item.paymentmethods',
            'reviseitemresponse.item.paymentmethods',
            'verifyadditemresponse.item.paymentmethods',
            'verifyrelistitemresponse.item.paymentmethods',
            'addfixedpriceitemresponse.item.shiptolocations',
            'additemresponse.item.shiptolocations',
            'additemsresponse.item.shiptolocations',
            'addsellingmanagertemplateresponse.item.shiptolocations',
            'getitemrecommendationsresponse.item.shiptolocations',
            'relistfixedpriceitemresponse.item.shiptolocations',
            'relistitemresponse.item.shiptolocations',
            'revisefixedpriceitemresponse.item.shiptolocations',
            'reviseitemresponse.item.shiptolocations',
            'revisesellingmanagertemplateresponse.item.shiptolocations',
            'verifyadditemresponse.item.shiptolocations',
            'verifyrelistitemresponse.item.shiptolocations',
            'addfixedpriceitemresponse.item.skypecontactoption',
            'additemresponse.item.skypecontactoption',
            'additemsresponse.item.skypecontactoption',
            'addsellingmanagertemplateresponse.item.skypecontactoption',
            'relistfixedpriceitemresponse.item.skypecontactoption',
            'relistitemresponse.item.skypecontactoption',
            'revisefixedpriceitemresponse.item.skypecontactoption',
            'reviseitemresponse.item.skypecontactoption',
            'revisesellingmanagertemplateresponse.item.skypecontactoption',
            'verifyadditemresponse.item.skypecontactoption',
            'verifyrelistitemresponse.item.skypecontactoption',
            'addfixedpriceitemresponse.item.crossbordertrade',
            'additemresponse.item.crossbordertrade',
            'additemsresponse.item.crossbordertrade',
            'addsellingmanagertemplateresponse.item.crossbordertrade',
            'relistfixedpriceitemresponse.item.crossbordertrade',
            'relistitemresponse.item.crossbordertrade',
            'revisefixedpriceitemresponse.item.crossbordertrade',
            'reviseitemresponse.item.crossbordertrade',
            'revisesellingmanagertemplateresponse.item.crossbordertrade',
            'verifyadditemresponse.item.crossbordertrade',
            'verifyrelistitemresponse.item.crossbordertrade',
            'getitemresponse.item.paymentallowedsite',
            'getsellingmanagertemplatesresponse.item.paymentallowedsite',
            'getcategoryfeaturesresponse.listingdurationdefinition.duration',
            'getcategoryfeaturesresponse.listingdurationdefinitions.listingduration',
            'getcategoryfeaturesresponse.listingenhancementdurationreference.duration',
            'addfixedpriceitemresponse.listingrecommendation.value',
            'additemresponse.listingrecommendation.value',
            'additemsresponse.listingrecommendation.value',
            'relistfixedpriceitemresponse.listingrecommendation.value',
            'relistitemresponse.listingrecommendation.value',
            'revisefixedpriceitemresponse.listingrecommendation.value',
            'reviseitemresponse.listingrecommendation.value',
            'verifyadditemresponse.listingrecommendation.value',
            'verifyaddfixedpriceitemresponse.listingrecommendation.value',
            'verifyrelistitemresponse.listingrecommendation.value',
            'addfixedpriceitemresponse.listingrecommendations.recommendation',
            'additemresponse.listingrecommendations.recommendation',
            'additemsresponse.listingrecommendations.recommendation',
            'relistfixedpriceitemresponse.listingrecommendations.recommendation',
            'relistitemresponse.listingrecommendations.recommendation',
            'revisefixedpriceitemresponse.listingrecommendations.recommendation',
            'reviseitemresponse.listingrecommendations.recommendation',
            'verifyadditemresponse.listingrecommendations.recommendation',
            'verifyaddfixedpriceitemresponse.listingrecommendations.recommendation',
            'verifyrelistitemresponse.listingrecommendations.recommendation',
            'getitemrecommendationsresponse.listingtiparray.listingtip',
            'getnotificationsusageresponse.markupmarkdownhistory.markupmarkdownevent',
            'getebaydetailsresponse.maximumbuyerpolicyviolationsdetails.policyviolationduration',
            'getebaydetailsresponse.maximumitemrequirementsdetails.maximumitemcount',
            'getebaydetailsresponse.maximumitemrequirementsdetails.minimumfeedbackscore',
            'getebaydetailsresponse.maximumunpaiditemstrikescountdetails.count',
            'getebaydetailsresponse.maximumunpaiditemstrikesinfodetails.maximumunpaiditemstrikesduration',
            'getadformatleadsresponse.membermessageexchangearray.membermessageexchange',
            'getadformatleadsresponse.membermessageexchange.response',
            'getmembermessagesresponse.membermessageexchange.messagemedia',
            'addmembermessageaaqtopartnerresponse.membermessage.recipientid',
            'addmembermessagertqresponse.membermessage.recipientid',
            'addmembermessagesaaqtobidderresponse.membermessage.recipientid',
            'addmembermessageaaqtopartnerresponse.membermessage.messagemedia',
            'addmembermessagertqresponse.membermessage.messagemedia',
            'addmembermessagecemresponse.membermessage.messagemedia',
            'addmembermessageaaqtosellerresponse.membermessage.messagemedia',
            'getebaydetailsresponse.minimumfeedbackscoredetails.feedbackscore',
            'relistfixedpriceitemresponse.modifynamearray.modifyname',
            'revisefixedpriceitemresponse.modifynamearray.modifyname',
            'getmymessagesresponse.mymessagesexternalmessageidarray.externalmessageid',
            'getmymessagesresponse.mymessagesmessagearray.message',
            'deletemymessagesresponse.mymessagesmessageidarray.messageid',
            'getmymessagesresponse.mymessagesmessage.messagemedia',
            'getmymessagesresponse.mymessagessummary.foldersummary',
            'getmyebaybuyingresponse.myebayfavoritesearchlist.favoritesearch',
            'getmyebaybuyingresponse.myebayfavoritesearch.searchflag',
            'getmyebaybuyingresponse.myebayfavoritesearch.sellerid',
            'getmyebaybuyingresponse.myebayfavoritesearch.selleridexclude',
            'getmyebaybuyingresponse.myebayfavoritesellerlist.favoriteseller',
            'getcategoryspecificsresponse.namerecommendation.valuerecommendation',
            'getitemrecommendationsresponse.namerecommendation.valuerecommendation',
            'addfixedpriceitemresponse.namevaluelistarray.namevaluelist',
            'additemresponse.namevaluelistarray.namevaluelist',
            'additemsresponse.namevaluelistarray.namevaluelist',
            'addsellingmanagertemplateresponse.namevaluelistarray.namevaluelist',
            'addliveauctionitemresponse.namevaluelistarray.namevaluelist',
            'relistfixedpriceitemresponse.namevaluelistarray.namevaluelist',
            'relistitemresponse.namevaluelistarray.namevaluelist',
            'revisefixedpriceitemresponse.namevaluelistarray.namevaluelist',
            'reviseitemresponse.namevaluelistarray.namevaluelist',
            'revisesellingmanagertemplateresponse.namevaluelistarray.namevaluelist',
            'reviseliveauctionitemresponse.namevaluelistarray.namevaluelist',
            'verifyaddfixedpriceitemresponse.namevaluelistarray.namevaluelist',
            'verifyadditemresponse.namevaluelistarray.namevaluelist',
            'verifyrelistitemresponse.namevaluelistarray.namevaluelist',
            'additemresponse.namevaluelist.value',
            'additemfromsellingmanagertemplateresponse.namevaluelist.value',
            'additemsresponse.namevaluelist.value',
            'addsellingmanagertemplateresponse.namevaluelist.value',
            'addliveauctionitemresponse.namevaluelist.value',
            'relistitemresponse.namevaluelist.value',
            'reviseitemresponse.namevaluelist.value',
            'revisesellingmanagertemplateresponse.namevaluelist.value',
            'reviseliveauctionitemresponse.namevaluelist.value',
            'verifyadditemresponse.namevaluelist.value',
            'verifyrelistitemresponse.namevaluelist.value',
            'getnotificationsusageresponse.notificationdetailsarray.notificationdetails',
            'setnotificationpreferencesresponse.notificationenablearray.notificationenable',
            'setnotificationpreferencesresponse.notificationuserdata.summaryschedule',
            'getebaydetailsresponse.numberofpolicyviolationsdetails.count',
            'getallbiddersresponse.offerarray.offer',
            'gethighbiddersresponse.offerarray.offer',
            'getordersresponse.orderarray.order',
            'getordersresponse.orderarray.order.transactionarray.transaction',
            'getordersresponse.orderidarray.orderid',
            'getmyebaybuyingresponse.ordertransactionarray.ordertransaction',
            'addorderresponse.order.paymentmethods',
            'getordertransactionsresponse.order.externaltransaction',
            'getordersresponse.order.externaltransaction',
            'getordersresponse.paymentinformationcode.payment',
            'getordersresponse.paymentinformation.payment',
            'getordersresponse.paymenttransactioncode.paymentreferenceid',
            'getordersresponse.paymenttransaction.paymentreferenceid',
            'getsellerdashboardresponse.performancedashboard.site',
            'getordersresponse.pickupdetails.pickupoptions',
            'additemresponse.picturedetails.pictureurl',
            'additemsresponse.picturedetails.pictureurl',
            'addsellingmanagertemplateresponse.picturedetails.pictureurl',
            'getitemrecommendationsresponse.picturedetails.pictureurl',
            'relistitemresponse.picturedetails.pictureurl',
            'reviseitemresponse.picturedetails.pictureurl',
            'revisesellingmanagertemplateresponse.picturedetails.pictureurl',
            'verifyadditemresponse.picturedetails.pictureurl',
            'verifyrelistitemresponse.picturedetails.pictureurl',
            'getitemresponse.picturedetails.externalpictureurl',
            'addfixedpriceitemresponse.pictures.variationspecificpictureset',
            'verifyaddfixedpriceitemresponse.pictures.variationspecificpictureset',
            'relistfixedpriceitemresponse.pictures.variationspecificpictureset',
            'revisefixedpriceitemresponse.pictures.variationspecificpictureset',
            'getsellerdashboardresponse.powersellerdashboard.alert',
            'getbidderlistresponse.productlistingdetails.copyright',
            'getitemrecommendationsresponse.productrecommendations.product',
            'addfixedpriceitemresponse.productsuggestions.productsuggestion',
            'additemresponse.productsuggestions.productsuggestion',
            'relistfixedpriceitemresponse.productsuggestions.productsuggestion',
            'relistitemresponse.productsuggestions.productsuggestion',
            'revisefixedpriceitemresponse.productsuggestions.productsuggestion',
            'reviseitemresponse.productsuggestions.productsuggestion',
            'verifyadditemresponse.productsuggestions.productsuggestion',
            'verifyrelistitemresponse.productsuggestions.productsuggestion',
            'getpromotionalsaledetailsresponse.promotionalsalearray.promotionalsale',
            'addfixedpriceitemresponse.recommendation.recommendedvalue',
            'additemresponse.recommendation.recommendedvalue',
            'additemsresponse.recommendation.recommendedvalue',
            'relistfixedpriceitemresponse.recommendation.recommendedvalue',
            'relistitemresponse.recommendation.recommendedvalue',
            'revisefixedpriceitemresponse.recommendation.recommendedvalue',
            'reviseitemresponse.recommendation.recommendedvalue',
            'verifyadditemresponse.recommendation.recommendedvalue',
            'verifyaddfixedpriceitemresponse.recommendation.recommendedvalue',
            'verifyrelistitemresponse.recommendation.recommendedvalue',
            'getcategoryspecificsresponse.recommendationvalidationrules.relationship',
            'getitemrecommendationsresponse.recommendationvalidationrules.relationship',
            'getcategoryspecificsresponse.recommendations.namerecommendation',
            'getitemrecommendationsresponse.recommendations.namerecommendation',
            'getuserresponse.recoupmentpolicyconsent.site',
            'getordersresponse.refundarray.refund',
            'getordersresponse.refundfundingsourcearray.refundfundingsource',
            'getitemtransactionsresponse.refundfundingsourcearray.refundfundingsource',
            'getordertransactionsresponse.refundfundingsourcearray.refundfundingsource',
            'getsellertransactionsresponse.refundfundingsourcearray.refundfundingsource',
            'getordersresponse.refundinformation.refund',
            'getordersresponse.refundlinearray.refundline',
            'getitemtransactionsresponse.refundlinearray.refundline',
            'getordertransactionsresponse.refundlinearray.refundline',
            'getsellertransactionsresponse.refundlinearray.refundline',
            'getordersresponse.refundtransactionarray.refundtransaction',
            'getitemtransactionsresponse.refundtransactionarray.refundtransaction',
            'getordertransactionsresponse.refundtransactionarray.refundtransaction',
            'getsellertransactionsresponse.refundtransactionarray.refundtransaction',
            'getordersresponse.requiredselleractionarray.requiredselleraction',
            'getebaydetailsresponse.returnpolicydetails.refund',
            'getebaydetailsresponse.returnpolicydetails.returnswithin',
            'getebaydetailsresponse.returnpolicydetails.returnsaccepted',
            'getebaydetailsresponse.returnpolicydetails.warrantyoffered',
            'getebaydetailsresponse.returnpolicydetails.warrantytype',
            'getebaydetailsresponse.returnpolicydetails.warrantyduration',
            'getebaydetailsresponse.returnpolicydetails.shippingcostpaidby',
            'getebaydetailsresponse.returnpolicydetails.restockingfeevalue',
            'getsellertransactionsresponse.skuarray.sku',
            'getsellerlistresponse.skuarray.sku',
            'getsellerdashboardresponse.selleraccountdashboard.alert',
            'getitemtransactionsresponse.sellerdiscounts.sellerdiscount',
            'getordersresponse.sellerdiscounts.sellerdiscount',
            'getordertransactionsresponse.sellerdiscounts.sellerdiscount',
            'getsellertransactionsresponse.sellerdiscounts.sellerdiscount',
            'getuserpreferencesresponse.sellerexcludeshiptolocationpreferences.excludeshiptolocation',
            'getuserpreferencesresponse.sellerfavoriteitempreferences.favoriteitemid',
            'getfeedbackresponse.sellerratingsummaryarray.averageratingsummary',
            'getbidderlistresponse.sellerebaypaymentprocessconsentcode.useragreementinfo',
            'getsellingmanagertemplateautomationruleresponse.sellingmanagerautolistaccordingtoschedule.dayofweek',
            'getsellingmanagerinventoryfolderresponse.sellingmanagerfolderdetails.childfolder',
            'revisesellingmanagerinventoryfolderresponse.sellingmanagerfolderdetails.childfolder',
            'getsellingmanagersalerecordresponse.sellingmanagersoldorder.sellingmanagersoldtransaction',
            'getsellingmanagersoldlistingsresponse.sellingmanagersoldorder.sellingmanagersoldtransaction',
            'getsellingmanagersalerecordresponse.sellingmanagersoldorder.vatrate',
            'getsellingmanagersoldlistingsresponse.sellingmanagersoldtransaction.listedon',
            'getsellingmanagertemplatesresponse.sellingmanagertemplatedetailsarray.sellingmanagertemplatedetails',
            'completesaleresponse.shipmentlineitem.lineitem',
            'addshipmentresponse.shipmentlineitem.lineitem',
            'reviseshipmentresponse.shipmentlineitem.lineitem',
            'revisesellingmanagersalerecordresponse.shipmentlineitem.lineitem',
            'setshipmenttrackinginforesponse.shipmentlineitem.lineitem',
            'completesaleresponse.shipment.shipmenttrackingdetails',
            'getitemresponse.shippingdetails.shippingserviceoptions',
            'getsellingmanagertemplatesresponse.shippingdetails.shippingserviceoptions',
            'addfixedpriceitemresponse.shippingdetails.internationalshippingserviceoption',
            'additemresponse.shippingdetails.internationalshippingserviceoption',
            'additemsresponse.shippingdetails.internationalshippingserviceoption',
            'addsellingmanagertemplateresponse.shippingdetails.internationalshippingserviceoption',
            'addorderresponse.shippingdetails.internationalshippingserviceoption',
            'getitemrecommendationsresponse.shippingdetails.internationalshippingserviceoption',
            'relistfixedpriceitemresponse.shippingdetails.internationalshippingserviceoption',
            'relistitemresponse.shippingdetails.internationalshippingserviceoption',
            'revisefixedpriceitemresponse.shippingdetails.internationalshippingserviceoption',
            'reviseitemresponse.shippingdetails.internationalshippingserviceoption',
            'revisesellingmanagertemplateresponse.shippingdetails.internationalshippingserviceoption',
            'verifyadditemresponse.shippingdetails.internationalshippingserviceoption',
            'verifyrelistitemresponse.shippingdetails.internationalshippingserviceoption',
            'getsellerlistresponse.shippingdetails.excludeshiptolocation',
            'getitemtransactionsresponse.shippingdetails.shipmenttrackingdetails',
            'getsellertransactionsresponse.shippingdetails.shipmenttrackingdetails',
            'getshippingdiscountprofilesresponse.shippinginsurance.flatrateinsurancerangecost',
            'addfixedpriceitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'additemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'additemsresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'verifyadditemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'verifyaddfixedpriceitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'verifyrelistitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'relistfixedpriceitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'relistitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'revisefixedpriceitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'reviseitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'addsellingmanagertemplateresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'revisesellingmanagertemplateresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'getebaydetailsresponse.shippingservicedetails.servicetype',
            'getebaydetailsresponse.shippingservicedetails.shippingpackage',
            'getebaydetailsresponse.shippingservicedetails.shippingcarrier',
            'getebaydetailsresponse.shippingservicedetails.deprecationdetails',
            'getebaydetailsresponse.shippingservicedetails.shippingservicepackagedetails',
            'getordersresponse.shippingserviceoptions.shippingpackageinfo',
            'getcategoryfeaturesresponse.sitedefaults.listingduration',
            'getcategoryfeaturesresponse.sitedefaults.paymentmethod',
            'uploadsitehostedpicturesresponse.sitehostedpicturedetails.picturesetmember',
            'getcategory2csresponse.sitewidecharacteristics.excludecategoryid',
            'getstoreoptionsresponse.storecolorschemearray.colorscheme',
            'getstoreresponse.storecustomcategoryarray.customcategory',
            'getstoreresponse.storecustomcategory.childcategory',
            'setstorecategoriesresponse.storecustomcategory.childcategory',
            'setstoreresponse.storecustomlistingheader.linktoinclude',
            'getstorecustompageresponse.storecustompagearray.custompage',
            'getstoreoptionsresponse.storelogoarray.logo',
            'getcategoryfeaturesresponse.storeownerextendedlistingdurations.duration',
            'getstoreoptionsresponse.storesubscriptionarray.subscription',
            'getstoreoptionsresponse.storethemearray.theme',
            'getsuggestedcategoriesresponse.suggestedcategoryarray.suggestedcategory',
            'getuserpreferencesresponse.supportedsellerprofiles.supportedsellerprofile',
            'settaxtableresponse.taxtable.taxjurisdiction',
            'getitemtransactionsresponse.taxes.taxdetails',
            'getordersresponse.taxes.taxdetails',
            'getordertransactionsresponse.taxes.taxdetails',
            'getsellertransactionsresponse.taxes.taxdetails',
            'getdescriptiontemplatesresponse.themegroup.themeid',
            'getuserresponse.topratedsellerdetails.topratedprogram',
            'getordersresponse.transactionarray.transaction',
            'getitemtransactionsresponse.transaction.externaltransaction',
            'getsellertransactionsresponse.transaction.externaltransaction',
            'getebaydetailsresponse.unitofmeasurementdetails.unitofmeasurement',
            'getebaydetailsresponse.unitofmeasurement.alternatetext',
            'getuserpreferencesresponse.unpaiditemassistancepreferences.excludeduser',
            'getsellerlistresponse.useridarray.userid',
            'getuserresponse.user.usersubscription',
            'getuserresponse.user.skypeid',
            'addfixedpriceitemresponse.variationspecificpictureset.pictureurl',
            'revisefixedpriceitemresponse.variationspecificpictureset.pictureurl',
            'relistfixedpriceitemresponse.variationspecificpictureset.pictureurl',
            'verifyaddfixedpriceitemresponse.variationspecificpictureset.pictureurl',
            'getitemresponse.variationspecificpictureset.externalpictureurl',
            'getitemsresponse.variationspecificpictureset.externalpictureurl',
            'addfixedpriceitemresponse.variations.variation',
            'revisefixedpriceitemresponse.variations.variation',
            'relistfixedpriceitemresponse.variations.variation',
            'verifyaddfixedpriceitemresponse.variations.variation',
            'addfixedpriceitemresponse.variations.pictures',
            'revisefixedpriceitemresponse.variations.pictures',
            'relistfixedpriceitemresponse.variations.pictures',
            'verifyaddfixedpriceitemresponse.variations.pictures',
            'getveroreasoncodedetailsresponse.veroreasoncodedetails.verositedetail',
            'veroreportitemsresponse.veroreportitem.region',
            'veroreportitemsresponse.veroreportitem.country',
            'veroreportitemsresponse.veroreportitems.reportitem',
            'getveroreportstatusresponse.veroreporteditemdetails.reporteditem',
            'getveroreasoncodedetailsresponse.verositedetail.reasoncodedetail',
            'getebaydetailsresponse.verifieduserrequirementsdetails.feedbackscore',
            'getwantitnowsearchresultsresponse.wantitnowpostarray.wantitnowpost',
        ]

    def build_request_headers(self, verb):
        headers = {
            "X-EBAY-API-COMPATIBILITY-LEVEL": self.config.get('compatibility', ''),
            "X-EBAY-API-DEV-NAME": self.config.get('devid', ''),
            "X-EBAY-API-APP-NAME": self.config.get('appid', ''),
            "X-EBAY-API-CERT-NAME": self.config.get('certid', ''),
            "X-EBAY-API-SITEID": str(self.config.get('siteid', '')),
            "X-EBAY-API-CALL-NAME": self.verb,
            "Content-Type": "text/xml"
        }
        if self.config.get('iaf_token', None):
            headers["X-EBAY-API-IAF-TOKEN"] = self.config.get('iaf_token')

        return headers

    def build_request_data(self, verb, data, verb_attrs):
        xml = "<?xml version='1.0' encoding='utf-8'?>"
        xml += "<{verb}Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">".format(
            verb=self.verb)
        if not self.config.get('iaf_token', None):
            xml += "<RequesterCredentials>"
            if self.config.get('token', None):
                xml += "<eBayAuthToken>{token}</eBayAuthToken>".format(
                    token=self.config.get('token'))
            elif self.config.get('username', None):
                xml += "<Username>{username}</Username>".format(
                    username=self.config.get('username', ''))
                if self.config.get('password', None):
                    xml += "<Password>{password}</Password>".format(
                        password=self.config.get('password', None))
            xml += "</RequesterCredentials>"
        xml += dict2xml(data, self.escape_xml)
        xml += "</{verb}Request>".format(verb=self.verb)
        return xml

    def warnings(self):
        warning_string = ""

        if len(self._resp_body_warnings) > 0:
            warning_string = "{verb}: {message}" \
                .format(verb=self.verb, message=", ".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('Errors'):
            eSeverity = None
            eClass = None
            eShortMsg = None
            eLongMsg = None
            eCode = None

            try:
                eSeverity = e.findall('SeverityCode')[0].text
            except IndexError:
                pass

            try:
                eClass = e.findall('ErrorClassification')[0].text
            except IndexError:
                pass

            try:
                eCode = e.findall('ErrorCode')[0].text
            except IndexError:
                pass

            try:
                eShortMsg = smart_encode(e.findall('ShortMessage')[0].text)
            except IndexError:
                pass

            try:
                eLongMsg = smart_encode(e.findall('LongMessage')[0].text)
            except IndexError:
                pass

            try:
                eCode = e.findall('ErrorCode')[0].text
                if int(eCode) not in resp_codes:
                    resp_codes.append(int(eCode))
            except IndexError:
                pass

            msg = str("Class: {eClass}, Severity: {severity}, Code: {code}, {shortMsg} {longMsg}") \
                .format(eClass=eClass, severity=eSeverity, code=eCode, shortMsg=eShortMsg,
                        longMsg=eLongMsg)

            # from IPython import embed; embed()

            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("{verb}: {message}\n\n".format(
                verb=self.verb, message="\n".join(warnings)))

        if self.response.reply.Ack == 'Failure':
            if self.config.get('errors'):
                log.error("{verb}: {message}\n\n".format(
                    verb=self.verb, message="\n".join(errors)))

            return errors

        return []

    def pages(self):

        tot_pages = 0
        epp = self._request_dict.get(
            'Pagination', {}).get('EntriesPerPage', None)

        if not self.response:
            resp = self.execute(self.verb, self._request_dict)
            tot_pages = int(resp.reply.PaginationResult.TotalNumberOfPages)
            yield resp

        for page in range(tot_pages)[1:]:
            self._request_dict['Pagination'] = {}

            if epp:
                self._request_dict['Pagination']['EntriesPerPage'] = epp

            self._request_dict['Pagination']['PageNumber'] = int(page) + 1

            yield self.execute(self.verb, self._request_dict)
Ejemplo n.º 2
0
class Connection(BaseConnection):
    """Shopping API class

    API documentation:
    http://developer.ebay.com/products/shopping/

    Supported calls:
    getSingleItem
    getMultipleItems
    (all others, see API docs)

    Doctests:
    >>> s = Connection(config_file=os.environ.get('EBAY_YAML'))
    >>> retval = s.execute('FindPopularItems', {'QueryKeywords': 'Python'})
    >>> print(s.response_obj().Ack)
    Success
    >>> print(s.error())
    None
    """
    def __init__(self, **kwargs):
        """Shopping 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: /shopping)
        appid         -- eBay application id
        siteid        -- eBay country site id (default: 0 (US))
        compatibility -- 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
        trackingid    -- ID to identify you to your tracking partner
        trackingpartnercode -- third party who is your tracking partner
        response_encoding   -- API encoding (default: XML)
        request_encoding    -- API encoding (default: XML)

        More affiliate tracking info:
        http://developer.ebay.com/DevZone/shopping/docs/Concepts/ShoppingAPI_FormatOverview.html#StandardURLParameters

        """
        super(Connection, self).__init__(method='POST', **kwargs)

        self.config = Config(domain=kwargs.get('domain', 'open.api.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', 'open.api.ebay.com'))
        self.config.set('uri', '/shopping')
        self.config.set('warnings', True)
        self.config.set('errors', True)
        self.config.set('https', False)
        self.config.set('siteid', '0')
        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('appid', None)
        self.config.set('version', '799')
        self.config.set('trackingid', None)
        self.config.set('trackingpartnercode', None)
        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 = [
            'findhalfproductsresponse.halfcatalogproduct.productid',
            'findhalfproductsresponse.halfproducts.product',
            'getshippingcostsresponse.internationalshippingserviceoption.shipsto',
            'getsingleitemresponse.itemcompatibility.compatibility',
            'getsingleitemresponse.itemcompatibility.namevaluelist',
            'getsingleitemresponse.variationspecifics.namevaluelist',
            'getsingleitemresponse.namevaluelist.value',
            'getsingleitemresponse.pictures.variationspecificpictureset',
            'getmultipleitemsresponse.pictures.variationspecificpictureset',
            'findreviewsandguidesresponse.reviewdetails.review',
            'getshippingcostsresponse.shippingdetails.internationalshippingserviceoption',
            'getshippingcostsresponse.shippingdetails.shippingserviceoption',
            'getshippingcostsresponse.shippingdetails.excludeshiptolocation',
            'getshippingcostsresponse.shippingserviceoption.shipsto',
            'findpopularitemsresponse.itemarray.item',
            'findproductsresponse.itemarray.item',
            'getsingleitemresponse.item.paymentmethods',
            'getmultipleitemsresponse.item.pictureurl',
            'getsingleitemresponse.item.pictureurl',
            'findproductsresponse.item.shiptolocations',
            'getmultipleitemsresponse.item.shiptolocations',
            'getsingleitemresponse.item.shiptolocations',
            'getmultipleitemsresponse.item.paymentallowedsite',
            'getsingleitemresponse.item.paymentallowedsite',
            'getsingleitemresponse.item.excludeshiptolocation',
            'getshippingcostsresponse.taxtable.taxjurisdiction',
            'getsingleitemresponse.variationspecificpictureset.pictureurl',
            'getmultipleitemsresponse.variationspecificpictureset.pictureurl',
            'getsingleitemresponse.variations.variation',
            'getmultipleitemsresponse.variations.variation',
            'getsingleitemresponse.variations.pictures',
            'getmultipleitemsresponse.variations.pictures',
        ]

    def build_request_headers(self, verb):
        headers = {
            "X-EBAY-API-VERSION": self.config.get('version', ''),
            "X-EBAY-API-APP-ID": self.config.get('appid', ''),
            "X-EBAY-API-SITE-ID": self.config.get('siteid', ''),
            "X-EBAY-API-CALL-NAME": verb,
            "X-EBAY-API-REQUEST-ENCODING": "XML",
            "Content-Type": "text/xml"
        }

        if self.config.get('trackingid'):
            headers.update(
                {"X-EBAY-API-TRACKING-ID": self.config.get('trackingid')})

        if self.config.get('trackingpartnercode'):
            headers.update({
                "X-EBAY-API-TRACKING-PARTNER-CODE":
                self.config.get('trackingpartnercode')
            })

        return headers

    def build_request_data(self, verb, data, verb_attrs):

        xml = "<?xml version='1.0' encoding='utf-8'?>"
        xml += "<" + verb + "Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">"
        xml += dict2xml(data, self.escape_xml)
        xml += "</" + verb + "Request>"

        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('Errors'):
            eSeverity = None
            eClass = None
            eShortMsg = None
            eLongMsg = None
            eCode = None

            try:
                eSeverity = e.findall('SeverityCode')[0].text
            except IndexError:
                pass

            try:
                eClass = e.findall('ErrorClassification')[0].text
            except IndexError:
                pass

            try:
                eCode = e.findall('ErrorCode')[0].text
            except IndexError:
                pass

            try:
                eShortMsg = e.findall('ShortMessage')[0].text
            except IndexError:
                pass

            try:
                eLongMsg = e.findall('LongMessage')[0].text
            except IndexError:
                pass

            try:
                eCode = float(e.findall('ErrorCode')[0].text)
                if eCode.is_integer():
                    eCode = int(eCode)

                if eCode not in resp_codes:
                    resp_codes.append(eCode)
            except IndexError:
                pass

            msg = "Class: %s, Severity: %s, Code: %s, %s%s" \
                % (eClass, eSeverity, eCode, eShortMsg, eLongMsg)

            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)))

        if self.response.reply.Ack == 'Failure':
            if self.config.get('errors'):
                log.error("%s: %s\n\n" % (self.verb, "\n".join(errors)))
            return errors

        return []
Ejemplo n.º 3
0
class Connection(BaseConnection):
    """Shopping API class

    API documentation:
    http://developer.ebay.com/products/shopping/

    Supported calls:
    getSingleItem
    getMultipleItems
    (all others, see API docs)

    Doctests:
    >>> s = Connection(config_file=os.environ.get('EBAY_YAML'))
    >>> retval = s.execute('FindPopularItems', {'QueryKeywords': 'Python'})
    >>> print(s.response_obj().Ack)
    Success
    >>> print(s.error())
    None
    """

    def __init__(self, **kwargs):
        """Shopping 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: /shopping)
        appid         -- eBay application id
        siteid        -- eBay country site id (default: 0 (US))
        compatibility -- 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
        trackingid    -- ID to identify you to your tracking partner
        trackingpartnercode -- third party who is your tracking partner
        response_encoding   -- API encoding (default: XML)
        request_encoding    -- API encoding (default: XML)

        More affiliate tracking info:
        http://developer.ebay.com/DevZone/shopping/docs/Concepts/ShoppingAPI_FormatOverview.html#StandardURLParameters

        """
        super(Connection, self).__init__(method='POST', **kwargs)

        self.config=Config(domain=kwargs.get('domain', 'open.api.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', 'open.api.ebay.com'))
        self.config.set('uri', '/shopping')
        self.config.set('warnings', True)
        self.config.set('errors', True)
        self.config.set('https', False)
        self.config.set('siteid', '0')
        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('appid', None)
        self.config.set('version', '799')
        self.config.set('trackingid', None)
        self.config.set('trackingpartnercode', None)
        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=[
            'findhalfproductsresponse.halfcatalogproduct.productid',
            'findhalfproductsresponse.halfproducts.product',
            'getshippingcostsresponse.internationalshippingserviceoption.shipsto',
            'getsingleitemresponse.itemcompatibility.compatibility',
            'getsingleitemresponse.itemcompatibility.namevaluelist',
            'getsingleitemresponse.variationspecifics.namevaluelist',
            'getsingleitemresponse.namevaluelist.value',
            'getsingleitemresponse.pictures.variationspecificpictureset',
            'getmultipleitemsresponse.pictures.variationspecificpictureset',
            'findreviewsandguidesresponse.reviewdetails.review',
            'getshippingcostsresponse.shippingdetails.internationalshippingserviceoption',
            'getshippingcostsresponse.shippingdetails.shippingserviceoption',
            'getshippingcostsresponse.shippingdetails.excludeshiptolocation',
            'getshippingcostsresponse.shippingserviceoption.shipsto',
            'findpopularitemsresponse.itemarray.item',
            'findproductsresponse.itemarray.item',
            'getsingleitemresponse.item.paymentmethods',
            'getmultipleitemsresponse.item.pictureurl',
            'getsingleitemresponse.item.pictureurl',
            'findproductsresponse.item.shiptolocations',
            'getmultipleitemsresponse.item.shiptolocations',
            'getsingleitemresponse.item.shiptolocations',
            'getmultipleitemsresponse.item.paymentallowedsite',
            'getsingleitemresponse.item.paymentallowedsite',
            'getsingleitemresponse.item.excludeshiptolocation',
            'getshippingcostsresponse.taxtable.taxjurisdiction',
            'getsingleitemresponse.variationspecificpictureset.pictureurl',
            'getmultipleitemsresponse.variationspecificpictureset.pictureurl',
            'getsingleitemresponse.variations.variation',
            'getmultipleitemsresponse.variations.variation',
            'getsingleitemresponse.variations.pictures',
            'getmultipleitemsresponse.variations.pictures',
        ]

    def build_request_headers(self, verb):
        headers = {
            "X-EBAY-API-VERSION": self.config.get('version', ''),
            "X-EBAY-API-APP-ID":  self.config.get('appid', ''),
            "X-EBAY-API-SITE-ID":  self.config.get('siteid', ''),
            "X-EBAY-API-CALL-NAME": verb,
            "X-EBAY-API-REQUEST-ENCODING": "XML",
            "Content-Type": "text/xml"
        }

        if self.config.get('trackingid'):
            headers.update({
                "X-EBAY-API-TRACKING-ID": self.config.get('trackingid')
            })

        if self.config.get('trackingpartnercode'):
            headers.update({
                "X-EBAY-API-TRACKING-PARTNER-CODE": self.config.get('trackingpartnercode')
            })

        return headers

    def build_request_data(self, verb, data, verb_attrs):

        xml = "<?xml version='1.0' encoding='utf-8'?>"
        xml += "<" + verb + "Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">"
        xml += dict2xml(data, self.escape_xml)
        xml += "</" + verb + "Request>"

        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('Errors'):
            eSeverity = None
            eClass = None
            eShortMsg = None
            eLongMsg = None
            eCode = None

            try:
                eSeverity = e.findall('SeverityCode')[0].text
            except IndexError:
                pass

            try:
                eClass = e.findall('ErrorClassification')[0].text
            except IndexError:
                pass

            try:
                eCode = e.findall('ErrorCode')[0].text
            except IndexError:
                pass

            try:
                eShortMsg = e.findall('ShortMessage')[0].text
            except IndexError:
                pass

            try:
                eLongMsg = e.findall('LongMessage')[0].text
            except IndexError:
                pass

            try:
                eCode = float(e.findall('ErrorCode')[0].text)
                if eCode.is_integer():
                    eCode = int(eCode)

                if eCode not in resp_codes:
                    resp_codes.append(eCode)
            except IndexError:
                pass

            msg = "Class: %s, Severity: %s, Code: %s, %s%s" \
                % (eClass, eSeverity, eCode, eShortMsg, eLongMsg)

            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)))

        if self.response.reply.Ack == 'Failure':
            if self.config.get('errors'):
                log.error("%s: %s\n\n" % (self.verb, "\n".join(errors)))
            return errors

        return []
Ejemplo n.º 4
0
class Connection(BaseConnection):
    """Connection class for a base SOA service"""
    def __init__(self,
                 app_config=None,
                 site_id='EBAY-US',
                 debug=False,
                 **kwargs):
        """SOA Connection class constructor"""

        super(Connection, self).__init__(method='POST', debug=debug, **kwargs)

        self.config = Config(domain=kwargs.get('domain', ''),
                             connection_kwargs=kwargs,
                             config_file=kwargs.get('config_file',
                                                    'ebay.yaml'))

        self.config.set('https', False)
        self.config.set('site_id', site_id)
        self.config.set('content_type', 'text/xml;charset=UTF-8')
        self.config.set('request_encoding', 'XML')
        self.config.set('response_encoding', 'XML')
        self.config.set('message_protocol', 'SOAP12')
        # http://www.ebay.com/marketplace/fundraising/v1/services',
        self.config.set('soap_env_str', '')

        ph = None
        pp = 80
        if app_config:
            self.load_from_app_config(app_config)
            ph = self.config.get('proxy_host', ph)
            pp = self.config.get('proxy_port', pp)

    # override this method, to provide setup through a config object, which
    # should provide a get() method for extracting constants we care about
    # this method should then set the .api_config[] dict (e.g. the comment
    # below)
    def load_from_app_config(self, app_config):
        # self.api_config['domain'] = app_config.get('API_SERVICE_DOMAIN')
        # self.api_config['uri'] = app_config.get('API_SERVICE_URI')
        pass

    # Note: this method will always return at least an empty object_dict!
    #   It used to return None in some cases. If you get an empty dict,
    #   you can use the .error() method to look for the cause.
    def response_dict(self):
        return self.response.dict()

    def build_request_headers(self, verb):
        return {
            'Content-Type': self.config.get('content_type'),
            'X-EBAY-SOA-SERVICE-NAME': self.config.get('service'),
            'X-EBAY-SOA-OPERATION-NAME': verb,
            'X-EBAY-SOA-GLOBAL-ID': self.config.get('site_id'),
            'X-EBAY-SOA-REQUEST-DATA-FORMAT':
            self.config.get('request_encoding'),
            'X-EBAY-SOA-RESPONSE-DATA-FORMAT':
            self.config.get('response_encoding'),
            'X-EBAY-SOA-MESSAGE-PROTOCOL': self.config.get('message_protocol'),
        }

    def build_request_data(self, verb, data, verb_attrs):
        xml = '<?xml version="1.0" encoding="utf-8"?>'
        xml += '<soap:Envelope'
        xml += ' xmlns:soap="http://www.w3.org/2003/05/soap-envelope"'
        xml += ' xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"'
        xml += ' xmlns:ser="%s" >' % self.config.get('soap_env_str')
        xml += '<soap:Body>'
        xml += '<ser:%sRequest>' % verb
        xml += dict2xml(self.soapify(data), self.escape_xml)
        xml += '</ser:%sRequest>' % verb
        xml += '</soap:Body>'
        xml += '</soap:Envelope>'
        return xml

    def soapify(self, xml):
        xml_type = type(xml)
        if xml_type == dict:
            soap = {}
            for k, v in list(xml.items()):
                if k == '@attrs' or k == '#text':
                    soap[k] = v

                # skip nodes that have ns defined
                elif ':' in k:
                    soap[k] = self.soapify(v)
                else:
                    soap['ser:%s' % (k)] = self.soapify(v)

        elif xml_type == list:
            soap = []
            for x in xml:
                soap.append(self.soapify(x))
        else:
            soap = xml
        return soap

    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()

        <errorMessage xmlns="http://www.ebay.com/marketplace/search/v1/services"><error><errorId>5014</errorId><domain>CoreRuntime</domain><severity>Error</severity><category>System</category><message>
        """

        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:
            pass

        return []
Ejemplo n.º 5
0
class Connection(BaseConnection):
    """Connection class for the Business Policies 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 version='1.0' encoding='utf-8'?>"
        xml += "<{verb}Request xmlns=\"http://www.ebay.com/marketplace/selling\">".format(verb=verb)
        xml += dict2xml(data, self.escape_xml)
        xml += "</{verb}Request>".format(verb=verb)

        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 []
Ejemplo n.º 6
0
class Connection(BaseConnection):
    """Connection class for a base SOA service"""

    def __init__(self, app_config=None, site_id='EBAY-US', debug=False, **kwargs):
        """SOA Connection class constructor"""
        
        super(Connection, self).__init__(method='POST', debug=debug, **kwargs)

        self.config=Config(domain=kwargs.get('domain', ''),
                           connection_kwargs=kwargs,
                           config_file=kwargs.get('config_file', 'ebay.yaml'))

        self.config.set('https', False)
        self.config.set('site_id', site_id)
        self.config.set('content_type', 'text/xml;charset=UTF-8')
        self.config.set('request_encoding', 'XML')
        self.config.set('response_encoding', 'XML')
        self.config.set('message_protocol', 'SOAP12')
        self.config.set('soap_env_str', '') ## http://www.ebay.com/marketplace/fundraising/v1/services',

        ph = None
        pp = 80
        if app_config:
            self.load_from_app_config(app_config)
            ph = self.config.get('proxy_host', ph)
            pp = self.config.get('proxy_port', pp)


    # override this method, to provide setup through a config object, which
    # should provide a get() method for extracting constants we care about
    # this method should then set the .api_config[] dict (e.g. the comment below)
    def load_from_app_config(self, app_config):
        #self.api_config['domain'] = app_config.get('API_SERVICE_DOMAIN')
        #self.api_config['uri'] = app_config.get('API_SERVICE_URI')
        pass

    # Note: this method will always return at least an empty object_dict!
    #   It used to return None in some cases. If you get an empty dict,
    #   you can use the .error() method to look for the cause.
    def response_dict(self):
        return self.response.dict()

        '''
        if self._response_dict:
            return self._response_dict

        if self._response_content:

            mydict = self.response.dict()
            
            try:
                verb = self.verb + 'Response'
                self._response_dict = mydict['Envelope']['Body'][verb]

            except KeyError:
                self._response_dict = mydict.get(self.verb + 'Response', mydict)

        return self._response_dict
        '''

    def build_request_headers(self, verb):
        return {
            'Content-Type': self.config.get('content_type'),
            'X-EBAY-SOA-SERVICE-NAME': self.config.get('service'),
            'X-EBAY-SOA-OPERATION-NAME': verb,
            'X-EBAY-SOA-GLOBAL-ID': self.config.get('site_id'),
            'X-EBAY-SOA-REQUEST-DATA-FORMAT': self.config.get('request_encoding'),
            'X-EBAY-SOA-RESPONSE-DATA-FORMAT': self.config.get('response_encoding'),
            'X-EBAY-SOA-MESSAGE-PROTOCOL': self.config.get('message_protocol'),
        }

    def build_request_data(self, verb, data, verb_attrs):
        xml = '<?xml version="1.0" encoding="utf-8"?>'
        xml += '<soap:Envelope'
        xml += ' xmlns:soap="http://www.w3.org/2003/05/soap-envelope"'
        xml += ' xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"'
        xml += ' xmlns:ser="%s" >' % self.config.get('soap_env_str')
        xml += '<soap:Body>'
        xml += '<ser:%sRequest>' % verb
        xml += dict2xml(self.soapify(data))
        xml += '</ser:%sRequest>' % verb
        xml += '</soap:Body>'
        xml += '</soap:Envelope>'
        return xml

    def soapify(self, xml):
        xml_type = type(xml)
        if xml_type == dict:
            soap = {}
            for k, v in list(xml.items()):
                if k == '@attrs' or k == '#text':
                    soap[k] = v
                    
                # skip nodes that have ns defined
                elif ':' in k:
                    soap[k] = self.soapify(v)
                else:
                    soap['ser:%s' % (k)] = self.soapify(v)
                
        elif xml_type == list:
            soap = []
            for x in xml:
                soap.append(self.soapify(x))
        else:
            soap = xml
        return soap

    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()
        
        <errorMessage xmlns="http://www.ebay.com/marketplace/search/v1/services"><error><errorId>5014</errorId><domain>CoreRuntime</domain><severity>Error</severity><category>System</category><message>
        """

        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:
            pass

        return []
Ejemplo n.º 7
0
class Connection(BaseConnection):
    """Trading API class

    API documentation:
    https://www.x.com/developers/ebay/products/trading-api

    Supported calls:
    AddItem
    ReviseItem
    GetUser
    (all others, see API docs)

    Doctests:
    >>> import datetime
    >>> t = Connection(config_file=os.environ.get('EBAY_YAML'))
    >>> response = t.execute(u'GetCharities', {'CharityID': 3897})
    >>> charity_name = ''
    >>> if len( t.response.dom().xpath('//Name') ) > 0:
    ...   charity_name = t.response.dom().xpath('//Name')[0].text
    >>> print(charity_name)
    Sunshine Kids Foundation
    >>> isinstance(response.reply.Timestamp, datetime.datetime)
    True
    >>> print(t.error())
    None
    >>> t2 = Connection(errors=False, debug=False, config_file=os.environ.get('EBAY_YAML'))
    >>> response = t2.execute(u'VerifyAddItem', {})
    >>> print(t2.response_codes())
    [10009]

    Proof that utf8 errors work (calling .error() was triggering UTF8 Errors
    >>> t3 = Connection(token="WRONG_TOKEN", errors=False, debug=False, config_file=os.environ.get('EBAY_YAML'))
    >>> response = t3.execute(u'VerifyAddItem', {u'ErrorLanguage': u'de_DE'})
    >>> error = t3.error()
    >>> error.startswith('VerifyAddItem: Class: RequestError, Severity:')
    True
    """

    def __init__(self, **kwargs):
        """Trading class constructor.

        Keyword arguments:
        domain        -- API endpoint (default: api.ebay.com)
        config_file   -- YAML defaults (default: ebay.yaml)
        debug         -- debugging enabled (default: False)
        warnings      -- warnings enabled (default: False)
        uri           -- API endpoint uri (default: /ws/api.dll)
        appid         -- eBay application id
        devid         -- eBay developer id
        certid        -- eBay cert id
        token         -- eBay application/user token
        siteid        -- eBay country site id (default: 0 (US))
        compatibility -- version number (default: 648)
        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__(method='POST', **kwargs)

        self.config=Config(domain=kwargs.get('domain', 'api.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', 'api.ebay.com'))
        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('siteid', '0')
        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('devid', None)
        self.config.set('certid', None)
        self.config.set('compatibility', '837')
        self.config.set('doc_url', 'http://developer.ebay.com/devzone/xml/docs/reference/ebay/index.html')

        self.datetime_nodes = [
            'shippingtime',
            'starttime',
            'endtime',
            'scheduletime',
            'createdtime',
            'hardexpirationtime',
            'invoicedate',
            'begindate',
            'enddate',
            'startcreationtime',
            'endcreationtime',
            'endtimefrom',
            'endtimeto',
            'updatetime',
            'lastupdatetime',
            'lastmodifiedtime',
            'modtimefrom',
            'modtimeto',
            'createtimefrom',
            'createtimeto',
            'starttimefrom',
            'starttimeto',
            'timeto',
            'paymenttimefrom',
            'paymenttimeto',
            'inventorycountlastcalculateddate',
            'registrationdate',
            'timefrom',
            'timestamp',
            'messagecreationtime',
            'resolutiontime',
            'date',
            'bankmodifydate',
            'creditcardexpiration',
            'creditcardmodifydate',
            'lastpaymentdate',
            'submittedtime',
            'announcementstarttime',
            'eventtime',
            'periodicstartdate',
            'modtime',
            'expirationtime',
            'creationtime',
            'lastusedtime',
            'disputecreatedtime',
            'disputemodifiedtime',
            'externaltransactiontime',
            'commenttime',
            'lastbidtime',
            'time',
            'creationdate',
            'lastmodifieddate',
            'receivedate',
            'expirationdate',
            'resolutiondate',
            'lastreaddate',
            'userforwarddate',
            'itemendtime',
            'userresponsedate',
            'nextretrytime',
            'deliverytime',
            'timebid',
            'paidtime',
            'shippedtime',
            'expectedreleasedate',
            'paymenttime',
            'promotionalsalestarttime',
            'promotionalsaleendtime',
            'refundtime',
            'refundrequestedtime',
            'refundcompletiontime',
            'estimatedrefundcompletiontime',
            'lastemailsenttime',
            'sellerinvoicetime',
            'estimateddeliverydate',
            'printedtime',
            'deliverydate',
            'refundgrantedtime',
            'scheduleddeliverytimemin',
            'scheduleddeliverytimemax',
            'actualdeliverytime',
            'usebydate',
            'lastopenedtime',
            'returndate',
            'revocationtime',
            'lasttimemodified',
            'createddate',
            'invoicesenttime',
            'acceptedtime',
            'sellerebaypaymentprocessenabletime',
            'useridlastchanged',
            'actionrequiredby',
        ]

        self.base_list_nodes = [
            'getmymessagesresponse.abstractrequest.detaillevel',
            'getaccountresponse.abstractrequest.outputselector',
            'getadformatleadsresponse.abstractrequest.outputselector',
            'getallbiddersresponse.abstractrequest.outputselector',
            'getbestoffersresponse.abstractrequest.outputselector',
            'getbidderlistresponse.abstractrequest.outputselector',
            'getcategoriesresponse.abstractrequest.outputselector',
            'getcategoryfeaturesresponse.abstractrequest.outputselector',
            'getcategorylistingsresponse.abstractrequest.outputselector',
            'getcrosspromotionsresponse.abstractrequest.outputselector',
            'getfeedbackresponse.abstractrequest.outputselector',
            'gethighbiddersresponse.abstractrequest.outputselector',
            'getitemresponse.abstractrequest.outputselector',
            'getitemsawaitingfeedbackresponse.abstractrequest.outputselector',
            'getitemshippingresponse.abstractrequest.outputselector',
            'getitemtransactionsresponse.abstractrequest.outputselector',
            'getmembermessagesresponse.abstractrequest.outputselector',
            'getmyebaybuyingresponse.abstractrequest.outputselector',
            'getmyebaysellingresponse.abstractrequest.outputselector',
            'getmymessagesresponse.abstractrequest.outputselector',
            'getnotificationpreferencesresponse.abstractrequest.outputselector',
            'getordersresponse.abstractrequest.outputselector',
            'getordertransactionsresponse.abstractrequest.outputselector',
            'getproductsresponse.abstractrequest.outputselector',
            'getsearchresultsresponse.abstractrequest.outputselector',
            'getsellereventsresponse.abstractrequest.outputselector',
            'getsellerlistresponse.abstractrequest.outputselector',
            'getsellerpaymentsresponse.abstractrequest.outputselector',
            'getsellertransactionsresponse.abstractrequest.outputselector',
            'getmessagepreferencesresponse.asqpreferences.subject',
            'getaccountresponse.accountentries.accountentry',
            'getaccountresponse.accountsummary.additionalaccount',
            'additemresponse.additemresponsecontainer.discountreason',
            'additemsresponse.additemresponsecontainer.discountreason',
            'setnotificationpreferencesresponse.applicationdeliverypreferences.deliveryurldetails',
            'additemresponse.attributearray.attribute',
            'additemsresponse.attributearray.attribute',
            'verifyadditemresponse.attributearray.attribute',
            'additemresponse.attribute.value',
            'additemsresponse.attribute.value',
            'addsellingmanagertemplateresponse.attribute.value',
            'addliveauctionitemresponse.attribute.value',
            'getitemrecommendationsresponse.attribute.value',
            'verifyadditemresponse.attribute.value',
            'addfixedpriceitemresponse.attribute.value',
            'relistfixedpriceitemresponse.attribute.value',
            'revisefixedpriceitemresponse.attribute.value',
            'getfeedbackresponse.averageratingdetailarray.averageratingdetails',
            'getfeedbackresponse.averageratingsummary.averageratingdetails',
            'respondtobestofferresponse.bestofferarray.bestoffer',
            'getliveauctionbiddersresponse.bidderdetailarray.bidderdetail',
            'getallbiddersresponse.biddingsummary.itembiddetails',
            'getsellerdashboardresponse.buyersatisfactiondashboard.alert',
            'getshippingdiscountprofilesresponse.calculatedshippingdiscount.discountprofile',
            'getcategoriesresponse.categoryarray.category',
            'getcategoryfeaturesresponse.categoryfeature.listingduration',
            'getcategoryfeaturesresponse.categoryfeature.paymentmethod',
            'getcategoriesresponse.category.categoryparentid',
            'getsuggestedcategoriesresponse.category.categoryparentname',
            'getcategory2csresponse.category.productfinderids',
            'getcategory2csresponse.category.characteristicssets',
            'getproductfamilymembersresponse.characteristicsset.characteristics',
            'getproductsearchpageresponse.characteristicsset.characteristics',
            'getproductsearchresultsresponse.characteristicsset.characteristics',
            'getuserresponse.charityaffiliationdetails.charityaffiliationdetail',
            'getbidderlistresponse.charityaffiliations.charityid',
            'setcharitiesresponse.charityinfo.nonprofitaddress',
            'setcharitiesresponse.charityinfo.nonprofitsocialaddress',
            'getcategoryfeaturesresponse.conditionvalues.condition',
            'getbidderlistresponse.crosspromotions.promoteditem',
            'getuserdisputesresponse.disputearray.dispute',
            'getuserdisputesresponse.dispute.disputeresolution',
            'getdisputeresponse.dispute.disputemessage',
            'setsellingmanagerfeedbackoptionsresponse.feedbackcommentarray.storedcommenttext',
            'getfeedbackresponse.feedbackdetailarray.feedbackdetail',
            'getfeedbackresponse.feedbackperiodarray.feedbackperiod',
            'addfixedpriceitemresponse.fees.fee',
            'additemresponse.fees.fee',
            'additemsresponse.fees.fee',
            'addliveauctionitemresponse.fees.fee',
            'relistfixedpriceitemresponse.fees.fee',
            'relistitemresponse.fees.fee',
            'revisefixedpriceitemresponse.fees.fee',
            'reviseitemresponse.fees.fee',
            'reviseliveauctionitemresponse.fees.fee',
            'verifyaddfixedpriceitemresponse.fees.fee',
            'verifyadditemresponse.fees.fee',
            'reviseinventorystatusresponse.fees.fee',
            'verifyrelistitemresponse.fees.fee',
            'getshippingdiscountprofilesresponse.flatshippingdiscount.discountprofile',
            'getitemrecommendationsresponse.getrecommendationsrequestcontainer.recommendationengine',
            'getitemrecommendationsresponse.getrecommendationsrequestcontainer.deletedfield',
            'getuserresponse.integratedmerchantcreditcardinfo.supportedsite',
            'sendinvoiceresponse.internationalshippingserviceoptions.shiptolocation',
            'reviseinventorystatusresponse.inventoryfees.fee',
            'getbidderlistresponse.itemarray.item',
            'getbestoffersresponse.itembestoffersarray.itembestoffers',
            'addfixedpriceitemresponse.itemcompatibilitylist.compatibility',
            'additemresponse.itemcompatibilitylist.compatibility',
            'additemfromsellingmanagertemplateresponse.itemcompatibilitylist.compatibility',
            'additemsresponse.itemcompatibilitylist.compatibility',
            'addsellingmanagertemplateresponse.itemcompatibilitylist.compatibility',
            'relistfixedpriceitemresponse.itemcompatibilitylist.compatibility',
            'relistitemresponse.itemcompatibilitylist.compatibility',
            'revisefixedpriceitemresponse.itemcompatibilitylist.compatibility',
            'reviseitemresponse.itemcompatibilitylist.compatibility',
            'revisesellingmanagertemplateresponse.itemcompatibilitylist.compatibility',
            'verifyaddfixedpriceitemresponse.itemcompatibilitylist.compatibility',
            'verifyadditemresponse.itemcompatibilitylist.compatibility',
            'verifyrelistitemresponse.itemcompatibilitylist.compatibility',
            'addfixedpriceitemresponse.itemcompatibility.namevaluelist',
            'additemresponse.itemcompatibility.namevaluelist',
            'additemfromsellingmanagertemplateresponse.itemcompatibility.namevaluelist',
            'additemsresponse.itemcompatibility.namevaluelist',
            'addsellingmanagertemplateresponse.itemcompatibility.namevaluelist',
            'relistfixedpriceitemresponse.itemcompatibility.namevaluelist',
            'relistitemresponse.itemcompatibility.namevaluelist',
            'revisefixedpriceitemresponse.itemcompatibility.namevaluelist',
            'reviseitemresponse.itemcompatibility.namevaluelist',
            'revisesellingmanagertemplateresponse.itemcompatibility.namevaluelist',
            'verifyadditemresponse.itemcompatibility.namevaluelist',
            'verifyrelistitemresponse.itemcompatibility.namevaluelist',
            'getpromotionalsaledetailsresponse.itemidarray.itemid',
            'leavefeedbackresponse.itemratingdetailarray.itemratingdetails',
            'getordertransactionsresponse.itemtransactionidarray.itemtransactionid',
            'addfixedpriceitemresponse.item.giftservices',
            'additemresponse.item.giftservices',
            'additemsresponse.item.giftservices',
            'addsellingmanagertemplateresponse.item.giftservices',
            'getitemrecommendationsresponse.item.giftservices',
            'relistfixedpriceitemresponse.item.giftservices',
            'relistitemresponse.item.giftservices',
            'revisefixedpriceitemresponse.item.giftservices',
            'reviseitemresponse.item.giftservices',
            'revisesellingmanagertemplateresponse.item.giftservices',
            'verifyadditemresponse.item.giftservices',
            'verifyrelistitemresponse.item.giftservices',
            'addfixedpriceitemresponse.item.listingenhancement',
            'additemresponse.item.listingenhancement',
            'additemsresponse.item.listingenhancement',
            'addsellingmanagertemplateresponse.item.listingenhancement',
            'getitemrecommendationsresponse.item.listingenhancement',
            'relistfixedpriceitemresponse.item.listingenhancement',
            'relistitemresponse.item.listingenhancement',
            'revisefixedpriceitemresponse.item.listingenhancement',
            'reviseitemresponse.item.listingenhancement',
            'revisesellingmanagertemplateresponse.item.listingenhancement',
            'verifyadditemresponse.item.listingenhancement',
            'verifyrelistitemresponse.item.listingenhancement',
            'addfixedpriceitemresponse.item.paymentmethods',
            'additemresponse.item.paymentmethods',
            'additemfromsellingmanagertemplateresponse.item.paymentmethods',
            'additemsresponse.item.paymentmethods',
            'addsellingmanagertemplateresponse.item.paymentmethods',
            'relistfixedpriceitemresponse.item.paymentmethods',
            'relistitemresponse.item.paymentmethods',
            'revisefixedpriceitemresponse.item.paymentmethods',
            'reviseitemresponse.item.paymentmethods',
            'verifyadditemresponse.item.paymentmethods',
            'verifyrelistitemresponse.item.paymentmethods',
            'addfixedpriceitemresponse.item.shiptolocations',
            'additemresponse.item.shiptolocations',
            'additemsresponse.item.shiptolocations',
            'addsellingmanagertemplateresponse.item.shiptolocations',
            'getitemrecommendationsresponse.item.shiptolocations',
            'relistfixedpriceitemresponse.item.shiptolocations',
            'relistitemresponse.item.shiptolocations',
            'revisefixedpriceitemresponse.item.shiptolocations',
            'reviseitemresponse.item.shiptolocations',
            'revisesellingmanagertemplateresponse.item.shiptolocations',
            'verifyadditemresponse.item.shiptolocations',
            'verifyrelistitemresponse.item.shiptolocations',
            'addfixedpriceitemresponse.item.skypecontactoption',
            'additemresponse.item.skypecontactoption',
            'additemsresponse.item.skypecontactoption',
            'addsellingmanagertemplateresponse.item.skypecontactoption',
            'relistfixedpriceitemresponse.item.skypecontactoption',
            'relistitemresponse.item.skypecontactoption',
            'revisefixedpriceitemresponse.item.skypecontactoption',
            'reviseitemresponse.item.skypecontactoption',
            'revisesellingmanagertemplateresponse.item.skypecontactoption',
            'verifyadditemresponse.item.skypecontactoption',
            'verifyrelistitemresponse.item.skypecontactoption',
            'addfixedpriceitemresponse.item.crossbordertrade',
            'additemresponse.item.crossbordertrade',
            'additemsresponse.item.crossbordertrade',
            'addsellingmanagertemplateresponse.item.crossbordertrade',
            'relistfixedpriceitemresponse.item.crossbordertrade',
            'relistitemresponse.item.crossbordertrade',
            'revisefixedpriceitemresponse.item.crossbordertrade',
            'reviseitemresponse.item.crossbordertrade',
            'revisesellingmanagertemplateresponse.item.crossbordertrade',
            'verifyadditemresponse.item.crossbordertrade',
            'verifyrelistitemresponse.item.crossbordertrade',
            'getitemresponse.item.paymentallowedsite',
            'getsellingmanagertemplatesresponse.item.paymentallowedsite',
            'getcategoryfeaturesresponse.listingdurationdefinition.duration',
            'getcategoryfeaturesresponse.listingdurationdefinitions.listingduration',
            'getcategoryfeaturesresponse.listingenhancementdurationreference.duration',
            'addfixedpriceitemresponse.listingrecommendation.value',
            'additemresponse.listingrecommendation.value',
            'additemsresponse.listingrecommendation.value',
            'relistfixedpriceitemresponse.listingrecommendation.value',
            'relistitemresponse.listingrecommendation.value',
            'revisefixedpriceitemresponse.listingrecommendation.value',
            'reviseitemresponse.listingrecommendation.value',
            'verifyadditemresponse.listingrecommendation.value',
            'verifyaddfixedpriceitemresponse.listingrecommendation.value',
            'verifyrelistitemresponse.listingrecommendation.value',
            'addfixedpriceitemresponse.listingrecommendations.recommendation',
            'additemresponse.listingrecommendations.recommendation',
            'additemsresponse.listingrecommendations.recommendation',
            'relistfixedpriceitemresponse.listingrecommendations.recommendation',
            'relistitemresponse.listingrecommendations.recommendation',
            'revisefixedpriceitemresponse.listingrecommendations.recommendation',
            'reviseitemresponse.listingrecommendations.recommendation',
            'verifyadditemresponse.listingrecommendations.recommendation',
            'verifyaddfixedpriceitemresponse.listingrecommendations.recommendation',
            'verifyrelistitemresponse.listingrecommendations.recommendation',
            'getitemrecommendationsresponse.listingtiparray.listingtip',
            'getnotificationsusageresponse.markupmarkdownhistory.markupmarkdownevent',
            'getebaydetailsresponse.maximumbuyerpolicyviolationsdetails.policyviolationduration',
            'getebaydetailsresponse.maximumitemrequirementsdetails.maximumitemcount',
            'getebaydetailsresponse.maximumitemrequirementsdetails.minimumfeedbackscore',
            'getebaydetailsresponse.maximumunpaiditemstrikescountdetails.count',
            'getebaydetailsresponse.maximumunpaiditemstrikesinfodetails.maximumunpaiditemstrikesduration',
            'getadformatleadsresponse.membermessageexchangearray.membermessageexchange',
            'getadformatleadsresponse.membermessageexchange.response',
            'getmembermessagesresponse.membermessageexchange.messagemedia',
            'addmembermessageaaqtopartnerresponse.membermessage.recipientid',
            'addmembermessagertqresponse.membermessage.recipientid',
            'addmembermessagesaaqtobidderresponse.membermessage.recipientid',
            'addmembermessageaaqtopartnerresponse.membermessage.messagemedia',
            'addmembermessagertqresponse.membermessage.messagemedia',
            'addmembermessagecemresponse.membermessage.messagemedia',
            'addmembermessageaaqtosellerresponse.membermessage.messagemedia',
            'getebaydetailsresponse.minimumfeedbackscoredetails.feedbackscore',
            'relistfixedpriceitemresponse.modifynamearray.modifyname',
            'revisefixedpriceitemresponse.modifynamearray.modifyname',
            'getmymessagesresponse.mymessagesexternalmessageidarray.externalmessageid',
            'getmymessagesresponse.mymessagesmessagearray.message',
            'deletemymessagesresponse.mymessagesmessageidarray.messageid',
            'getmymessagesresponse.mymessagesmessage.messagemedia',
            'getmymessagesresponse.mymessagessummary.foldersummary',
            'getmyebaybuyingresponse.myebayfavoritesearchlist.favoritesearch',
            'getmyebaybuyingresponse.myebayfavoritesearch.searchflag',
            'getmyebaybuyingresponse.myebayfavoritesearch.sellerid',
            'getmyebaybuyingresponse.myebayfavoritesearch.selleridexclude',
            'getmyebaybuyingresponse.myebayfavoritesellerlist.favoriteseller',
            'getcategoryspecificsresponse.namerecommendation.valuerecommendation',
            'getitemrecommendationsresponse.namerecommendation.valuerecommendation',
            'addfixedpriceitemresponse.namevaluelistarray.namevaluelist',
            'additemresponse.namevaluelistarray.namevaluelist',
            'additemsresponse.namevaluelistarray.namevaluelist',
            'addsellingmanagertemplateresponse.namevaluelistarray.namevaluelist',
            'addliveauctionitemresponse.namevaluelistarray.namevaluelist',
            'relistfixedpriceitemresponse.namevaluelistarray.namevaluelist',
            'relistitemresponse.namevaluelistarray.namevaluelist',
            'revisefixedpriceitemresponse.namevaluelistarray.namevaluelist',
            'reviseitemresponse.namevaluelistarray.namevaluelist',
            'revisesellingmanagertemplateresponse.namevaluelistarray.namevaluelist',
            'reviseliveauctionitemresponse.namevaluelistarray.namevaluelist',
            'verifyaddfixedpriceitemresponse.namevaluelistarray.namevaluelist',
            'verifyadditemresponse.namevaluelistarray.namevaluelist',
            'verifyrelistitemresponse.namevaluelistarray.namevaluelist',
            'additemresponse.namevaluelist.value',
            'additemfromsellingmanagertemplateresponse.namevaluelist.value',
            'additemsresponse.namevaluelist.value',
            'addsellingmanagertemplateresponse.namevaluelist.value',
            'addliveauctionitemresponse.namevaluelist.value',
            'relistitemresponse.namevaluelist.value',
            'reviseitemresponse.namevaluelist.value',
            'revisesellingmanagertemplateresponse.namevaluelist.value',
            'reviseliveauctionitemresponse.namevaluelist.value',
            'verifyadditemresponse.namevaluelist.value',
            'verifyrelistitemresponse.namevaluelist.value',
            'getnotificationsusageresponse.notificationdetailsarray.notificationdetails',
            'setnotificationpreferencesresponse.notificationenablearray.notificationenable',
            'setnotificationpreferencesresponse.notificationuserdata.summaryschedule',
            'getebaydetailsresponse.numberofpolicyviolationsdetails.count',
            'getallbiddersresponse.offerarray.offer',
            'gethighbiddersresponse.offerarray.offer',
            'getordersresponse.orderarray.order',
            'getordersresponse.orderarray.order.transactionarray.transaction',
            'getordersresponse.orderidarray.orderid',
            'getmyebaybuyingresponse.ordertransactionarray.ordertransaction',
            'addorderresponse.order.paymentmethods',
            'getordertransactionsresponse.order.externaltransaction',
            'getordersresponse.order.externaltransaction',
            'getordersresponse.paymentinformationcode.payment',
            'getordersresponse.paymentinformation.payment',
            'getordersresponse.paymenttransactioncode.paymentreferenceid',
            'getordersresponse.paymenttransaction.paymentreferenceid',
            'getsellerdashboardresponse.performancedashboard.site',
            'getordersresponse.pickupdetails.pickupoptions',
            'additemresponse.picturedetails.pictureurl',
            'additemsresponse.picturedetails.pictureurl',
            'addsellingmanagertemplateresponse.picturedetails.pictureurl',
            'getitemrecommendationsresponse.picturedetails.pictureurl',
            'relistitemresponse.picturedetails.pictureurl',
            'reviseitemresponse.picturedetails.pictureurl',
            'revisesellingmanagertemplateresponse.picturedetails.pictureurl',
            'verifyadditemresponse.picturedetails.pictureurl',
            'verifyrelistitemresponse.picturedetails.pictureurl',
            'getitemresponse.picturedetails.externalpictureurl',
            'addfixedpriceitemresponse.pictures.variationspecificpictureset',
            'verifyaddfixedpriceitemresponse.pictures.variationspecificpictureset',
            'relistfixedpriceitemresponse.pictures.variationspecificpictureset',
            'revisefixedpriceitemresponse.pictures.variationspecificpictureset',
            'getsellerdashboardresponse.powersellerdashboard.alert',
            'getbidderlistresponse.productlistingdetails.copyright',
            'getitemrecommendationsresponse.productrecommendations.product',
            'addfixedpriceitemresponse.productsuggestions.productsuggestion',
            'additemresponse.productsuggestions.productsuggestion',
            'relistfixedpriceitemresponse.productsuggestions.productsuggestion',
            'relistitemresponse.productsuggestions.productsuggestion',
            'revisefixedpriceitemresponse.productsuggestions.productsuggestion',
            'reviseitemresponse.productsuggestions.productsuggestion',
            'verifyadditemresponse.productsuggestions.productsuggestion',
            'verifyrelistitemresponse.productsuggestions.productsuggestion',
            'getpromotionalsaledetailsresponse.promotionalsalearray.promotionalsale',
            'addfixedpriceitemresponse.recommendation.recommendedvalue',
            'additemresponse.recommendation.recommendedvalue',
            'additemsresponse.recommendation.recommendedvalue',
            'relistfixedpriceitemresponse.recommendation.recommendedvalue',
            'relistitemresponse.recommendation.recommendedvalue',
            'revisefixedpriceitemresponse.recommendation.recommendedvalue',
            'reviseitemresponse.recommendation.recommendedvalue',
            'verifyadditemresponse.recommendation.recommendedvalue',
            'verifyaddfixedpriceitemresponse.recommendation.recommendedvalue',
            'verifyrelistitemresponse.recommendation.recommendedvalue',
            'getcategoryspecificsresponse.recommendationvalidationrules.relationship',
            'getitemrecommendationsresponse.recommendationvalidationrules.relationship',
            'getcategoryspecificsresponse.recommendations.namerecommendation',
            'getitemrecommendationsresponse.recommendations.namerecommendation',
            'getuserresponse.recoupmentpolicyconsent.site',
            'getordersresponse.refundarray.refund',
            'getordersresponse.refundfundingsourcearray.refundfundingsource',
            'getitemtransactionsresponse.refundfundingsourcearray.refundfundingsource',
            'getordertransactionsresponse.refundfundingsourcearray.refundfundingsource',
            'getsellertransactionsresponse.refundfundingsourcearray.refundfundingsource',
            'getordersresponse.refundinformation.refund',
            'getordersresponse.refundlinearray.refundline',
            'getitemtransactionsresponse.refundlinearray.refundline',
            'getordertransactionsresponse.refundlinearray.refundline',
            'getsellertransactionsresponse.refundlinearray.refundline',
            'getordersresponse.refundtransactionarray.refundtransaction',
            'getitemtransactionsresponse.refundtransactionarray.refundtransaction',
            'getordertransactionsresponse.refundtransactionarray.refundtransaction',
            'getsellertransactionsresponse.refundtransactionarray.refundtransaction',
            'getordersresponse.requiredselleractionarray.requiredselleraction',
            'getebaydetailsresponse.returnpolicydetails.refund',
            'getebaydetailsresponse.returnpolicydetails.returnswithin',
            'getebaydetailsresponse.returnpolicydetails.returnsaccepted',
            'getebaydetailsresponse.returnpolicydetails.warrantyoffered',
            'getebaydetailsresponse.returnpolicydetails.warrantytype',
            'getebaydetailsresponse.returnpolicydetails.warrantyduration',
            'getebaydetailsresponse.returnpolicydetails.shippingcostpaidby',
            'getebaydetailsresponse.returnpolicydetails.restockingfeevalue',
            'getsellertransactionsresponse.skuarray.sku',
            'getsellerlistresponse.skuarray.sku',
            'getsellerdashboardresponse.selleraccountdashboard.alert',
            'getitemtransactionsresponse.sellerdiscounts.sellerdiscount',
            'getordersresponse.sellerdiscounts.sellerdiscount',
            'getordertransactionsresponse.sellerdiscounts.sellerdiscount',
            'getsellertransactionsresponse.sellerdiscounts.sellerdiscount',
            'getuserpreferencesresponse.sellerexcludeshiptolocationpreferences.excludeshiptolocation',
            'getuserpreferencesresponse.sellerfavoriteitempreferences.favoriteitemid',
            'getfeedbackresponse.sellerratingsummaryarray.averageratingsummary',
            'getbidderlistresponse.sellerebaypaymentprocessconsentcode.useragreementinfo',
            'getsellingmanagertemplateautomationruleresponse.sellingmanagerautolistaccordingtoschedule.dayofweek',
            'getsellingmanagerinventoryfolderresponse.sellingmanagerfolderdetails.childfolder',
            'revisesellingmanagerinventoryfolderresponse.sellingmanagerfolderdetails.childfolder',
            'getsellingmanagersalerecordresponse.sellingmanagersoldorder.sellingmanagersoldtransaction',
            'getsellingmanagersoldlistingsresponse.sellingmanagersoldorder.sellingmanagersoldtransaction',
            'getsellingmanagersalerecordresponse.sellingmanagersoldorder.vatrate',
            'getsellingmanagersoldlistingsresponse.sellingmanagersoldtransaction.listedon',
            'getsellingmanagertemplatesresponse.sellingmanagertemplatedetailsarray.sellingmanagertemplatedetails',
            'completesaleresponse.shipmentlineitem.lineitem',
            'addshipmentresponse.shipmentlineitem.lineitem',
            'reviseshipmentresponse.shipmentlineitem.lineitem',
            'revisesellingmanagersalerecordresponse.shipmentlineitem.lineitem',
            'setshipmenttrackinginforesponse.shipmentlineitem.lineitem',
            'completesaleresponse.shipment.shipmenttrackingdetails',
            'getitemresponse.shippingdetails.shippingserviceoptions',
            'getsellingmanagertemplatesresponse.shippingdetails.shippingserviceoptions',
            'addfixedpriceitemresponse.shippingdetails.internationalshippingserviceoption',
            'additemresponse.shippingdetails.internationalshippingserviceoption',
            'additemsresponse.shippingdetails.internationalshippingserviceoption',
            'addsellingmanagertemplateresponse.shippingdetails.internationalshippingserviceoption',
            'addorderresponse.shippingdetails.internationalshippingserviceoption',
            'getitemrecommendationsresponse.shippingdetails.internationalshippingserviceoption',
            'relistfixedpriceitemresponse.shippingdetails.internationalshippingserviceoption',
            'relistitemresponse.shippingdetails.internationalshippingserviceoption',
            'revisefixedpriceitemresponse.shippingdetails.internationalshippingserviceoption',
            'reviseitemresponse.shippingdetails.internationalshippingserviceoption',
            'revisesellingmanagertemplateresponse.shippingdetails.internationalshippingserviceoption',
            'verifyadditemresponse.shippingdetails.internationalshippingserviceoption',
            'verifyrelistitemresponse.shippingdetails.internationalshippingserviceoption',
            'getsellerlistresponse.shippingdetails.excludeshiptolocation',
            'getitemtransactionsresponse.shippingdetails.shipmenttrackingdetails',
            'getsellertransactionsresponse.shippingdetails.shipmenttrackingdetails',
            'getshippingdiscountprofilesresponse.shippinginsurance.flatrateinsurancerangecost',
            'addfixedpriceitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'additemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'additemsresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'verifyadditemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'verifyaddfixedpriceitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'verifyrelistitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'relistfixedpriceitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'relistitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'revisefixedpriceitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'reviseitemresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'addsellingmanagertemplateresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'revisesellingmanagertemplateresponse.shippingservicecostoverridelist.shippingservicecostoverride',
            'getebaydetailsresponse.shippingservicedetails.servicetype',
            'getebaydetailsresponse.shippingservicedetails.shippingpackage',
            'getebaydetailsresponse.shippingservicedetails.shippingcarrier',
            'getebaydetailsresponse.shippingservicedetails.deprecationdetails',
            'getebaydetailsresponse.shippingservicedetails.shippingservicepackagedetails',
            'getordersresponse.shippingserviceoptions.shippingpackageinfo',
            'getcategoryfeaturesresponse.sitedefaults.listingduration',
            'getcategoryfeaturesresponse.sitedefaults.paymentmethod',
            'uploadsitehostedpicturesresponse.sitehostedpicturedetails.picturesetmember',
            'getcategory2csresponse.sitewidecharacteristics.excludecategoryid',
            'getstoreoptionsresponse.storecolorschemearray.colorscheme',
            'getstoreresponse.storecustomcategoryarray.customcategory',
            'getstoreresponse.storecustomcategory.childcategory',
            'setstorecategoriesresponse.storecustomcategory.childcategory',
            'setstoreresponse.storecustomlistingheader.linktoinclude',
            'getstorecustompageresponse.storecustompagearray.custompage',
            'getstoreoptionsresponse.storelogoarray.logo',
            'getcategoryfeaturesresponse.storeownerextendedlistingdurations.duration',
            'getstoreoptionsresponse.storesubscriptionarray.subscription',
            'getstoreoptionsresponse.storethemearray.theme',
            'getsuggestedcategoriesresponse.suggestedcategoryarray.suggestedcategory',
            'getuserpreferencesresponse.supportedsellerprofiles.supportedsellerprofile',
            'settaxtableresponse.taxtable.taxjurisdiction',
            'getitemtransactionsresponse.taxes.taxdetails',
            'getordersresponse.taxes.taxdetails',
            'getordertransactionsresponse.taxes.taxdetails',
            'getsellertransactionsresponse.taxes.taxdetails',
            'getdescriptiontemplatesresponse.themegroup.themeid',
            'getuserresponse.topratedsellerdetails.topratedprogram',
            'getordersresponse.transactionarray.transaction',
            'getitemtransactionsresponse.transaction.externaltransaction',
            'getsellertransactionsresponse.transaction.externaltransaction',
            'getebaydetailsresponse.unitofmeasurementdetails.unitofmeasurement',
            'getebaydetailsresponse.unitofmeasurement.alternatetext',
            'getuserpreferencesresponse.unpaiditemassistancepreferences.excludeduser',
            'getsellerlistresponse.useridarray.userid',
            'getuserresponse.user.usersubscription',
            'getuserresponse.user.skypeid',
            'addfixedpriceitemresponse.variationspecificpictureset.pictureurl',
            'revisefixedpriceitemresponse.variationspecificpictureset.pictureurl',
            'relistfixedpriceitemresponse.variationspecificpictureset.pictureurl',
            'verifyaddfixedpriceitemresponse.variationspecificpictureset.pictureurl',
            'getitemresponse.variationspecificpictureset.externalpictureurl',
            'getitemsresponse.variationspecificpictureset.externalpictureurl',
            'addfixedpriceitemresponse.variations.variation',
            'revisefixedpriceitemresponse.variations.variation',
            'relistfixedpriceitemresponse.variations.variation',
            'verifyaddfixedpriceitemresponse.variations.variation',
            'addfixedpriceitemresponse.variations.pictures',
            'revisefixedpriceitemresponse.variations.pictures',
            'relistfixedpriceitemresponse.variations.pictures',
            'verifyaddfixedpriceitemresponse.variations.pictures',
            'getveroreasoncodedetailsresponse.veroreasoncodedetails.verositedetail',
            'veroreportitemsresponse.veroreportitem.region',
            'veroreportitemsresponse.veroreportitem.country',
            'veroreportitemsresponse.veroreportitems.reportitem',
            'getveroreportstatusresponse.veroreporteditemdetails.reporteditem',
            'getveroreasoncodedetailsresponse.verositedetail.reasoncodedetail',
            'getebaydetailsresponse.verifieduserrequirementsdetails.feedbackscore',
            'getwantitnowsearchresultsresponse.wantitnowpostarray.wantitnowpost',
        ]

    def build_request_headers(self, verb):
        headers = {
            "X-EBAY-API-COMPATIBILITY-LEVEL": self.config.get('compatibility', ''),
            "X-EBAY-API-DEV-NAME": self.config.get('devid', ''),
            "X-EBAY-API-APP-NAME": self.config.get('appid', ''),
            "X-EBAY-API-CERT-NAME": self.config.get('certid', ''),
            "X-EBAY-API-SITEID": self.config.get('siteid', ''),
            "X-EBAY-API-CALL-NAME": self.verb,
            "Content-Type": "text/xml"
        }
        if self.config.get('iaf_token', None):
            headers["X-EBAY-API-IAF-TOKEN"] = self.config.get('iaf_token')

        return headers

    def build_request_data(self, verb, data, verb_attrs):
        xml = "<?xml version='1.0' encoding='utf-8'?>"
        xml += "<{verb}Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">".format(verb=self.verb)
        if not self.config.get('iaf_token', None):
            xml += "<RequesterCredentials>"
            if self.config.get('token', None):
                xml += "<eBayAuthToken>{token}</eBayAuthToken>".format(token=self.config.get('token'))
            elif self.config.get('username', None):
                xml += "<Username>{username}</Username>".format(username=self.config.get('username', ''))
                if self.config.get('password', None):
                    xml += "<Password>{password}</Password>".format(password=self.config.get('password', None))
            xml += "</RequesterCredentials>"
        xml += dict2xml(data, self.escape_xml)
        xml += "</{verb}Request>".format(verb=self.verb)
        return xml

    def warnings(self):
        warning_string = ""

        if len(self._resp_body_warnings) > 0:
            warning_string = "{verb}: {message}" \
                .format(verb=self.verb, message=", ".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('Errors'):
            eSeverity = None
            eClass = None
            eShortMsg = None
            eLongMsg = None
            eCode = None

            try:
                eSeverity = e.findall('SeverityCode')[0].text
            except IndexError:
                pass

            try:
                eClass = e.findall('ErrorClassification')[0].text
            except IndexError:
                pass

            try:
                eCode = e.findall('ErrorCode')[0].text
            except IndexError:
                pass

            try:
                eShortMsg = smart_encode(e.findall('ShortMessage')[0].text)
            except IndexError:
                pass

            try:
                eLongMsg = smart_encode(e.findall('LongMessage')[0].text)
            except IndexError:
                pass

            try:
                eCode = e.findall('ErrorCode')[0].text
                if int(eCode) not in resp_codes:
                    resp_codes.append(int(eCode))    
            except IndexError:
                pass

            msg = str("Class: {eClass}, Severity: {severity}, Code: {code}, {shortMsg} {longMsg}") \
                .format(eClass=eClass, severity=eSeverity, code=eCode, shortMsg=eShortMsg,
                        longMsg=eLongMsg)

            #from IPython import embed; embed()

            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("{verb}: {message}\n\n".format(verb=self.verb, message="\n".join(warnings)))

        if self.response.reply.Ack == 'Failure':
            if self.config.get('errors'):
                log.error("{verb}: {message}\n\n".format(verb=self.verb, message="\n".join(errors)))
            
            return errors

        return []

    def pages(self):

        tot_pages = 0
        epp = self._request_dict.get('Pagination', {}).get('EntriesPerPage', None)

        if not self.response:
            resp = self.execute(self.verb, self._request_dict)
            tot_pages = int(resp.reply.PaginationResult.TotalNumberOfPages)
            yield resp


        for page in range(tot_pages)[1:]:
            self._request_dict['Pagination'] = {}

            if epp:
                self._request_dict['Pagination']['EntriesPerPage'] = epp

            self._request_dict['Pagination']['PageNumber'] = int(page) + 1

            yield self.execute(self.verb, self._request_dict)
Ejemplo n.º 8
0
class Connection(BaseConnection):
    """Trading API class

    API documentation:
    https://www.x.com/developers/ebay/products/trading-api

    Supported calls:
    AddItem
    ReviseItem
    GetUser
    (all others, see API docs)

    Doctests:
    >>> t = Connection(config_file=os.environ.get('EBAY_YAML'))
    >>> retval = t.execute('GetCharities', {'CharityID': 3897})
    >>> charity_name = ''
    >>> if len( t.response_dom().getElementsByTagName('Name') ) > 0:
    ...   charity_name = getNodeText(t.response_dom().getElementsByTagName('Name')[0])
    >>> print(charity_name)
    Sunshine Kids Foundation
    >>> print(t.error())
    None
    >>> t2 = Connection(errors=False, debug=False, config_file=os.environ.get('EBAY_YAML'))
    >>> retval2 = t2.execute('VerifyAddItem', {})
    >>> print(t2.response_codes())
    [10009]
    """
    def __init__(self, **kwargs):
        """Trading class constructor.

        Keyword arguments:
        domain        -- API endpoint (default: api.ebay.com)
        config_file   -- YAML defaults (default: ebay.yaml)
        debug         -- debugging enabled (default: False)
        warnings      -- warnings enabled (default: False)
        uri           -- API endpoint uri (default: /ws/api.dll)
        appid         -- eBay application id
        devid         -- eBay developer id
        certid        -- eBay cert id
        token         -- eBay application/user token
        siteid        -- eBay country site id (default: 0 (US))
        compatibility -- version number (default: 648)
        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__(method='POST', **kwargs)

        self.config = Config(domain=kwargs.get('domain', 'api.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', 'api.ebay.com'))
        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('siteid', 0)
        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('devid', None)
        self.config.set('certid', None)
        self.config.set('version', '837')
        self.config.set('compatibility', '837')

    def build_request_headers(self, verb):
        headers = {
            "X-EBAY-API-COMPATIBILITY-LEVEL": self.config.get('version', ''),
            "X-EBAY-API-DEV-NAME": self.config.get('devid', ''),
            "X-EBAY-API-APP-NAME": self.config.get('appid', ''),
            "X-EBAY-API-CERT-NAME": self.config.get('certid', ''),
            "X-EBAY-API-SITEID": self.config.get('siteid', ''),
            "X-EBAY-API-CALL-NAME": self.verb,
            "Content-Type": "text/xml"
        }
        if self.config.get('iaf_token', None):
            headers["X-EBAY-API-IAF-TOKEN"] = self.config.get('iaf_token')

        return headers

    def build_request_data(self, verb, data):
        xml = "<?xml version='1.0' encoding='utf-8'?>"
        xml += "<" + self.verb + "Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">"
        if not self.config.get('iaf_token', None):
            xml += "<RequesterCredentials>"
            if self.config.get('token', None):
                xml += "<eBayAuthToken>%s</eBayAuthToken>" % self.config.get(
                    'token')
            elif self.config.get('username', None):
                xml += "<Username>%s</Username>" % self.config.get(
                    'username', '')
                if self.config.get('password', None):
                    xml += "<Password>%s</Password>" % self.config.get(
                        'password', '')
            xml += "</RequesterCredentials>"
        xml += to_xml(data) or ''
        xml += "</" + self.verb + "Request>"
        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.getElementsByTagName("Errors"):
            eSeverity = None
            eClass = None
            eShortMsg = None
            eLongMsg = None
            eCode = None

            if e.getElementsByTagName('SeverityCode'):
                eSeverity = getNodeText(
                    e.getElementsByTagName('SeverityCode')[0])

            if e.getElementsByTagName('ErrorClassification'):
                eClass = getNodeText(
                    e.getElementsByTagName('ErrorClassification')[0])

            if e.getElementsByTagName('ErrorCode'):
                eCode = getNodeText(e.getElementsByTagName('ErrorCode')[0])
                if int(eCode) not in resp_codes:
                    resp_codes.append(int(eCode))

            if e.getElementsByTagName('ShortMessage'):
                eShortMsg = getNodeText(
                    e.getElementsByTagName('ShortMessage')[0])

            if e.getElementsByTagName('LongMessage'):
                eLongMsg = getNodeText(
                    e.getElementsByTagName('LongMessage')[0])

            msg = "Class: %s, Severity: %s, Code: %s, %s%s" \
                % (eClass, eSeverity, eCode, eShortMsg, eLongMsg)

            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)))

        if self.response_dict().Ack == 'Failure':
            if self.config.get('errors'):
                log.error("%s: %s\n\n" % (self.verb, "\n".join(errors)))

            return errors

        return []
Ejemplo n.º 9
0
class Connection(BaseConnection):
    """Connection class for the Business Policies 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 version='1.0' encoding='utf-8'?>"
        xml += "<{verb}Request xmlns=\"http://www.ebay.com/marketplace/selling\">".format(
            verb=verb)
        xml += dict2xml(data, self.escape_xml)
        xml += "</{verb}Request>".format(verb=verb)

        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 []
Ejemplo n.º 10
0
class Connection(BaseConnection):
    """Connection class for the Inventory Management service

    API documentation:
    http://developer.ebay.com/Devzone/store-pickup/InventoryManagement/index.html

    Supported calls:
    AddInventory
    AddInventoryLocation
    DeleteInventory
    DeleteInventoryLocation
    (all others, see API docs)

    Doctests:
    Create location first
    >>> f = Connection(config_file=os.environ.get('EBAY_YAML'), debug=False)

    Take care here, unicode string is put here specially to ensure lib can handle it properly. If not we got an error:
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 28: ordinal not in range(128)
    >>> try:
    ...     retval = f.execute(u'AddInventoryLocation', {
    ...         'Address1': u'Alexanderplatz 12 ąśćł',
    ...         'Address2': u'Gebaude 6',
    ...         'City': u'Berlin',
    ...         'Country': u'DE',
    ...         'PostalCode': u'13355',
    ...         'Latitude': u'37.374488',
    ...         'Longitude': u'-122.032876',
    ...         'LocationID': u'ebaysdk_test',
    ...         'LocationType': u'STORE',
    ...         'Phone': u'(408)408-4080',
    ...         'URL': u'http://store.com',
    ...         'UTCOffset': u'+02:00',
    ...         'Name': 'Test',
    ...         'Region': 'Berlin',
    ...         'PickupInstructions': 'Pick it up soon',
    ...         'Hours': [{'Day': {'DayOfWeek': 1, 'Interval': {'Open': '08:00:00', 'Close': '10:00:00'}}}]
    ...     })
    ...     print(f.response.reply.LocationID.lower())
    ... except ConnectionError as e:
    ...     print(f.error()) # doctest: +SKIP
    ebaysdk_test

    And now add item it it
    >>> try:
    ...     f = Connection(config_file=os.environ.get('EBAY_YAML'), debug=False)
    ...     retval = f.execute('AddInventory', {"SKU": "SKU_TEST", "Locations": {"Location": [
    ...     {"Availability": "IN_STOCK", "LocationID": "ebaysdk_test", "Quantity": 10}
    ...     ]}})
    ...     print(f.response.reply.SKU.lower())
    ... except ConnectionError as e:
    ...     print(f.error()) # doctest: +SKIP
    sku_test


    Delete item from all locations
    >>> try:
    ...     f = Connection(config_file=os.environ.get('EBAY_YAML'), debug=False)
    ...     retval = f.execute('DeleteInventory', {"SKU": "SKU_TEST", "Confirm": 'true'})
    ...     print(f.response.reply.SKU.lower())
    ... except ConnectionError as e:
    ...     print(f.error()) # doctest: +SKIP
    sku_test


    Delete location
    >>> try:
    ...     f = Connection(config_file=os.environ.get('EBAY_YAML'), debug=False)
    ...     retval = f.execute('DeleteInventoryLocation', {"LocationID": "ebaysdk_test"})
    ...     print(f.response.reply.LocationID.lower())
    ... except ConnectionError as e:
    ...     print(f.error()) # doctest: +SKIP
    ebaysdk_test


    Check errors handling
    >>> try:
    ...     f = Connection(token='WRONG TOKEN', config_file=os.environ.get('EBAY_YAML'), debug=False, errors=True)
    ...     retval = f.execute('DeleteInventoryLocation', {"LocationID": "ebaysdk_test"})
    ... except ConnectionError as e:
    ...     print(f.error()) # doctest: +SKIP
    DeleteInventoryLocation: Bad Request, Class: RequestError, Severity: Error, Code: 503, Authentication: Invalid user token Authentication: Invalid user token


    Sometimes ebay returns us really weird error message, already reported to ebay, if it will be fixed I will remove
    all special cases to handle it.
    Example of wrong response:
    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
       <soapenv:Body>
          <Response>
             <Timestamp>Wed May 06 2015 02:15:49 GMT-0700 (GMT-07:00)</Timestamp>
             <Ack>Failure</Ack>
             <Errors>
                <ShortMessage>Gateway Error</ShortMessage>
                <LongMessage>Failover endpoint : Selling_Inventory_REST_SVC_V1 - no ready child endpoints</LongMessage>
                <ErrorCode>99.99</ErrorCode>
                <SeverityCode>Error</SeverityCode>
                <ErrorClassification>RequestError</ErrorClassification>
             </Errors>
             <ResponseCode>null</ResponseCode>
             <Version>653</Version>
          </Response>
       </soapenv:Body>
    </soapenv:Envelope>
    """

    def __init__(self, **kwargs):
        """Inventory Management class constructor.

        Keyword arguments:
        domain        -- API endpoint (default: api.ebay.com)
        config_file   -- YAML defaults (default: ebay.yaml)
        debug         -- debugging enabled (default: False)
        warnings      -- warnings enabled (default: False)
        uri           -- API endpoint uri (default: /selling/inventory/v1)
        token         -- eBay application/user token
        version       -- version number (default: 1.0.0)
        https         -- execute of https (required by this API) (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__(method='POST', **kwargs)

        self.config=Config(domain=kwargs.get('domain', 'api.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', 'api.ebay.com'))
        self.config.set('uri', '/selling/inventory/v1')
        self.config.set('https', True)
        self.config.set('warnings', True)
        self.config.set('errors', True)
        self.config.set('siteid', None)
        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', 'InventoryManagement')
        self.config.set('doc_url', 'http://developer.ebay.com/Devzone/store-pickup/InventoryManagement/index.html')

        self.datetime_nodes = ['starttimefrom', 'timestamp', 'starttime',
                               'endtime']
        self.base_list_nodes = [
        ]

    endpoints = {
        'addinventorylocation': 'locations/delta/add',
        'addinventory': 'inventory/delta/add',
        'deleteinventory': 'inventory/delta/delete',
        'deleteinventorylocation': 'locations/delta/delete',
    }

    def build_request_url(self, verb):
        url = super(Connection, self).build_request_url(verb)
        endpoint = self.endpoints[verb.lower()]
        return "{0}/{1}".format(url, endpoint)

    def build_request_headers(self, verb):
        return {
            "Authorization": "TOKEN {0}".format(self.config.get('token')),
            "Content-Type": "application/xml"
        }

    def build_request_data(self, verb, data, verb_attrs):
        xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
        xml += "<{verb}Request>".format(verb=verb)
        xml += dict2xml(data)
        xml += "</{verb}Request>".format(verb=verb)

        return xml

    def warnings(self):
        warning_string = ""

        if len(self._resp_body_warnings) > 0:
            warning_string = "{verb}: {message}" \
                .format(verb=self.verb, message=", ".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

        # In special case we get errors in this format...
        if not dom.findall('Errors') and dom.find('Body') is not None:
            dom = dom.find('Body').find('Response')

        if dom is None:
            return errors

        for e in dom.findall('Errors'):
            eSeverity = None
            eClass = None
            eShortMsg = None
            eLongMsg = None
            eCode = None

            try:
                eSeverity = e.findall('SeverityCode')[0].text
            except IndexError:
                pass

            try:
                eClass = e.findall('ErrorClassification')[0].text
            except IndexError:
                pass

            try:
                eCode = e.findall('ErrorCode')[0].text
            except IndexError:
                pass

            try:
                eShortMsg = e.findall('ShortMessage')[0].text
            except IndexError:
                pass

            try:
                eLongMsg = e.findall('LongMessage')[0].text
            except IndexError:
                pass

            try:
                eCode = e.findall('ErrorCode')[0].text
                try:
                    int_code = int(eCode)
                except ValueError:
                    int_code = None

                if int_code and int_code not in resp_codes:
                    resp_codes.append(int_code)

            except IndexError:
                pass

            msg = "Class: {eClass}, Severity: {severity}, Code: {code}, {shortMsg} {longMsg}" \
                .format(eClass=eClass, severity=eSeverity, code=eCode, shortMsg=smart_encode(eShortMsg),
                        longMsg=smart_encode(eLongMsg))

            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("{verb}: {message}\n\n".format(verb=self.verb, message="\n".join(warnings)))

        # In special case of error 500 on ebay side, we get really weird response so I need to fallback to this one
        Ack = getattr(self.response.reply, 'Ack', None)
        if Ack is None:
            Ack = self.response.reply.Envelope.Body.Response.Ack

        if Ack == 'Failure':
            if self.config.get('errors'):
                log.error("{verb}: {message}\n\n".format(verb=self.verb, message="\n".join(errors)))

            return errors

        return []
Ejemplo n.º 11
0
class Connection(BaseConnection):
    """Trading API class

    API documentation:
    https://www.x.com/developers/ebay/products/trading-api

    Supported calls:
    AddItem
    ReviseItem
    GetUser
    (all others, see API docs)

    Doctests:
    >>> t = Connection(config_file=os.environ.get('EBAY_YAML'))
    >>> retval = t.execute('GetCharities', {'CharityID': 3897})
    >>> charity_name = ''
    >>> if len( t.response_dom().getElementsByTagName('Name') ) > 0:
    ...   charity_name = getNodeText(t.response_dom().getElementsByTagName('Name')[0])
    >>> print(charity_name)
    Sunshine Kids Foundation
    >>> print(t.error())
    None
    >>> t2 = Connection(errors=False, config_file=os.environ.get('EBAY_YAML'))
    >>> retval2 = t2.execute('VerifyAddItem', {})
    >>> print(t2.response_codes())
    [5]
    """

    def __init__(self, **kwargs):
        """Trading class constructor.

        Keyword arguments:
        domain        -- API endpoint (default: api.ebay.com)
        config_file   -- YAML defaults (default: ebay.yaml)
        debug         -- debugging enabled (default: False)
        warnings      -- warnings enabled (default: False)
        uri           -- API endpoint uri (default: /ws/api.dll)
        appid         -- eBay application id
        devid         -- eBay developer id
        certid        -- eBay cert id
        token         -- eBay application/user token
        siteid        -- eBay country site id (default: 0 (US))
        compatibility -- version number (default: 648)
        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__(method='POST', **kwargs)

        self.config=Config(domain=kwargs.get('domain', 'api.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', 'api.ebay.com'))
        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('siteid', 0)
        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('devid', None)
        self.config.set('certid', None)
        self.config.set('version', '837')
        self.config.set('compatibility', '837')

    def build_request_headers(self, verb):
        headers = {
            "X-EBAY-API-COMPATIBILITY-LEVEL": self.config.get('version', ''),
            "X-EBAY-API-DEV-NAME": self.config.get('devid', ''),
            "X-EBAY-API-APP-NAME": self.config.get('appid', ''),
            "X-EBAY-API-CERT-NAME": self.config.get('certid', ''),
            "X-EBAY-API-SITEID": self.config.get('siteid', ''),
            "X-EBAY-API-CALL-NAME": self.verb,
            "Content-Type": "text/xml"
        }
        if self.config.get('iaf_token', None):
            headers["X-EBAY-API-IAF-TOKEN"] = self.config.get('iaf_token')

        return headers

    def build_request_data(self, verb, data):
        xml = "<?xml version='1.0' encoding='utf-8'?>"
        xml += "<" + self.verb + "Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">"
        if not self.config.get('iaf_token', None):
            xml += "<RequesterCredentials>"
            if self.config.get('token', None):
                xml += "<eBayAuthToken>%s</eBayAuthToken>" % self.config.get('token')
            elif self.config.get('username', None):
                xml += "<Username>%s</Username>" % self.config.get('username', '')
                if self.config.get('password', None):
                    xml += "<Password>%s</Password>" % self.config.get('password', '')
            xml += "</RequesterCredentials>"
        xml += to_xml(data) or ''
        xml += "</" + self.verb + "Request>"
        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.getElementsByTagName("Errors"):
            eSeverity = None
            eClass = None
            eShortMsg = None
            eLongMsg = None
            eCode = None

            if e.getElementsByTagName('SeverityCode'):
                eSeverity = getNodeText(e.getElementsByTagName('SeverityCode')[0])

            if e.getElementsByTagName('ErrorClassification'):
                eClass = getNodeText(e.getElementsByTagName('ErrorClassification')[0])

            if e.getElementsByTagName('ErrorCode'):
                eCode = getNodeText(e.getElementsByTagName('ErrorCode')[0])
                if int(eCode) not in resp_codes:
                    resp_codes.append(int(eCode))

            if e.getElementsByTagName('ShortMessage'):
                eShortMsg = getNodeText(e.getElementsByTagName('ShortMessage')[0])

            if e.getElementsByTagName('LongMessage'):
                eLongMsg = getNodeText(e.getElementsByTagName('LongMessage')[0])

            msg = "Class: %s, Severity: %s, Code: %s, %s%s" \
                % (eClass, eSeverity, eCode, eShortMsg, eLongMsg)

            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)))

        if self.response_dict().Ack == 'Failure':
            if self.config.get('errors'):
                log.error("%s: %s\n\n" % (self.verb, "\n".join(errors)))
            
            return errors

        return []
Ejemplo n.º 12
0
class Connection(BaseConnection):
    """Connection class for the Finding service

    API documentation:
    https://www.x.com/developers/ebay/products/finding-api

    Supported calls:
    findItemsAdvanced
    findItemsByCategory
    (all others, see API docs)

    Doctests:
    >>> f = Connection(config_file=os.environ.get('EBAY_YAML'), debug=False)
    >>> retval = f.execute('findItemsAdvanced', {'keywords': u'niño'})
    >>> error = f.error()
    >>> print(error)
    None
    >>> if not f.error():
    ...   print(f.response.reply.itemSearchURL != '')
    ...   items = f.response.reply.searchResult.item
    ...   print(len(items) > 2)
    ...   print(f.response.reply.ack)
    True
    True
    Success

    """

    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/search/FindingService/v1)
        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/search/FindingService/v1')
        self.config.set('https', False)
        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.12.0')
        self.config.set('service', 'FindingService')
        self.config.set('doc_url', 'http://developer.ebay.com/DevZone/finding/CallRef/index.html')

        self.datetime_nodes = ['starttimefrom', 'timestamp', 'starttime',
                               'endtime']
        self.base_list_nodes = [
            'findcompleteditemsresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsadvancedresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsbycategoryresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsbyimageresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsbykeywordsresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsbyproductresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsinebaystoresresponse.categoryhistogramcontainer.categoryhistogram',
            'findcompleteditemsresponse.aspecthistogramcontainer.aspect',
            'finditemsadvancedresponse.aspecthistogramcontainer.aspect',
            'finditemsbycategoryresponse.aspecthistogramcontainer.aspect',
            'finditemsbyimageresponse.aspecthistogramcontainer.aspect',
            'finditemsbykeywordsresponse.aspecthistogramcontainer.aspect',
            'finditemsbyproductresponse.aspecthistogramcontainer.aspect',
            'finditemsinebaystoresresponse.aspecthistogramcontainer.aspect',
            'findcompleteditemsresponse.aspect.valuehistogram',
            'finditemsadvancedresponse.aspect.valuehistogram',
            'finditemsbycategoryresponse.aspect.valuehistogram',
            'finditemsbyimageresponse.aspect.valuehistogram',
            'finditemsbykeywordsresponse.aspect.valuehistogram',
            'finditemsbyproductresponse.aspect.valuehistogram',
            'finditemsinebaystoresresponse.aspect.valuehistogram',
            'findcompleteditemsresponse.aspectfilter.aspectvaluename',
            'finditemsadvancedresponse.aspectfilter.aspectvaluename',
            'finditemsbycategoryresponse.aspectfilter.aspectvaluename',
            'finditemsbyimageresponse.aspectfilter.aspectvaluename',
            'finditemsbykeywordsresponse.aspectfilter.aspectvaluename',
            'finditemsbyproductresponse.aspectfilter.aspectvaluename',
            'finditemsinebaystoresresponse.aspectfilter.aspectvaluename',
            'findcompleteditemsresponse.searchresult.item',
            'finditemsadvancedresponse.searchresult.item',
            'finditemsbycategoryresponse.searchresult.item',
            'finditemsbyimageresponse.searchresult.item',
            'finditemsbykeywordsresponse.searchresult.item',
            'finditemsbyproductresponse.searchresult.item',
            'finditemsinebaystoresresponse.searchresult.item',
            'findcompleteditemsresponse.domainfilter.domainname',
            'finditemsadvancedresponse.domainfilter.domainname',
            'finditemsbycategoryresponse.domainfilter.domainname',
            'finditemsbyimageresponse.domainfilter.domainname',
            'finditemsbykeywordsresponse.domainfilter.domainname',
            'finditemsinebaystoresresponse.domainfilter.domainname',
            'findcompleteditemsresponse.itemfilter.value',
            'finditemsadvancedresponse.itemfilter.value',
            'finditemsbycategoryresponse.itemfilter.value',
            'finditemsbyimageresponse.itemfilter.value',
            'finditemsbykeywordsresponse.itemfilter.value',
            'finditemsbyproductresponse.itemfilter.value',
            'finditemsinebaystoresresponse.itemfilter.value',
            'findcompleteditemsresponse.conditionhistogramcontainer.conditionhistogram',
            'finditemsadvancedresponse.conditionhistogramcontainer.conditionhistogram',
            'finditemsbycategoryresponse.conditionhistogramcontainer.conditionhistogram',
            'finditemsbyimageresponse.conditionhistogramcontainer.conditionhistogram',
            'finditemsbykeywordsresponse.conditionhistogramcontainer.conditionhistogram',
            'finditemsinebaystoresresponse.conditionhistogramcontainer.conditionhistogram',
            'finditemsbyproductresponse.conditionhistogramcontainer.conditionhistogram',
            'findcompleteditemsresponse.searchitem.paymentmethod',
            'finditemsadvancedresponse.searchitem.paymentmethod',
            'finditemsbycategoryresponse.searchitem.paymentmethod',
            'finditemsbyimageresponse.searchitem.paymentmethod',
            'finditemsbykeywordsresponse.searchitem.paymentmethod',
            'finditemsbyproductresponse.searchitem.paymentmethod',
            'finditemsinebaystoresresponse.searchitem.paymentmethod',
            'findcompleteditemsresponse.searchitem.gallerypluspictureurl',
            'finditemsadvancedresponse.searchitem.gallerypluspictureurl',
            'finditemsbycategoryresponse.searchitem.gallerypluspictureurl',
            'finditemsbyimageresponse.searchitem.gallerypluspictureurl',
            'finditemsbykeywordsresponse.searchitem.gallerypluspictureurl',
            'finditemsbyproductresponse.searchitem.gallerypluspictureurl',
            'finditemsinebaystoresresponse.searchitem.gallerypluspictureurl',
            'finditemsbycategoryresponse.searchitem.attribute',
            'finditemsadvancedresponse.searchitem.attribute',
            'finditemsbykeywordsresponse.searchitem.attribute',
            'finditemsinebaystoresresponse.searchitem.attribute',
            'finditemsbyproductresponse.searchitem.attribute',
            'findcompleteditemsresponse.searchitem.attribute',
            'findcompleteditemsresponse.shippinginfo.shiptolocations',
            'finditemsadvancedresponse.shippinginfo.shiptolocations',
            'finditemsbycategoryresponse.shippinginfo.shiptolocations',
            'finditemsbyimageresponse.shippinginfo.shiptolocations',
            'finditemsbykeywordsresponse.shippinginfo.shiptolocations',
            'finditemsbyproductresponse.shippinginfo.shiptolocations',
            'finditemsinebaystoresresponse.shippinginfo.shiptolocations',
        ]

    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-APPNAME": 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": 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 version='1.0' encoding='utf-8'?>"
        xml += "<" + verb + "Request xmlns=\"http://www.ebay.com/marketplace/search/v1/services\">"
        xml += dict2xml(data)
        xml += "</" + verb + "Request>"

        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 []

    def next_page(self):
        if type(self._request_dict) is not dict:
            raise RequestPaginationError("request data is not of type dict", self.response) 

        epp = self._request_dict.get('paginationInput', {}).get('enteriesPerPage', None)
        num = int(self.response.reply.paginationOutput.pageNumber)

        if num >= int(self.response.reply.paginationOutput.totalPages):
            raise PaginationLimit("no more pages to process", self.response)
            return None

        self._request_dict['paginationInput'] = {}

        if epp:
            self._request_dict['paginationInput']['enteriesPerPage'] = epp

        self._request_dict['paginationInput']['pageNumber'] = int(num) + 1
        
        return self.execute(self.verb, self._request_dict)
Ejemplo n.º 13
0
from ebaysdk.config import Config

PRIVATE_CONFIG = Config(domain='app_config',
                        config_file='config.yaml')

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
# SECRET_KEY = 'p5mn)hat@j)1oi&4)ga9t4s2!isqcrhk!b4!s$)0ob5$l3%xy!'
SECRET_KEY = PRIVATE_CONFIG.get('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ROOT_URLCONF = 'core.urls'

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
Ejemplo n.º 14
0
class Connection(BaseConnection):
    """Connection class for the Finding service

    API documentation:
    https://www.x.com/developers/ebay/products/finding-api

    Supported calls:
    findItemsAdvanced
    findItemsByCategory
    (all others, see API docs)

    Doctests:
    >>> f = Connection(config_file=os.environ.get('EBAY_YAML'))
    >>> retval = f.execute('findItemsAdvanced', {'keywords': 'shoes'})
    >>> error = f.error()
    >>> print(error)
    None
    >>> if not f.error():
    ...   print(f.response_obj().itemSearchURL != '')
    ...   items = f.response_obj().searchResult.item
    ...   print(len(items))
    ...   print(f.response_dict().ack)
    True
    100
    Success

    """

    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/search/FindingService/v1)
        appid         -- eBay application id
        siteid        -- eBay country site id (default: EBAY-US)
        compatibility -- 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/search/FindingService/v1')
        self.config.set('https', False)
        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.12.0')
        self.config.set('compatibility', '1.0.0')
        self.config.set('service', 'FindingService')

    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-APPNAME": 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": 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):
        xml = "<?xml version='1.0' encoding='utf-8'?>"
        xml += "<" + verb + "Request xmlns=\"http://www.ebay.com/marketplace/search/v1/services\">"
        xml += to_xml(data) or ''
        xml += "</" + verb + "Request>"

        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.getElementsByTagName("error"):
            eSeverity = None
            eDomain = None
            eMsg = None
            eId = None

            if e.getElementsByTagName('severity'):
                eSeverity = getNodeText(e.getElementsByTagName('severity')[0])

            if e.getElementsByTagName('domain'):
                eDomain = getNodeText(e.getElementsByTagName('domain')[0])

            if e.getElementsByTagName('errorId'):
                eId = getNodeText(e.getElementsByTagName('errorId')[0])
                if int(eId) not in resp_codes:
                    resp_codes.append(int(eId))

            if e.getElementsByTagName('message'):
                eMsg = getNodeText(e.getElementsByTagName('message')[0])

            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_dict().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:
            pass

        return []
Ejemplo n.º 15
0
class Connection(BaseConnection):
    """Connection class for the Inventory Management service

    API documentation:
    http://developer.ebay.com/Devzone/store-pickup/InventoryManagement/index.html

    Supported calls:
    AddInventory
    AddInventoryLocation
    DeleteInventory
    DeleteInventoryLocation
    (all others, see API docs)

    Doctests:
    Create location first
    >>> f = Connection(config_file=os.environ.get('EBAY_YAML'), debug=False)

    Take care here, unicode string is put here specially to ensure lib can handle it properly. If not we got an error:
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 28: ordinal not in range(128)
    >>> try:
    ...     retval = f.execute(u'AddInventoryLocation', {
    ...         'Address1': u'Alexanderplatz 12 ąśćł',
    ...         'Address2': u'Gebaude 6',
    ...         'City': u'Berlin',
    ...         'Country': u'DE',
    ...         'PostalCode': u'13355',
    ...         'Latitude': u'37.374488',
    ...         'Longitude': u'-122.032876',
    ...         'LocationID': u'ebaysdk_test',
    ...         'LocationType': u'STORE',
    ...         'Phone': u'(408)408-4080',
    ...         'URL': u'http://store.com',
    ...         'UTCOffset': u'+02:00',
    ...         'Name': 'Test',
    ...         'Region': 'Berlin',
    ...         'PickupInstructions': 'Pick it up soon',
    ...         'Hours': [{'Day': {'DayOfWeek': 1, 'Interval': {'Open': '08:00:00', 'Close': '10:00:00'}}}]
    ...     })
    ...     print(f.response.reply.LocationID.lower())
    ... except ConnectionError as e:
    ...     print(f.error()) # doctest: +SKIP
    ebaysdk_test

    And now add item it it
    >>> try:
    ...     f = Connection(config_file=os.environ.get('EBAY_YAML'), debug=False)
    ...     retval = f.execute('AddInventory', {"SKU": "SKU_TEST", "Locations": {"Location": [
    ...     {"Availability": "IN_STOCK", "LocationID": "ebaysdk_test", "Quantity": 10}
    ...     ]}})
    ...     print(f.response.reply.SKU.lower())
    ... except ConnectionError as e:
    ...     print(f.error()) # doctest: +SKIP
    sku_test


    Delete item from all locations
    >>> try:
    ...     f = Connection(config_file=os.environ.get('EBAY_YAML'), debug=False)
    ...     retval = f.execute('DeleteInventory', {"SKU": "SKU_TEST", "Confirm": 'true'})
    ...     print(f.response.reply.SKU.lower())
    ... except ConnectionError as e:
    ...     print(f.error()) # doctest: +SKIP
    sku_test


    Delete location
    >>> try:
    ...     f = Connection(config_file=os.environ.get('EBAY_YAML'), debug=False)
    ...     retval = f.execute('DeleteInventoryLocation', {"LocationID": "ebaysdk_test"})
    ...     print(f.response.reply.LocationID.lower())
    ... except ConnectionError as e:
    ...     print(f.error()) # doctest: +SKIP
    ebaysdk_test


    Check errors handling
    >>> try:
    ...     f = Connection(token='WRONG TOKEN', config_file=os.environ.get('EBAY_YAML'), debug=False, errors=True)
    ...     retval = f.execute('DeleteInventoryLocation', {"LocationID": "ebaysdk_test"})
    ... except ConnectionError as e:
    ...     print(f.error()) # doctest: +SKIP
    DeleteInventoryLocation: Bad Request, Class: RequestError, Severity: Error, Code: 503, Authentication: Invalid user token Authentication: Invalid user token


    Sometimes ebay returns us really weird error message, already reported to ebay, if it will be fixed I will remove
    all special cases to handle it.
    Example of wrong response:
    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
       <soapenv:Body>
          <Response>
             <Timestamp>Wed May 06 2015 02:15:49 GMT-0700 (GMT-07:00)</Timestamp>
             <Ack>Failure</Ack>
             <Errors>
                <ShortMessage>Gateway Error</ShortMessage>
                <LongMessage>Failover endpoint : Selling_Inventory_REST_SVC_V1 - no ready child endpoints</LongMessage>
                <ErrorCode>99.99</ErrorCode>
                <SeverityCode>Error</SeverityCode>
                <ErrorClassification>RequestError</ErrorClassification>
             </Errors>
             <ResponseCode>null</ResponseCode>
             <Version>653</Version>
          </Response>
       </soapenv:Body>
    </soapenv:Envelope>
    """
    def __init__(self, **kwargs):
        """Inventory Management class constructor.

        Keyword arguments:
        domain        -- API endpoint (default: api.ebay.com)
        config_file   -- YAML defaults (default: ebay.yaml)
        debug         -- debugging enabled (default: False)
        warnings      -- warnings enabled (default: False)
        uri           -- API endpoint uri (default: /selling/inventory/v1)
        token         -- eBay application/user token
        version       -- version number (default: 1.0.0)
        https         -- execute of https (required by this API) (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__(method='POST', **kwargs)

        self.config = Config(domain=kwargs.get('domain', 'api.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', 'api.ebay.com'))
        self.config.set('uri', '/selling/inventory/v1')
        self.config.set('https', True)
        self.config.set('warnings', True)
        self.config.set('errors', True)
        self.config.set('siteid', None)
        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', 'InventoryManagement')
        self.config.set(
            'doc_url',
            'http://developer.ebay.com/Devzone/store-pickup/InventoryManagement/index.html'
        )

        self.datetime_nodes = [
            'starttimefrom', 'timestamp', 'starttime', 'endtime'
        ]
        self.base_list_nodes = []

    endpoints = {
        'addinventorylocation': 'locations/delta/add',
        'addinventory': 'inventory/delta/add',
        'deleteinventory': 'inventory/delta/delete',
        'deleteinventorylocation': 'locations/delta/delete',
    }

    def build_request_url(self, verb):
        url = super(Connection, self).build_request_url(verb)
        endpoint = self.endpoints[verb.lower()]
        return "{0}/{1}".format(url, endpoint)

    def build_request_headers(self, verb):
        return {
            "Authorization": "TOKEN {0}".format(self.config.get('token')),
            "Content-Type": "application/xml"
        }

    def build_request_data(self, verb, data, verb_attrs):
        xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
        xml += "<{verb}Request>".format(verb=verb)
        xml += dict2xml(data)
        xml += "</{verb}Request>".format(verb=verb)

        return xml

    def warnings(self):
        warning_string = ""

        if len(self._resp_body_warnings) > 0:
            warning_string = "{verb}: {message}" \
                .format(verb=self.verb, message=", ".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

        # In special case we get errors in this format...
        if not dom.findall('Errors') and dom.find('Body') is not None:
            dom = dom.find('Body').find('Response')

        if dom is None:
            return errors

        for e in dom.findall('Errors'):
            eSeverity = None
            eClass = None
            eShortMsg = None
            eLongMsg = None
            eCode = None

            try:
                eSeverity = e.findall('SeverityCode')[0].text
            except IndexError:
                pass

            try:
                eClass = e.findall('ErrorClassification')[0].text
            except IndexError:
                pass

            try:
                eCode = e.findall('ErrorCode')[0].text
            except IndexError:
                pass

            try:
                eShortMsg = e.findall('ShortMessage')[0].text
            except IndexError:
                pass

            try:
                eLongMsg = e.findall('LongMessage')[0].text
            except IndexError:
                pass

            try:
                eCode = e.findall('ErrorCode')[0].text
                try:
                    int_code = int(eCode)
                except ValueError:
                    int_code = None

                if int_code and int_code not in resp_codes:
                    resp_codes.append(int_code)

            except IndexError:
                pass

            msg = "Class: {eClass}, Severity: {severity}, Code: {code}, {shortMsg} {longMsg}" \
                .format(eClass=eClass, severity=eSeverity, code=eCode, shortMsg=smart_encode(eShortMsg),
                        longMsg=smart_encode(eLongMsg))

            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("{verb}: {message}\n\n".format(
                verb=self.verb, message="\n".join(warnings)))

        # In special case of error 500 on ebay side, we get really weird response so I need to fallback to this one
        Ack = getattr(self.response.reply, 'Ack', None)
        if Ack is None:
            Ack = self.response.reply.Envelope.Body.Response.Ack

        if Ack == 'Failure':
            if self.config.get('errors'):
                log.error("{verb}: {message}\n\n".format(
                    verb=self.verb, message="\n".join(errors)))

            return errors

        return []
Ejemplo n.º 16
0
class Connection(BaseConnection):
    """Connection class for the Finding service

    API documentation:
    https://www.x.com/developers/ebay/products/finding-api

    Supported calls:
    findItemsAdvanced
    findItemsByCategory
    (all others, see API docs)

    Doctests:
    >>> f = Connection(config_file=os.environ.get('EBAY_YAML'), debug=False)
    >>> retval = f.execute('findItemsAdvanced', {'keywords': u'El Niño'})
    >>> error = f.error()
    >>> print(error)
    None
    >>> if not f.error():
    ...   print(f.response.reply.itemSearchURL != '')
    ...   items = f.response.reply.searchResult.item
    ...   print(len(items) > 2)
    ...   print(f.response.reply.ack)
    True
    True
    Success

    """
    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/search/FindingService/v1)
        appid         -- eBay application id
        siteid        -- eBay country site id (default: EBAY-US)
        version       -- version number (default: 1.0.0)
        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__(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/search/FindingService/v1')
        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.12.0')
        self.config.set('service', 'FindingService')
        self.config.set(
            'doc_url',
            'http://developer.ebay.com/DevZone/finding/CallRef/index.html')

        self.datetime_nodes = [
            'starttimefrom', 'timestamp', 'starttime', 'endtime'
        ]
        self.base_list_nodes = [
            'findcompleteditemsresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsadvancedresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsbycategoryresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsbyimageresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsbykeywordsresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsbyproductresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsinebaystoresresponse.categoryhistogramcontainer.categoryhistogram',
            'finditemsinebaystoresresponse.categoryhistogramcontainer.categoryhistogram.childcategoryhistogram',
            'findcompleteditemsresponse.aspecthistogramcontainer.aspect',
            'finditemsadvancedresponse.aspecthistogramcontainer.aspect',
            'finditemsbycategoryresponse.aspecthistogramcontainer.aspect',
            'finditemsbyimageresponse.aspecthistogramcontainer.aspect',
            'finditemsbykeywordsresponse.aspecthistogramcontainer.aspect',
            'finditemsbyproductresponse.aspecthistogramcontainer.aspect',
            'finditemsinebaystoresresponse.aspecthistogramcontainer.aspect',
            'findcompleteditemsresponse.aspect.valuehistogram',
            'finditemsadvancedresponse.aspect.valuehistogram',
            'finditemsbycategoryresponse.aspect.valuehistogram',
            'finditemsbyimageresponse.aspect.valuehistogram',
            'finditemsbykeywordsresponse.aspect.valuehistogram',
            'finditemsbyproductresponse.aspect.valuehistogram',
            'finditemsinebaystoresresponse.aspect.valuehistogram',
            'findcompleteditemsresponse.aspectfilter.aspectvaluename',
            'finditemsadvancedresponse.aspectfilter.aspectvaluename',
            'finditemsbycategoryresponse.aspectfilter.aspectvaluename',
            'finditemsbyimageresponse.aspectfilter.aspectvaluename',
            'finditemsbykeywordsresponse.aspectfilter.aspectvaluename',
            'finditemsbyproductresponse.aspectfilter.aspectvaluename',
            'finditemsinebaystoresresponse.aspectfilter.aspectvaluename',
            'findcompleteditemsresponse.searchresult.item',
            'finditemsadvancedresponse.searchresult.item',
            'finditemsbycategoryresponse.searchresult.item',
            'finditemsbyimageresponse.searchresult.item',
            'finditemsbykeywordsresponse.searchresult.item',
            'finditemsbyproductresponse.searchresult.item',
            'finditemsinebaystoresresponse.searchresult.item',
            'findcompleteditemsresponse.domainfilter.domainname',
            'finditemsadvancedresponse.domainfilter.domainname',
            'finditemsbycategoryresponse.domainfilter.domainname',
            'finditemsbyimageresponse.domainfilter.domainname',
            'finditemsbykeywordsresponse.domainfilter.domainname',
            'finditemsinebaystoresresponse.domainfilter.domainname',
            'findcompleteditemsresponse.itemfilter.value',
            'finditemsadvancedresponse.itemfilter.value',
            'finditemsbycategoryresponse.itemfilter.value',
            'finditemsbyimageresponse.itemfilter.value',
            'finditemsbykeywordsresponse.itemfilter.value',
            'finditemsbyproductresponse.itemfilter.value',
            'finditemsinebaystoresresponse.itemfilter.value',
            'findcompleteditemsresponse.conditionhistogramcontainer.conditionhistogram',
            'finditemsadvancedresponse.conditionhistogramcontainer.conditionhistogram',
            'finditemsbycategoryresponse.conditionhistogramcontainer.conditionhistogram',
            'finditemsbyimageresponse.conditionhistogramcontainer.conditionhistogram',
            'finditemsbykeywordsresponse.conditionhistogramcontainer.conditionhistogram',
            'finditemsinebaystoresresponse.conditionhistogramcontainer.conditionhistogram',
            'finditemsbyproductresponse.conditionhistogramcontainer.conditionhistogram',
            'findcompleteditemsresponse.searchitem.paymentmethod',
            'finditemsadvancedresponse.searchitem.paymentmethod',
            'finditemsbycategoryresponse.searchitem.paymentmethod',
            'finditemsbyimageresponse.searchitem.paymentmethod',
            'finditemsbykeywordsresponse.searchitem.paymentmethod',
            'finditemsbyproductresponse.searchitem.paymentmethod',
            'finditemsinebaystoresresponse.searchitem.paymentmethod',
            'findcompleteditemsresponse.searchitem.gallerypluspictureurl',
            'finditemsadvancedresponse.searchitem.gallerypluspictureurl',
            'finditemsbycategoryresponse.searchitem.gallerypluspictureurl',
            'finditemsbyimageresponse.searchitem.gallerypluspictureurl',
            'finditemsbykeywordsresponse.searchitem.gallerypluspictureurl',
            'finditemsbyproductresponse.searchitem.gallerypluspictureurl',
            'finditemsinebaystoresresponse.searchitem.gallerypluspictureurl',
            'finditemsbycategoryresponse.searchitem.attribute',
            'finditemsadvancedresponse.searchitem.attribute',
            'finditemsbykeywordsresponse.searchitem.attribute',
            'finditemsinebaystoresresponse.searchitem.attribute',
            'finditemsbyproductresponse.searchitem.attribute',
            'findcompleteditemsresponse.searchitem.attribute',
            'findcompleteditemsresponse.shippinginfo.shiptolocations',
            'finditemsadvancedresponse.shippinginfo.shiptolocations',
            'finditemsbycategoryresponse.shippinginfo.shiptolocations',
            'finditemsbyimageresponse.shippinginfo.shiptolocations',
            'finditemsbykeywordsresponse.shippinginfo.shiptolocations',
            'finditemsbyproductresponse.shippinginfo.shiptolocations',
            'finditemsinebaystoresresponse.shippinginfo.shiptolocations',
        ]

    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-APPNAME":
            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":
            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 version='1.0' encoding='utf-8'?>"
        xml += "<" + verb + "Request xmlns=\"http://www.ebay.com/marketplace/search/v1/services\">"
        xml += dict2xml(data, self.escape_xml)
        xml += "</" + verb + "Request>"

        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 []

    def next_page(self):
        if type(self._request_dict) is not dict:
            raise RequestPaginationError("request data is not of type dict",
                                         self.response)

        epp = self._request_dict.get('paginationInput',
                                     {}).get('enteriesPerPage', None)
        num = int(self.response.reply.paginationOutput.pageNumber)

        if num >= int(self.response.reply.paginationOutput.totalPages):
            raise PaginationLimit("no more pages to process", self.response)
            return None

        self._request_dict['paginationInput'] = {}

        if epp:
            self._request_dict['paginationInput']['enteriesPerPage'] = epp

        self._request_dict['paginationInput']['pageNumber'] = int(num) + 1

        return self.execute(self.verb, self._request_dict)
Ejemplo n.º 17
0
class Connection(BaseConnection):
    """Connection class for the Finding service

    API documentation:
    https://www.x.com/developers/ebay/products/finding-api

    Supported calls:
    findItemsAdvanced
    findItemsByCategory
    (all others, see API docs)

    Doctests:
    >>> f = Connection(config_file=os.environ.get('EBAY_YAML'))
    >>> retval = f.execute('findItemsAdvanced', {'keywords': u'niño'})
    >>> error = f.error()
    >>> print(error)
    None
    >>> if not f.error():
    ...   print(f.response_obj().itemSearchURL != '')
    ...   items = f.response_obj().searchResult.item
    ...   print(len(items) > 2)
    ...   print(f.response_dict().ack)
    True
    True
    Success

    """

    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/search/FindingService/v1)
        appid         -- eBay application id
        siteid        -- eBay country site id (default: EBAY-US)
        compatibility -- 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/search/FindingService/v1')
        self.config.set('https', False)
        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.12.0')
        self.config.set('compatibility', '1.0.0')
        self.config.set('service', 'FindingService')

    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-APPNAME": 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": 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):
        xml = "<?xml version='1.0' encoding='utf-8'?>"
        xml += "<" + verb + "Request xmlns=\"http://www.ebay.com/marketplace/search/v1/services\">"
        xml += to_xml(data) or ''
        xml += "</" + verb + "Request>"

        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.getElementsByTagName("error"):
            eSeverity = None
            eDomain = None
            eMsg = None
            eId = None

            if e.getElementsByTagName('severity'):
                eSeverity = getNodeText(e.getElementsByTagName('severity')[0])

            if e.getElementsByTagName('domain'):
                eDomain = getNodeText(e.getElementsByTagName('domain')[0])

            if e.getElementsByTagName('errorId'):
                eId = getNodeText(e.getElementsByTagName('errorId')[0])
                if int(eId) not in resp_codes:
                    resp_codes.append(int(eId))

            if e.getElementsByTagName('message'):
                eMsg = getNodeText(e.getElementsByTagName('message')[0])

            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_dict().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:
            pass

        return []