Skip to content

Commit

Permalink
expand support parse version id
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Nov 18, 2024
1 parent 666f86c commit 580e639
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 11 additions & 3 deletions APSToolkitPython/src/aps_toolkit/BIM360.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,37 @@ def __init__(self, token: Token = None):
self.host = "https://developer.api.autodesk.com"

@staticmethod
def parse_url(url: str) -> dict:
def parse_url(url: str) -> pd.Series:
"""
Parse url to get project_id, folder_urn, version_id, viewable_guid
:param url: the url from bim360 or autodesk construction cloud (ACC)
:return: :class:`dict` project_id, folder_urn, version_id, viewable_guid
"""
if url is None:
raise Exception("url is required")
if not str.__contains__(url, "autodesk.com"):
raise Exception("url is not valid")
project_id_match = re.search(r'projects/([^\/?#]+)', url)
project_id = 'b.' + project_id_match.group(1) if project_id_match else ''
query_params = parse_qs(urlparse(url).query)
folder_urn = query_params.get('folderUrn', [''])[0]
version_id = query_params.get('entityId', [''])[0]
version_encoder = urllib.parse.quote(version_id)
item_id = None
if version_id is not None or version_id != '':
item_id =version_id.split("?")[0]
viewable_guid = query_params.get('viewable_guid', [''])[0]

return {
data = {
'project_id': project_id,
'folder_urn': folder_urn,
'item_id': item_id,
'version_id': version_id,
'version_encoder': version_encoder,
'viewable_guid': viewable_guid,
}
series = pd.Series(data)
return series

def publish_model(self, project_id: str, item_id: str):
"""
Expand Down Expand Up @@ -377,7 +385,7 @@ def get_version_info(self, project_id: str, version_id: str):
:return: :class:`dict` all information of version
"""
headers = {'Authorization': 'Bearer ' + self.token.access_token}
# encoder version_id
# URL-encode the version_id
version_id = urllib.parse.quote(version_id)
url = f"{self.host}/data/v1/projects/{project_id}/versions/{version_id}"
response = requests.get(url, headers=headers)
Expand Down
11 changes: 7 additions & 4 deletions APSToolkitPython/src/test/test_bim360.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ def setUp(self):
def test_parse_url(self):
url = "https://acc.autodesk.com/docs/files/projects/ca790fb5-141d-4ad5-b411-0461af2e9748?folderUrn=urn%3Aadsk.wipprod%3Afs.folder%3Aco.kHlWc1ajSHSxey-_bGjKwg&entityId=urn%3Aadsk.wipprod%3Afs.file%3Avf.QOFE_uOpSmaK-5JWkn3yYQ%3Fversion%3D5&viewModel=detail&moduleId=folders&viewableGuid=517b8739-48df-bcb2-be30-dda4b1eee186"
result = self.bim360.parse_url(url)
# check projectid
self.assertEqual(result['project_id'], "b." + "ca790fb5-141d-4ad5-b411-0461af2e9748")
self.assertEqual(result['folder_urn'], "urn:adsk.wipprod:fs.folder:co.uX9MsdjjSraK_3p5qXyE_A")
self.assertEqual(result['entity_id'], "urn:adsk.wipprod:dm.lineage:wGXA2ljoSQaXtGOEepawIg")
project_id = result.project_id
self.assertEqual(project_id, "b.ca790fb5-141d-4ad5-b411-0461af2e9748")
self.assertEqual(result.folder_urn, "urn:adsk.wipprod:fs.folder:co.kHlWc1ajSHSxey-_bGjKwg")
self.assertEqual(result.item_id, "urn:adsk.wipprod:fs.file:vf.QOFE_uOpSmaK-5JWkn3yYQ")
self.assertEqual(result.version_id, "urn:adsk.wipprod:fs.file:vf.QOFE_uOpSmaK-5JWkn3yYQ?version=5")
self.assertEqual(result.version_encoder,'urn%3Aadsk.wipprod%3Afs.file%3Avf.QOFE_uOpSmaK-5JWkn3yYQ%3Fversion%3D5')


def test_publish_model(self):
item_id = "urn:adsk.wipprod:dm.lineage:Od8txDbKSSelToVg1oc1VA"
Expand Down

0 comments on commit 580e639

Please sign in to comment.