embiggen 1.0.0 → 1.1.0

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: f799848928c0c97fed7139de5465eaf62b564c35
4
- data.tar.gz: 6da8a48878868a89f5837b15c0cceca531eece18
3
+ metadata.gz: 0b3a9d107ca9bb152b4430ce5d756fbead2d3815
4
+ data.tar.gz: 17319b76182cb9a89851657088ee611b74d2c429
5
5
  SHA512:
6
- metadata.gz: 185ef0720cd5c8a438aad74c4f15f68c68a5d37934ae829d777377330a57c2cfb070ac880945f5e85277a1359bad9070c45be273e567529377ce033a1e316acf
7
- data.tar.gz: 84d6bc662878057e2dfe1f8a0e212947d41f53b4d0cd664810a47a2f96d7617de1957d79005f1cc3e700b74cfb270770f6da19cb492f279f7451a92303b1672d
6
+ metadata.gz: bd6f7205ef18c9b9154d26086b5ee83ec24088e03171c4b9c814a336d9385b9bcac4b3b992775db4b3189e7d6bab9b7991d1510f7f3d9f384ee5c4a7164eb3d4
7
+ data.tar.gz: c34a4493bfb2eabb949d8f62fcaf86c3742fc6c379a09423545a8feee51a245fd83b787c18ac2eaa16bd2e235630db9cce99c9f556f8ba195202b01f572b8603
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Altmetric LLP
3
+ Copyright (c) 2015-2016 Altmetric LLP
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -2,19 +2,19 @@
2
2
 
3
3
  A Ruby library to expand shortened URLs.
4
4
 
5
- **Current version:** 1.0.0
5
+ **Current version:** 1.1.0
6
6
  **Supported Ruby versions:** 1.8.7, 1.9.2, 1.9.3, 2.0, 2.1, 2.2
7
7
 
8
8
  ## Installation
9
9
 
10
10
  ```
11
- gem install embiggen -v '~> 1.0'
11
+ gem install embiggen -v '~> 1.1'
12
12
  ```
13
13
 
14
14
  Or, in your `Gemfile`:
15
15
 
16
16
  ```ruby
17
- gem 'embiggen', '~> 1.0'
17
+ gem 'embiggen', '~> 1.1'
18
18
  ```
19
19
 
20
20
  ## Usage
@@ -64,9 +64,10 @@ end
64
64
  ## Shorteners
65
65
 
66
66
  Embiggen ships with a default list of URL shortening service domains (c.f.
67
- [Acknowledgements](#acknowledgements)) but as it is likely to be outdated and
68
- incomplete, you are strongly encouraged to supply your own via
69
- `Embiggen.configure`.
67
+ [Acknowledgements](#acknowledgements)) in
68
+ [`shorteners.txt`](https://github.com/altmetric/embiggen/blob/master/shorteners.txt)
69
+ but as it is likely to be outdated and incomplete, you are strongly encouraged
70
+ to supply your own via `Embiggen.configure`.
70
71
 
71
72
  The list of shorteners is an object that responds to `include?` and will be
72
73
  passed a URI. By default, Embiggen ships with a `ShortenerList` class which
@@ -205,12 +206,15 @@ Override the following settings:
205
206
 
206
207
  ## Acknowledgements
207
208
 
209
+ * The extraction of `shorteners.txt` and performance improvements to the
210
+ shortener list were contributed by [Avner
211
+ Cohen](https://github.com/AvnerCohen);
208
212
  * The default list of shorteners comes from [LongURL.org's curated
209
213
  list](http://longurl.org/services).
210
214
 
211
215
  ## License
212
216
 
213
- Copyright © 2015 Altmetric LLP
217
+ Copyright © 2015-2016 Altmetric LLP
214
218
 
215
219
  Distributed under the MIT License.
216
220
 
@@ -18,52 +18,12 @@ module Embiggen
18
18
 
19
19
  # From http://longurl.org/services
20
20
  def self.shorteners
21
- @shorteners ||= ShortenerList.new(%w(
22
- 0rz.tw 1link.in 1url.com 2.gp 2big.at 2tu.us 3.ly 307.to 4ms.me
23
- 4sq.com 4url.cc 6url.com 7.ly a.gg a.nf aa.cx abcurl.net ad.vu adf.ly
24
- adjix.com afx.cc all.fuseurl.com alturl.com amzn.to ar.gy arst.ch
25
- atu.ca azc.cc b23.ru b2l.me bacn.me bcool.bz binged.it bit.ly bizj.us
26
- bloat.me bravo.ly bsa.ly budurl.com canurl.com chilp.it chzb.gr cl.lk
27
- cl.ly clck.ru cli.gs cliccami.info clickthru.ca clop.in conta.cc
28
- cort.as cot.ag crks.me ctvr.us cutt.us dai.ly decenturl.com dfl8.me
29
- digbig.com digg.com disq.us dld.bz dlvr.it do.my doiop.com dopen.us
30
- easyuri.com easyurl.net eepurl.com eweri.com fa.by fav.me fb.me
31
- fbshare.me ff.im fff.to fire.to firsturl.de firsturl.net flic.kr
32
- flq.us fly2.ws fon.gs freak.to fuseurl.com fuzzy.to fwd4.me fwib.net
33
- g.ro.lt gizmo.do gl.am go.9nl.com go.ign.com go.usa.gov goo.gl
34
- goshrink.com gurl.es hex.io hiderefer.com hmm.ph href.in hsblinks.com
35
- htxt.it huff.to hulu.com hurl.me hurl.ws icanhaz.com idek.net ilix.in
36
- is.gd its.my ix.lt j.mp jijr.com kl.am klck.me korta.nu krunchd.com
37
- l9k.net lat.ms liip.to liltext.com linkbee.com linkbun.ch liurl.cn
38
- ln-s.net ln-s.ru lnk.gd lnk.ms lnkd.in lnkurl.com lru.jp lt.tl lurl.no
39
- macte.ch mash.to merky.de migre.me miniurl.com minurl.fr mke.me
40
- moby.to moourl.com mrte.ch myloc.me myurl.in n.pr nbc.co nblo.gs nn.nf
41
- not.my notlong.com nsfw.in nutshellurl.com nxy.in nyti.ms o-x.fr
42
- oc1.us om.ly omf.gd omoikane.net on.cnn.com on.mktw.net onforb.es
43
- orz.se ow.ly ping.fm pli.gs pnt.me politi.co post.ly pp.gg profile.to
44
- ptiturl.com pub.vitrue.com qlnk.net qte.me qu.tc qy.fi r.im rb6.me
45
- read.bi readthis.ca reallytinyurl.com redir.ec stub_redirects.ca
46
- redirx.com retwt.me ri.ms rickroll.it riz.gd rt.nu ru.ly rubyurl.com
47
- rurl.org rww.tw s4c.in s7y.us safe.mn sameurl.com sdut.us shar.es
48
- shink.de shorl.com short.ie short.to shortlinks.co.uk shorturl.com
49
- shout.to show.my shrinkify.com shrinkr.com shrt.fr shrt.st shrten.com
50
- shrunkin.com simurl.com slate.me smallr.com smsh.me smurl.name sn.im
51
- snipr.com snipurl.com snurl.com sp2.ro spedr.com srnk.net srs.li
52
- starturl.com su.pr surl.co.uk surl.hu t.cn t.co t.lh.com ta.gd tbd.ly
53
- tcrn.ch tgr.me tgr.ph tighturl.com tiniuri.com tiny.cc tiny.ly tiny.pl
54
- tinylink.in tinyuri.ca tinyurl.com tk tl.gd tmi.me tnij.org tnw.to
55
- tny.com to to.ly togoto.us totc.us toysr.us tpm.ly tr.im tra.kz
56
- trunc.it twhub.com twirl.at twitclicks.com twitterurl.net
57
- twitterurl.org twiturl.de twurl.cc twurl.nl u.mavrev.com u.nu u76.org
58
- ub0.cc ulu.lu updating.me ur1.ca url.az url.co.uk url.ie url360.me
59
- url4.eu urlborg.com urlbrief.com urlcover.com urlcut.com urlenco.de
60
- urli.nl urls.im urlshorteningservicefortwitter.com urlx.ie urlzen.com
61
- usat.ly use.my vb.ly vgn.am vl.am vm.lc w55.de wapo.st wapurl.co.uk
62
- wipi.es wp.me x.vu xr.com xrl.in xrl.us xurl.es xurl.jp y.ahoo.it
63
- yatuc.com ye.pe yep.it yfrog.com yhoo.it yiyd.com youtu.be yuarel.com
64
- z0p.de zi.ma zi.mu zipmyurl.com zud.me zurl.ws zz.gd zzang.kr ›.ws
65
- ✩.ws ✿.ws ❥.ws ➔.ws ➞.ws ➡.ws ➨.ws ➯.ws ➹.ws ➽.ws
66
- ))
21
+ @shorteners ||= ShortenerList.new(shorteners_from_file)
22
+ end
23
+
24
+ def self.shorteners_from_file
25
+ file_path = File.expand_path('../../../shorteners.txt', __FILE__)
26
+ File.readlines(file_path).map(&:chomp)
67
27
  end
68
28
  end
69
29
  end
@@ -9,17 +9,31 @@ module Embiggen
9
9
  attr_reader :domains
10
10
 
11
11
  def initialize(domains)
12
- @domains = Set.new(domains)
12
+ @domains = Set.new(domains.map { |domain| host_pattern(domain) })
13
13
  end
14
14
 
15
15
  def include?(uri)
16
- domains.any? { |domain| uri.host =~ /\b#{domain}\z/i }
16
+ domains.any? { |domain| uri.host =~ domain }
17
17
  end
18
18
 
19
19
  def +(other)
20
20
  self.class.new(domains + other)
21
21
  end
22
22
 
23
- def_delegators :domains, :<<, :size, :delete, :empty?, :each
23
+ def <<(domain)
24
+ domains << host_pattern(domain)
25
+
26
+ self
27
+ end
28
+
29
+ def delete(domain)
30
+ domains.delete(host_pattern(domain))
31
+ end
32
+
33
+ def_delegators :domains, :size, :empty?, :each
34
+
35
+ def host_pattern(domain)
36
+ /\b#{domain}\z/i
37
+ end
24
38
  end
25
39
  end
data/shorteners.txt ADDED
@@ -0,0 +1,344 @@
1
+ 0rz.tw
2
+ 1link.in
3
+ 1url.com
4
+ 2.gp
5
+ 2big.at
6
+ 2tu.us
7
+ 3.ly
8
+ 307.to
9
+ 4ms.me
10
+ 4sq.com
11
+ 4url.cc
12
+ 6url.com
13
+ 7.ly
14
+ a.gg
15
+ a.nf
16
+ aa.cx
17
+ abcurl.net
18
+ ad.vu
19
+ adf.ly
20
+ adfoc.us
21
+ adjix.com
22
+ afx.cc
23
+ all.fuseurl.com
24
+ alturl.com
25
+ amzn.to
26
+ ar.gy
27
+ arst.ch
28
+ atu.ca
29
+ azc.cc
30
+ b23.ru
31
+ b2l.me
32
+ bacn.me
33
+ bc.vc
34
+ bcool.bz
35
+ binged.it
36
+ bit.do
37
+ bit.ly
38
+ bizj.us
39
+ bloat.me
40
+ bravo.ly
41
+ bsa.ly
42
+ budurl.com
43
+ canurl.com
44
+ chilp.it
45
+ chzb.gr
46
+ cl.lk
47
+ cl.ly
48
+ clck.ru
49
+ cli.gs
50
+ cliccami.info
51
+ clickthru.ca
52
+ clop.in
53
+ conta.cc
54
+ cort.as
55
+ cot.ag
56
+ crks.me
57
+ ctvr.us
58
+ cutt.us
59
+ dai.ly
60
+ decenturl.com
61
+ dfl8.me
62
+ digbig.com
63
+ digg.com
64
+ disq.us
65
+ dld.bz
66
+ dlvr.it
67
+ do.my
68
+ doiop.com
69
+ dopen.us
70
+ easyuri.com
71
+ easyurl.net
72
+ eepurl.com
73
+ eweri.com
74
+ fa.by
75
+ fav.me
76
+ fb.me
77
+ fbshare.me
78
+ ff.im
79
+ fff.to
80
+ fire.to
81
+ firsturl.de
82
+ firsturl.net
83
+ flic.kr
84
+ flq.us
85
+ fly2.ws
86
+ fon.gs
87
+ freak.to
88
+ fur.ly
89
+ fuseurl.com
90
+ fuzzy.to
91
+ fwd4.me
92
+ fwib.net
93
+ g.ro.lt
94
+ gizmo.do
95
+ gl.am
96
+ go.9nl.com
97
+ go.ign.com
98
+ go.usa.gov
99
+ goo.gl
100
+ goshrink.com
101
+ gurl.es
102
+ hex.io
103
+ hiderefer.com
104
+ hmm.ph
105
+ href.in
106
+ hsblinks.com
107
+ htxt.it
108
+ huff.to
109
+ hulu.com
110
+ hurl.me
111
+ hurl.ws
112
+ icanhaz.com
113
+ idek.net
114
+ ilix.in
115
+ is.gd
116
+ its.my
117
+ ix.lt
118
+ j.mp
119
+ jijr.com
120
+ kl.am
121
+ klck.me
122
+ korta.nu
123
+ krunchd.com
124
+ l9k.net
125
+ lat.ms
126
+ liip.to
127
+ liltext.com
128
+ linkbee.com
129
+ linkbun.ch
130
+ liurl.cn
131
+ ln-s.net
132
+ ln-s.ru
133
+ lnk.gd
134
+ lnk.ms
135
+ lnkd.in
136
+ lnkurl.com
137
+ lru.jp
138
+ lt.tl
139
+ lurl.no
140
+ macte.ch
141
+ mash.to
142
+ merky.de
143
+ migre.me
144
+ miniurl.com
145
+ minurl.fr
146
+ mke.me
147
+ moby.to
148
+ moourl.com
149
+ mrte.ch
150
+ myloc.me
151
+ myurl.in
152
+ n.pr
153
+ nbc.co
154
+ nblo.gs
155
+ nn.nf
156
+ not.my
157
+ notlong.com
158
+ nsfw.in
159
+ nutshellurl.com
160
+ nxy.in
161
+ nyti.ms
162
+ o-x.fr
163
+ oc1.us
164
+ om.ly
165
+ omf.gd
166
+ omoikane.net
167
+ on.cnn.com
168
+ on.mktw.net
169
+ onforb.es
170
+ orz.se
171
+ ow.ly
172
+ ping.fm
173
+ pli.gs
174
+ pnt.me
175
+ politi.co
176
+ post.ly
177
+ pp.gg
178
+ profile.to
179
+ ptiturl.com
180
+ pub.vitrue.com
181
+ qlnk.net
182
+ qte.me
183
+ qu.tc
184
+ qy.fi
185
+ r.im
186
+ rb6.me
187
+ read.bi
188
+ readthis.ca
189
+ reallytinyurl.com
190
+ redir.ec
191
+ redirx.com
192
+ retwt.me
193
+ ri.ms
194
+ rickroll.it
195
+ riz.gd
196
+ rt.nu
197
+ ru.ly
198
+ rubyurl.com
199
+ rurl.org
200
+ rww.tw
201
+ s4c.in
202
+ s7y.us
203
+ safe.mn
204
+ sameurl.com
205
+ sdut.us
206
+ seomafia.net
207
+ shar.es
208
+ shink.de
209
+ shorl.com
210
+ short.ie
211
+ short.to
212
+ shortlinks.co.uk
213
+ shorturl.com
214
+ shout.to
215
+ show.my
216
+ shrinkify.com
217
+ shrinkr.com
218
+ shrt.fr
219
+ shrt.st
220
+ shrten.com
221
+ shrunkin.com
222
+ simurl.com
223
+ slate.me
224
+ smallr.com
225
+ smsh.me
226
+ smurl.name
227
+ sn.im
228
+ snipr.com
229
+ snipurl.com
230
+ snurl.com
231
+ sp2.ro
232
+ spedr.com
233
+ srnk.net
234
+ srs.li
235
+ starturl.com
236
+ su.pr
237
+ surl.co.uk
238
+ surl.hu
239
+ t.cn
240
+ t.co
241
+ t.lh.com
242
+ ta.gd
243
+ tbd.ly
244
+ tcrn.ch
245
+ tgr.me
246
+ tgr.ph
247
+ tighturl.com
248
+ tiniuri.com
249
+ tiny.cc
250
+ tiny.ly
251
+ tiny.pl
252
+ tinylink.in
253
+ tinyuri.ca
254
+ tinyurl.com
255
+ tk
256
+ tl.gd
257
+ tmi.me
258
+ tnij.org
259
+ tnw.to
260
+ tny.com
261
+ to
262
+ to.ly
263
+ togoto.us
264
+ totc.us
265
+ toysr.us
266
+ tpm.ly
267
+ tr.im
268
+ tra.kz
269
+ trunc.it
270
+ twhub.com
271
+ twirl.at
272
+ twitclicks.com
273
+ twitterurl.net
274
+ twitterurl.org
275
+ twiturl.de
276
+ twurl.cc
277
+ twurl.nl
278
+ u.mavrev.com
279
+ u.nu
280
+ u76.org
281
+ ub0.cc
282
+ ulu.lu
283
+ updating.me
284
+ ur1.ca
285
+ url.az
286
+ url.co.uk
287
+ url.ie
288
+ url360.me
289
+ url4.eu
290
+ urlborg.com
291
+ urlbrief.com
292
+ urlcover.com
293
+ urlcut.com
294
+ urlenco.de
295
+ urli.nl
296
+ urls.im
297
+ urlshorteningservicefortwitter.com
298
+ urlx.ie
299
+ urlzen.com
300
+ usat.ly
301
+ use.my
302
+ vb.ly
303
+ vgn.am
304
+ vl.am
305
+ vm.lc
306
+ w55.de
307
+ wapo.st
308
+ wapurl.co.uk
309
+ wipi.es
310
+ wp.me
311
+ x.vu
312
+ xr.com
313
+ xrl.in
314
+ xrl.us
315
+ xurl.es
316
+ xurl.jp
317
+ y.ahoo.it
318
+ yatuc.com
319
+ ye.pe
320
+ yep.it
321
+ yfrog.com
322
+ yhoo.it
323
+ yiyd.com
324
+ youtu.be
325
+ yuarel.com
326
+ z0p.de
327
+ zi.ma
328
+ zi.mu
329
+ zipmyurl.com
330
+ zud.me
331
+ zurl.ws
332
+ zz.gd
333
+ zzang.kr
334
+ ›.ws
335
+ ✩.ws
336
+ ✿.ws
337
+ ❥.ws
338
+ ➔.ws
339
+ ➞.ws
340
+ ➡.ws
341
+ ➨.ws
342
+ ➯.ws
343
+ ➹.ws
344
+ ➽.ws
@@ -27,6 +27,12 @@ RSpec.describe Embiggen::ShortenerList do
27
27
 
28
28
  expect(list).to_not include(URI('http://www.altmetric.com'))
29
29
  end
30
+
31
+ it 'returns true if a URL host without a subdomain is on the whitelist' do
32
+ list = described_class.new(%w(bit.ly))
33
+
34
+ expect(list).to include(URI('http://www.bit.ly/foo'))
35
+ end
30
36
  end
31
37
 
32
38
  describe '#<<' do
@@ -248,10 +248,27 @@ module Embiggen
248
248
  expect(uri).to be_shortened
249
249
  end
250
250
 
251
- it 'returns false if the link is not shortened but uses a similar ' \
251
+ it 'returns false if link is not shortened but uses a similar ' \
252
252
  'domain' do
253
253
  uri = described_class.new('http://notbit.ly/1ciyUPh')
254
+ expect(uri).to_not be_shortened
255
+ end
256
+
257
+ it 'returns false if link is not shortened but uses a similar ' \
258
+ 'domain without protocol' do
259
+ uri = described_class.new('notbit.ly/1ciyUPh')
260
+ expect(uri).to_not be_shortened
261
+ end
262
+
263
+ it 'returns false if link is not shortened but uses the same domain ' \
264
+ 'with a different TLD' do
265
+ uri = described_class.new('http://nbc.com/1ciyUPh')
266
+ expect(uri).to_not be_shortened
267
+ end
254
268
 
269
+ it 'returns false if link is not shortened but uses the same domain ' \
270
+ 'with a different TLD without protocol' do
271
+ uri = described_class.new('nbc.com/1ciyUPh')
255
272
  expect(uri).to_not be_shortened
256
273
  end
257
274
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embiggen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Mucur
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-21 00:00:00.000000000 Z
12
+ date: 2016-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -69,6 +69,7 @@ files:
69
69
  - lib/embiggen/http_client.rb
70
70
  - lib/embiggen/shortener_list.rb
71
71
  - lib/embiggen/uri.rb
72
+ - shorteners.txt
72
73
  - spec/embiggen/configuration_spec.rb
73
74
  - spec/embiggen/shortener_list_spec.rb
74
75
  - spec/embiggen/uri_spec.rb
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  version: '0'
95
96
  requirements: []
96
97
  rubyforge_project:
97
- rubygems_version: 2.4.5
98
+ rubygems_version: 2.5.1
98
99
  signing_key:
99
100
  specification_version: 4
100
101
  summary: A library to expand shortened URLs