Skip to content

Commit

Permalink
get_latest_derivative_urn
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed May 14, 2024
1 parent 266f3a4 commit 39c1099
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions APSToolkitPython/src/aps_toolkit/BIM360.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ def get_item_info(self, project_id: str, item_id: str):
raise Exception(response.content)
return response.json()

def get_latest_derivative_urn(self, project_id: str, item_id: str):
"""
Get the latest derivative urn of an item by project_id and item_id
:param project_id: :class:`str` the unique identifier of a project
:param item_id: :class:`str` the unique identifier of an item
:return: :class:`str` the latest derivative urn of an item
"""
headers = {'Authorization': 'Bearer ' + self.token.access_token}
url = f"{self.host}/data/v1/projects/{project_id}/items/{item_id}/versions"
response = requests.get(url, headers=headers)
if response.status_code != 200:
raise Exception(response.content)
item_versions = response.json()
return item_versions['data'][0]['relationships']['derivatives']['data']['id']

def batch_report_projects(self, hub_id: str) -> pd.DataFrame:
"""
Get batch all projects with general information by hub_id
Expand Down
4 changes: 4 additions & 0 deletions APSToolkitPython/src/test/test_bim360.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def test_get_item_info(self):
item_info = self.bim360.get_item_info(self.project_id, self.item_id)
self.assertNotEquals(item_info, 0)

def test_get_latest_derivative_urn(self):
urn = self.bim360.get_latest_derivative_urn(self.project_id, self.item_id)
self.assertNotEquals(urn, "")

def test_get_item_versions(self):
items = self.bim360.batch_report_items(self.project_id, self.folder_id)
self.assertNotEquals(len(items), 0)
Expand Down

0 comments on commit 39c1099

Please sign in to comment.