A simple URL shortener.
- Docker
- SQLite
- Rails 6.0.0
- Ruby 2.6.5
- Rspec
- brakeman: static analysis security vulnerability scanner for Ruby on Rails applications (via pronto-brakeman)
- fasterer: performance checker and suggester (via pronto-fasterer)
- flay: analyzes code for structural similarities (via pronto-flay)
- reek: code smell detector for Ruby (via pronto-reek)
- rubocop: Ruby static code analyzer and formatter, based on the community Ruby style guide (via pronto-rubocop)
- poper: makes sure that your git commit messages are well-formed (via pronto-poper)
For this project, we use Docker and docker-compose. So if you want to run this project, be sure to have both installed before continuing.
You can follow this tutorial explaining how to install them.
To download and install this project, just run the following commands:
$ git clone [email protected]:rodrigo93/shortify.git
$ docker-compose up
This might take some minutes, depending on you internet speed to download the necessary images.
All you need to do to run this project is running the following command in the root directory of this project:
$ docker-compose up
Wait for the build and shortify! :D
dev/bash
Open a bash session inside a temporary shortify
container.
dev/build
Build and run everything that is declared in Dockerfile
.
dev/bundle-install
Runs bundle install
inside a temporary shortify
container.
dev/bundle-update
Runs bundle update
inside a temporary shortify
container.
dev/console
Open a rails console
inside a container. By default it will open inside the shortify
container.
dev/lint
Run all configured lints in the project.
dev/logs
Check log outputs from shortify
container.
dev/restart
Restarts all containers from this project.
dev/rspec FILE_PATH
Run all RSpec tests or just the given specs passed in the FILE_PATH
argument.
dev/start
Start all containers from this project.
dev/stop
Stop all containers from this project.
POST /shorten
Content-Type: "application/json"
{
"url": "http://example.com",
"shortcode": "example"
}
Attribute | Description |
---|---|
url | url to shorten |
shortcode | preferential shortcode |
201 Created
Content-Type: "application/json"
{
"shortcode": :shortcode
}
A random shortcode is generated if none is requested, the generated short code has exactly 6 alpahnumeric characters and passes the following regexp: ^[0-9a-zA-Z_]{6}$
.
Error | Description |
---|---|
400 | url is not present |
409 | The the desired shortcode is already in use. Shortcodes are case-sensitive. |
422 | The shortcode fails to meet the following regexp: ^[0-9a-zA-Z_]{4,}$ . |
GET /:shortcode
Content-Type: "application/json"
Attribute | Description |
---|---|
shortcode | url encoded shortcode |
302 response with the location header pointing to the shortened URL
HTTP/1.1 302 Found
Location: http://www.example.com
Error | Description |
---|---|
404 | The shortcode cannot be found in the system |
GET /:shortcode/stats
Content-Type: "application/json"
Attribute | Description |
---|---|
shortcode | url encoded shortcode |
200 OK
Content-Type: "application/json"
{
"start_date": "2012-04-23T18:25:43.511Z",
"last_seen_date": "2012-04-23T18:25:43.511Z",
"redirect_count": 1
}
Attribute | Description |
---|---|
start_date | date when the url was encoded, conformant to ISO8601 |
redirect_count | number of times the endpoint GET /shortcode was called |
last_seen_date | date of the last time the a redirect was issued, not present if redirect_count == 0 |
Error | Description |
---|---|
404 | The shortcode cannot be found in the system |