Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for archived tickets #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions freshdesk/v2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ def get_ticket(self, ticket_id, *include):
url = "tickets/%d%s" % (ticket_id, "?include=%s" % ",".join(include) if include else "")
ticket = self._api._get(url)
return Ticket(**ticket)

def get_ticket_archived(self, ticket_id, *include):
"""
Fetches the ticket for the given ticket ID
You can pass strings for the include parameter and they'll be included as include params to the request
ex: get_ticket(some_id, "stats", "conversations", "requester", "company") will result in the following request:
tickets/[some_id]?include=stats,conversations,requester,company
"""
url = "tickets/archived/%d%s" % (ticket_id, "?include=%s" % ",".join(include) if include else "")
ticket = self._api._get(url)
return Ticket(**ticket)

def create_ticket(self, subject, **kwargs):
"""
Expand Down Expand Up @@ -222,6 +233,24 @@ def list_comments(self, ticket_id, **kwargs):
page += 1

return [Comment(**c) for c in comments]

def list_comments_archived(self, ticket_id, **kwargs):
url = "tickets/archived/%d/conversations?" % ticket_id
page = kwargs.get("page", 1)
per_page = kwargs.get("per_page", 100)

comments = []

# Skip pagination by looping over each page and adding comments if 'page' key is not in kwargs.
# else return the requested page and break the loop
while True:
this_page = self._api._get(url + "page=%d&per_page=%d" % (page, per_page), kwargs)
comments += this_page
if len(this_page) < per_page or "page" in kwargs:
break
page += 1

return [Comment(**c) for c in comments]

def create_note(self, ticket_id, body, **kwargs):
url = "tickets/%d/notes" % ticket_id
Expand Down