Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
This merge adds the get_all_connections method.
  • Loading branch information
Pääkkönen Juho committed Dec 14, 2016
2 parents d1e9a4f + fa2d4b7 commit ae079c3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions facebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import re

try:
from urllib.parse import parse_qs, urlencode
from urllib.parse import parse_qs, urlencode, urlparse
except ImportError:
from urlparse import parse_qs
from urlparse import parse_qs, urlparse
from urllib import urlencode

from . import version
Expand Down Expand Up @@ -120,6 +120,22 @@ def get_connections(self, id, connection_name, **args):
return self.request(
"{0}/{1}/{2}".format(self.version, id, connection_name), args)

def get_all_connections(self, id, connection_name, **args):
"""Get all pages from a get_connections call
This will iterate over all pages returned by a get_connections call
and yield the individual items.
"""
while True:
page = self.get_connections(id, connection_name, **args)
for post in page['data']:
yield post
next = page.get('paging', {}).get('next')
if not next:
return
args = parse_qs(urlparse(next).query)
del args['access_token']

def put_object(self, parent_object, connection_name, **data):
"""Writes the given object to the graph, connected to the given parent.
Expand Down

0 comments on commit ae079c3

Please sign in to comment.