Skip to content

Commit afbbf2c

Browse files
committed
iter_all
1 parent 64c3b9d commit afbbf2c

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

README.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ provides CRUD operations, depending on capabilities of the resource:
4242

4343
.. code:: python
4444
45-
api.Products.all() # GET /products
45+
api.Products.all() # GET /products (returns only a single page of products as a list)
46+
api.Products.iterall() # GET /products (autopaging generator that yields all
47+
# products from all pages product by product.)
4648
api.Products.get(1) # GET /products/1
4749
api.Products.create(name='', type='', ...) # POST /products
4850
api.Products.get(1).update(price='199.90') # PUT /products/1
@@ -110,7 +112,7 @@ Full documentation of the API is available on the Bigcommerce
110112
To do
111113
-----
112114

113-
- Automatic enumeration of multiple page responses
115+
- Automatic enumeration of multiple page responses for subresources.
114116

115117
.. |Build Status| image:: https://api.travis-ci.org/bigcommerce/bigcommerce-api-python.svg?branch=master
116118
:target: https://travis-ci.org/bigcommerce/bigcommerce-api-python

bigcommerce/resources/base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,19 @@ def _get_all_path(cls):
9999
return cls.resource_name
100100

101101
@classmethod
102-
def all(cls, connection=None, **kwargs):
102+
def all(cls, connection=None, **params):
103+
"""
104+
Returns first page if no params passed in as a list.
105+
"""
106+
107+
request = cls._make_request('GET', cls._get_all_path(), connection, params=params)
108+
return cls._create_object(request, connection=connection)
109+
110+
@classmethod
111+
def iterall(cls, connection=None, **kwargs):
112+
"""
113+
Returns a autopaging generator that yields each object returned one by one.
114+
"""
103115

104116
try:
105117
limit = kwargs['limit']

0 commit comments

Comments
 (0)