Skip to content

Commit b96c136

Browse files
authored
Include Stats in get_ticket method (#59)
1 parent 0e0ae50 commit b96c136

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,23 @@ Or converted from indexes to their descriptions:
142142
'phone'
143143
```
144144

145+
You can get additional details of the ticket in the response using extra arguments.
146+
147+
Please take a look at the FreshDesk documentation for more details: [View a Ticket](http://developer.freshdesk.com/api/#view_a_ticket)
148+
149+
```python
150+
>>> ticket = a.tickets.get_ticket(4, "conversation", "requester", "company", "stats")
151+
>>> ticket.stats
152+
{'agent_responded_at': '2020-06-26T01:23:39Z',
153+
'requester_responded_at': '2020-06-25T23:10:15Z',
154+
'first_responded_at': '2020-06-17T20:23:43Z',
155+
'status_updated_at': '2020-07-24T15:35:21Z',
156+
'reopened_at': None,
157+
'resolved_at': '2020-07-24T15:35:21Z',
158+
'closed_at': None,
159+
'pending_since': None}
160+
```
161+
145162
Creating a ticket can be done by calling `create_ticket()`:
146163

147164
```python

freshdesk/v2/api.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ class TicketAPI(object):
3030
def __init__(self, api):
3131
self._api = api
3232

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

freshdesk/v2/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(self, *args):
2323
re.compile(r"tickets\?filter=new_and_my_open&updated_since=2014-01-01&page=1&per_page=100"): self.read_test_file("all_tickets.json"),
2424
re.compile(r"tickets\?page=1&per_page=100"): self.read_test_file("all_tickets.json"),
2525
re.compile(r"tickets/1$"): self.read_test_file("ticket_1.json"),
26+
re.compile(r"tickets/1?include=stats,requester$"): self.read_test_file("ticket_1.json"),
2627
re.compile(r"tickets/1/conversations"): self.read_test_file("conversations.json"),
2728
re.compile(r"companies\?page=1&per_page=100$"): self.read_test_file("companies.json"),
2829
re.compile(r"companies/1$"): self.read_test_file("company.json"),

freshdesk/v2/tests/sample_json_data/ticket_1.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,22 @@
4848
"created_at":"2014-07-28T16:20:03+05:30",
4949
"updated_at":"2014-07-28T16:20:03+05:30"
5050
}
51-
]
51+
],
52+
"stats": {
53+
"agent_responded_at":"2020-06-26T01:23:39Z",
54+
"requester_responded_at":"2020-06-25T23:10:15Z",
55+
"first_responded_at": "2020-06-17T20:23:43Z",
56+
"status_updated_at": "2020-07-24T15:35:21Z",
57+
"reopened_at": null,
58+
"resolved_at": "2020-07-24T15:35:21Z",
59+
"closed_at": null,
60+
"pending_since": null
61+
},
62+
"requester": {
63+
"id": 43026449322,
64+
"name": "Dummyname",
65+
"email": "[email protected]",
66+
"mobile": null,
67+
"phone": null
68+
}
5269
}

freshdesk/v2/tests/test_ticket.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ def ticket(api):
1313
return api.tickets.get_ticket(1)
1414

1515

16+
@pytest.fixture
17+
def ticket_include(api):
18+
return api.tickets.get_ticket(1,"stats","requester")
19+
20+
1621
@pytest.fixture
1722
def ticket_json():
1823
return json.loads(open(os.path.join(os.path.dirname(__file__), "sample_json_data", "ticket_1.json")).read())
@@ -210,4 +215,4 @@ def test_filter_query(api, ticket):
210215
def test_updated_since_filter(api):
211216
tickets = api.tickets.list_tickets(updated_since="2014-01-01")
212217
assert isinstance(tickets, list)
213-
assert len(tickets) == 1
218+
assert len(tickets) == 1

0 commit comments

Comments
 (0)