Commits

Sebastian Rahlf committed cf91860

As of Oct 1, 2012 Amazon has removed XSLT transform from the API!
https://forums.aws.amazon.com/thread.jspa?threadID=101170&tstart=175

  • Participants
  • Parent commits e855c3a

Comments (0)

Files changed (4)

File amazonproduct/api.py

 
 #: Hosts used by Amazon for normal/XSLT operations
 HOSTS = {
-    'ca': ('ecs.amazonaws.ca', 'xml-ca.amznxslt.com'),
-    'cn': ('webservices.amazon.cn', 'xml-cn.amznxslt.com'),
-    'de': ('ecs.amazonaws.de', 'xml-de.amznxslt.com'),
-    'es': ('webservices.amazon.es', 'xml-es.amznxslt.com'),
-    'fr': ('ecs.amazonaws.fr', 'xml-fr.amznxslt.com'),
-    'it': ('webservices.amazon.it', 'xml-it.amznxslt.com'),
-    'jp': ('ecs.amazonaws.jp', 'xml-jp.amznxslt.com'),
-    'uk': ('ecs.amazonaws.co.uk', 'xml-uk.amznxslt.com'),
-    'us': ('ecs.amazonaws.com', 'xml-us.amznxslt.com'),
+    'ca': 'ecs.amazonaws.ca',
+    'cn': 'webservices.amazon.cn',
+    'de': 'ecs.amazonaws.de',
+    'es': 'webservices.amazon.es',
+    'fr': 'ecs.amazonaws.fr',
+    'it': 'webservices.amazon.it',
+    'jp': 'ecs.amazonaws.jp',
+    'uk': 'ecs.amazonaws.co.uk',
+    'us': 'ecs.amazonaws.com',
 }
 
 
         # create signature
         keys = sorted(qargs.keys())
         args = '&'.join('%s=%s' % (key, quote(unicode(qargs[key])
-                        .encode('utf-8'),safe='~')) for key in keys)
-
-        # Amazon uses a different host for XSLT operations
-        host = self.host['Style' in qargs]
+                        .encode('utf-8'), safe='~')) for key in keys)
 
         msg = 'GET'
-        msg += '\n' + host
+        msg += '\n' + self.host
         msg += '\n/onca/xml'
         msg += '\n' + args
 
         signature = quote(
             b64encode(hmac.new(self.secret_key or '', msg, sha256).digest()))
 
-        url = 'http://%s/onca/xml?%s&Signature=%s' % (host, args, signature)
-        return url
+        return 'http://%s/onca/xml?%s&Signature=%s' % (
+            self.host, args, signature)
 
     def _fetch(self, url):
         """

File examples/json-results.py

-
-"""
-All calls to the API will be translated to JSON via XSLT.
-"""
-
-from config import AWS_KEY, SECRET_KEY
-from amazonproduct.api import API
-from amazonproduct.errors import AWSError
-
-import simplejson
-
-class JSONAPI (API):
-    
-    """
-    This API uses Doeke Zanstra's XSLT stylesheet which converts XML to JSON
-    http://code.google.com/p/xml2json-xslt/
-    """
-    
-    STYLE_SHEET = 'http://xml2json-xslt.googlecode.com/svn/trunk/xml2json.xslt'
-    
-    def __init__(self, *args, **kwargs):
-        API.__init__(self, *args, **kwargs)
-        self.processor = self.json_processor
-    
-    def _build_url(self, **qargs):
-        qargs['Style'] = self.STYLE_SHEET
-        return  API._build_url(self, **qargs)
-    
-    @staticmethod
-    def json_processor(fp):
-        """
-        Returns response as Python dict.
-        """
-        def _find_errors(root):
-            "Find Error nodes"
-            if type(root) != dict: return 
-            for parent, children in root.items():
-                if parent == 'Error':
-                    raise AWSError(children['Code'], children['Message'])
-                _find_errors(children)
-        parsed = simplejson.load(fp)
-        _find_errors(parsed)
-        return parsed
-
-if __name__ == '__main__':
-    
-    api = JSONAPI(AWS_KEY, SECRET_KEY, 'us')
-    
-    # This request finds "The Art of Computer Programming Vol. 1"
-    print api.item_lookup('0201896834') 
-    
-    # This one will raise an InvalidParameterValue error
-    print api.item_lookup('0201894')
-    

File tests/conftest.py

 from ConfigParser import SafeConfigParser
 import os.path
+import pytest
 import re
 import textwrap
 

File tests/test_api_basics.py

 def pytest_funcarg__api(request):
     server = request.getfuncargvalue('server')
     api = API('XXX', 'XXX', 'uk') # locale does not matter here!
-    api.host = ['%s:%s' % server.server_address for _ in range(2)]
+    api.host = '%s:%s' % server.server_address
     if hasattr(request, 'param'): # for tests generated by pytest_generate_tests
         api.VERSION = request.param['version']
         api.REQUESTS_PER_SECOND = 10000 # just for here!