Skip to content

Commit

Permalink
Refactor Google Admin using new authed request session
Browse files Browse the repository at this point in the history
  • Loading branch information
austinweisgrau committed Jun 21, 2024
1 parent b762af1 commit c87fc62
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions parsons/google/google_admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import uuid

from google.auth.transport.requests import AuthorizedSession
Expand Down Expand Up @@ -51,7 +50,9 @@ def _paginate_request(self, endpoint, collection, params=None):

# Return type from Google Admin is a tuple of length 2. Extract desired result from 2nd item
# in tuple and convert to json
res = json.loads(self.client.request(req_url + param_str, "GET")[1].decode("utf-8"))
res = self.client.request("GET", req_url + param_str).json()
if "error" in res:
raise RuntimeError(res["error"].get("message"))

# Paginate
ret = []
Expand All @@ -63,12 +64,10 @@ def _paginate_request(self, endpoint, collection, params=None):
param_arr.append("pageToken=" + res["nextPageToken"])
else:
param_arr[-1] = "pageToken=" + res["nextPageToken"]
res = json.loads(
self.client.request(req_url + "?" + "&".join(param_arr), "GET")[1].decode(
"utf-8"
)
)
ret += res[collection]
response = self.client.request("GET", req_url + "?" + "&".join(param_arr)).json()
if "error" in response:
raise RuntimeError(response["error"].get("message"))
ret += response[collection]

return Table(ret)

Expand Down

0 comments on commit c87fc62

Please sign in to comment.