Leaderboard Posts is a Ruby on Rails application that implements a RESTful API for creating, rating, and retrieving posts. It is designed to store posts, ratings, and users in a PostgreSQL database.
To install and use Leaderboard Posts, please follow the instructions below:
- Install the latest the version of Ruby specified in the
.ruby-version
file. - Install and configure PostgreSQL.
- Clone the source code from GitHub:
git clone https://github.com/antarr/leaderboard-posts.git
- Change into the project directory:
cd leaderboard-posts
- Install the required gems:
bundle install
- Set up the database:
rails db:migrate
- Load the seed data:
rails db:seed
- Start the server:
rails server
To use the Leaderboard Posts API, you can send HTTP requests to the following endpoints:
To create a new post, send a POST
request to /posts
with the following parameters:
title
- the title of the post (required)body
- the body of the post (required)login
- the login of the user who created the post (required)ip
- the IP address of the user who created the post (required)
If the user does not exist, they will be created. On success, the response will include post attributes with user attributes. On failure, the response will include validation errors.
To rate a post, send a POST
request to /ratings
with the following parameters:
post_id
- the ID of the post to be rated (required)user_id
- the ID of the user who is rating the post (required)value
- the rating value from 1 to 5 (required)
Users can only rate each post once. The response will include the average post rating.
To get the top N posts by average rating, send a GET
request to /posts?limit=N
, where N is the number of posts to retrieve. The response will include an array of post attributes (id, title, body).
To get a list of IPs that were posted by several different authors, send a GET
request to /ips
. The response will be an array of objects with fields: ip and an array of author logins.