diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..4015781
Binary files /dev/null and b/.DS_Store differ
diff --git a/source/.DS_Store b/source/.DS_Store
new file mode 100644
index 0000000..fadd49a
Binary files /dev/null and b/source/.DS_Store differ
diff --git a/source/app/assets/javascripts/application.js b/source/app/assets/javascripts/application.js
index d6925fa..1ca0e3b 100644
--- a/source/app/assets/javascripts/application.js
+++ b/source/app/assets/javascripts/application.js
@@ -12,5 +12,4 @@
//
//= require jquery
//= require jquery_ujs
-//= require turbolinks
//= require_tree .
diff --git a/source/app/assets/stylesheets/application.css b/source/app/assets/stylesheets/application.scss
similarity index 52%
rename from source/app/assets/stylesheets/application.css
rename to source/app/assets/stylesheets/application.scss
index a443db3..3f007aa 100644
--- a/source/app/assets/stylesheets/application.css
+++ b/source/app/assets/stylesheets/application.scss
@@ -13,3 +13,46 @@
*= require_tree .
*= require_self
*/
+$cmm_orange: #F59222;
+$cmm_pink: #B31944;
+$cmm_blue: #F8AD59;
+
+html, body, h1, .container, table{
+ padding:0;
+ margin:0 auto;
+ border-style:none;
+ text-align:center;
+}
+h3{
+ color: $cmm_blue;
+ text-align: center;
+ background-color: $cmm_pink;
+ border-radius:5em;
+ word-wrap: break-word;
+}
+
+header, footer{
+ width:100%;
+ text-align:center;
+ line-height:3em;
+ color:white;
+ font-family: monospace;
+}
+
+table, td{
+ border-style:groove;
+}
+
+a{
+ text-decoration:none;
+ color:$cmm_pink;
+}
+
+header{
+ background-color: $cmm_orange;
+}
+footer{
+ background-color: $cmm_pink;
+ position:fixed;
+ top:75vh;
+}
diff --git a/source/app/controllers/urls_controller.rb b/source/app/controllers/urls_controller.rb
index ef26710..5332d25 100644
--- a/source/app/controllers/urls_controller.rb
+++ b/source/app/controllers/urls_controller.rb
@@ -1,2 +1,33 @@
class UrlsController < ApplicationController
+ #GET urls
+ #def index
+ #@urls = Url.all #rake db:reset db:migrate
+ #end
+
+ #GET url
+ def new
+ @url = Url.new
+ @urls = Url.all
+ end
+
+ #POST urls
+ def create
+ check = Url.find_by(:address => params[:url][:address])
+ if !check
+ @url = Url.create(:address => params[:url][:address])
+ end
+ flash[:error] = @url.errors.full_messages.to_sentence
+ redirect_to root_path
+ end
+
+ def move
+ @url = Url.where :bitly_clone => params[:short]
+ if @url[0]
+ @url[0].increment!(:click_count)
+ redirect_to @url[0].address
+ else
+ redirect_to urls_path
+ end
+
+ end
end
diff --git a/source/app/models/url.rb b/source/app/models/url.rb
new file mode 100644
index 0000000..5a6894f
--- /dev/null
+++ b/source/app/models/url.rb
@@ -0,0 +1,19 @@
+require 'uri'
+class Url < ActiveRecord::Base
+ before_save :bitly_generate, :unless => :bitly_clone
+ validates :address, :if => :validate_url, presence: true, uniqueness: true, length: {minimum: 1}, :format => /\Ahttp[s]?:\/\/\S+/
+ validates :bitly_clone, uniqueness: true
+
+ private
+ def bitly_generate
+ rando_arr = ('a'..'z').to_a + ('A'..'Z').to_a
+ #bitly_link = "https://cmm.ly/"+rando_arr.sample(6).join
+ bitly_link = rando_arr.sample(8).join
+ self.bitly_clone = bitly_link
+ end
+
+ def validate_url
+ !!URI.regexp(['http','https'])
+ end
+
+end
diff --git a/source/app/views/layouts/application.html.erb b/source/app/views/layouts/application.html.erb
index f946432..6bad4c1 100644
--- a/source/app/views/layouts/application.html.erb
+++ b/source/app/views/layouts/application.html.erb
@@ -1,14 +1,21 @@
-
- Source
- <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
- <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
- <%= csrf_meta_tags %>
+
+ Source
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
+ <%= csrf_meta_tags %>
-
+
+ <%= link_to "CMMly", root_path %>
+ <% if flash[:error] %>
+ <%= flash[:error] %>
+ <% end %>
+
-<%= yield %>
+ <%= yield %>
-
+
+
+
diff --git a/source/app/views/urls/index.html.erb b/source/app/views/urls/index.html.erb
new file mode 100644
index 0000000..c892e1f
--- /dev/null
+++ b/source/app/views/urls/index.html.erb
@@ -0,0 +1,16 @@
+CMMly Keys
+
+
+ | URL |
+ CMMly URL |
+
+<% if @urls %>
+ <% @urls.each do |u|%>
+
+ | <%= u.address %> |
+ <%= link_to "https://cmm.ly/#{u.bitly_clone}", move_url_path(:short => u.bitly_clone)%> |
+ Clicks: <%= u.click_count %> |
+
+ <% end %>
+
+<% end %>
diff --git a/source/app/views/urls/new.html.erb b/source/app/views/urls/new.html.erb
new file mode 100644
index 0000000..de8d963
--- /dev/null
+++ b/source/app/views/urls/new.html.erb
@@ -0,0 +1,25 @@
+Generate CMMly URL
+
+<%= form_for @url, url: urls_path do |u| %>
+<%= u.label :address %>
+<%= u.text_field :address %>
+<%= u.submit %>
+<% end %>
+
+<% if @urls %>
+ CMMly Keys
+
+
+ | URL |
+ CMMly URL |
+ Clicks |
+
+ <% @urls.each do |u|%>
+
+ | <%= u.address %> |
+ <%= link_to "https://cmm.ly/#{u.bitly_clone}", move_url_path(:short => u.bitly_clone)%> |
+ Clicks: <%= u.click_count %> |
+
+ <% end %>
+
+<% end %>
diff --git a/source/config/routes.rb b/source/config/routes.rb
index 3f66539..16f4c49 100644
--- a/source/config/routes.rb
+++ b/source/config/routes.rb
@@ -1,4 +1,13 @@
Rails.application.routes.draw do
+ #get '/urls/new' => 'urls#new'
+ #post '/urls' => 'urls#create'
+ #get '/urls' => 'urls#index'
+ root 'urls#new'
+ get '/:short' => 'urls#move', :as => "move_url"
+ resources :urls, :except => [:update, :destroy, :edit, :show]
+
+
+
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
diff --git a/source/db/migrate/20170118215020_create_urls.rb b/source/db/migrate/20170118215020_create_urls.rb
new file mode 100644
index 0000000..c5398f1
--- /dev/null
+++ b/source/db/migrate/20170118215020_create_urls.rb
@@ -0,0 +1,10 @@
+class CreateUrls < ActiveRecord::Migration
+ def change
+ create_table :urls do |t|
+ t.string :address
+ t.string :bitly_clone
+
+ t.timestamps
+ end
+ end
+end
diff --git a/source/db/migrate/20170119162045_add_click_count_to_url.rb b/source/db/migrate/20170119162045_add_click_count_to_url.rb
new file mode 100644
index 0000000..e3488f1
--- /dev/null
+++ b/source/db/migrate/20170119162045_add_click_count_to_url.rb
@@ -0,0 +1,5 @@
+class AddClickCountToUrl < ActiveRecord::Migration
+ def change
+ add_column :urls, :click_count, :integer
+ end
+end
diff --git a/source/db/migrate/20170119180835_change_click_countin_urls.rb b/source/db/migrate/20170119180835_change_click_countin_urls.rb
new file mode 100644
index 0000000..ccf563b
--- /dev/null
+++ b/source/db/migrate/20170119180835_change_click_countin_urls.rb
@@ -0,0 +1,5 @@
+class ChangeClickCountinUrls < ActiveRecord::Migration
+ def change
+ change_column :urls, :click_count, :integer, :default => 0
+ end
+end
diff --git a/source/db/schema.rb b/source/db/schema.rb
new file mode 100644
index 0000000..e812f3c
--- /dev/null
+++ b/source/db/schema.rb
@@ -0,0 +1,24 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 20170119180835) do
+
+ create_table "urls", force: true do |t|
+ t.string "address"
+ t.string "bitly_clone"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "click_count", default: 0
+ end
+
+end
diff --git a/source/spec/controllers/urls_controller_spec.rb b/source/spec/controllers/urls_controller_spec.rb
new file mode 100644
index 0000000..a1f5d09
--- /dev/null
+++ b/source/spec/controllers/urls_controller_spec.rb
@@ -0,0 +1,33 @@
+require 'rails_helper'
+
+RSpec.describe UrlsController, :type => :controller do
+
+ describe "GET index" do
+ it "returns http success" do
+ get :index
+ expect(response).to have_http_status(:success)
+ end
+ end
+
+ describe "GET new" do
+ it "returns http success" do
+ get :new
+ expect(response).to have_http_status(:success)
+ end
+ end
+
+ describe "GET create" do
+ it "returns http success" do
+ get :create
+ expect(response).to have_http_status(:success)
+ end
+ end
+
+ describe "GET move" do
+ it "returns http success" do
+ get :move
+ expect(response).to have_http_status(:success)
+ end
+ end
+
+end
diff --git a/source/spec/helpers/urls_helper_spec.rb b/source/spec/helpers/urls_helper_spec.rb
new file mode 100644
index 0000000..bbafaf3
--- /dev/null
+++ b/source/spec/helpers/urls_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'rails_helper'
+
+# Specs in this file have access to a helper object that includes
+# the UrlsHelper. For example:
+#
+# describe UrlsHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# expect(helper.concat_strings("this","that")).to eq("this that")
+# end
+# end
+# end
+RSpec.describe UrlsHelper, :type => :helper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/source/spec/models/url_spec.rb b/source/spec/models/url_spec.rb
new file mode 100644
index 0000000..209ca4c
--- /dev/null
+++ b/source/spec/models/url_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe Url, :type => :model do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/source/spec/views/urls/bitly_path.html.erb_spec.rb b/source/spec/views/urls/bitly_path.html.erb_spec.rb
new file mode 100644
index 0000000..b7a1d6b
--- /dev/null
+++ b/source/spec/views/urls/bitly_path.html.erb_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe "urls/bitly_path.html.erb", :type => :view do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/source/spec/views/urls/create.html.erb_spec.rb b/source/spec/views/urls/create.html.erb_spec.rb
new file mode 100644
index 0000000..0d08e4e
--- /dev/null
+++ b/source/spec/views/urls/create.html.erb_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe "urls/create.html.erb", :type => :view do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/source/spec/views/urls/index.html.erb_spec.rb b/source/spec/views/urls/index.html.erb_spec.rb
new file mode 100644
index 0000000..432ab97
--- /dev/null
+++ b/source/spec/views/urls/index.html.erb_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe "urls/index.html.erb", :type => :view do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/source/spec/views/urls/new.html.erb_spec.rb b/source/spec/views/urls/new.html.erb_spec.rb
new file mode 100644
index 0000000..ddb3204
--- /dev/null
+++ b/source/spec/views/urls/new.html.erb_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe "urls/new.html.erb", :type => :view do
+ pending "add some examples to (or delete) #{__FILE__}"
+end