Exemplo n.º 1
0
def run(opts):

    try:

        shopping = Shopping(debug=opts.debug,
                            appid=opts.appid,
                            config_file=opts.yaml,
                            warnings=False)

        shopping.execute('FindPopularItems', {'QueryKeywords': 'Python'})
        nodes = shopping.response_dom().getElementsByTagName('ItemID')
        itemIds = [getNodeText(n) for n in nodes]

        api = FindItem(debug=opts.debug,
                       consumer_id=opts.consumer_id,
                       config_file=opts.yaml)

        records = api.find_items_by_ids(itemIds)

        for r in records:
            print("ID(%s) TITLE(%s)" % (r['ITEM_ID'], r['TITLE'][:35]))

        dump(api)

    except ConnectionError as e:
        print e
Exemplo n.º 2
0
def verifyAddItemErrorCodes(opts):
    """http://www.utilities-online.info/xmltojson/#.UXli2it4avc
    """

    try:
        api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid,
                      certid=opts.certid, devid=opts.devid, warnings=False)

        myitem = {
            "Item": {
                "Title": "Harry Potter and the Philosopher's Stone",
                "Description": "This is the first book in the Harry Potter series. In excellent condition!",
                "PrimaryCategory": {"CategoryID": "377aaaaaa"},
                "StartPrice": "1.0",
                "CategoryMappingAllowed": "true",
                "Country": "US",
                "ConditionID": "3000",
                "Currency": "USD",
                "DispatchTimeMax": "3",
                "ListingDuration": "Days_7",
                "ListingType": "Chinese",
                "PaymentMethods": "PayPal",
                "PayPalEmailAddress": "*****@*****.**",
                "PictureDetails": {"PictureURL": "http://i1.sandbox.ebayimg.com/03/i/00/30/07/20_1.JPG?set_id=8800005007"},
                "PostalCode": "95125",
                "Quantity": "1",
                "ReturnPolicy": {
                    "ReturnsAcceptedOption": "ReturnsAccepted",
                    "RefundOption": "MoneyBack",
                    "ReturnsWithinOption": "Days_30",
                    "Description": "If you are not satisfied, return the book for refund.",
                    "ShippingCostPaidByOption": "Buyer"
                },
                "ShippingDetails": {
                    "ShippingType": "Flat",
                    "ShippingServiceOptions": {
                        "ShippingServicePriority": "1",
                        "ShippingService": "USPSMedia",
                        "ShippingServiceCost": "2.50"
                    }
                },
                "Site": "US"
            }
        }

        api.execute('VerifyAddItem', myitem)
    
    except ConnectionError as e:
        # traverse the DOM to look for error codes
        for node in api.response_dom().getElementsByTagName('ErrorCode'):
            print("error code: %s" % getNodeText(node))

        # check for invalid data - error code 37
        if 37 in api.response_codes():
            print("Invalid data in request")

        print e
Exemplo n.º 3
0
def run(opts):

    try:

        shopping = Shopping(debug=opts.debug, appid=opts.appid, 
            config_file=opts.yaml, warnings=False)

        shopping.execute('FindPopularItems', {'QueryKeywords': 'Python'})
        nodes = shopping.response_dom().getElementsByTagName('ItemID')
        itemIds = [getNodeText(n) for n in nodes]

        api = FindItem(debug=opts.debug, consumer_id=opts.consumer_id, config_file=opts.yaml)
        
        records = api.find_items_by_ids(itemIds)

        for r in records:
            print("ID(%s) TITLE(%s)" % (r['ITEM_ID'], r['TITLE'][:35]))

        dump(api)

    except ConnectionError as e:
        print e
Exemplo n.º 4
0
    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 []
Exemplo n.º 5
0
    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.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 []
Exemplo n.º 6
0
    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 []
Exemplo n.º 7
0
    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 []
Exemplo n.º 8
0
def verifyAddItemErrorCodes(opts):
    """http://www.utilities-online.info/xmltojson/#.UXli2it4avc
    """

    try:
        api = Trading(debug=opts.debug,
                      config_file=opts.yaml,
                      appid=opts.appid,
                      certid=opts.certid,
                      devid=opts.devid,
                      warnings=False)

        myitem = {
            "Item": {
                "Title": "Harry Potter and the Philosopher's Stone",
                "Description":
                "This is the first book in the Harry Potter series. In excellent condition!",
                "PrimaryCategory": {
                    "CategoryID": "377aaaaaa"
                },
                "StartPrice": "1.0",
                "CategoryMappingAllowed": "true",
                "Country": "US",
                "ConditionID": "3000",
                "Currency": "USD",
                "DispatchTimeMax": "3",
                "ListingDuration": "Days_7",
                "ListingType": "Chinese",
                "PaymentMethods": "PayPal",
                "PayPalEmailAddress": "*****@*****.**",
                "PictureDetails": {
                    "PictureURL":
                    "http://i1.sandbox.ebayimg.com/03/i/00/30/07/20_1.JPG?set_id=8800005007"
                },
                "PostalCode": "95125",
                "Quantity": "1",
                "ReturnPolicy": {
                    "ReturnsAcceptedOption": "ReturnsAccepted",
                    "RefundOption": "MoneyBack",
                    "ReturnsWithinOption": "Days_30",
                    "Description":
                    "If you are not satisfied, return the book for refund.",
                    "ShippingCostPaidByOption": "Buyer"
                },
                "ShippingDetails": {
                    "ShippingType": "Flat",
                    "ShippingServiceOptions": {
                        "ShippingServicePriority": "1",
                        "ShippingService": "USPSMedia",
                        "ShippingServiceCost": "2.50"
                    }
                },
                "Site": "US"
            }
        }

        api.execute('VerifyAddItem', myitem)

    except ConnectionError as e:
        # traverse the DOM to look for error codes
        for node in api.response_dom().getElementsByTagName('ErrorCode'):
            print("error code: %s" % getNodeText(node))

        # check for invalid data - error code 37
        if 37 in api.response_codes():
            print("Invalid data in request")

        print e