corto 0.90.0 → 0.99.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/corto.gemspec +144 -0
- data/db/corto.db +0 -0
- data/lib/corto.rb +28 -10
- metadata +6 -13
- data/.gitignore +0 -21
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.99.0
|
data/corto.gemspec
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{corto}
|
8
|
+
s.version = "0.99.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Paolo Perego"]
|
12
|
+
s.date = %q{2011-03-25}
|
13
|
+
s.default_executable = %q{corto}
|
14
|
+
s.description = %q{CORTO - your url shortner gem
|
15
|
+
-----------------------------
|
16
|
+
|
17
|
+
- Yet another url shortner?
|
18
|
+
|
19
|
+
corto is a ruby gem that shorten a URL for you and store the result in a SQLite3 database.
|
20
|
+
Why the world needs another url shortener? Well, true to be told I don't know the answer and I'm
|
21
|
+
pretty sure this code is far away from being revolutionary.
|
22
|
+
|
23
|
+
However... corto is funniest!
|
24
|
+
|
25
|
+
- Usage
|
26
|
+
|
27
|
+
Using corto as standalone utility is straightforward. In case you want to shorten an url you just
|
28
|
+
launch the program with the url as parameter.
|
29
|
+
|
30
|
+
% bin/corto http://www.armoredcode.com
|
31
|
+
% corto: http://www.armoredcode.com shrunk as ji5jnu
|
32
|
+
|
33
|
+
Please note that you've to supply a valid URL, since internally it's parsed and rejected anything but
|
34
|
+
HTTP and HTTPS verbs.
|
35
|
+
|
36
|
+
% bin/corto funnystatementhere
|
37
|
+
% corto: it seems funnystatementhere is not a valid url to shrink
|
38
|
+
|
39
|
+
If you want to deflate a shrunk url, you have just to specify the '-d' flag this way.
|
40
|
+
|
41
|
+
% bin/corto -d ji5jnu
|
42
|
+
% corto: ji5jnu deflated is http://www.armoredcode.com
|
43
|
+
|
44
|
+
Super easy, isn't it? Now, go ahead and shrink the web!
|
45
|
+
|
46
|
+
- API
|
47
|
+
|
48
|
+
A simple corto shortening session start with class initialization, optionally telling which SQLite3
|
49
|
+
database to use and then mastering the parameter.
|
50
|
+
|
51
|
+
require 'corto'
|
52
|
+
|
53
|
+
...
|
54
|
+
corto = Corto.new # we're now saying the gem we want to use it's internal database stored in db/corto.db
|
55
|
+
s = corto.shrink('http://www.armoredcode.com')
|
56
|
+
|
57
|
+
# s now stores the shrinked url that is already added to database if not present.
|
58
|
+
# If you'll pass an invalid url to shrink(), nil will be returned instead
|
59
|
+
|
60
|
+
Deflating a URL is super easy as well
|
61
|
+
|
62
|
+
# The deflate process is quite straightforward as well
|
63
|
+
|
64
|
+
d = corto.deflate(s)
|
65
|
+
# d has now the deflated url or nil if that url was not found
|
66
|
+
|
67
|
+
You can also count how many urls contained into db
|
68
|
+
|
69
|
+
# If you want to know how many urls you have in your database, just call the count() method.
|
70
|
+
puts 'Hey, I have stored ' + corto.count() + ' urls'
|
71
|
+
|
72
|
+
And finally you can purge your db
|
73
|
+
|
74
|
+
# Tired of your database and time for a massive clean has come? Let's purge the db.
|
75
|
+
corto.purge
|
76
|
+
|
77
|
+
# corto.count == 0 now
|
78
|
+
|
79
|
+
|
80
|
+
- Note on Patches/Pull Requests
|
81
|
+
|
82
|
+
* Fork the project.
|
83
|
+
* Make your feature addition or bug fix.
|
84
|
+
* Add tests for it. This is important so I don’t break it in a future version unintentionally.
|
85
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version,
|
86
|
+
that is fine but bump version in a commit by itself I can ignore when I pull)
|
87
|
+
* Send me a pull request. Bonus points for topic branches.
|
88
|
+
|
89
|
+
- Copyright
|
90
|
+
|
91
|
+
Copyright © 2011 Paolo Perego. See LICENSE for details.}
|
92
|
+
s.email = %q{thesp0nge@gmail.com}
|
93
|
+
s.executables = ["corto"]
|
94
|
+
s.extra_rdoc_files = [
|
95
|
+
"LICENSE",
|
96
|
+
"README"
|
97
|
+
]
|
98
|
+
s.files = [
|
99
|
+
".document",
|
100
|
+
"LICENSE",
|
101
|
+
"README",
|
102
|
+
"Rakefile",
|
103
|
+
"VERSION",
|
104
|
+
"bin/corto",
|
105
|
+
"corto.gemspec",
|
106
|
+
"db/corto.db",
|
107
|
+
"lib/corto.rb",
|
108
|
+
"spec/corto_spec.rb",
|
109
|
+
"spec/data/test_db.db",
|
110
|
+
"spec/spec.opts",
|
111
|
+
"spec/spec_helper.rb"
|
112
|
+
]
|
113
|
+
s.homepage = %q{http://github.com/thesp0nge/corto}
|
114
|
+
s.require_paths = ["lib"]
|
115
|
+
s.rubygems_version = %q{1.3.7}
|
116
|
+
s.summary = %q{corto is an url shortenizer gem}
|
117
|
+
s.test_files = [
|
118
|
+
"spec/corto_spec.rb",
|
119
|
+
"spec/spec_helper.rb"
|
120
|
+
]
|
121
|
+
|
122
|
+
if s.respond_to? :specification_version then
|
123
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
124
|
+
s.specification_version = 3
|
125
|
+
|
126
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
127
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
128
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
129
|
+
s.add_runtime_dependency(%q<sqlite3>, [">= 0"])
|
130
|
+
s.add_runtime_dependency(%q<awesome_print>, [">= 0"])
|
131
|
+
else
|
132
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
133
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
134
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
135
|
+
s.add_dependency(%q<awesome_print>, [">= 0"])
|
136
|
+
end
|
137
|
+
else
|
138
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
139
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
140
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
141
|
+
s.add_dependency(%q<awesome_print>, [">= 0"])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
data/db/corto.db
CHANGED
Binary file
|
data/lib/corto.rb
CHANGED
@@ -9,11 +9,20 @@ class Corto
|
|
9
9
|
def initialize (options={})
|
10
10
|
@db_name= options["db_name"]
|
11
11
|
@db_name= './db/corto.db' unless options.has_key? "db_name"
|
12
|
-
|
12
|
+
@use_db= options["use_db"]
|
13
|
+
@use_db= true unless options.has_key? "use_db"
|
14
|
+
|
15
|
+
if @use_db
|
16
|
+
init_db
|
17
|
+
end
|
13
18
|
end
|
14
19
|
|
15
20
|
|
16
21
|
def purge
|
22
|
+
if ! @use_db
|
23
|
+
return nil
|
24
|
+
end
|
25
|
+
|
17
26
|
if File.exists?(@db_name)
|
18
27
|
File.delete(@db_name)
|
19
28
|
end
|
@@ -23,6 +32,9 @@ class Corto
|
|
23
32
|
end
|
24
33
|
|
25
34
|
def count
|
35
|
+
if ! @use_db
|
36
|
+
return -1
|
37
|
+
end
|
26
38
|
@db = SQLite3::Database.new(@db_name)
|
27
39
|
count = @db.execute("SELECT COUNT(*) FROM urls;")
|
28
40
|
@db.close
|
@@ -35,20 +47,26 @@ class Corto
|
|
35
47
|
uri = URI::parse(url)
|
36
48
|
return nil unless uri.kind_of? URI::HTTP or uri.kind_of? URI::HTTPS
|
37
49
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
50
|
+
if @use_db
|
51
|
+
@db = SQLite3::Database.new(@db_name)
|
52
|
+
count = @db.execute("SELECT COUNT(*) FROM urls WHERE url='" +url.hash.abs.to_s(36)+"'")
|
53
|
+
if count.first.first == 0
|
54
|
+
@db.execute("INSERT INTO urls (url, original) VALUES ('"+url.hash.abs.to_s(36)+ "', '"+url+"')")
|
55
|
+
end
|
56
|
+
@db.close
|
42
57
|
end
|
43
|
-
@db.close
|
44
58
|
|
45
59
|
url.hash.abs.to_s(36)
|
46
60
|
end
|
47
61
|
|
48
62
|
def deflate(shrunk_url)
|
49
|
-
|
50
|
-
|
51
|
-
|
63
|
+
if @use_db
|
64
|
+
@db = SQLite3::Database.new(@db_name)
|
65
|
+
result = @db.execute("SELECT original FROM urls WHERE url='" +shrunk_url+"'")
|
66
|
+
(! result.first.nil?) ? result.first.first : nil
|
67
|
+
else
|
68
|
+
nil
|
69
|
+
end
|
52
70
|
end
|
53
71
|
|
54
72
|
private
|
@@ -59,4 +77,4 @@ class Corto
|
|
59
77
|
@db.close
|
60
78
|
end
|
61
79
|
end
|
62
|
-
end
|
80
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 375
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
7
|
+
- 99
|
9
8
|
- 0
|
10
|
-
version: 0.
|
9
|
+
version: 0.99.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Paolo Perego
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-25 00:00:00 +01:00
|
19
18
|
default_executable: corto
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 13
|
30
28
|
segments:
|
31
29
|
- 1
|
32
30
|
- 2
|
@@ -42,7 +40,6 @@ dependencies:
|
|
42
40
|
requirements:
|
43
41
|
- - ">="
|
44
42
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
43
|
segments:
|
47
44
|
- 0
|
48
45
|
version: "0"
|
@@ -56,7 +53,6 @@ dependencies:
|
|
56
53
|
requirements:
|
57
54
|
- - ">="
|
58
55
|
- !ruby/object:Gem::Version
|
59
|
-
hash: 3
|
60
56
|
segments:
|
61
57
|
- 0
|
62
58
|
version: "0"
|
@@ -70,7 +66,6 @@ dependencies:
|
|
70
66
|
requirements:
|
71
67
|
- - ">="
|
72
68
|
- !ruby/object:Gem::Version
|
73
|
-
hash: 3
|
74
69
|
segments:
|
75
70
|
- 0
|
76
71
|
version: "0"
|
@@ -158,12 +153,12 @@ extra_rdoc_files:
|
|
158
153
|
- README
|
159
154
|
files:
|
160
155
|
- .document
|
161
|
-
- .gitignore
|
162
156
|
- LICENSE
|
163
157
|
- README
|
164
158
|
- Rakefile
|
165
159
|
- VERSION
|
166
160
|
- bin/corto
|
161
|
+
- corto.gemspec
|
167
162
|
- db/corto.db
|
168
163
|
- lib/corto.rb
|
169
164
|
- spec/corto_spec.rb
|
@@ -175,8 +170,8 @@ homepage: http://github.com/thesp0nge/corto
|
|
175
170
|
licenses: []
|
176
171
|
|
177
172
|
post_install_message:
|
178
|
-
rdoc_options:
|
179
|
-
|
173
|
+
rdoc_options: []
|
174
|
+
|
180
175
|
require_paths:
|
181
176
|
- lib
|
182
177
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -184,7 +179,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
184
179
|
requirements:
|
185
180
|
- - ">="
|
186
181
|
- !ruby/object:Gem::Version
|
187
|
-
hash: 3
|
188
182
|
segments:
|
189
183
|
- 0
|
190
184
|
version: "0"
|
@@ -193,7 +187,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
187
|
requirements:
|
194
188
|
- - ">="
|
195
189
|
- !ruby/object:Gem::Version
|
196
|
-
hash: 3
|
197
190
|
segments:
|
198
191
|
- 0
|
199
192
|
version: "0"
|