- Pluvio - Rain Data Reporting for the Global South
.
├── Makefile
├── Procfile
├── README.md
├── VXML - Contains the VXML files which are copied into voxeo
│ ├── PourleMali.wav
│ ├── pluvio.xml
│ └── pluvio_prototype.xml
├── api - Go files
│ ├── api.go
│ └── handler.go
├── cmd - Contains the main.go files for the binaries
│ └── pluvio-api
│ └── main.go
├── go.mod
├── go.sum
└── mdb - Contains the MongoDB files for the application
├── models.go
└── mongodb.go
The backend API for pluvio functionality. The Website/Frontend code is available here: lds19/Pluvio
- Docker
- Go (you need this to build the binaries on your local machine)
TODO
docker-compose build
docker-compose up
You can now execute requests at port 4242
at /api/v1/rain
using POST
or GET
.
For example:
curl -d '{"location": "Mali", "amount": 10}' -H "Content-Type: application/json" -X POST http://localhost:4242/api/v1/rain
cat .env.example > .env
go mod download
make
./bin/pluvio-api
Be sure to reach out to Joel to get the connection uri for the database. The other defaults should be fine.
go test ./...
We use golangci-lint
golangci-lint run
When making requests to the API, keep in mind that it can return either XML or JSON depending on the Accept
header.
curl -H "Accept: application/json" -X GET http://localhost:4242/api/v1/rain/day?location=Mali
curl -H "Accept: application/xml" -X GET http://localhost:4242/api/v1/rain/day?location=Mali
curl -d '{"location": "Mali", "amount": 10, "phoneNumber":"+31612345678"}' -H "Content-Type: application/json" -X POST http://localhost:4242/api/v1/rain
<?xml version="1.0" ?>
<vxml version="2.1">
<form>
<block>
<prompt>Thank you for your report!</prompt>
</block>
</form>
</vxml>
Response if no phoneNumber
is provided and USE_PHONE_AUTH
is set to true
in the .env
file.
<?xml version="1.0" ?>
<vxml version="2.1">
<form>
<block>
<prompt>No phone number provided, please call back and try again.</prompt>
</block>
</form>
</vxml>
Response if USE_PHONE_AUTH
is set to true
in the .env
file and the user is not in the DB.
<?xml version="1.0" ?>
<vxml version="2.1">
<form>
<block>
<prompt>You are not authorized to use this service.</prompt>
</block>
</form>
</vxml>
Reponse if USE_PHONE_AUTH
is set to true
in the .env
file and you have already made a report for the last 24 hours.
<?xml version="1.0" ?>
<vxml version="2.1">
<form>
<block>
<prompt>Sorry, you have reached the maximum number of reports for today.</prompt>
</block>
</form>
</vxml>
curl -X GET "http://localhost:4242/api/v1/rain/:timeRange?location=<location>"
Where:
:timeRange
is one ofday
,week
,month
- (Optional)
location
is one ofMali
,(Burkina) Faso
. Leaving this out will return data from all locations.
<?xml version="1.0" ?>
<vxml version="2.1">
<form>
<block>
<prompt>In the past [day|week|month] it rained 100 milliliters</prompt>
</block>
</form>
</vxml>
curl -d '{"name": "Joel", "phone": "+31612345678"}' -H "Content-Type: application/json" -X POST http://localhost:4242/api/v1/user
Created user with ID: 645bb964c8dfb30099937009
User already exists
Internal server error