Giter Site home page Giter Site logo

zensearch's Introduction

ZenSearch โ„ค๐Ÿ”Ž

The (almost) best way to query JSON files after jq.

For project specifications see ./docs/Zendesk Coding Challenge- Back End.pdf.

System Requirements

  • Needs docker and docker-compose to be installed.
  • Does not require any local tooling like python, mypy, etc., as it all runs inside Docker.

How to run

  • 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.

How to use

You can run the app using ./auto/dev-environment python ./zensearch/main.py

List available assets

Use the assets command.

Usage example
command > assets

0) Organizations
1) Tickets
2) Users

Get detail about an asset

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
--------------------------------------------------

Query an asset

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"
  }
]
--------------------------------------------------

Exit the program

Use the exit or quit command.

Usage examples
command > exit

--- Goodbye ---
command > quit

--- Goodbye ---

Design Decisions / Possible Extensions / After-thoughts / Comments

  • 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 to Asset.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 not list[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.

zensearch's People

Contributors

dctr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.