shortener 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +24 -0
- data/app/helpers/shortener/shortener_helper.rb +2 -2
- data/lib/shortener/version.rb +1 -1
- data/shortener.gemspec +1 -1
- metadata +7 -6
data/README.rdoc
CHANGED
@@ -2,6 +2,30 @@
|
|
2
2
|
|
3
3
|
Shortener makes it easy to create shortened URLs for your rails application.
|
4
4
|
|
5
|
+
== Overview
|
6
|
+
|
7
|
+
The majority of the solution consists of two parts:
|
8
|
+
|
9
|
+
* a model for storing the details of the shortened link (including the user the shortened link belongs to and counter that increments as the link is clicked);
|
10
|
+
* a controller to accept incoming requests, grab the shortened link data out of the database and redirecting the visitors request to the target URL;
|
11
|
+
|
12
|
+
=== Some niceities of shortener:
|
13
|
+
|
14
|
+
* The controller does a 301 redirect, which is the recommended type of redirect for maintaining maximum google juice to the original URL;
|
15
|
+
* A unique code of is generated for each shortened link, instead of using the id of the shortened link record. This means that we can get more unique combinations than if we just used numbers;
|
16
|
+
* The link records a count of how many times it has been “un-shortened”;
|
17
|
+
* The link can be linked to a user, this allows for stats of the link usage for a particular user and other interesting things;
|
18
|
+
* The controller spawns a new thread to record information to the database, allowing the redirect to happen as quickly as possible;
|
19
|
+
|
20
|
+
=== Future (possible) improvements:
|
21
|
+
|
22
|
+
* There has not been an attempt to remove ambiguous characters (i.e. 1 l and capital i, or 0 and O etc.) from the unique key generated for the link. This means people might copy the link incorrectly if copying the link by hand;
|
23
|
+
* The shortened links are found with a case-insensitive search on the unique key. This means that the system can’t take advantage of upper and lower case to increase the number of unique combinations. This may have an effect for people copying the link by hand;
|
24
|
+
* The system could pre-generate unique keys in advance, avoiding the database penalty when checking that a newly generated key is unique;
|
25
|
+
* The system could store the shortened URL if the url is to be continually rendered;
|
26
|
+
* Some implementations might want duplicate links to be generated each time a user requests it.
|
27
|
+
|
28
|
+
|
5
29
|
== Installation
|
6
30
|
|
7
31
|
You can use the latest Rails 3 gem with the latest Shortener gem. In your Gemfile:
|
@@ -12,10 +12,10 @@ module Shortener::ShortenerHelper
|
|
12
12
|
# if the user has passed in a shortened url, with a user, then
|
13
13
|
# work out the link for the shortened url and make another with the
|
14
14
|
# passed user
|
15
|
-
short_url = ShortenedUrl.generate(shortened_url(url_object), user)
|
15
|
+
short_url = Shortener::ShortenedUrl.generate(shortened_url(url_object), user)
|
16
16
|
end
|
17
17
|
else
|
18
|
-
short_url = ShortenedUrl.generate(url_object, user)
|
18
|
+
short_url = Shortener::ShortenedUrl.generate(url_object, user)
|
19
19
|
end
|
20
20
|
|
21
21
|
return short_url.nil? ? nil : shortener_translate_url(short_url.unique_key)
|
data/lib/shortener/version.rb
CHANGED
data/shortener.gemspec
CHANGED
@@ -5,7 +5,7 @@ require File.expand_path("../lib/shortener/version", __FILE__)
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "shortener"
|
7
7
|
s.summary = "Shortener makes it easy to create shortened URLs for your rails application."
|
8
|
-
s.description = "Shortener
|
8
|
+
s.description = "Shortener is a Rails Engine that allows you to generate and store shortened URLs and serve them up for your own application."
|
9
9
|
s.files = `git ls-files`.split("\n")
|
10
10
|
s.version = Shortener::VERSION
|
11
11
|
s.platform = Gem::Platform::RUBY
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shortener
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-01 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &10296620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *10296620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &10296020 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,8 +32,9 @@ dependencies:
|
|
32
32
|
version: 3.0.7
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
description: Shortener
|
35
|
+
version_requirements: *10296020
|
36
|
+
description: Shortener is a Rails Engine that allows you to generate and store shortened
|
37
|
+
URLs and serve them up for your own application.
|
37
38
|
email:
|
38
39
|
- gems@jamespmcgrath.com
|
39
40
|
executables: []
|