项目作者: MarketaWachtlova

项目描述 :
The Caffeine Manager allows its users to manage and monitor their caffeine intoxication and helps them to administer their caffeine level
高级语言: Perl
项目地址: git://github.com/MarketaWachtlova/CaffeineManager.git
创建时间: 2018-07-20T11:27:54Z
项目社区:https://github.com/MarketaWachtlova/CaffeineManager

开源协议:

下载


The Caffeine Manager

The Caffeine Manager allows its users to manage and monitor their caffeine intoxication and helps them to administer their caffeine level

Author

Markéta Wachtlová


The Deployment

Install the required Perl modules

cpanfile specifies exact modules versions

Install PostgreSQL DBMS

Installation guides

Create the database and the tables

  1. psql < create.sql

Define your database connection details in config.yml

  1. plugins:
  2. Pg:
  3. host: 'localhost'
  4. port: '5432'
  5. base: 'caffeine_manager'
  6. username: ''
  7. password: ''

Usage

Start the application

  1. plackup -r bin/app.psgi

Standalone server that serves the application is listening on port 5000.

Run tests

  1. perl Makefile.PL
  2. make test

Send a request

Examples:

Register a user
  1. curl -X PUT -H "Content-Type: application/json" -d '{"login":"login", "email":"email@email.com","password":"password"}' http://0.0.0.0:5000/user/request
Register a machine
  1. curl -X POST -H "Content-Type: application/json" -d '{"name":"name", "caffeine":12}' http://0.0.0.0:5000/machine
Buy a coffee
  1. curl http://0.0.0.0:5000/coffee/buy/1/1
Get stats
  1. curl http://0.0.0.0:5000/stats/level/user/1

The assignment details

Every POST/PUT request accepts json object with keys described below.
Every request returns json object with

  1. * status 200 with described keys on success
  2. * status 4xx with optional json error object with mandatory keys
  3. * error_code
  4. * error_text

PUT /user/request

  • arg keys
    • login - mandatory, unique
    • password - mandatory
    • email - mandatory, unique
  • result keys
    • id

POST /machine

  • registry machine
    • name
    • caffeine - mg per cup
  • returns
    • id

GET /coffee/buy/:user-id/:machine-id

  • registry coffee bought by user at current time

PUT /coffee/buy/:user-id/:machine

  • similar to GET but use given timestamp
  • args
    • timestamp - iso-8601 timestamp

GET /stats/coffee
GET /stats/coffee/machine/:id
GET /stats/coffee/user/:id

  • return history of user transactions per user/machine/ or global
  • list of objects with
    • machine - object with name and id keys
    • user - object with login and id keys
    • timestamp

GET /stats/level/user/:id

  • return caffeine level history of user
  • let’s assume that caffeine level
    • increases linearly from 0 to 100% in first hour
    • is reduced afterwards by half every 5 hour
  • return list of levels for past 24 hour using 1h resolution