Skip to content

Commit

Permalink
Merge pull request #13 from pepsimidamerica/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lambertjonchris authored Nov 20, 2024
2 parents c63e701 + c35acf8 commit a9fdee6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
8 changes: 8 additions & 0 deletions nacwrap/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class Action(BaseModel):
errorMessage: Optional[str] = Field(default=None)
logMessage: Optional[str] = Field(default=None)

@property
def age(self) -> timedelta:
return datetime.now(timezone.utc) - self.startDateTime

# NintexInstance attributes
instanceId: str
name: Optional[str] = Field(default=None)
Expand Down Expand Up @@ -156,3 +160,7 @@ class NintexUser(BaseModel):
@property
def name(self):
return self.firstName + " " + self.lastName


class InstanceStartData(BaseModel):
pass
51 changes: 48 additions & 3 deletions nacwrap/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def instances_list_pd(
result: List[NintexInstance] = []
for i in instance:
result.append(NintexInstance(**i))

return result


Expand Down Expand Up @@ -300,6 +300,51 @@ def instance_resolve(instance_id: str, resolveType: ResolveType, message: str):
)


# TODO Delete instance
@Decorators.refresh_token
def instance_start_data(instance_id: str):
"""
Returns start data from a specific workflow instance.
# TODO Get instance start data
:param instance_id: ID of instance to return start data for.
"""
url = (
os.environ["NINTEX_BASE_URL"]
+ f"/workflows/v2/instances/{instance_id}/startdata"
)

try:
response = _fetch_page(
url,
headers={
"Authorization": "Bearer " + os.environ["NTX_BEARER_TOKEN"],
"Content-Type": "application/json",
},
params={},
)
response.raise_for_status()

except requests.exceptions.HTTPError as e:
raise Exception(
f"Error, instance not found when retrieving start data: {e.response.status_code} - {e.response.content}"
)

except requests.exceptions.RequestException as e:
raise Exception(f"Error, could not get instance start data: {e}")

data = response.json()
return data


def instance_start_data_pd(instance_id: str, pydantic_model: InstanceStartData):
"""
Returns start data as a pydantic object for a specific workflow instance.
:param instance_id: ID of instance to return start data for.
:param pydantic_model: Pydantic model to populate with results returned from Nintex API.
"""

sd = instance_start_data(instance_id=instance_id)
return pydantic_model(**sd)


# TODO Delete instance
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name="nacwrap",
version="0.1.8",
version="0.1.9",
description="Python package that acts as a wrapper for the Nintex Automation Cloud system.",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
21 changes: 20 additions & 1 deletion tests/instance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
import sys
from datetime import datetime, timedelta
from pprint import pprint
from pydantic import BaseModel

sys.path.insert(0, "")
from nacwrap import *


class PurchDocStartData(InstanceStartData):
requestor: str = Field(alias='se_txtrequestor')
requestor_email: str = Field(alias="se_txtrequestoremail")
purchaser_code: str = Field(alias='se_txtpurchasercode')


def test_list_instances():
instances = nacwrap.instances_list(
workflow_name="Purchase Approval", status=WorkflowStatus.RUNNING
Expand All @@ -33,5 +40,17 @@ def test_get_instance():
print(instance)


def test_instance_start_data():
# sd = nacwrap.instance_start_data(instance_id='d39c4615-863d-47ff-a800-c4b82cdc1e1f_0_4')
# pprint(sd)

sd = nacwrap.instance_start_data_pd(
instance_id="d39c4615-863d-47ff-a800-c4b82cdc1e1f_0_4",
pydantic_model=PurchDocStartData,
)
pprint(sd)


# test_get_instance()
test_list_instances()
# test_list_instances()
test_instance_start_data()

0 comments on commit a9fdee6

Please sign in to comment.