Skip to content

Swarangigaurkar/receipt-processor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fetch Receipt Processor

Build a webservice that fulfils the documented API. The API is described below.


Summary of API Specification

Endpoint: Process Receipts

  • Path: /receipts/process
  • Method: POST
  • Payload: Receipt JSON
  • Response: JSON containing an id for the receipt.

Description: Takes in a JSON receipt (see example in the examples directory) and returns a JSON object with an ID generated by your code. The ID returned is the ID that should be passed into /receipts/{id}/points to get the number of points the receipt was awarded.

Example Response: { "id": "7fb1377b-b223-49d9-a31a-5a02701dd310" }

Endpoint: Get Points

  • Path: /receipts/{id}/points
  • Method: GET
  • Response: A JSON object containing the number of points awarded.

Description: A simple Getter endpoint that looks up the receipt by the ID and returns an object specifying the points awarded.

Example Response: { "points": 32 }

Rules

These rules collectively define how many points should be awarded to a receipt.

  1. One point for every alphanumeric character in the retailer name.
  2. 50 points if the total is a round dollar amount with no cents.
  3. 25 points if the total is a multiple of 0.25.
  4. 5 points for every two items on the receipt.
  5. If the trimmed length of the item description is a multiple of 3, multiply the price by 0.2 and round up to the nearest integer. The result is the number of points earned.
  6. 6 points if the day in the purchase date is odd.
  7. 10 points if the time of purchase is after 2:00pm and before 4:00pm.

Setup and Running

Instructions to run with docker image

  1. Load the docker image -
docker load -i /path/to/saved/image.tar
  1. Check if image is loaded successfully -
docker images

You should see your imported images.

  1. Run a Container from the Image -
docker run -d -p 8080:8000 <image_name>
  1. Now that the server is up and running, send CURL request to local server. Change @examples/receipt2 for second receipt data.
curl -X POST "http://localhost:8000/receipts/process" -H "Content-Type: application/json" -d @examples/receipt1.json

You should receive a ID as a response.

  1. To get points
curl -X GET "http://localhost:8000/receipts/<id>/points"

You should get the points corresponding to given example receipt.

  1. Stop the container
    docker ps
    docker stop <container_id_or_name>

Instructions to run without Docker image

  1. Clone the repository
git clone <repository_url>
cd receipt-processor
  1. Install Dependencies
pip install -r requirements.txt
  1. Run the Flask Application
python app/main.py
  1. Access the API endpoints using curl or postman-
curl -X POST "http://localhost:8000/receipts/process" -H "Content-Type: application/json" -d @examples/receipt1.json

curl -X GET "http://localhost:8000/receipts/<id>/points"

About

This web service implements an API for processing receipts and calculating points based on specified rules. It utilizes Python with Flask for handling HTTP requests and responses, and it is packaged to run in a Docker container.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors