From 9731bbeb31a403f6dc8caf6b03f3ef476067f56b Mon Sep 17 00:00:00 2001 From: Hagen Fritz Date: Tue, 13 May 2025 11:09:40 -0500 Subject: [PATCH 1/3] hotfix: use correct accessor --- snippets/documents.ipynb | 116 +++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/snippets/documents.ipynb b/snippets/documents.ipynb index 1407db1..b01b313 100644 --- a/snippets/documents.ipynb +++ b/snippets/documents.ipynb @@ -122,7 +122,7 @@ "# Example 1: Get all folders\n", "# ---------\n", "print(\"Example 1\")\n", - "folders = connection.__folders__.get(\n", + "folders = connection.folders.get(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"]\n", ")\n", @@ -138,7 +138,7 @@ "# Example 3: Get all children folders from parent\n", "# ---------\n", "print(\"\\nExample 3\")\n", - "subfolders = connection.__folders__.get(\n", + "subfolders = connection.folders.get(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " folder_id=607848046\n", @@ -155,7 +155,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -186,7 +186,7 @@ "# ---------\n", "print(\"Example 1\")\n", "try:\n", - " root_folder = connection.documents.folders.create(\n", + " root_folder = connection.folders.create(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " folder_name=\"Z-Research and Development\"\n", @@ -284,7 +284,7 @@ "# Example 1: Find folder in root\n", "# ---------\n", "print(\"Example 1\")\n", - "folder1 = connection.__folders__.find(\n", + "folder1 = connection.folders.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " identifier=\"Z-Research and Development\"\n", @@ -303,7 +303,7 @@ "# Example 2: Find subfolder\n", "# ----------\n", "print(\"\\nExample 2\")\n", - "folder2 = connection.__folders__.find(\n", + "folder2 = connection.folders.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " identifier=\"Subcontractors Orientation\"\n", @@ -322,13 +322,13 @@ "# ---------\n", "print(\"\\nExample 3\")\n", "try:\n", - " folder3 = connection.__folders__.find(\n", + " folder3 = connection.folders.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " identifier=\"Not a folder\"\n", " )\n", " print(folder3)\n", - "except NotFoundItemError as e:\n", + "except NotFoundItemError as e: \n", " print(e)\n", "# 'Could not find document Not a folder'" ] @@ -342,7 +342,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -359,16 +359,16 @@ ], "source": [ "# create a folder\n", - "connection.__folders__.create(\n", + "connection.folders.create(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " folder_name=f\"Folder_in_Root\"\n", ")\n", "\n", - "folder = connection.find_doc(\n", + "folder = connection.folders.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", - " name=\"Folder_in_Root\"\n", + " identifier=\"Folder_in_Root\"\n", ")" ] }, @@ -381,13 +381,13 @@ "# Example 1: Move folder\n", "# ---------\n", "print(\"Example 1\")\n", - "subfolder = connection.find_doc(\n", + "subfolder = connection.folders.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", - " name=\"I-Safety and Environmental\"\n", + " identifier=\"I-Safety and Environmental\"\n", ")\n", "\n", - "connection.__folders__.update(\n", + "connection.folders.update(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " doc_id=folder[\"id\"],\n", @@ -404,7 +404,7 @@ "# Example 2: Update folder name\n", "# ---------\n", "print(\"\\nExample 2\")\n", - "connection.__folders__.update(\n", + "connection.folders.update(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " doc_id=folder[\"id\"],\n", @@ -421,7 +421,7 @@ "# Example 3: Change permissions\n", "# ---------\n", "print(\"\\nExample 2\")\n", - "connection.__folders__.update(\n", + "connection.folders.update(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " doc_id=folder[\"id\"],\n", @@ -452,7 +452,7 @@ "# Example 2: Get all files\n", "# ---------\n", "print(\"\\nExample 2\")\n", - "files = connection.__files__.get(\n", + "files = connection.files.get(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"]\n", ")\n", @@ -471,7 +471,7 @@ "# Example 4: Get all children files from parent\n", "# ---------\n", "print(\"\\nExample 4\")\n", - "subfiles = connection.__files__.get(\n", + "subfiles = connection.files.get(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " folder_id=607848046\n", @@ -496,7 +496,7 @@ "# ---------\n", "print(\"Example 1\")\n", "try:\n", - " file_in_root = connection.__files__.create(\n", + " file_in_root = connection.files.create(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " filepath=f\"{pathlib.Path(__file__).resolve().parent.parent}/data/test/test_pdf.pdf\"\n", @@ -517,13 +517,13 @@ "# ---------\n", "print(\"\\nExample 2\")\n", "try:\n", - " folder = connection.__folders__.find(\n", + " folder = connection.folders.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " identifier=\"Subcontractors Orientation\" # this needs to be a folder in your procore project\n", " )\n", "\n", - " file = connection.__files__.create(\n", + " file = connection.files.create(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " folder_id=folder[\"id\"],\n", @@ -544,7 +544,7 @@ "# Example 3: File already exists\n", "# ---------\n", "try:\n", - " file = connection.__files__.create(\n", + " file = connection.files.create(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " folder_id=folder[\"id\"],\n", @@ -572,7 +572,7 @@ "# Example 1: Find file in root\n", "# ---------\n", "print(\"Example 1\")\n", - "file1 = connection.__files__.find(\n", + "file1 = connection.files.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " identifier=\"test_pdf.pdf\"\n", @@ -592,7 +592,7 @@ "# Example 2: Find file in subfolder\n", "# ----------\n", "print(\"\\nExample 2\")\n", - "file2 = connection.__files__.find(\n", + "file2 = connection.files.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " identifier=\"another_test_pdf.pdf\"\n", @@ -611,7 +611,7 @@ "# ---------\n", "print(\"\\nExample 3\")\n", "try:\n", - " file3 = connection.__files__.find(\n", + " file3 = connection.files.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " identifier=\"Not a file.txt\"\n", @@ -631,10 +631,10 @@ "# Example 1: Search for file with multiple perfect matches\n", "# ---------\n", "print(\"Example 1\")\n", - "doc1 = connection.__files__.search(\n", + "doc1 = connection.files.search(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", - " value=\"test\"\n", + " value=\"test\" \n", ")\n", "print(f\"{doc1['id']}: {doc1['name']}\")\n", "# warn(\"Multiple 100% matches - try refining your search critera for better results\")\n", @@ -650,7 +650,7 @@ "# Example 1: Search for private file\n", "# ---------\n", "print(\"\\nExample 2\")\n", - "doc2 = connection.__files__.search(\n", + "doc2 = connection.files.search(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " value=\"another\"\n", @@ -668,7 +668,7 @@ "# Example 3: Find folder \n", " # ---------\n", " print(\"\\nExample 3\")\n", - " doc3 = connection.__folders__.search(\n", + " doc3 = connection.folders.search(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " value=\"training\"\n", @@ -683,22 +683,22 @@ "metadata": {}, "outputs": [], "source": [ - "# Example 4: Find file in subfolder \n", - " # ---------\n", - " print(\"\\nExample 4\")\n", - " folder = connection.__folders__.find(\n", - " company_id=company[\"id\"],\n", - " project_id=project[\"id\"],\n", - " identifier=\"I-Safety and Environmental\"\n", - " )\n", - " doc4 = connection.__files__.search(\n", - " company_id=company[\"id\"],\n", - " project_id=project[\"id\"],\n", - " folder_id=folder[\"id\"],\n", - " value=\"test\"\n", - " )\n", - " print(f\"{doc4['id']}: {doc4['name']}\")\n", - " # 607851830: another_test_pdf.pdf" + "# Example 5: Find file in subfolder \n", + "# ---------\n", + "print(\"\\nExample 5\")\n", + "folder = connection.folders.find(\n", + " company_id=company[\"id\"],\n", + " project_id=project[\"id\"],\n", + " identifier=\"I-Safety and Environmental\"\n", + ")\n", + "doc4 = connection.files.search(\n", + " company_id=company[\"id\"],\n", + " project_id=project[\"id\"],\n", + " folder_id=folder[\"id\"],\n", + " value=\"test\"\n", + ")\n", + "print(f\"{doc4['id']}: {doc4['name']}\")\n", + "# 607851830: another_test_pdf.pdf" ] }, { @@ -710,12 +710,12 @@ "# Example 5: Find subfolder in specified folder \n", "# ---------\n", "print(\"\\nExample 5\")\n", - "folder = connection.__folders__.find(\n", + "folder = connection.folders.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " identifier=\"I-Safety and Environmental\"\n", ")\n", - "doc5 = connection.__folders__.search(\n", + "doc5 = connection.folders.search(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " folder_id=folder[\"id\"],\n", @@ -744,13 +744,13 @@ "for old_file in [\"test_pdf.pdf\", \"renamed_test_pdf\", \"another_test_pdf.pdf\"]:\n", " # look for the filename\n", " try:\n", - " file_temp = connection.__files__.find(\n", + " file_temp = connection.files.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " identifier=old_file\n", " )\n", " \n", - " response = connection.__files__.remove(\n", + " response = connection.files.remove(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " doc_id=file_temp[\"id\"],\n", @@ -761,7 +761,7 @@ "\n", "# create a file\n", "try:\n", - " connection.__files__.create(\n", + " connection.files.create(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " filepath=f\"{pathlib.Path(__file__).resolve().parent.parent}/data/test/test_pdf.pdf\",\n", @@ -770,7 +770,7 @@ "except WrongParamsError as e:\n", " print(e)\n", "\n", - "file_original = connection.__files__.find(\n", + "file_original = connection.files.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " identifier=\"test_pdf.pdf\"\n", @@ -786,13 +786,13 @@ "# Example 1: Move file\n", "# ---------\n", "print(\"Example 1\")\n", - "subfolder = connection.__folders__.find(\n", + "subfolder = connection.folders.find(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " identifier=\"I-Safety and Environmental\"\n", ")\n", "\n", - "file_new_loc = connection.__files__.update(\n", + "file_new_loc = connection.files.update(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " doc_id=file_original[\"id\"],\n", @@ -811,7 +811,7 @@ "# Example 2: Update file name\n", "# ---------\n", "print(\"\\nExample 2\")\n", - "file_new_name = connection.__files__.update(\n", + "file_new_name = connection.files.update(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " doc_id=file_original[\"id\"],\n", @@ -830,7 +830,7 @@ "# Example 3: Change Description\n", "# ---------\n", "print(\"\\nExample 3\")\n", - "file_new_desc = connection.__files__.update(\n", + "file_new_desc = connection.files.update(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " doc_id=file_original[\"id\"],\n", @@ -849,7 +849,7 @@ "# Example 4: Change permissions\n", "# ---------\n", "print(\"\\nExample 4\")\n", - "file_new_permissions = connection.__files__.update(\n", + "file_new_permissions = connection.files.update(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " doc_id=file_original[\"id\"],\n", @@ -868,7 +868,7 @@ "# Example 5: Update file content\n", "# ---------\n", "print(\"\\nExample 5\")\n", - "file_new_content = connection.__files__.update(\n", + "file_new_content = connection.files.update(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", " doc_id=file_original[\"id\"],\n", From 66c5abe2d6197d9c1be254761a44818ffc11215c Mon Sep 17 00:00:00 2001 From: Hagen Fritz Date: Tue, 13 May 2025 11:09:52 -0500 Subject: [PATCH 2/3] feat: add view --- ProPyCore/access/documents/files.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ProPyCore/access/documents/files.py b/ProPyCore/access/documents/files.py index 0516507..a1ce1dd 100644 --- a/ProPyCore/access/documents/files.py +++ b/ProPyCore/access/documents/files.py @@ -225,7 +225,7 @@ def remove(self, company_id, project_id, doc_id): return doc_info - def get(self, company_id, project_id, folder_id=None): + def get(self, company_id, project_id, folder_id=None, view="normal"): """ Gets all documents in a project. @@ -235,6 +235,10 @@ def get(self, company_id, project_id, folder_id=None): Unique identifier for the company. project_id : int Unique identifier for the project. + folder_id : int, default None + ID of parent folder. + view : str, default "normal" + View to use for the request: "normal" or "extended" Returns ------- @@ -248,7 +252,7 @@ def get(self, company_id, project_id, folder_id=None): docs = [] while n_docs > 0: params = { - "view": "normal", + "view": view, "sort": "name", "page": page, "per_page": 10000, @@ -284,7 +288,7 @@ def get(self, company_id, project_id, folder_id=None): f"from Parent ID {folder_id if folder_id is not None else 'Root'}", ) - def search(self, company_id, project_id, value, folder_id=None): + def search(self, company_id, project_id, value, folder_id=None, view="normal"): """ Searches through all available files to find the closest match to the given value. @@ -308,6 +312,7 @@ def search(self, company_id, project_id, value, folder_id=None): company_id=company_id, project_id=project_id, folder_id=folder_id, + view=view, ) doc_type = self.endpoint.split("/")[-1][:-1] @@ -331,4 +336,4 @@ def search(self, company_id, project_id, value, folder_id=None): raise NotFoundItemError(f"Could not find document {value}") else: result["search_criteria"] = {"value": value, "match": score} - return result + return result \ No newline at end of file From 2d0c978acb0d35c38edf8071c21adda60ee02a44 Mon Sep 17 00:00:00 2001 From: Hagen Fritz Date: Tue, 13 May 2025 11:10:02 -0500 Subject: [PATCH 3/3] feat: bump to 0.6.2 --- CHANGELOG.md | 5 +++++ ProPyCore/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bd2260..969fc88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [0.6.2] - 2025-05-13 + +### Added +* `documents.files`: add `view` parameter to `get()` and `search()` methods + ## [0.6.1] - 2025-05-07 ### Added diff --git a/ProPyCore/__init__.py b/ProPyCore/__init__.py index e122884..b0c6774 100644 --- a/ProPyCore/__init__.py +++ b/ProPyCore/__init__.py @@ -3,4 +3,4 @@ from .exceptions import * from .procore import Procore -__version__ = "0.6.1" \ No newline at end of file +__version__ = "0.6.2" \ No newline at end of file diff --git a/setup.py b/setup.py index 23360ae..a919f8b 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="ProPyCore", - version="0.6.1", + version="0.6.2", author="Hagen E. Fritz", author_email="hfritz@r-o.com", description="Interact with Procore through Python for data connection applications",