This project is a Ruby on Rails-based Treasure Hunt game designed around a RESTful API. Users can submit guesses for the treasure's location through the API, and the system calculates the distance to the actual treasure location. If a guess is within 1000 meters of the treasure, the user is marked as a winner and receives an email confirmation.
- Guess Submission: Users can submit their guesses with their email and guessed coordinates.
- Winner Determination: The system calculates if the guess is within 1000 meters of the treasure and marks the guess as a winning attempt.
- Email Confirmation: Winners receive an email confirmation.
- Winner List: An API endpoint provides a list of winners, optionally supporting sorting and pagination.
- Framework: Ruby on Rails
- Database: PostgreSQL
- Additional Libraries: Geocoder for distance calculation
- Ruby 3
- Rails 7
- PostgreSQL
- A mail sending service configuration for Action Mailer
- Clone the repository:
git clone https://github.com/uuchoaa/treasure-hunt
- Navigate to the project directory:
cd treasure-hunt
- Install dependencies:
bundle install
- Create and migrate your database:
bin/rails db:create db:migrate
- Seed your database:
bin/rails db:seed
Start the Rails server:
bin/rails server
The API will be accessible at http://localhost:3000
.
The location of the treasure is configured within the application using the following settings:
- Latitude: The geographic latitude of the treasure.
- Longitude: The geographic longitude of the treasure.
- Radius: The radius (in meters) around the treasure that defines a winning guess.
Note: To maintain the secrecy of the actual treasure location, these values are not stored within the code itself. Instead, they are configured through the Rails environment during application startup. Check config/initializers/treasure_config.rb
for details. You can override the configuration through environment variables. Example:
TREASURE_RADIUS=500 TREASURE_LATITUDE=4.777775 TREASURE_LONGITUDE=2.777775 bin/rails server
-
Submit a Guess: POST
/guesses
with JSON payload containingemail
,latitude
, andlongitude
. -
List Winners: GET
/winners
to retrieve a list of winners. Supports query parameters for sorting and pagination.
Our Treasure Hunt game API is fully documented with Swagger. To access the documentation, start the Rails server and navigate to /api-docs
in your web browser:
http://localhost:3000/api-docs
Contributions are welcome! Please fork the repository and submit a pull request with your proposed changes or improvements.
This project is open source and available under the MIT License.