expurrel 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +26 -5
- data/VERSION +1 -1
- data/expurrel.gemspec +59 -0
- data/lib/expurrel.rb +15 -18
- data/spec/expurrel_spec.rb +4 -4
- data/urlshorteners.txt +210 -0
- metadata +4 -3
- data/tinyurlproviders.txt +0 -1
data/README.rdoc
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
= Expurrel
|
2
2
|
|
3
|
-
Expurrel is a
|
4
|
-
providers by doing a request to the tiny url provider and getting back the redirect code.
|
5
|
-
|
3
|
+
Expurrel is a library that does short url decoding for each url shortener service. It supports most of the tiny url
|
4
|
+
providers by doing a request to the tiny url provider and getting back the redirect code. Expurrel tries to be fast by also doing
|
5
|
+
some simple caching.
|
6
6
|
|
7
7
|
== Install
|
8
8
|
|
9
|
+
To install expurrel:
|
10
|
+
|
11
|
+
gem install expurrel
|
9
12
|
|
10
13
|
== Usage
|
11
14
|
|
12
15
|
|
13
16
|
e = Expurrel.new('http://bit.ly/aanv6P')
|
14
|
-
e.decode
|
17
|
+
e.decode == 'http://www.jaapvandermeer.com/2010/02/12/introducing-myself/'
|
15
18
|
|
16
19
|
== Notes
|
17
20
|
|
@@ -19,7 +22,25 @@ The cache size is standard 1000 urls, to make it bigger:
|
|
19
22
|
|
20
23
|
Expurrel.cache = SimpleCache.new(:max_size => 10000)
|
21
24
|
|
22
|
-
|
25
|
+
== Adding new tiny URL providers
|
26
|
+
|
27
|
+
Standard there is a list of about 200 providers. If one is missing, please add it to
|
28
|
+
urlshorteners.txt or let me know by adding a issue.
|
29
|
+
|
30
|
+
e = Expurrel.PROVIDERS << 'bit.ly'
|
31
|
+
|
32
|
+
|
33
|
+
== Source
|
34
|
+
|
35
|
+
The source is maintained here:
|
36
|
+
|
37
|
+
http://github.com/japetheape/expurrel
|
38
|
+
|
39
|
+
|
40
|
+
An introductory post is here:
|
41
|
+
|
42
|
+
http://www.jaapvandermeer.com/2010/02/13/expurrel-a-library-to-decode-short-urls-in-ruby
|
43
|
+
|
23
44
|
|
24
45
|
|
25
46
|
== Note on Patches/Pull Requests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/expurrel.gemspec
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{expurrel}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jaap van der Meer"]
|
12
|
+
s.date = %q{2010-02-13}
|
13
|
+
s.description = %q{Expurrel decodes tiny urls in a efficient way.}
|
14
|
+
s.email = %q{jaapvandermeer@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"expurrel.gemspec",
|
27
|
+
"lib/expurrel.rb",
|
28
|
+
"lib/simple_cache.rb",
|
29
|
+
"spec/expurrel_spec.rb",
|
30
|
+
"spec/simple_cache_spec.rb",
|
31
|
+
"spec/spec.opts",
|
32
|
+
"spec/spec_helper.rb",
|
33
|
+
"urlshorteners.txt"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/japetheape/expurrel}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.5}
|
39
|
+
s.summary = %q{Library to decode tiny urls in a efficient way}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/expurrel_spec.rb",
|
42
|
+
"spec/simple_cache_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/lib/expurrel.rb
CHANGED
@@ -2,48 +2,46 @@ require 'open-uri'
|
|
2
2
|
require 'net/http'
|
3
3
|
require 'simple_cache'
|
4
4
|
|
5
|
-
# Expurrel is a
|
5
|
+
# Expurrel is a url that can be a shortened one Expurrel can decode it then.
|
6
6
|
class Expurrel
|
7
7
|
PROVIDERS = []
|
8
|
-
PROVIDERS_LIST_FILE = File.join(File.dirname(__FILE__), '..', '
|
9
|
-
|
8
|
+
PROVIDERS_LIST_FILE = File.join(File.dirname(__FILE__), '..', 'urlshorteners.txt')
|
10
9
|
|
11
10
|
@@cache = SimpleCache.new(:max_size => 1000)
|
12
11
|
|
13
|
-
# Give expurrel a new url
|
12
|
+
# Give expurrel a new url.
|
14
13
|
def initialize(url)
|
15
14
|
@url = url
|
16
15
|
end
|
17
16
|
|
18
17
|
|
19
18
|
# This method checks first if it's a tiny url domain from the list.
|
20
|
-
# 1. Is it a
|
19
|
+
# 1. Is it a short url?
|
21
20
|
# 2. It is cached? (tinyurls won't change we can cache forever)
|
22
21
|
# 3. Decode (slow!), does http request.
|
23
22
|
def decode
|
24
23
|
return begin
|
25
|
-
if !self.
|
24
|
+
if !self.is_short_url?
|
26
25
|
@url
|
27
26
|
elsif @@cache.has_key?(@url)
|
28
27
|
@@cache.value(@url)
|
29
28
|
else
|
30
29
|
# TODO add it to the cache
|
31
|
-
decoded_url = self.class.
|
30
|
+
decoded_url = self.class.reverse_shorturl(@url)
|
32
31
|
@@cache.cache!(@url, decoded_url)
|
33
32
|
decoded_url
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
is_tiny_domain?(self.domain)
|
37
|
+
# Is this a short url
|
38
|
+
def is_short_url?
|
39
|
+
is_short_domain?(self.domain)
|
42
40
|
end
|
43
41
|
|
44
42
|
|
45
|
-
# Is it a
|
46
|
-
def
|
43
|
+
# Is it a short domain?
|
44
|
+
def is_short_domain?(domain)
|
47
45
|
PROVIDERS.each do |l|
|
48
46
|
# TODO regular expression matching
|
49
47
|
if domain.include?(l)
|
@@ -71,18 +69,17 @@ class Expurrel
|
|
71
69
|
def load_providers!
|
72
70
|
return if !PROVIDERS.empty?
|
73
71
|
File.open(PROVIDERS_LIST_FILE, "r") .each_line do |line|
|
74
|
-
|
72
|
+
l = line.strip
|
73
|
+
PROVIDERS << l unless l.empty?
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
78
77
|
|
79
|
-
|
80
|
-
|
81
78
|
# Uses the header file sent back to decode
|
82
|
-
# the
|
79
|
+
# the shortened url.
|
83
80
|
# Trick provided by:
|
84
81
|
# http://garrickvanburen.com/archive/how-to-decode-tinyurls-with-ruby
|
85
|
-
def
|
82
|
+
def reverse_shorturl(tinyurl)
|
86
83
|
Net::HTTP.get_response(URI.parse(tinyurl)).to_hash['location'].to_s
|
87
84
|
end
|
88
85
|
|
data/spec/expurrel_spec.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "Expurrel" do
|
4
|
-
it "fails" do
|
5
|
-
#fail "hey buddy, you should probably rename this file and start specing for real"
|
6
|
-
1.should eql(1)
|
7
|
-
end
|
8
4
|
|
9
5
|
it "should load the text file into a constant" do
|
10
6
|
Expurrel::PROVIDERS.include?('bit.ly').should be true
|
@@ -21,4 +17,8 @@ describe "Expurrel" do
|
|
21
17
|
end
|
22
18
|
|
23
19
|
|
20
|
+
it "should decode a url from bacn.me" do
|
21
|
+
e = Expurrel.new('http://bacn.me/xg4')
|
22
|
+
e.decode.should eql('http://www.jo.com')
|
23
|
+
end
|
24
24
|
end
|
data/urlshorteners.txt
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
bit.ly
|
2
|
+
0rz.tw
|
3
|
+
2tu.us
|
4
|
+
307.to
|
5
|
+
6url.com
|
6
|
+
a.gg
|
7
|
+
a.nf
|
8
|
+
a2n.eu
|
9
|
+
ad.vu
|
10
|
+
adf.ly
|
11
|
+
adjix.com
|
12
|
+
alturl.com
|
13
|
+
atu.ca
|
14
|
+
azqq.com
|
15
|
+
b23.ru
|
16
|
+
b65.com
|
17
|
+
bacn.me
|
18
|
+
bit.ly
|
19
|
+
bloat.me
|
20
|
+
budurl.com
|
21
|
+
buk.me
|
22
|
+
canurl.com
|
23
|
+
chilp.it
|
24
|
+
clck.ru
|
25
|
+
cli.gs
|
26
|
+
cliccami.info
|
27
|
+
clipurl.us
|
28
|
+
clop.in
|
29
|
+
cort.as
|
30
|
+
cuturls.com
|
31
|
+
decenturl.com
|
32
|
+
digg.com
|
33
|
+
doiop.com
|
34
|
+
dwarfurl.com
|
35
|
+
easyurl.net
|
36
|
+
eepurl.com
|
37
|
+
ewerl.com
|
38
|
+
ff.im
|
39
|
+
fff.to
|
40
|
+
fhurl.com
|
41
|
+
flingk.com
|
42
|
+
flq.us
|
43
|
+
fly2.ws
|
44
|
+
fwd4.me
|
45
|
+
fwdurl.net
|
46
|
+
g8l.us
|
47
|
+
gl.am
|
48
|
+
go.9nl.com
|
49
|
+
goshrink.com
|
50
|
+
hex.io
|
51
|
+
href.in
|
52
|
+
htxt.it
|
53
|
+
hugeurl.com
|
54
|
+
hurl.ws
|
55
|
+
icanhaz.com
|
56
|
+
idek.net
|
57
|
+
is.gd
|
58
|
+
jijr.com
|
59
|
+
kissa.be
|
60
|
+
kl.am
|
61
|
+
klck.me
|
62
|
+
korta.nu
|
63
|
+
l9k.net
|
64
|
+
liip.to
|
65
|
+
liltext.com
|
66
|
+
lin.cr
|
67
|
+
linkgap.com
|
68
|
+
liurl.cn
|
69
|
+
ln-s.net
|
70
|
+
ln-s.ru
|
71
|
+
lnkurl.com
|
72
|
+
lru.jp
|
73
|
+
lu.to
|
74
|
+
lurl.no
|
75
|
+
memurl.com
|
76
|
+
merky.de
|
77
|
+
migre.me
|
78
|
+
minilien.com
|
79
|
+
moourl.com
|
80
|
+
myurl.in
|
81
|
+
nanoref.com
|
82
|
+
nanourl.se
|
83
|
+
netnet.me
|
84
|
+
ni.to
|
85
|
+
nn.nf
|
86
|
+
notlong.com
|
87
|
+
nutshellurl.com
|
88
|
+
o-x.fr
|
89
|
+
offur.com
|
90
|
+
omf.gd
|
91
|
+
onsaas.info
|
92
|
+
ow.ly
|
93
|
+
parv.us
|
94
|
+
peaurl.com
|
95
|
+
ping.fm
|
96
|
+
piurl.com
|
97
|
+
plumurl.com
|
98
|
+
plurl.me
|
99
|
+
pnt.me
|
100
|
+
poprl.com
|
101
|
+
post.ly
|
102
|
+
ptiturl.com
|
103
|
+
qlnk.net
|
104
|
+
qurlyq.com
|
105
|
+
r.im
|
106
|
+
rb6.me
|
107
|
+
rde.me
|
108
|
+
reallytinyurl.com
|
109
|
+
redir.ec
|
110
|
+
redirects.ca
|
111
|
+
redirx.com
|
112
|
+
ri.ms
|
113
|
+
rickroll.it
|
114
|
+
rubyurl.com
|
115
|
+
s3nt.com
|
116
|
+
s7y.us
|
117
|
+
shink.de
|
118
|
+
short.ie
|
119
|
+
short.to
|
120
|
+
shortenurl.com
|
121
|
+
shorterlink.com
|
122
|
+
shortlinks.co.uk
|
123
|
+
shoturl.us
|
124
|
+
shredurl.com
|
125
|
+
shrinkify.com
|
126
|
+
shrinkr.com
|
127
|
+
shrinkurl.us
|
128
|
+
shrtnd.com
|
129
|
+
shurl.net
|
130
|
+
shw.me
|
131
|
+
smallr.com
|
132
|
+
smurl.com
|
133
|
+
sn.im
|
134
|
+
sn.vc
|
135
|
+
snadr.it
|
136
|
+
snipr.com
|
137
|
+
snipurl.com
|
138
|
+
snurl.com
|
139
|
+
sp2.ro
|
140
|
+
spedr.com
|
141
|
+
srnk.net
|
142
|
+
srs.li
|
143
|
+
starturl.com
|
144
|
+
surl.co.uk
|
145
|
+
ta.gd
|
146
|
+
tcrn.ch
|
147
|
+
tgr.me
|
148
|
+
tighturl.com
|
149
|
+
tiny.cc
|
150
|
+
tiny.pl
|
151
|
+
tinylink.com
|
152
|
+
tinyurl.com
|
153
|
+
to.ly
|
154
|
+
togoto.us
|
155
|
+
tr.im
|
156
|
+
tra.kz
|
157
|
+
trunc.it
|
158
|
+
tubeurl.com
|
159
|
+
twitclicks.com
|
160
|
+
twitterurl.net
|
161
|
+
twiturl.de
|
162
|
+
twurl.cc
|
163
|
+
twurl.nl
|
164
|
+
u.mavrev.com
|
165
|
+
u.nu
|
166
|
+
u76.org
|
167
|
+
ub0.cc
|
168
|
+
ulu.lu
|
169
|
+
updating.me
|
170
|
+
ur1.ca
|
171
|
+
url.az
|
172
|
+
url.co.uk
|
173
|
+
url.ie
|
174
|
+
urlborg.com
|
175
|
+
urlbrief.com
|
176
|
+
urlcut.com
|
177
|
+
urlcutter.com
|
178
|
+
urlhawk.com
|
179
|
+
urlkiss.com
|
180
|
+
urlpire.com
|
181
|
+
urlvi.be
|
182
|
+
urlx.ie
|
183
|
+
virl.com
|
184
|
+
wapurl.co.uk
|
185
|
+
wipi.es
|
186
|
+
x.se
|
187
|
+
xil.in
|
188
|
+
xrl.in
|
189
|
+
xrl.us
|
190
|
+
xurl.jp
|
191
|
+
xzb.cc
|
192
|
+
yatuc.com
|
193
|
+
yep.it
|
194
|
+
yfrog.com
|
195
|
+
zi.ma
|
196
|
+
zurl.ws
|
197
|
+
zz.gd
|
198
|
+
zzang.kr
|
199
|
+
›.ws
|
200
|
+
✩.ws
|
201
|
+
✿.ws
|
202
|
+
❥.ws
|
203
|
+
➔.ws
|
204
|
+
➞.ws
|
205
|
+
➡.ws
|
206
|
+
➨.ws
|
207
|
+
➯.ws
|
208
|
+
➹.ws
|
209
|
+
➽.ws
|
210
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expurrel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jaap van der Meer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-13 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -38,13 +38,14 @@ files:
|
|
38
38
|
- README.rdoc
|
39
39
|
- Rakefile
|
40
40
|
- VERSION
|
41
|
+
- expurrel.gemspec
|
41
42
|
- lib/expurrel.rb
|
42
43
|
- lib/simple_cache.rb
|
43
44
|
- spec/expurrel_spec.rb
|
44
45
|
- spec/simple_cache_spec.rb
|
45
46
|
- spec/spec.opts
|
46
47
|
- spec/spec_helper.rb
|
47
|
-
-
|
48
|
+
- urlshorteners.txt
|
48
49
|
has_rdoc: true
|
49
50
|
homepage: http://github.com/japetheape/expurrel
|
50
51
|
licenses: []
|
data/tinyurlproviders.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
bit.ly
|