Skip to content

Commit

Permalink
add get versions information
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Nov 18, 2024
1 parent 0dc3827 commit b0bfb34
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
36 changes: 35 additions & 1 deletion APSToolkitPython/src/aps_toolkit/BIM360.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import re
from urllib.parse import urlparse, parse_qs
from io import BytesIO

import urllib.parse

class BIM360:
def __init__(self, token: Token = None):
Expand Down Expand Up @@ -364,6 +364,40 @@ def get_item_info(self, project_id: str, item_id: str):
raise Exception(response.reason)
return response.json()

def get_version_info(self, project_id: str, version_id: str):
"""
Returns the version with the given version_id.
https://aps.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-versions-version_id-GET/
:param project_id: :class:`str` The unique identifier of a project.
:param version_id: :class:`str` The unique identifier of a version.
:return: :class:`dict` all information of version
"""
headers = {'Authorization': 'Bearer ' + self.token.access_token}
# encoder 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)
if response.status_code != 200:
raise Exception(response.reason)
return response.json()

def get_item_from_version(self, project_id: str, version_id: str):
"""
Returns the item the given version is associated with.
https://aps.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-versions-version_id-item-GET/
:param project_id: :class:`str` The unique identifier of a project.
:param version_id: :class:`str` The unique identifier of a version.
:return: :class:`dict` all information of version
"""
headers = {'Authorization': 'Bearer ' + self.token.access_token}
# encoder version_id
version_id = urllib.parse.quote(version_id)
url = f"{self.host}/data/v1/projects/{project_id}/versions/{version_id}/item"
response = requests.get(url, headers=headers)
if response.status_code != 200:
raise Exception(response.reason)
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
Expand Down
15 changes: 12 additions & 3 deletions APSToolkitPython/src/test/test_bim360.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ def setUp(self):
self.token = Auth().auth2leg()
self.bim360 = BIM360(self.token)
self.hub_id = "b.1715cf2b-cc12-46fd-9279-11bbc47e72f6"
self.project_id = "b.ec0f8261-aeca-4ab9-a1a5-5845f952b17d"
self.folder_id = "urn:adsk.wipprod:fs.folder:co.2yCTHGmWSvSCzlaIzdrFKA"
self.item_id = "urn:adsk.wipprod:dm.lineage:-wv2uodvSgaXmUZ4O0oYkw"
self.project_id = "b.ca790fb5-141d-4ad5-b411-0461af2e9748"
self.folder_id = "urn:adsk.wipprod:fs.folder:co.kHlWc1ajSHSxey-_bGjKwg"
self.item_id = "urn:adsk.wipprod:dm.lineage:aK6QZ3gUQPGI63FxRBA3tQ"
self.version_id = "urn:adsk.wipprod:fs.file:vf.aK6QZ3gUQPGI63FxRBA3tQ?version=4"

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.uX9MsdjjSraK_3p5qXyE_A&entityId=urn%3Aadsk.wipprod%3Adm.lineage%3AwGXA2ljoSQaXtGOEepawIg&viewModel=detail&moduleId=folders"
Expand Down Expand Up @@ -79,6 +80,14 @@ 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_version_info(self):
version_info = self.bim360.get_version_info(self.project_id, self.version_id)
self.assertNotEquals(version_info, 0)

def test_get_item_from_version(self):
item = self.bim360.get_item_from_version(self.project_id, self.version_id)
self.assertNotEquals(item, 0)

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

0 comments on commit b0bfb34

Please sign in to comment.