Skip to content

Commit

Permalink
Merge pull request #49 from rogers-obrien-rad/feature/48/types-and-re…
Browse files Browse the repository at this point in the history
…gions

Feature/48/types and regions
  • Loading branch information
HagenFritz committed Nov 9, 2023
2 parents faad540 + 84062b4 commit f226061
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 1 deletion.
89 changes: 88 additions & 1 deletion propycore/access/companies.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,91 @@ def find(self, identifier):
if company[key] == identifier:
return company

raise NotFoundItemError(f"Could not find company {identifier}")
raise NotFoundItemError(f"Could not find company {identifier}")

def get_projects(self, company_id):
"""
"""
endpoint = f"{self.endpoint}/{company_id}/projects"

headers = {
"Procore-Company-Id": f"{company_id}"
}

projects = self.get_request(
api_url=endpoint,
additional_headers=headers
)

return projects

def get_regions(self, company_id, page=1, per_page=100):
"""
Gets all regions for a specified company
Parameters
----------
company_id : int
The identifier for the company
per_page : int, default 100
Number of regions to include per page
Returns
-------
regions : list of dict
List where each value is a dict with the region's details
"""
endpoint = f"{self.endpoint}/{company_id}/project_regions"

params = {
"page": page,
"per_page": per_page
}

headers = {
"Procore-Company-Id": f"{company_id}"
}

regions = self.get_request(
api_url=endpoint,
additional_headers=headers,
params=params
)

return regions

def get_project_types(self, company_id, page=1, per_page=100):
"""
Gets all project types for a specified company
Parameters
----------
company_id : int
The identifier for the company
per_page : int, default 100
Number of project types to include per page
Returns
-------
project_types : list of dict
List where each value is a dict with the project type's details
"""
endpoint = f"{self.endpoint}/{company_id}/project_types"

params = {
"page": page,
"per_page": per_page
}

headers = {
"Procore-Company-Id": f"{company_id}"
}

project_types = self.get_request(
api_url=endpoint,
additional_headers=headers,
params=params
)

return project_types
57 changes: 57 additions & 0 deletions snippets/get_company_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os
import sys
import json
import urllib
import pathlib
sys.path.append(f"{pathlib.Path(__file__).resolve().parent.parent}")

from propycore.procore import Procore

from dotenv import load_dotenv

if os.getenv("CLIENT_ID") is None:
load_dotenv()

if __name__ == "__main__":
connection = Procore(
client_id=os.getenv("CLIENT_ID"),
client_secret=os.getenv("CLIENT_SECRET"),
redirect_uri=os.getenv("REDIRECT_URI"),
oauth_url=os.getenv("OAUTH_URL"),
base_url=os.getenv("BASE_URL")
)

# Example 1: Get all companies with the app installed
# ---------
print("Example 1")
companies = connection.__companies__.get()
print(json.dumps(companies, indent=4))

# Example 2: Find a specific company
# ---------
print("Example 2")
company = connection.__companies__.find(identifier="Rogers-O`Brien Construction")
print(json.dumps(company, indent=4))

# Example 3: Get company projects
projects = connection.__companies__.get_projects(
company_id=company["id"]
)
print(f"Number of projects: {len(projects)}")
print(json.dumps(projects[1], indent=4))

# Example 4: Get project regions
# ---------
print("Example 4")
regions = connection.__companies__.get_regions(
company_id=company["id"]
)
print(json.dumps(regions, indent=4))

# Example 5: Get project types
# ---------
print("Example 5")
project_types = connection.__companies__.get_project_types(
company_id=company["id"]
)
print(json.dumps(project_types, indent=4))
44 changes: 44 additions & 0 deletions snippets/get_project_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import sys
import json
import urllib
import pathlib
sys.path.append(f"{pathlib.Path(__file__).resolve().parent.parent}")

from propycore.procore import Procore

from dotenv import load_dotenv

if os.getenv("CLIENT_ID") is None:
load_dotenv()

if __name__ == "__main__":
connection = Procore(
client_id=os.getenv("CLIENT_ID"),
client_secret=os.getenv("CLIENT_SECRET"),
redirect_uri=os.getenv("REDIRECT_URI"),
oauth_url=os.getenv("OAUTH_URL"),
base_url=os.getenv("BASE_URL")
)

company = connection.__companies__.find(identifier="Rogers-O`Brien Construction")


# Example 1: Get all projects with the app installed
# ---------
print("Example 1")
projects = connection.__projects__.get(
company_id=company["id"]
)
print(f"Number of projects: {len(projects)}")

# Example 2: Find a specific project
# ---------
print("Example 2")
project = connection.__projects__.find(
company_id=company["id"],
identifier="1301 South Lamar"
)
print(json.dumps(project, indent=4))


0 comments on commit f226061

Please sign in to comment.