Walter Cruz avatar Walter Cruz committed eb5c3f6

Fixing tests

Comments (0)

Files changed (5)

boo_box/boo_box.egg-info/PKG-INFO

 Metadata-Version: 1.0
 Name: boo-box
-Version: 0.3.5
+Version: 0.3.7
 Summary: Boo-Box to monetize
 Home-page: http://www.assembla.com/spaces/py_boo_box
 Author: Walter Cruz
Add a comment to this file

boo_box/boo_box/boo_box.pyc

Binary file modified.

boo_box/build/lib/boo_box/affiliates.py

 amazon_jp = 'amazonjpid'
 amazon_fr = 'amazonfrid'
 amazon_de = 'amazondeid'
+americanas ='americanasid'
+buscape = 'buscapeid'
 ebay = 'ebayid'
+jacotei = 'jacoteiid'
 mercadolivre = 'mercadolivreid'
 submarino = 'submarinoid'
 americanas = 'americanasid'

boo_box/build/lib/boo_box/boo_box.py

 import sys
 
 class Box(object):
-    def __init__(self,aff,uid):
+    def __init__(self, aff, uid):
         """ You should suply your affiliate and your user id"""
+        self.limit = 6
         self.aff = aff
         self.uid = uid
 
-    def _do_get(self,tags):
+    def _do_get(self, tags, limit):
+        """
+        This will make the real API call
+        API format: http://boo-box.com/api/format:formato/aff:ecommid/uid:userid/tags:searchterms/limit:number
+        docs: http://www.boo-box.com/blog/br/2009/boo-api-nova-versao/
+        """
         import sys
         caller = sys._getframe(1).f_code.co_name
         method = caller.split('_')[-1]
         tags = urllib.quote(tags)
-        add = 'http://boo-box.com/api/format:' + method +'/aff:' + self.aff +'/uid:' + self.uid + '/tags:' + tags
-        content = urllib.urlopen(add).read()
+        url_base = 'http://boo-box.com/api/format:%(method)s/aff:%(aff)s/uid:%(uid)s/tags:%(tags)s/limit:%(limit)s'
+        url = url_base % {'method':method,'aff':self.aff,'uid':self.uid,'tags':tags,'limit':limit}
+        content = urllib.urlopen(url).read()
+        return content.strip()
+
+    def _do_get_xml(self,tags,limit):
+        content = self._do_get(tags,limit)
         return content
 
-    def _do_get_xml(self,tags):
-        content = self._do_get(tags)
+    def _do_get_json(self,tags,limit):
+        content = self._do_get(tags,limit)
         return content
 
-    def _do_get_json(self,tags):
-        content = self._do_get(tags)
-        return content
-
-    def _do_get_object(self,tags):
-        content = self._do_get_json(tags)
+    def _do_get_object(self,tags,limit):
+        content = self._do_get_json(tags,limit)
         content = content.replace('jsonBooboxApi(','')
         import simplejson
-        return simplejson.loads(content[:-1])
+        return simplejson.loads(content[:-2])
 
-    def get(self, format, tags):
+    def get(self, format, tags, limit=6):
         """get the response for your tags. Three formats supported by now:
         object, that returns a dict, json, that returns a json string
         and XML, that returns XML"""
         handler = getattr(self, '_do_get_%s' % format.lower(),None)
         if handler:
-            return  handler(tags)
+            return  handler(tags,limit)
         else:
             raise NotImplementedError
 

boo_box/tests/test.py

         content = boo.replace('jsonBooboxApi(','')
         import simplejson
         box = simplejson.loads(content[:-2])
-        assert(len(box['item']) == 4)
+        assert(len(box['products']) == 4)
 
     def test_xml(self):
         boo = boo_box.Box(submarino,'173097').get('XML','livros xml')
 
     def test_object(self):
         boo = boo_box.Box(submarino,'173097').get('object','livros xml')
+	import pdb;pdb.set_trace()
         assert isinstance(boo,dict)
-        assert(len(boo['item']) == 6)
+        assert(len(boo['products']) == 6)
         boo = boo_box.Box(submarino,'173097').get('object','livros xml',3)
         assert isinstance(boo,dict)
-        assert(len(boo['item']) == 3)
+        assert(len(boo['products']) == 3)
         boo = boo_box.Box(submarino,'173097').get('object','livros xml',6)
         assert isinstance(boo,dict)
-        assert(len(boo['item']) == 6)
+        assert(len(boo['products']) == 6)
 
     @raises(NotImplementedError)
     def test_pdf(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.