The (almost) best way to query JSON files after jq
.
For project specifications see ./docs/Zendesk Coding Challenge- Back End.pdf
.
- Needs
docker
anddocker-compose
to be installed. - Does not require any local tooling like python, mypy, etc., as it all runs inside Docker.
- Use
./auto/dev-environment
to get bash in a local environment to run your dev tools in. ./auto/test
,./auto/check
,./auto/package
and./auto/build
are intended to become CI/CD steps../auto/run
can be used to simulate the CI/CD pipeline locally and then runs the app.
You can run the app using ./auto/dev-environment python ./zensearch/main.py
Use the assets
command.
Usage example
command > assets
0) Organizations
1) Tickets
2) Users
Use the info [n]
command, where [n]
is the number of an asset in the list generated by assets
.
Usage example
command > info 1
Asset Tickets has {len(self._asset)} entries and {len(self.keys)} keys.
Queryable keys:
--------------------------------------------------
_id
url
external_id
created_at
type
subject
description
priority
status
submitter_id
assignee_id
organization_id
tags
has_incidents
due_at
via
--------------------------------------------------
Use the search [n]
command, where [n]
is the number of an asset in the list generated by assets
.
Usage example
command > search 1
key > submitter_id
value > 38
Searching Tickets for entries with key {key} and value {value}.
--------------------------------------------------
[
{
"_id": "436bf9b0-1147-4c0a-8439-6f79833bff5b",
"url": "http://initech.zendesk.com/api/v2/tickets/436bf9b0-1147-4c0a-8439-6f79833bff5b.json",
"external_id": "9210cdc9-4bee-485f-a078-35396cd74063",
"created_at": "2016-04-28T11:19:34 -10:00",
"type": "incident",
"subject": "A Catastrophe in Korea (North)",
"description": "Nostrud ad sit velit cupidatat laboris ipsum nisi amet laboris ex exercitation amet et proident. Ipsum fugiat aute dolore tempor nostrud velit ipsum.",
"priority": "high",
"status": "pending",
"submitter_id": 38,
"assignee_id": 24,
"organization_id": 116,
"tags": [
"Ohio",
"Pennsylvania",
"American Samoa",
"Northern Mariana Islands"
],
"has_incidents": false,
"due_at": "2016-07-31T02:37:50 -10:00",
"via": "web"
},
{
"_id": "6403bd08-b7a0-49a3-a843-14ccb8ebbfca",
"url": "http://initech.zendesk.com/api/v2/tickets/6403bd08-b7a0-49a3-a843-14ccb8ebbfca.json",
"external_id": "3f8fe9d5-f0d7-4944-8ad9-e835da7b87f5",
"created_at": "2016-02-14T12:25:53 -11:00",
"type": "question",
"subject": "A Drama in El Salvador",
"description": "In minim cillum labore esse fugiat tempor irure aliqua laborum veniam consectetur. Laborum aliquip deserunt ad nisi.",
"priority": "urgent",
"status": "closed",
"submitter_id": 38,
"assignee_id": 73,
"organization_id": 108,
"tags": [
"Oklahoma",
"Louisiana",
"Massachusetts",
"New York"
],
"has_incidents": true,
"due_at": "2016-08-23T02:11:24 -10:00",
"via": "chat"
},
{
"_id": "c702e937-5f2d-4d34-878a-fcb7d1ddf6aa",
"url": "http://initech.zendesk.com/api/v2/tickets/c702e937-5f2d-4d34-878a-fcb7d1ddf6aa.json",
"external_id": "5e349072-774b-4c77-ba63-61bca77c82ff",
"created_at": "2016-05-25T12:48:45 -10:00",
"type": "question",
"subject": "A Drama in Zimbabwe",
"description": "Nostrud elit et minim ex adipisicing. Deserunt nostrud sint veniam voluptate in laborum officia incididunt mollit culpa do veniam eiusmod ipsum.",
"priority": "low",
"status": "pending",
"submitter_id": 38,
"assignee_id": 46,
"organization_id": 106,
"tags": [
"Oklahoma",
"Louisiana",
"Massachusetts",
"New York"
],
"has_incidents": true,
"due_at": "2016-08-15T08:34:44 -10:00",
"via": "web"
}
]
--------------------------------------------------
Use the exit
or quit
command.
Usage examples
command > exit
--- Goodbye ---
command > quit
--- Goodbye ---
- The search is case-sensitive. There was no clear information on requirements in the document,
but a simple
.lower()
on the input query parameters can solve that. - The REPL could have a nicer parser and make use of the command pattern.
- As the target output is command line, there is no dedicated error handling for
Asset.search()
, instead I chose an error format that is easily displayable on the command line. - Python's native JSON parser does not parse dates,
I could have implemented a manual one in
asset_loader
and then added date parsing logic toAsset.search()
. - I determine the available keys to query by the first item in an asset. This is a good choice to improve performance on large assets, but assumes a uniform data format. For non-uniform data, it would be necessary to loop over the entire asset, which can take some time on large assets.
- The asset search only covers the types present in the provided JSON files,
e.g. it support search on
list[str]
but notlist[int]
. - There are no unit tests for the REPL and
error_handler
. - A line length on 79 characters is standard for Python but might be bothersome for some readers.