diff --git a/gratipay/elsewhere/_paginators.py b/gratipay/elsewhere/_paginators.py index 42cb400e7e..a33b47d5da 100644 --- a/gratipay/elsewhere/_paginators.py +++ b/gratipay/elsewhere/_paginators.py @@ -70,16 +70,18 @@ def f(self, response, parsed): return f -def keys_paginator(**kw): +def keys_paginator(page_key, **kw): # https://confluence.atlassian.com/display/BITBUCKET/Version+2#Version2-Pagingthroughobjectcollections - page_key = kw.get('page', 'values') - total_count_key = kw.get('total_count', 'size') + # https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#paging + paging_key = kw.get('paging') + total_key = kw.get('total') links_keys_map = tuple((k, kw.get(k, k)) for k in links_keys) def f(self, response, parsed): page = parsed[page_key] - links = {k: _strip_prefix(self.api_url, parsed[k2]) + paging = parsed.get(paging_key, {}) if paging_key else parsed + links = {k: _strip_prefix(self.api_url, paging[k2]) for k, k2 in links_keys_map - if parsed.get(k2)} - total_count = parsed.get(total_count_key, -1) if links else len(page) + if paging.get(k2)} + total_count = paging.get(total_key, -1) if links else len(page) return page, total_count, links return f diff --git a/gratipay/elsewhere/bitbucket.py b/gratipay/elsewhere/bitbucket.py index 65ae9ad26d..690de50e5f 100644 --- a/gratipay/elsewhere/bitbucket.py +++ b/gratipay/elsewhere/bitbucket.py @@ -19,7 +19,7 @@ class Bitbucket(PlatformOAuth1): # API attributes api_format = 'json' - api_paginator = keys_paginator(prev='previous') + api_paginator = keys_paginator('values', prev='previous', total='size') api_url = 'https://bitbucket.org/api' api_user_info_path = '/2.0/users/{user_name}' api_user_self_info_path = '/2.0/user' diff --git a/gratipay/elsewhere/facebook.py b/gratipay/elsewhere/facebook.py index fe6fba15c8..c5b24c59c8 100644 --- a/gratipay/elsewhere/facebook.py +++ b/gratipay/elsewhere/facebook.py @@ -2,6 +2,7 @@ from gratipay.elsewhere import PlatformOAuth2 from gratipay.elsewhere._extractors import key +from gratipay.elsewhere._paginators import keys_paginator class Facebook(PlatformOAuth2): @@ -18,6 +19,7 @@ class Facebook(PlatformOAuth2): # API attributes api_format = 'json' + api_paginator = keys_paginator('data', paging='paging', prev='previous') api_url = 'https://graph.facebook.com' api_user_info_path = '/{user_name}' api_user_self_info_path = '/me'