A lightweight API service designed to track user activities such as deposits and withdrawals. The application provides alert functionality based on predefined rules, allowing users to monitor financial activities in real-time. This service is built with Ruby on Rails, containerized with Docker for easy deployment, and can be tested via a /event API endpoint.
The application has been designed to gracefully handle errors and a wide range of edge cases.
- Ruby on Rails
- Docker
- SQLite
- Puma
- Git & GitHub
- Docker Hub
- Endpoint:
/event
- Method:
POST
- Description: Accepts user activities (like deposits or withdrawals) and checks predefined rules to determine if an alert is raised.
Sample Request:
curl -X POST http://localhost:3000/event -H 'Content-Type: application/json' \
-d '{"type": "deposit", "amount": 50, "user_id": 1, "time": 1}'
Parameter | Type | Required | Description |
---|---|---|---|
type |
String | Yes | The type of action (deposit or withdrawal ). |
amount |
Float | Yes | The amount involved in the action. |
user_id |
Integer | Yes | The ID of the user performing the action. |
time |
Integer | Yes | Timestamp of when the action occurred (in seconds). |
Here are some examples of valid POST
requests to test the /event
endpoint:
# Example 1: Deposit
curl -X POST http://localhost:3000/event -H 'Content-Type: application/json' \ -d '{"type": "deposit", "amount": 100, "user_id": 1, "time": 1618304476}'
# Example 2: Withdrawal
curl -X POST http://localhost:3000/event -H 'Content-Type: application/json' \ -d '{"type": "withdrawal", "amount": 200, "user_id": 2, "time": 1618304480}'
- Clone the Repository:
git clone https://github.com/AmaraFinbarrs/payload-activity-monitor.git
- Navigate to the Project Directory:
cd payload-activity-monitor
- Install Dependencies:
bundle install
- Setup the Database:
rails db:create db:migrate
- Start the Rails Server:
rails server
The app will be accessible at http://localhost:3000
.
-
Install Docker
Make sure Docker is installed on your system. Follow the official Docker installation guide if you haven't installed Docker yet.
-
Pull the Image from Docker Hub
docker pull amarafinbarrs/payload-activity-monitor:latest
-
Run the Container mapping port 3000 to your local machine
docker run -p 3000:3000 amarafinbarrs/payload-activity-monitor:latest
-
Access the API endpoint using the curl command
curl -X POST http://localhost:3000/event -H 'Content-Type: application/json' \ -d '{"type": "deposit", "amount": 50, "user_id": 1, "time": 1}' ```