This repository contains code, unit tests and other artifacts for my submission to Zendesk's Summer 2022 Internship challenge - The Zendesk Ticket Viewer.
Start by git-cloning the repository with the following command. This will download all the files of this project to the directory (which you'll choose) on your local system
git clone https://github.com/Anacoder1/zendesk-ticket-cli.git
Navigate to the project directory in the terminal (using cd
) and run python setup.py install
or make install
.
(make install
will run on Linux / MacOS systems, while the former command python setup.py install
can run on systems having Python installed on them)
On a terminal shell, define 3 environment variables shown as follows (these details aren't real, it's shown as an example):
Before every variable, make sure to prefix the command set
(for Windows environments) or export
(for Linux / MacOS environment) (e.g. export ZENDESK_EMAIL = [email protected]
)
ZENDESK_EMAIL = [email protected]
ZENDESK_URL = zccsomeuser1.zendesk.com
ZENDESK_PASSWORD = PpaSswwOoRrDd123!@#
CAUTION: These variables contain sensitive information, so be thoughtful of the development environment you're typing them in.
Activate the CLI with the command zendesk
.
Choosing option 1
will display all the tickets there are in the user's Zendesk account, with 25 tickets per page.
At the end of each page, the user has the option of choosing if he/she wishes to view the next page of tickets (if option y
is chosen)...
...or not (option n
is chosen).
If a user reaches the last page of tickets, the CLI would show that all tickets have been covered.
Choosing option 2
will display various details about a specific ticket, selected by the ticket ID.
In case the environment variables were set incorrectly, the following error is thrown.
A similar error would be thrown in case the API is unavailable due to server-side issues.
For option 2
, if a ID of a ticket is entered which doesn't exist in the user's account, a 404 error is returned.
And finally, when a user's done using the ticket-viewer CLI, he/she can exit using option 3
.
Until a user specifically wishes to exit (using option 3
), they'll be repeatedly prompted for input after the results of the previous query have been displayed.
Unit tests have been written for 5 functions and the total code coverage for the project is 97%.
Tests can be run with py.test tests/unit/test_*.py
(from the main project directory) or coverage run -m pytest tests/unit/test_*.py
(requires coverage
and pytest
Python libraries to be installed).
The coverage report could be viewed using coverage report -m
Unlike many other versions of ticket-viewer
available online, the setup for this CLI doesn't require the user to manually install the dependency libraries (using say pip install -r requirements.txt
).
Setup is as simple as running the command python setup.py install
In addition, whereas most implementations might have stored the user credentials (email_id, zendesk_url, password) in a config file, secret file, etc., this implementation doesn't store them anywhere - it simply asks the user to enter the details by defining environment variables, which get removed automatically once the session is closed.
The Makefile
contains other commands of interest regarding setup and testing.
Sample Zendesk tickets are contained in the tickets.json
file.
The following code snippet bulk loads the tickets in tickets.json
to a user's Zendesk account.
import json
import requests
user = [email protected]
pwd = PpaSswwOoRrDd123!@#
file_object = open('tickets.json')
tickets_data = json.load(file_object)
payload = json.dumps(tickets_data)
url = 'https://zccsomeuser1.zendesk.com/api/v2/imports/tickets/create_many.json'
headers = {'content-type': 'application/json'}
response = requests.post(url, data = payload, auth = (user, pwd), headers = headers)
Name
: Anamitra Musib
Email
: ana1998musib [email protected]