Battlequest API is a Ruby on Rails application that processes logs from Battlequest matches, stores structured data in a database, and exposes endpoints for querying player, event, and leaderboard information.
- Log Processing: Parses game log files and imports events (player joins, kills, item pickups, quest completions, boss kills, etc.) into the database.
- REST API: Provides endpoints to query players, events, leaderboards, and dashboard statistics.
- Authentication: The dashboard endpoint requires a valid API token.
- Requirements Rails 8.0.2+, Ruby 3.3.2+
- Player: Stores player information (
id,name,score,xp,gold). - Kill: Records kills between players (
killer_id,victim_id,method). - ItemPickup: Tracks items collected by players (
player_id,item_name,quantity). - QuestCompletion: Logs quest completions (
player_id,quest_id,xp_gained,gold_gained). - BossKill: Records boss defeats (
player_id,boss_name,xp_gained,gold_gained). - GameEvent: Stores raw log events and their parsed types/timestamps.
- ApiToken: Used for authenticating dashboard requests.
All endpoints are prefixed with /api/v1/.
-
GET /api/v1/players
List all players with basic information.-
Filters: name (partial match), min_score, max_score, min_kills, etc
-
Pagination: page (default: 1), per_page (default: 5, max: 100)
-
Example:
/players?name=dragon&min_kills=10&page=2
-
-
GET /api/v1/players/:id/stats
Shows detailed stats for a specific player, including: -
Basic info (id, name, score, gold, xp)
-
Combat stats (kills, deaths, nemesis)
-
Collections (bosses_killed_names, collected_item_names)
-
Quest progress (quests_started, quests_completed, started_quest_names, finished_quest_names)
-
PvP stats (killed_player_names)
-
GET /api/v1/players/:player_id/quests/startedLists all quests a player has started but not yet completed. Supports a limit parameter.
-
GET /api/v1/players/:player_id/quests/completedLists all quests a player has completed. Supports a limit parameter.
-
GET /api/v1/leaderboard
List players ordered by score (default).-
Filters: name (partial match), min_score, min_gold
-
Pagination: page (default: 1), per_page (default: 5, max: 100)
-
Example:
/leaderboard?min_gold=50&per_page=20
-
-
GET api/v1/leaderboard/goldLists players ordered by total gold.
-
GET api/v1/leaderboard/xpLists players ordered by total XP.
-
GET /api/v1/items/top
List the top looted items.-
Filters: name (partial match), gt (greater than x), gte (greater than or equal to x), lt (lower than x), lte (lower than or equal to x), eq (for total quantity)
-
Pagination: page (default: 1), per_page (default: 5, max: 100)
-
Example:
/items/top?name=potion>e=100
-
-
GET api/v1/eventsList the last logged events.-
Pagination: page (default: 1), per_page (default: 25, max: 200)
-
Example:
/events?page=3&per_page=50
-
-
GET /api/v1/dashboard/index
Returns:active_players: Total number of playerstotal_score: Sum of all player scorestop_items: Top 5 items collected overalltop_killers: Top 5 players by killsbosses_defeated: Count of each boss defeatedcompleted_quests: Count of each quest completed
Authentication:
Pass a valid API token in theAuthorizationheader:
Authorization: Bearer <token>When$ bin/rails db:seedis executed, it outputs an access token on the terminal:Token de acesso criado: <your-access-token>Then, it's possible to access the dashboard endpoint with$ curl -H "Authorization: Bearer <your-access-token>" http://localhost:3000/api/v1/dashboard/index
-GET /chat
Lists recent chat messages and server announcements, ordered by most recent.
**Query Parameters:**
-`limit` (optional): The maximum number of messages to return. Defaults to `100`.
-`start_time` (optional): The start of the time interval to filter messages. Should be in ISO 8601 format (e.g., `2025-08-10T20:00:00Z`).
-`end_time` (optional): The end of the time interval to filter messages. Should be in ISO 8601 format.
This project is configured to run in a Docker container, providing a consistent development environment.
Docker and Docker Compose: Ensure you have both installed on your system.
VS Code + Dev Containers extension: Install Visual Studio Code and the ms-vscode-remote.remote-containers extension.
Clone the repository to your local machine.
Open the project folder in VS Code.
A notification will appear asking to "Reopen in Container". Click it.
VS Code will build the Docker image and start the container. This may take a few minutes on the first run.
Once the container is running, open a new terminal within VS Code (Terminal > New Terminal). All subsequent commands should be run inside this container terminal.
` Bash
bin/rails db:create
bin/rails db:migrate `
This command will parse the game_log_large.txt file and populate your database. It will also generate a valid API token for the dashboard.
` Bash
bin/rails db:seed `
Your Rails server is automatically started by Docker Compose. You can access the API at http://localhost:3000.
To run the test suite, use the following command in the container terminal:
` Bash
bin/rails test `
To process new lines that have been added to the log file after the initial seed, run:
` Bash
bin/rails log:import `