@@ -694,30 +694,38 @@ def instance_url(self):
694
694
# Classes of API operations
695
695
696
696
697
+ def get_link (response , rel ):
698
+ links = response .get ('links' , None )
699
+ for link in links :
700
+ if link .get ('rel' , None ) == rel :
701
+ return link .get ('uri' )
702
+ return None
703
+
697
704
class ListableAPIResource (APIResource ):
705
+ ITER_LIMIT = 1000
698
706
699
707
@classmethod
700
708
def all (cls , auth = None , ** params ):
701
709
return list (cls .iter (auth , ** params ))
702
710
703
711
@classmethod
704
712
def iter (cls , auth = None , ** params ):
705
- for unsupported_param in ['limit' , 'page' ]:
713
+ for unsupported_param in ['limit' , 'page' , 'starting_after' , 'ending_before' ]:
706
714
if unsupported_param in params :
707
715
raise CleverError ("ListableAPIResource does not support '%s' parameter" %
708
716
(unsupported_param ,))
709
717
710
718
requestor = APIRequestor (auth )
711
719
url = cls .class_url ()
712
- params ['page' ] = 1
713
- params ['limit' ] = 1000
714
- done_paginating = False
715
- while not done_paginating :
720
+ params ['limit' ] = cls .ITER_LIMIT
721
+
722
+ while url :
716
723
response , auth = requestor .request ('get' , url , params )
717
724
for datum in convert_to_clever_object (cls , response , auth ):
718
725
yield datum
719
- params ['page' ] += 1
720
- done_paginating = len (response ['data' ]) < params ['limit' ]
726
+ url = get_link (response , 'next' )
727
+ # params already included in url from get_link
728
+ params = {}
721
729
722
730
723
731
class CreatableAPIResource (APIResource ):
0 commit comments