Skip to content

Commit

Permalink
requester and custom fields added to Ticket obj
Browse files Browse the repository at this point in the history
  • Loading branch information
Ctri-The-Third committed Jun 11, 2022
1 parent 9bfc650 commit 61f8c21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions serviceHelpers/models/ZendeskTicket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import json
from datetime import datetime

from serviceHelpers.models.ZendeskUser import ZendeskUser

# 2021-11-25T12:00:15Z
_ZD_FORMAT = r"%Y-%m-%dT%H:%M:%SZ"

Expand All @@ -22,16 +24,18 @@ def __init__(self, host) -> None:
self.assignee_id = None
self.requester_id = None
self.requester_name = ""
self.requester = None
self.group_id = 0
self.lo = logging.getLogger("zendeskHelper.zendeskTicket")
self.logger = logging.getLogger("zendeskHelper.zendeskTicket")
self.custom_fields = {}
pass

def from_string(self, str):
"takes an unparsed string expected to be from the ZD API, parsed and loads it"
try:
self.from_dict(json.loads(str))
except Exception as e:
self.lo.error("Couldn't parse a ticket string into a dict")
self.logger.error("Couldn't parse a ticket string into a dict")
return self

def from_dict(self, source: dict):
Expand All @@ -54,7 +58,7 @@ def from_dict(self, source: dict):
else self.updated_ts
)
except ValueError as e:
self.lo.error(
self.logger.error(
"Date found but not parsed properly : %s", source["updated_at"]
)
self.summary = source["subject"] if "subject" in source else self.summary
Expand All @@ -68,7 +72,12 @@ def from_dict(self, source: dict):
self.group_id = source["group_id"] if "group_id" in source else self.group_id
self.status = source["status"] if "status" in source else self.status
self.priority = source["priority"] if "priority" in source else self.priority

for custom_field in source["custom_fields"]:
try:
if custom_field["value"] is not None:
self.custom_fields[custom_field["id"]] = custom_field["value"]
except KeyError as err:
self.logger.warning("Couldn't properly get a custom field - %s", err)
return self

def __str__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="hex-helpers",
version="2.3.0",
version="2.4.0",
description="A series of light helpers for `freshdesk`,`gmail`,`habitica`,`hue lights`,`jira`,`slack`,`trello`",
long_description=README,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 61f8c21

Please sign in to comment.