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
9 changes: 9 additions & 0 deletions .byebug_history
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
c
@urls.swapcase
@urls
c
Url.all
@urls
Url.last(5)
Url.last
@urls
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source 'https://rubygems.org'

# Ruby Version
# ruby "2.2.1"
ruby "2.4.0"

# Adding Sinatra Drivers
gem 'sinatra'
Expand All @@ -24,6 +25,9 @@ gem 'rake'
# Adding rspec for running unit testing
gem 'rspec'

# Add other gems
gem 'byebug'

group :development, :test do
# Adding shotgun for local web hosting
gem 'shotgun'
Expand All @@ -34,4 +38,4 @@ group :production do
# ==================
gem 'rails_12factor' # Heroku Gem Supports
gem 'puma' # Using puma for
end
end
95 changes: 47 additions & 48 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,77 +1,75 @@
GEM
remote: https://rubygems.org/
specs:
activemodel (4.2.5)
activesupport (= 4.2.5)
builder (~> 3.1)
activerecord (4.2.5)
activemodel (= 4.2.5)
activesupport (= 4.2.5)
arel (~> 6.0)
activesupport (4.2.5)
activemodel (5.0.2)
activesupport (= 5.0.2)
activerecord (5.0.2)
activemodel (= 5.0.2)
activesupport (= 5.0.2)
arel (~> 7.0)
activesupport (5.0.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
backports (3.6.7)
builder (3.2.2)
daemons (1.2.3)
diff-lcs (1.2.5)
eventmachine (1.0.8)
i18n (0.7.0)
json (1.8.3)
minitest (5.8.3)
multi_json (1.11.2)
pg (0.18.4)
puma (2.15.3)
rack (1.6.4)
arel (7.1.4)
backports (3.6.8)
byebug (9.0.6)
concurrent-ruby (1.0.5)
daemons (1.2.4)
diff-lcs (1.3)
eventmachine (1.2.3)
i18n (0.8.1)
minitest (5.10.1)
multi_json (1.12.1)
pg (0.19.0)
puma (3.7.1)
rack (1.6.5)
rack-protection (1.5.3)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.4)
rails_stdout_logging (0.0.4)
rake (10.4.2)
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-core (3.4.1)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5)
rake (12.0.0)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
shotgun (0.9.1)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
shotgun (0.9.2)
rack (>= 1.0)
sinatra (1.4.6)
rack (~> 1.4)
sinatra (1.4.8)
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
sinatra-activerecord (2.0.9)
sinatra-activerecord (2.0.12)
activerecord (>= 3.2)
sinatra (~> 1.0)
sinatra-contrib (1.4.6)
sinatra (>= 1.0)
sinatra-contrib (1.4.7)
backports (>= 2.0)
multi_json
rack-protection
rack-test
sinatra (~> 1.4.0)
tilt (>= 1.3, < 3)
thin (1.6.4)
thin (1.7.0)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (~> 1.0)
thread_safe (0.3.5)
tilt (2.0.1)
rack (>= 1, < 3)
thread_safe (0.3.6)
tilt (2.0.6)
tzinfo (1.2.2)
thread_safe (~> 0.1)

Expand All @@ -81,6 +79,7 @@ PLATFORMS
DEPENDENCIES
activerecord
activesupport
byebug
pg
puma
rails_12factor
Expand All @@ -93,4 +92,4 @@ DEPENDENCIES
thin

BUNDLED WITH
1.10.6
1.14.4
30 changes: 29 additions & 1 deletion app/controllers/static.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
get '/' do
# let user create new short URL, display a list of shortened URLs
@urls = Url.last(5)
# @test = "hi"
@urls.reverse!
erb :"static/index"
end
end

post '/urls' do
# create a new Url
@url = Url.new(long_url: params[:long_url])

if @url.save
redirect "/"
else
@error = "Invalid URL! Please include 'http://' OR 'https://'."
@urls.all
erb :"static/index"
end

end

# i.e. /q6bda
get '/:short_url' do
# redirect to appropriate "long" URL
@url = Url.find_by(short_url: params[:short_url])
redirect @url.long_url
@url.click_count += 1
@url.save
erb :"static/index"
end
15 changes: 15 additions & 0 deletions app/models/url.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'uri'

class Url < ActiveRecord::Base
# This is Sinatra! Remember to create a migration!
validates :long_url, :presence => true, :format => URI::regexp(%w(http https))
before_create :shorten, :counter

def shorten
self.short_url = SecureRandom.base64(6)
end

def counter
self.click_count = 0
end
end
51 changes: 49 additions & 2 deletions app/views/static/index.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
<h1>Hello World</h1>
<p>See Me in views/static/index.html.erb</p>
<!DOCTYPE html>
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="/css/application.css">
<title>v.l.bitly</title>
</head>



<h1>v.l.bitly</h1>

<h2>SIZE DOESN'T MATTER. SO KEEP IT SHORT!</h2>

<h3>Paste a link to shorten it</h3>

<form action="/urls" method="post">
<input type="text" name="long_url">
<input type="submit" value="SHORTEN">
</form>

<div class="recent_list">

<p>These are your shorten URLs!!! =)</p>

<table class="table table_hover">
<thead>
<tr>
<th>Long URL</th>
<th>Shorten URL</th>
<th>Visit Count</th>
</tr>
</thead>

<tbody>
<% @urls.each do |url| %>
<tr>
<td><%= url.long_url %></td>
<td><a href="http://localhost:9393/<%= url.short_url%>"> http://v.l.ty/<%= url.short_url%> </a></td>
<!-- url.long_url %>"><%= url.short_url %></a></td> -->
<td><%= url.click_count%></td>
</tr>
<% end %>

</tbody>
</table>
</div>
</html>
3 changes: 2 additions & 1 deletion config/environments/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'rubygems'
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'pathname'
require 'byebug'

# database
require 'pg'
Expand Down Expand Up @@ -51,4 +52,4 @@

# Setup controller (C)
Dir[APP_ROOT.join('app', 'controllers', '*.rb')].each { |file| require file }
######################################################################
######################################################################
12 changes: 12 additions & 0 deletions db/migrate/20170308190430_create_urls.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateUrls < ActiveRecord::Migration

def change
create_table :urls do |t|
t.string :long_url
t.string :short_url
t.integer :click_count

t.timestamps
end
end
end
13 changes: 13 additions & 0 deletions public/css/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body{
background-image:
linear-gradient(
rgba(0, 0, 0, 0.75),
rgba(0, 0, 0, 0.01)
),
url(../img/smile_lady.jpg);
background-size: cover;
}

h1{
text-align: center;
}
Binary file added public/img/smile_lady.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.