slim_fast 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.md +136 -0
- data/Rakefile +40 -0
- data/app/assets/javascripts/errors.js +2 -0
- data/app/assets/stylesheets/errors.css +4 -0
- data/app/controllers/errors_controller.rb +4 -0
- data/app/controllers/expansions_controller.rb +84 -0
- data/app/controllers/short_domains_controller.rb +85 -0
- data/app/controllers/short_urls_controller.rb +115 -0
- data/app/helpers/errors_helper.rb +2 -0
- data/app/helpers/slim_fast/application_helper.rb +4 -0
- data/app/helpers/slim_fast/expansions_helper.rb +4 -0
- data/app/helpers/slim_fast/short_domains_helper.rb +4 -0
- data/app/helpers/slim_fast/short_urls_helper.rb +4 -0
- data/app/models/expansion.rb +6 -0
- data/app/models/short_domain.rb +6 -0
- data/app/models/short_url.rb +35 -0
- data/app/views/errors/invalid_code.html.erb +2 -0
- data/app/views/expansions/_form.html.erb +45 -0
- data/app/views/expansions/edit.html.erb +5 -0
- data/app/views/expansions/index.html.erb +43 -0
- data/app/views/expansions/new.html.erb +5 -0
- data/app/views/expansions/show.html.erb +42 -0
- data/app/views/shared/_slim_fast_navigation.html.erb +11 -0
- data/app/views/short_domains/_form.html.erb +26 -0
- data/app/views/short_domains/edit.html.erb +5 -0
- data/app/views/short_domains/index.html.erb +38 -0
- data/app/views/short_domains/new.html.erb +5 -0
- data/app/views/short_domains/show.html.erb +27 -0
- data/app/views/short_urls/_form.html.erb +61 -0
- data/app/views/short_urls/_short_urls_table.html.erb +24 -0
- data/app/views/short_urls/edit.html.erb +5 -0
- data/app/views/short_urls/index.html.erb +19 -0
- data/app/views/short_urls/new.html.erb +5 -0
- data/app/views/short_urls/show.html.erb +77 -0
- data/config/routes.rb +17 -0
- data/db/migrate/20121004232924_create_slim_fast_short_domains.rb +10 -0
- data/db/migrate/20121004234409_create_slim_fast_short_urls.rb +22 -0
- data/db/migrate/20121004234536_create_slim_fast_expansions.rb +15 -0
- data/lib/slim_fast.rb +4 -0
- data/lib/slim_fast/engine.rb +5 -0
- data/lib/slim_fast/version.rb +3 -0
- data/lib/tasks/slim_fast_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +54 -0
- data/test/dummy/log/development.log +8542 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/tmp/cache/assets/C27/920/sprockets%2F1fe65007aa375565a9348253347444f9 +0 -0
- data/test/dummy/tmp/cache/assets/C2A/3C0/sprockets%2Fbf216b96e4625134934f18748756b125 +0 -0
- data/test/dummy/tmp/cache/assets/C50/380/sprockets%2F26016472b58ca461a65fa6951744c367 +0 -0
- data/test/dummy/tmp/cache/assets/C7F/E20/sprockets%2F33d534294133822566119b8d7d5ba6ec +0 -0
- data/test/dummy/tmp/cache/assets/CA7/F40/sprockets%2Fb9488f9fbe87445bc38136287d954775 +0 -0
- data/test/dummy/tmp/cache/assets/CC2/330/sprockets%2F07797d1858badd3219d57b87954b3d08 +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CDF/D90/sprockets%2F0d3e4f0a8075d386a6f5591146a078cd +0 -0
- data/test/dummy/tmp/cache/assets/D04/360/sprockets%2Ff72c7ca5bb201c3d8178112b5985cf03 +0 -0
- data/test/dummy/tmp/cache/assets/D10/EC0/sprockets%2F265d8e58821c5c1e766ddbf814800ba2 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D38/6D0/sprockets%2F73f8e43a3540a5da61c62fa8b51882ad +0 -0
- data/test/dummy/tmp/cache/assets/D4C/060/sprockets%2F696b70f02f9165e9b6b0a874fff13dd5 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D55/CD0/sprockets%2Fceb2e6285ffd7d7545b04757e8e6c357 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D62/500/sprockets%2Ff50e441403287cf5904aad30ffcbe05f +0 -0
- data/test/dummy/tmp/cache/assets/D7A/700/sprockets%2F8ec8c9e963236de2b707709ee3bb3f0c +0 -0
- data/test/dummy/tmp/cache/assets/DA7/2A0/sprockets%2Fa37ff5e4c7d9d5a93690eeec0c6072a5 +0 -0
- data/test/dummy/tmp/cache/assets/DBC/CC0/sprockets%2Fa16ccbfcd61258cc4a59171a1a8d6b1c +0 -0
- data/test/dummy/tmp/cache/assets/DC9/490/sprockets%2Ff0b23b7ce1fe240e2916fde55eb9cd51 +0 -0
- data/test/dummy/tmp/cache/assets/DCD/0B0/sprockets%2F8e74ddd350631963f4bdeee6cb017cac +0 -0
- data/test/dummy/tmp/cache/assets/DCD/3D0/sprockets%2F57b7ab77dabfd46f191fde6d2a45013f +0 -0
- data/test/dummy/tmp/cache/assets/DDA/BA0/sprockets%2F956c26dfdede717f68bac19770ee24aa +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E08/650/sprockets%2F5bee8a4b599a4fec8f50da484da0f7b6 +0 -0
- data/test/dummy/tmp/cache/assets/E29/DE0/sprockets%2Fef93d515dc6a6f05fee3a79e4bda1ab0 +0 -0
- data/test/fixtures/slim_fast/expansions.yml +19 -0
- data/test/fixtures/slim_fast/short_domains.yml +9 -0
- data/test/fixtures/slim_fast/short_urls.yml +33 -0
- data/test/functional/errors_controller_test.rb +9 -0
- data/test/functional/slim_fast/expansions_controller_test.rb +51 -0
- data/test/functional/slim_fast/short_domains_controller_test.rb +51 -0
- data/test/functional/slim_fast/short_urls_controller_test.rb +51 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/slim_fast_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/helpers/errors_helper_test.rb +4 -0
- data/test/unit/helpers/slim_fast/expansions_helper_test.rb +6 -0
- data/test/unit/helpers/slim_fast/short_domains_helper_test.rb +6 -0
- data/test/unit/helpers/slim_fast/short_urls_helper_test.rb +6 -0
- data/test/unit/slim_fast/expansion_test.rb +9 -0
- data/test/unit/slim_fast/short_domain_test.rb +9 -0
- data/test/unit/slim_fast/short_url_test.rb +9 -0
- metadata +278 -0
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2012 YOURNAME
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
slim_fast
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
The lightening speed diet plan that makes your URLs slimmer, faster.
|
|
5
|
+
|
|
6
|
+
slim_fast is a Ruby gem that makes it easy to create your own custom URL shortening service that can be embedded into your new or existing Rails app. Since it is a library and contains a Rails Engine, slim_fast will not interfere with your existing application.
|
|
7
|
+
|
|
8
|
+
Project Status
|
|
9
|
+
--------------
|
|
10
|
+
|
|
11
|
+
### Basic functionality implemented, but not yet stable.
|
|
12
|
+
|
|
13
|
+
slim_fast is not yet complete. It is under heavy development and this status will change when the first usable release is available.
|
|
14
|
+
|
|
15
|
+
Features
|
|
16
|
+
--------
|
|
17
|
+
|
|
18
|
+
Current:
|
|
19
|
+
|
|
20
|
+
* Gem & Rails Engine
|
|
21
|
+
* Custom Domain(s)
|
|
22
|
+
* Simple Admin Interface
|
|
23
|
+
* Basic Short Link Expansion Statistics
|
|
24
|
+
|
|
25
|
+
Pending:
|
|
26
|
+
|
|
27
|
+
* Shorten internal (Rails) and external URLs
|
|
28
|
+
* Detailed Short Link Statistics
|
|
29
|
+
* Google Analytics Campaign Tracking (utm_source, etc)
|
|
30
|
+
|
|
31
|
+
Future:
|
|
32
|
+
|
|
33
|
+
* Rack App
|
|
34
|
+
* Command-line Tools
|
|
35
|
+
* Integration with external URL shortening services (goo.gl, tinyurl, etc)?
|
|
36
|
+
* Downloadable Reports (csv, xls, json API)
|
|
37
|
+
|
|
38
|
+
Maybes:
|
|
39
|
+
|
|
40
|
+
* Captive Pausing (display another page for x seconds before redirecting to destination)
|
|
41
|
+
|
|
42
|
+
Installation
|
|
43
|
+
------------
|
|
44
|
+
|
|
45
|
+
```shell
|
|
46
|
+
$ gem install slim_fast
|
|
47
|
+
$ rails g slim_fast_engine:install:migrations
|
|
48
|
+
$ rake db:migrate
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Design Considerations
|
|
52
|
+
---------------------
|
|
53
|
+
|
|
54
|
+
* Must be easy to install/upgrade
|
|
55
|
+
* gem install slim_fast
|
|
56
|
+
* rails g slim_fast_engine:install:migrations
|
|
57
|
+
* edit initializer
|
|
58
|
+
* Must be testable
|
|
59
|
+
* rspec
|
|
60
|
+
* cucumber?
|
|
61
|
+
* Can be customized
|
|
62
|
+
* developer can configure via admin interface
|
|
63
|
+
* admin interface can be nested into existing admin UI
|
|
64
|
+
|
|
65
|
+
Model Structure
|
|
66
|
+
---------------
|
|
67
|
+
|
|
68
|
+
ShortDomain
|
|
69
|
+
<pre>
|
|
70
|
+
domain:string (required)
|
|
71
|
+
is_default:boolean (default: false)
|
|
72
|
+
</pre>
|
|
73
|
+
|
|
74
|
+
ShortUrl
|
|
75
|
+
<pre>
|
|
76
|
+
short_domain_id:integer (optional)
|
|
77
|
+
code:string (required)
|
|
78
|
+
destination_url:string (required)
|
|
79
|
+
name:string (required)
|
|
80
|
+
description:text (optional)
|
|
81
|
+
expansion_count:integer (default: 0)
|
|
82
|
+
owner_type:string (optional)
|
|
83
|
+
owner_id:integer (optional)
|
|
84
|
+
utm_enabled:boolean (default: false)
|
|
85
|
+
utm_source:string (optional)
|
|
86
|
+
utm_medium:string (optional)
|
|
87
|
+
utm_campaign:string (optional)
|
|
88
|
+
utm_term:string (optional)
|
|
89
|
+
utm_content:string (optional)
|
|
90
|
+
</pre>
|
|
91
|
+
|
|
92
|
+
Expansion
|
|
93
|
+
<pre>
|
|
94
|
+
short_url_id:integer (required)
|
|
95
|
+
domain_id:integer (optional)
|
|
96
|
+
request_url:string (optional)
|
|
97
|
+
referrer_url:string (optional)
|
|
98
|
+
remote_ip:string (optional)
|
|
99
|
+
remote_addr:string (optional)
|
|
100
|
+
user_agent:string (optional)
|
|
101
|
+
</pre>
|
|
102
|
+
|
|
103
|
+
Maintainer
|
|
104
|
+
----------
|
|
105
|
+
|
|
106
|
+
* Kevin Elliott - http://kevinelliott.net - http://github.com/kevinelliott
|
|
107
|
+
* WeLike - http://www.welikeinc.com - http://github.com/welike
|
|
108
|
+
|
|
109
|
+
Contributors
|
|
110
|
+
------------
|
|
111
|
+
|
|
112
|
+
A warm thank you to all contributors to the project, who have put effort and time into making this gem more useful.
|
|
113
|
+
|
|
114
|
+
License
|
|
115
|
+
-------
|
|
116
|
+
|
|
117
|
+
(The MIT License)
|
|
118
|
+
|
|
119
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
120
|
+
a copy of this software and associated documentation files (the
|
|
121
|
+
'Software'), to deal in the Software without restriction, including
|
|
122
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
123
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
124
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
125
|
+
the following conditions:
|
|
126
|
+
|
|
127
|
+
The above copyright notice and this permission notice shall be
|
|
128
|
+
included in all copies or substantial portions of the Software.
|
|
129
|
+
|
|
130
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
131
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
132
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
133
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
134
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
135
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
136
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
begin
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
6
|
+
end
|
|
7
|
+
begin
|
|
8
|
+
require 'rdoc/task'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
require 'rdoc/rdoc'
|
|
11
|
+
require 'rake/rdoctask'
|
|
12
|
+
RDoc::Task = Rake::RDocTask
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
17
|
+
rdoc.title = 'SlimFast'
|
|
18
|
+
rdoc.options << '--line-numbers'
|
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
|
24
|
+
load 'rails/tasks/engine.rake'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Bundler::GemHelper.install_tasks
|
|
29
|
+
|
|
30
|
+
require 'rake/testtask'
|
|
31
|
+
|
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
|
33
|
+
t.libs << 'lib'
|
|
34
|
+
t.libs << 'test'
|
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
|
36
|
+
t.verbose = false
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
task :default => :test
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
class ExpansionsController < ApplicationController
|
|
2
|
+
|
|
3
|
+
# GET /expansions
|
|
4
|
+
# GET /expansions.json
|
|
5
|
+
def index
|
|
6
|
+
@expansions = Expansion.all
|
|
7
|
+
|
|
8
|
+
respond_to do |format|
|
|
9
|
+
format.html # index.html.erb
|
|
10
|
+
format.json { render json: @expansions }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# GET /expansions/1
|
|
15
|
+
# GET /expansions/1.json
|
|
16
|
+
def show
|
|
17
|
+
@expansion = Expansion.find(params[:id])
|
|
18
|
+
|
|
19
|
+
respond_to do |format|
|
|
20
|
+
format.html # show.html.erb
|
|
21
|
+
format.json { render json: @expansion }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# GET /expansions/new
|
|
26
|
+
# GET /expansions/new.json
|
|
27
|
+
def new
|
|
28
|
+
@expansion = Expansion.new
|
|
29
|
+
|
|
30
|
+
respond_to do |format|
|
|
31
|
+
format.html # new.html.erb
|
|
32
|
+
format.json { render json: @expansion }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# GET /expansions/1/edit
|
|
37
|
+
def edit
|
|
38
|
+
@expansion = Expansion.find(params[:id])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# POST /expansions
|
|
42
|
+
# POST /expansions.json
|
|
43
|
+
def create
|
|
44
|
+
@expansion = Expansion.new(params[:expansion])
|
|
45
|
+
|
|
46
|
+
respond_to do |format|
|
|
47
|
+
if @expansion.save
|
|
48
|
+
format.html { redirect_to @expansion, notice: 'Expansion was successfully created.' }
|
|
49
|
+
format.json { render json: @expansion, status: :created, location: @expansion }
|
|
50
|
+
else
|
|
51
|
+
format.html { render action: "new" }
|
|
52
|
+
format.json { render json: @expansion.errors, status: :unprocessable_entity }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# PUT /expansions/1
|
|
58
|
+
# PUT /expansions/1.json
|
|
59
|
+
def update
|
|
60
|
+
@expansion = Expansion.find(params[:id])
|
|
61
|
+
|
|
62
|
+
respond_to do |format|
|
|
63
|
+
if @expansion.update_attributes(params[:expansion])
|
|
64
|
+
format.html { redirect_to @expansion, notice: 'Expansion was successfully updated.' }
|
|
65
|
+
format.json { head :no_content }
|
|
66
|
+
else
|
|
67
|
+
format.html { render action: "edit" }
|
|
68
|
+
format.json { render json: @expansion.errors, status: :unprocessable_entity }
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# DELETE /expansions/1
|
|
74
|
+
# DELETE /expansions/1.json
|
|
75
|
+
def destroy
|
|
76
|
+
@expansion = Expansion.find(params[:id])
|
|
77
|
+
@expansion.destroy
|
|
78
|
+
|
|
79
|
+
respond_to do |format|
|
|
80
|
+
format.html { redirect_to expansions_url }
|
|
81
|
+
format.json { head :no_content }
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
class ShortDomainsController < ApplicationController
|
|
2
|
+
|
|
3
|
+
# GET /short_domains
|
|
4
|
+
# GET /short_domains.json
|
|
5
|
+
def index
|
|
6
|
+
@short_domains = ShortDomain.all
|
|
7
|
+
|
|
8
|
+
respond_to do |format|
|
|
9
|
+
format.html # index.html.erb
|
|
10
|
+
format.json { render json: @short_domains }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# GET /short_domains/1
|
|
15
|
+
# GET /short_domains/1.json
|
|
16
|
+
def show
|
|
17
|
+
@short_domain = ShortDomain.find(params[:id], :include => { :short_urls => :short_domain })
|
|
18
|
+
|
|
19
|
+
respond_to do |format|
|
|
20
|
+
format.html # show.html.erb
|
|
21
|
+
format.json { render json: @short_domain }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# GET /short_domains/new
|
|
26
|
+
# GET /short_domains/new.json
|
|
27
|
+
def new
|
|
28
|
+
@short_domain = ShortDomain.new
|
|
29
|
+
|
|
30
|
+
respond_to do |format|
|
|
31
|
+
format.html # new.html.erb
|
|
32
|
+
format.json { render json: @short_domain }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# GET /short_domains/1/edit
|
|
37
|
+
def edit
|
|
38
|
+
@short_domain = ShortDomain.find(params[:id], :include => [:short_urls])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# POST /short_domains
|
|
42
|
+
# POST /short_domains.json
|
|
43
|
+
def create
|
|
44
|
+
@short_domain = ShortDomain.new(params[:short_domain])
|
|
45
|
+
puts @short_domain.inspect
|
|
46
|
+
|
|
47
|
+
respond_to do |format|
|
|
48
|
+
if @short_domain.save
|
|
49
|
+
format.html { redirect_to @short_domain, notice: 'Short domain was successfully created.' }
|
|
50
|
+
format.json { render json: @short_domain, status: :created, location: @short_domain }
|
|
51
|
+
else
|
|
52
|
+
format.html { render action: "new" }
|
|
53
|
+
format.json { render json: @short_domain.errors, status: :unprocessable_entity }
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# PUT /short_domains/1
|
|
59
|
+
# PUT /short_domains/1.json
|
|
60
|
+
def update
|
|
61
|
+
@short_domain = ShortDomain.find(params[:id])
|
|
62
|
+
|
|
63
|
+
respond_to do |format|
|
|
64
|
+
if @short_domain.update_attributes(params[:short_domain])
|
|
65
|
+
format.html { redirect_to @short_domain, notice: 'Short domain was successfully updated.' }
|
|
66
|
+
format.json { head :no_content }
|
|
67
|
+
else
|
|
68
|
+
format.html { render action: "edit" }
|
|
69
|
+
format.json { render json: @short_domain.errors, status: :unprocessable_entity }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# DELETE /short_domains/1
|
|
75
|
+
# DELETE /short_domains/1.json
|
|
76
|
+
def destroy
|
|
77
|
+
@short_domain = ShortDomain.find(params[:id])
|
|
78
|
+
@short_domain.destroy
|
|
79
|
+
|
|
80
|
+
respond_to do |format|
|
|
81
|
+
format.html { redirect_to short_domains_url }
|
|
82
|
+
format.json { head :no_content }
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
class ShortUrlsController < ApplicationController
|
|
2
|
+
|
|
3
|
+
# GET /short_urls
|
|
4
|
+
# GET /short_urls.json
|
|
5
|
+
def index
|
|
6
|
+
@short_domain = ShortDomain.find_by_id(params[:short_domain_id])
|
|
7
|
+
@short_urls = if @short_domain
|
|
8
|
+
@short_domain.short_urls.includes(:short_domain)
|
|
9
|
+
else
|
|
10
|
+
ShortUrl.includes(:short_domain)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
respond_to do |format|
|
|
14
|
+
format.html # index.html.erb
|
|
15
|
+
format.json { render json: @short_urls }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# GET /short_urls/1
|
|
20
|
+
# GET /short_urls/1.json
|
|
21
|
+
def show
|
|
22
|
+
@short_url = ShortUrl.find(params[:id])
|
|
23
|
+
|
|
24
|
+
respond_to do |format|
|
|
25
|
+
format.html # show.html.erb
|
|
26
|
+
format.json { render json: @short_url }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# GET /short_urls/new
|
|
31
|
+
# GET /short_urls/new.json
|
|
32
|
+
def new
|
|
33
|
+
@short_domain = ShortDomain.find_by_id(params[:short_domain_id], :include => [:short_urls])
|
|
34
|
+
@short_url = if @short_domain
|
|
35
|
+
@short_domain.short_urls.build
|
|
36
|
+
else
|
|
37
|
+
ShortUrl.new
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
respond_to do |format|
|
|
41
|
+
format.html # new.html.erb
|
|
42
|
+
format.json { render json: @short_url }
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# GET /short_urls/1/edit
|
|
47
|
+
def edit
|
|
48
|
+
@short_url = ShortUrl.find(params[:id])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# POST /short_urls
|
|
52
|
+
# POST /short_urls.json
|
|
53
|
+
def create
|
|
54
|
+
@short_url = ShortUrl.new(params[:short_url])
|
|
55
|
+
|
|
56
|
+
respond_to do |format|
|
|
57
|
+
if @short_url.save
|
|
58
|
+
format.html { redirect_to @short_url, notice: 'Short url was successfully created.' }
|
|
59
|
+
format.json { render json: @short_url, status: :created, location: @short_url }
|
|
60
|
+
else
|
|
61
|
+
format.html { render action: "new" }
|
|
62
|
+
format.json { render json: @short_url.errors, status: :unprocessable_entity }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# PUT /short_urls/1
|
|
68
|
+
# PUT /short_urls/1.json
|
|
69
|
+
def update
|
|
70
|
+
@short_url = ShortUrl.find(params[:id])
|
|
71
|
+
|
|
72
|
+
respond_to do |format|
|
|
73
|
+
if @short_url.update_attributes(params[:short_url])
|
|
74
|
+
format.html { redirect_to @short_url, notice: 'Short url was successfully updated.' }
|
|
75
|
+
format.json { head :no_content }
|
|
76
|
+
else
|
|
77
|
+
format.html { render action: "edit" }
|
|
78
|
+
format.json { render json: @short_url.errors, status: :unprocessable_entity }
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# DELETE /short_urls/1
|
|
84
|
+
# DELETE /short_urls/1.json
|
|
85
|
+
def destroy
|
|
86
|
+
@short_url = ShortUrl.find(params[:id])
|
|
87
|
+
@short_url.destroy
|
|
88
|
+
|
|
89
|
+
respond_to do |format|
|
|
90
|
+
format.html { redirect_to short_urls_url }
|
|
91
|
+
format.json { head :no_content }
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def expand
|
|
96
|
+
@short_url = ShortUrl.find_by_code(params[:code])
|
|
97
|
+
|
|
98
|
+
respond_to do |format|
|
|
99
|
+
if @short_url
|
|
100
|
+
@exp = @short_url.expansions.build
|
|
101
|
+
@exp.referrer_url = request.env['HTTP_REFERER']
|
|
102
|
+
@exp.request_url = request.original_url
|
|
103
|
+
@exp.user_agent = request.env["HTTP_USER_AGENT"]
|
|
104
|
+
@exp.remote_ip = request.remote_ip
|
|
105
|
+
@exp.remote_addr = request.remote_ip
|
|
106
|
+
@exp.save
|
|
107
|
+
@short_url.increment!(:expansion_count)
|
|
108
|
+
|
|
109
|
+
format.html { redirect_to @short_url.destination_url }
|
|
110
|
+
else
|
|
111
|
+
format.html { redirect_to invalid_code_path }
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|