shortener 0.5.6 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f710d548cc2a095e643ed04c786691a723f1449
4
- data.tar.gz: e3fc832851d5e4f72750883844cc6eaee97c5e65
3
+ metadata.gz: fe28326cb43bf61b21d93e6b358942fc5252c761
4
+ data.tar.gz: 9f974fd5c92613dbbd1548d9257c3b24a097cf1b
5
5
  SHA512:
6
- metadata.gz: e89866e4b81029b37adcadbe79e42cca296b57a60fb1c6fd4e50860258b2837d9c8250e2e4924f9d56f3026f1ac76b35b54a45ffdb87f43b72c55a44139c371d
7
- data.tar.gz: 3b79ef1a1fbf5b9145431bc239f1ab7aac331d37188cb37516f13a92415b48bac1a6601abb7190526cf14b19c86816c44b1eb3d0c9eb6925081f987d2007d8bd
6
+ metadata.gz: b60cc661851633cd890c7ce4c2c8aa0329b6be9132f05385104fe289bd47f0fe4fb11a121688d333bf4be078e939228829715c43b4f67f473b7c2e558e428a0e
7
+ data.tar.gz: 3e1376fb0c2f376672b14338dad3e6e58c3f76c051a3a863640e3b2fe44708420608d2817cef8368f2be74ca8e32ca7b095696d9e2c96e84ef079d884b29519d
@@ -39,6 +39,21 @@ migration:
39
39
  end
40
40
  end
41
41
 
42
+ === v0.5.6 to v0.6.1
43
+ v0.6.1 introduced the ability to category a shortened URL. The category value
44
+ is stored in a string column in the database, which can be added to your schema with the following
45
+ migration:
46
+
47
+ bundle exec rails g migration add_category_to_shortened_url
48
+
49
+
50
+ class AddCategoryToShortenedUrl < ActiveRecord::Migration
51
+ def change
52
+ add_column :shortened_urls, :category, :string
53
+ add_index :shortened_urls, :category
54
+ end
55
+ end
56
+
42
57
  === Some niceities of Shortener:
43
58
 
44
59
  * The controller does a 301 redirect, which is the recommended type of redirect for maintaining maximum google juice to the original URL;
@@ -228,6 +243,7 @@ Shortener is used in a number of production systems, including, but not limited
228
243
 
229
244
  - {Doorkeeper - An Event Management Tool}[http://www.doorkeeperhq.com/]
230
245
  - {1001tweets - Repost your tweets to get more clicks}[http://www.1001tweets.com/]
246
+ - {NewsMaker.io - The curated newsletter builder}[https://www.newsmaker.io/]
231
247
 
232
248
  If you are using Shortener in your project and would like to be added to this list, please get in touch!
233
249
 
@@ -25,33 +25,48 @@ class Shortener::ShortenedUrl < ActiveRecord::Base
25
25
  # generate a shortened link from a url
26
26
  # link to a user if one specified
27
27
  # throw an exception if anything goes wrong
28
- def self.generate!(destination_url, owner: nil, custom_key: nil, expires_at: nil, fresh: false)
28
+ def self.generate!(destination_url, owner: nil, custom_key: nil, expires_at: nil, fresh: false, category: nil)
29
29
  # if we get a shortened_url object with a different owner, generate
30
30
  # new one for the new owner. Otherwise return same object
31
31
  result = if destination_url.is_a? Shortener::ShortenedUrl
32
32
  if destination_url.owner == owner
33
33
  destination_url
34
34
  else
35
- generate!(destination_url.url,
36
- owner: owner,
37
- custom_key: custom_key,
38
- expires_at: expires_at,
39
- fresh: fresh
40
- )
35
+ generate!(
36
+ destination_url.url,
37
+ owner: owner,
38
+ custom_key: custom_key,
39
+ expires_at: expires_at,
40
+ fresh: fresh,
41
+ category: category
42
+ )
41
43
  end
42
44
  else
43
45
  scope = owner ? owner.shortened_urls : self
44
46
  creation_method = fresh ? 'create' : 'first_or_create'
45
- scope.where(url: clean_url(destination_url)).send(creation_method, unique_key: custom_key, custom_key: custom_key, expires_at: expires_at)
47
+
48
+ scope.where(url: clean_url(destination_url), category: category).send(
49
+ creation_method,
50
+ unique_key: custom_key,
51
+ custom_key: custom_key,
52
+ expires_at: expires_at
53
+ )
46
54
  end
47
55
 
48
56
  result
49
57
  end
50
58
 
51
59
  # return shortened url on success, nil on failure
52
- def self.generate(destination_url, owner: nil, custom_key: nil, expires_at: nil, fresh: false)
60
+ def self.generate(destination_url, owner: nil, custom_key: nil, expires_at: nil, fresh: false, category: nil)
53
61
  begin
54
- generate!(destination_url, owner: owner, custom_key: custom_key, expires_at: expires_at, fresh: fresh)
62
+ generate!(
63
+ destination_url,
64
+ owner: owner,
65
+ custom_key: custom_key,
66
+ expires_at: expires_at,
67
+ fresh: fresh,
68
+ category: category
69
+ )
55
70
  rescue => e
56
71
  logger.info e
57
72
  nil
@@ -11,6 +11,9 @@ class CreateShortenedUrlsTable < ActiveRecord::Migration
11
11
  # the unique key
12
12
  t.string :unique_key, limit: 10, null: false
13
13
 
14
+ # a label to help categorize shortened urls
15
+ t.string :label, :string
16
+
14
17
  # how many times the link has been clicked
15
18
  t.integer :use_count, null: false, default: 0
16
19
 
@@ -25,5 +28,6 @@ class CreateShortenedUrlsTable < ActiveRecord::Migration
25
28
  add_index :shortened_urls, :unique_key, unique: true
26
29
  add_index :shortened_urls, :url
27
30
  add_index :shortened_urls, [:owner_id, :owner_type]
31
+ add_index :shortened_urls, :label
28
32
  end
29
33
  end
@@ -1,3 +1,3 @@
1
1
  module Shortener
2
- VERSION = '0.5.6'
2
+ VERSION = '0.6.1'
3
3
  end
@@ -3,7 +3,7 @@ class CreateShortenedUrlsTable < ActiveRecord::Migration
3
3
  create_table :shortened_urls do |t|
4
4
  # we can link this to a user for interesting things
5
5
  t.integer :owner_id
6
- t.string :owner_type, limit: 20
6
+ t.string :owner_type, limit: 40
7
7
 
8
8
  # the real url that we will redirect to
9
9
  t.text :url, null: false
@@ -11,6 +11,9 @@ class CreateShortenedUrlsTable < ActiveRecord::Migration
11
11
  # the unique key
12
12
  t.string :unique_key, limit: 10, null: false
13
13
 
14
+ # a category to help categorize shortened urls
15
+ t.string :category
16
+
14
17
  # how many times the link has been clicked
15
18
  t.integer :use_count, null: false, default: 0
16
19
 
@@ -20,10 +23,11 @@ class CreateShortenedUrlsTable < ActiveRecord::Migration
20
23
  t.timestamps
21
24
  end
22
25
 
23
- # we will lookup the links in the db by key and owners.
26
+ # we will lookup the links in the db by key, urls and owners.
24
27
  # also make sure the unique keys are actually unique
25
28
  add_index :shortened_urls, :unique_key, unique: true
26
29
  add_index :shortened_urls, :url
27
30
  add_index :shortened_urls, [:owner_id, :owner_type]
31
+ add_index :shortened_urls, :category
28
32
  end
29
33
  end
@@ -0,0 +1,6 @@
1
+ class AddCategoryToShortenedUrl < ActiveRecord::Migration
2
+ # def change
3
+ # add_column :shortened_urls, :category, :string
4
+ # add_index :shortened_urls, :category
5
+ # end
6
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20150919033108) do
14
+ ActiveRecord::Schema.define(version: 20161104055303) do
15
15
 
16
16
  create_table "shortened_urls", force: true do |t|
17
17
  t.integer "owner_id"
@@ -22,8 +22,10 @@ ActiveRecord::Schema.define(version: 20150919033108) do
22
22
  t.datetime "expires_at"
23
23
  t.datetime "created_at"
24
24
  t.datetime "updated_at"
25
+ t.string "category"
25
26
  end
26
27
 
28
+ add_index "shortened_urls", ["category"], name: "index_shortened_urls_on_category"
27
29
  add_index "shortened_urls", ["owner_id", "owner_type"], name: "index_shortened_urls_on_owner_id_and_owner_type"
28
30
  add_index "shortened_urls", ["unique_key"], name: "index_shortened_urls_on_unique_key", unique: true
29
31
  add_index "shortened_urls", ["url"], name: "index_shortened_urls_on_url"
@@ -76,15 +76,34 @@ describe Shortener::ShortenedUrl, type: :model do
76
76
  end
77
77
 
78
78
  context 'same url as existing' do
79
- it 'returns the same shortened link record' do
80
- expect(Shortener::ShortenedUrl.generate!(url)).to eq existing_shortened_url
79
+ context 'no owner' do
80
+ it 'returns the same shortened link record' do
81
+ expect(Shortener::ShortenedUrl.generate!(url)).to eq existing_shortened_url
82
+ end
83
+
84
+ context 'with category' do
85
+ it 'returns a new shortened link record' do
86
+ new_url = Shortener::ShortenedUrl.generate!(url, category: 'test')
87
+ expect(new_url.category).to eq 'test'
88
+ expect(new_url).to_not eq existing_shortened_url
89
+ end
90
+
91
+ context 'original url had same category' do
92
+ let!(:existing_shortened_url) { Shortener::ShortenedUrl.generate!(url, category: 'test') }
93
+ it 'returns the same shortened link record' do
94
+ new_url = Shortener::ShortenedUrl.generate!(url, category: 'test')
95
+ expect(new_url).to eq existing_shortened_url
96
+ expect(new_url.category).to eq 'test'
97
+ end
98
+ end
99
+ end
81
100
  end
82
- end
83
101
 
84
- context 'same url as existing, but with a different owner' do
85
- let(:owner) { User.create }
86
- it 'returns the a new shortened link record' do
87
- expect(Shortener::ShortenedUrl.generate!(url, owner: owner)).not_to eq existing_shortened_url
102
+ context 'a different owner' do
103
+ let(:owner) { User.create }
104
+ it 'returns the a new shortened link record' do
105
+ expect(Shortener::ShortenedUrl.generate!(url, owner: owner)).not_to eq existing_shortened_url
106
+ end
88
107
  end
89
108
  end
90
109
 
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.5.6
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James P. McGrath
@@ -164,6 +164,7 @@ files:
164
164
  - spec/dummy/db/migrate/20120214023758_create_users.rb
165
165
  - spec/dummy/db/migrate/20150919033038_change_url_field_to_text_on_shortened_url.rb
166
166
  - spec/dummy/db/migrate/20150919033108_add_expires_at_to_shortened_url.rb
167
+ - spec/dummy/db/migrate/20161104055303_add_category_to_shortened_url.rb
167
168
  - spec/dummy/db/schema.rb
168
169
  - spec/dummy/public/favicon.ico
169
170
  - spec/dummy/script/rails