Skip to content

Commit

Permalink
Build and return all pages and not just the last one. (Fixes #205) (#211
Browse files Browse the repository at this point in the history
)
  • Loading branch information
MelissaAutumn authored Dec 11, 2023
1 parent e377ee5 commit 6311a46
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions backend/src/appointment/controller/apis/google_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,24 @@ def get_email(self, token):

def list_calendars(self, token):
response = {}
items = []
with build("calendar", "v3", credentials=token) as service:
request = service.calendarList().list()
while request is not None:
try:
response = request.execute()

items += response.get('items', [])
except HttpError as e:
logging.warning(f"[google_client.list_calendars] Request Error: {e.status_code}/{e.error_details}")

request = service.calendarList().list_next(request, response)

return response.get("items", [])
return items

def list_events(self, calendar_id, time_min, time_max, token):
response = {}
items = []

# Limit the fields we request
fields = ','.join(
Expand All @@ -123,12 +127,14 @@ def list_events(self, calendar_id, time_min, time_max, token):
while request is not None:
try:
response = request.execute()

items += response.get('items', [])
except HttpError as e:
logging.warning(f"[google_client.list_events] Request Error: {e.status_code}/{e.error_details}")

request = service.events().list_next(request, response)

return response.get("items", [])
return items

def create_event(self, calendar_id, body, token):
response = None
Expand Down

0 comments on commit 6311a46

Please sign in to comment.