Skip to content

Commit a60484c

Browse files
author
Bruno Vieira
committed
add support for cursor based pagination
Signed-off-by: Bruno Vieira <[email protected]>
1 parent f4041d4 commit a60484c

15 files changed

+505
-170
lines changed

chartmogul/api/activity.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ class Activity(Resource):
99
"""
1010
_path = "/customers{/uuid}/activities"
1111
_root_key = 'entries'
12-
_many = namedtuple('Activities', [_root_key, "has_more", "per_page", "page"])
12+
_many = namedtuple(
13+
'Activities',
14+
[_root_key, 'has_more', 'per_page', 'page', 'cursor'],
15+
defaults=[None, None, None, None]
16+
)
1317

1418
class _Schema(Schema):
1519
id = fields.Int()

chartmogul/api/customer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ class Customer(Resource):
3030
"""
3131
_path = "/customers{/uuid}"
3232
_root_key = 'entries'
33-
_many = namedtuple('Customers',
34-
[_root_key, "has_more", "per_page", "page", "current_page", "total_pages"])
33+
_many = namedtuple(
34+
'Customers',
35+
[_root_key, 'has_more', 'per_page', 'page', 'current_page', 'total_pages', 'cursor'],
36+
defaults=[None, None, None, None, None, None]
37+
)
3538

3639
class _Schema(Schema):
3740
# All operations

chartmogul/api/invoice.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ class Invoice(Resource):
3737
"""
3838
_path = "/import/customers{/uuid}/invoices"
3939
_root_key = 'invoices'
40-
_many = namedtuple('Invoices', [_root_key, "current_page", "total_pages", "customer_uuid"])
40+
_many = namedtuple(
41+
'Invoices',
42+
[_root_key, 'current_page', 'total_pages', 'cursor', 'has_more', 'customer_uuid'],
43+
defaults=[None, None, None, None, None]
44+
)
4145
_many.__new__.__defaults__ = (None,) * len(_many._fields)
4246

4347
class _Schema(Schema):

chartmogul/api/plan.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ class Plan(Resource):
99
"""
1010
_path = "/plans{/uuid}"
1111
_root_key = 'plans'
12-
_many = namedtuple('Plans', [_root_key, "current_page", "total_pages"])
12+
_many = namedtuple(
13+
'Plans',
14+
[_root_key, 'current_page', 'total_pages', 'has_more', 'cursor'],
15+
defaults=[None, None, None, None]
16+
)
1317

1418
class _Schema(Schema):
1519
uuid = fields.String()

chartmogul/api/plan_group.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ class PlanGroup(Resource):
1010
"""
1111
_path = "/plan_groups{/uuid}"
1212
_root_key = 'plan_groups'
13-
_many = namedtuple('PlanGroups', [_root_key, "current_page", "total_pages"])
13+
_many = namedtuple(
14+
'PlanGroups',
15+
[_root_key, 'current_page', 'total_pages', 'has_more', 'cursor'],
16+
defaults=[None, None, None, None]
17+
)
1418

1519
class _Schema(Schema):
1620
uuid = fields.String()

chartmogul/api/plan_group_plans.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ class PlanGroupPlans(Resource):
99
"""
1010
_path = "/plan_groups{/uuid}/plans"
1111
_root_key = 'plans'
12-
_many = namedtuple('PlanGroupPlans', [_root_key, "current_page", "total_pages"])
12+
_many = namedtuple(
13+
'PlanGroupPlans',
14+
[_root_key, 'current_page', 'total_pages', 'has_more', 'cursor'],
15+
defaults=[None, None, None, None]
16+
)
1317

1418
class _Schema(Schema):
1519
uuid = fields.String()

chartmogul/api/subscription.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ class Subscription(Resource):
1010
"""
1111
_path = "/customers{/uuid}/subscriptions"
1212
_root_key = 'entries'
13-
_many = namedtuple('Subscriptions', [_root_key, "has_more", "per_page", "page"])
13+
_many = namedtuple(
14+
'Subscriptions',
15+
[_root_key, 'has_more', 'per_page', 'page', 'cursor'],
16+
defaults=[None, None, None, None]
17+
)
1418

1519
class _Schema(Schema):
1620
id = fields.Int(allow_none=True)
@@ -45,11 +49,16 @@ def make(self, data, **kwargs):
4549
@classmethod
4650
def _loadJSON(cls, jsonObj):
4751
if "subscriptions" in jsonObj:
48-
_many = namedtuple('Subscriptions', ["subscriptions", "current_page", "total_pages", "customer_uuid"])
52+
_many = namedtuple(
53+
'Subscriptions',
54+
["subscriptions", "current_page", "total_pages", "customer_uuid", "has_more", "cursor"]
55+
)
4956
return _many(cls._schema.load(jsonObj["subscriptions"], many=True),
50-
jsonObj["current_page"],
51-
jsonObj["total_pages"],
52-
jsonObj["customer_uuid"])
57+
jsonObj.get("current_page", None),
58+
jsonObj.get("total_pages", None),
59+
jsonObj["customer_uuid"],
60+
jsonObj.get("has_more", None),
61+
jsonObj.get("cursor", None))
5362
else:
5463
return super(Subscription, cls)._loadJSON(jsonObj)
5564

chartmogul/resource.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@
2727
'update': 'put'
2828
}
2929

30-
LIST_PARAMS = ['current_page', 'total_pages',
31-
'has_more', 'per_page', 'page',
32-
'summary', 'customer_uuid']
30+
LIST_PARAMS = [
31+
'current_page',
32+
'total_pages',
33+
'has_more',
34+
'per_page',
35+
'page',
36+
'summary',
37+
'cursor',
38+
'customer_uuid'
39+
]
3340
ESCAPED_QUERY_KEYS = {
3441
'start_date': 'start-date',
3542
'end_date': 'end-date'

requirements-test.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-r requirements.txt
2+
yarl
3+
mock>=1.0.1
4+
requests-mock>=1.3.0
5+
vcrpy<3.0.0
6+
PyYAML>=5.1.2
7+
httpretty>=0.9.6
8+
wrapt>=1.11.2

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ uritemplate>=3.0.0
33
promise>=1.0.1
44
marshmallow>=3.10.0
55
future>=0.16.0
6+
urllib3<=2.0.0

0 commit comments

Comments
 (0)