Skip to content

Commit

Permalink
Merge pull request #10 from jefferlu/dev
Browse files Browse the repository at this point in the history
feat: Add pagination support to get_objects method
  • Loading branch information
chuongmep authored Jan 23, 2025
2 parents 6026a8a + ca3925a commit 9f3e663
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions APSToolkitPython/src/aps_toolkit/Bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def delete_bucket(self, bucket_name: str):
raise Exception(response.reason)
return response.content

def get_objects(self, bucket_name: str) -> pd.DataFrame:
def get_objects(self, bucket_name: str, limit: int = 10) -> pd.DataFrame:
"""
Retrieves all the objects in a specified bucket from the Autodesk OSS API.
Expand All @@ -106,12 +106,16 @@ def get_objects(self, bucket_name: str) -> pd.DataFrame:
headers = {
"Authorization": f"Bearer {self.token.access_token}"
}
url = f"{self.host}/{bucket_name}/objects"
response = requests.get(url, headers=headers)
if response.status_code != 200:
raise Exception(response.reason)
data = response.json()
df = pd.DataFrame(data["items"])
url = f"{self.host}/{bucket_name}/objects?limit={limit}"
fetched_objects = []
while url:
response = requests.get(url, headers=headers)
if response.status_code != 200:
raise Exception(response.reason)
data = response.json()
fetched_objects.extend(data["items"])
url = data.get("next")
df = pd.DataFrame(fetched_objects)
return df

def upload_object(self, bucket_name: str, file_path: str, object_name: str) -> dict:
Expand Down

0 comments on commit 9f3e663

Please sign in to comment.