Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
/db/*.sqlite3-*

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore uploaded files in development.
/storage/*
!/storage/.keep
.byebug_history

# Ignore master key for decrypting credentials and more.
/config/master.key
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.6.3
31 changes: 31 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'

gem 'bootsnap', '>= 1.4.2', require: false
gem 'fast_jsonapi'
gem 'puma', '~> 4.1'
gem 'rails', '~> 6.0.2', '>= 6.0.2.2'
gem 'sqlite3', '~> 1.4'

group :development, :test do
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'factory_bot_rails'
gem 'rspec-rails'
gem 'shoulda-matchers'
end

group :test do
gem 'database_cleaner'
end

group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end

gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
199 changes: 199 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (6.0.2.2)
actionpack (= 6.0.2.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.0.2.2)
actionpack (= 6.0.2.2)
activejob (= 6.0.2.2)
activerecord (= 6.0.2.2)
activestorage (= 6.0.2.2)
activesupport (= 6.0.2.2)
mail (>= 2.7.1)
actionmailer (6.0.2.2)
actionpack (= 6.0.2.2)
actionview (= 6.0.2.2)
activejob (= 6.0.2.2)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.0.2.2)
actionview (= 6.0.2.2)
activesupport (= 6.0.2.2)
rack (~> 2.0, >= 2.0.8)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.0.2.2)
actionpack (= 6.0.2.2)
activerecord (= 6.0.2.2)
activestorage (= 6.0.2.2)
activesupport (= 6.0.2.2)
nokogiri (>= 1.8.5)
actionview (6.0.2.2)
activesupport (= 6.0.2.2)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.0.2.2)
activesupport (= 6.0.2.2)
globalid (>= 0.3.6)
activemodel (6.0.2.2)
activesupport (= 6.0.2.2)
activerecord (6.0.2.2)
activemodel (= 6.0.2.2)
activesupport (= 6.0.2.2)
activestorage (6.0.2.2)
actionpack (= 6.0.2.2)
activejob (= 6.0.2.2)
activerecord (= 6.0.2.2)
marcel (~> 0.3.1)
activesupport (6.0.2.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2)
bootsnap (1.4.6)
msgpack (~> 1.0)
builder (3.2.4)
byebug (11.1.1)
concurrent-ruby (1.1.6)
crass (1.0.6)
database_cleaner (1.8.4)
diff-lcs (1.3)
erubi (1.9.0)
factory_bot (5.0.2)
activesupport (>= 4.2.0)
factory_bot_rails (5.0.2)
factory_bot (~> 5.0.2)
railties (>= 4.2.0)
fast_jsonapi (1.5)
activesupport (>= 4.2)
ffi (1.12.2)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.5.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (1.0.0)
mimemagic (0.3.4)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.0)
msgpack (1.3.3)
nio4r (2.5.2)
nokogiri (1.10.9)
mini_portile2 (~> 2.4.0)
puma (4.3.3)
nio4r (~> 2.0)
rack (2.2.2)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.0.2.2)
actioncable (= 6.0.2.2)
actionmailbox (= 6.0.2.2)
actionmailer (= 6.0.2.2)
actionpack (= 6.0.2.2)
actiontext (= 6.0.2.2)
actionview (= 6.0.2.2)
activejob (= 6.0.2.2)
activemodel (= 6.0.2.2)
activerecord (= 6.0.2.2)
activestorage (= 6.0.2.2)
activesupport (= 6.0.2.2)
bundler (>= 1.3.0)
railties (= 6.0.2.2)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (6.0.2.2)
actionpack (= 6.0.2.2)
activesupport (= 6.0.2.2)
method_source
rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0)
rake (13.0.1)
rb-fsevent (0.10.3)
rb-inotify (0.10.1)
ffi (~> 1.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-expectations (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-rails (4.0.0)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
rspec-core (~> 3.9)
rspec-expectations (~> 3.9)
rspec-mocks (~> 3.9)
rspec-support (~> 3.9)
rspec-support (3.9.2)
ruby_dep (1.5.0)
shoulda-matchers (4.3.0)
activesupport (>= 4.2.0)
spring (2.1.0)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (4.0.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
thor (1.0.1)
thread_safe (0.3.6)
tzinfo (1.2.7)
thread_safe (~> 0.1)
websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4)
zeitwerk (2.3.0)

PLATFORMS
ruby

DEPENDENCIES
bootsnap (>= 1.4.2)
byebug
database_cleaner
factory_bot_rails
fast_jsonapi
listen (>= 3.0.5, < 3.2)
puma (~> 4.1)
rails (~> 6.0.2, >= 6.0.2.2)
rspec-rails
shoulda-matchers
spring
spring-watcher-listen (~> 2.0.0)
sqlite3 (~> 1.4)
tzinfo-data

RUBY VERSION
ruby 2.6.3p62

BUNDLED WITH
1.17.2
115 changes: 9 additions & 106 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,15 @@
# Code Challenge
# README

Create a micro service to shorten urls like bit.ly or TinyURL do.
* Ruby version

## Rules
ruby-2.6.3

1. The service must expose HTTP endpoints according to the API Docs below.
2. Use your technology of choice, there's no restrictions. Instructions for the installation must be detailed in the INSTALL.md file.
3. Write the tests you consider necessary.
* Configuration

-------------------------------------------------------------------------
bundle install
rails db:migrate
rails s

## API Docs
* How to run the test suite

### POST /urls

```
POST /urls
Content-Type: "application/json"

{
"url": "http://example.com",
"code": "example"
}
```

##### Params:

* **url**: URL to shorten. Required
* code: Desired shortcode. Alphanumeric, case-sensitive 6 chars lenght.

Note: If code is not provided, a random code, with the same constraints, must be generated

##### Response:

```
201 Created
Content-Type: "application/json"

{
"code": :shortcode
}
```

##### Errors:

* Bad Request: If ```url``` is not present
* Conflict: If the the desired shortcode is already in use.
* Unprocessable Entity: If the shortcode doesn't doesn't comply with its description.


### GET /:code

```
GET /:code
Content-Type: "application/json"
```

##### Params:
* **code**: Encoded URL shortcode

##### Response

It's a redirect response including the target URL in its `Location` header.

```
HTTP/1.1 302 Found
Location: http://www.example.com
```

##### Errors

* Not Found: If the `shortcode` cannot be found

### GET /:code/stats

```
GET /:code/stats
Content-Type: "application/json"
```

##### Params:
* **code**: Encoded URL shortcode

##### Response

```
200 OK
Content-Type: "application/json"

{
"created_at": "2012-04-23T18:25:43.511Z",
"last_usage": "2012-04-23T18:25:43.511Z",
"usage_count": 1
}
```

* **`start_date`**: [ISO8601](http://en.wikipedia.org/wiki/ISO_8601) formatted date when the shortened URL was created
* **`usage_count`**: Number of requests to the endpoint `GET /code`
* `last_usage`: Date of the last time the shortened URL was requested. Not included if it has never been requested.

##### Errors

* Not Found: If the `shortcode` cannot be found

## Delivery Steps:

1. Fork this repo to your own Github account.
2. Implement the functionality, including any instructions to setup and run the application.
3. Submit a PR to the `master` branch of this repository.

Thank you and good luck!
rspec spec
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'

Rails.application.load_tasks
Loading