url_expander 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +131 -0
- data/Rakefile +70 -0
- data/VERSION +1 -0
- data/lib/url_expander/expanders/api/4sq.rb +12 -0
- data/lib/url_expander/expanders/api/bitly.rb +61 -0
- data/lib/url_expander/expanders/api/budurl.rb +41 -0
- data/lib/url_expander/expanders/api/cligs.rb +42 -0
- data/lib/url_expander/expanders/api/decenturl.rb +42 -0
- data/lib/url_expander/expanders/api/fxnws.rb +12 -0
- data/lib/url_expander/expanders/api/googl.rb +43 -0
- data/lib/url_expander/expanders/api/isgd.rb +41 -0
- data/lib/url_expander/expanders/api/nytims.rb +12 -0
- data/lib/url_expander/expanders/api/tcrnch.rb +12 -0
- data/lib/url_expander/expanders/api/xrlus.rb +40 -0
- data/lib/url_expander/expanders/api.rb +21 -0
- data/lib/url_expander/expanders/basic/adjix.rb +29 -0
- data/lib/url_expander/expanders/basic/digbig.rb +30 -0
- data/lib/url_expander/expanders/basic/doiop.rb +30 -0
- data/lib/url_expander/expanders/basic/easyurljp.rb +23 -0
- data/lib/url_expander/expanders/basic/justas.rb +23 -0
- data/lib/url_expander/expanders/basic/moourl.rb +29 -0
- data/lib/url_expander/expanders/basic/notlong.rb +29 -0
- data/lib/url_expander/expanders/basic/nutshellurl.rb +30 -0
- data/lib/url_expander/expanders/basic/owly.rb +23 -0
- data/lib/url_expander/expanders/basic/shrtst.rb +23 -0
- data/lib/url_expander/expanders/basic/snipurl.rb +26 -0
- data/lib/url_expander/expanders/basic/tco.rb +23 -0
- data/lib/url_expander/expanders/basic/tighturl.rb +23 -0
- data/lib/url_expander/expanders/basic/tinycc.rb +29 -0
- data/lib/url_expander/expanders/basic/tinyurl.rb +25 -0
- data/lib/url_expander/expanders/basic/twurlnl.rb +34 -0
- data/lib/url_expander/expanders/basic/urlie.rb +23 -0
- data/lib/url_expander/expanders/basic/youtube.rb +24 -0
- data/lib/url_expander/expanders/basic.rb +62 -0
- data/lib/url_expander/expanders/expanders.rb +49 -0
- data/lib/url_expander/expanders/scrape/qsrli.rb +30 -0
- data/lib/url_expander/expanders/scrape/shorl.rb +30 -0
- data/lib/url_expander/expanders/scrape/simurl.rb +34 -0
- data/lib/url_expander/expanders/scrape.rb +71 -0
- data/lib/url_expander.rb +62 -0
- data/test/helper.rb +18 -0
- data/test/test_url_expander.rb +7 -0
- metadata +216 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand Adjix URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://adjix.com/cm4m")
|
7
|
+
#
|
8
|
+
class Adjix < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://(?:adjix\.com|ad\.vu)(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch_url(path)
|
18
|
+
url = super(path)
|
19
|
+
raise UrlExpander::Error.new('page not found',404) if url == 'http://www.adjix.com/notfound.html'
|
20
|
+
url
|
21
|
+
end
|
22
|
+
|
23
|
+
class Request
|
24
|
+
include HTTParty
|
25
|
+
base_uri 'http://adjix.com'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand Digbig URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://digbig.com/3bbd")
|
7
|
+
#
|
8
|
+
class Digbig < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://(?:(?>[a-z0-9-]*\.)+?|)digbig\.com(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Custom fetcher.
|
18
|
+
def fetch_url(path)
|
19
|
+
url = super(path)
|
20
|
+
raise UrlExpander::Error.new('page not found',404) if url == "/error_404.html"
|
21
|
+
url
|
22
|
+
end
|
23
|
+
|
24
|
+
class Request
|
25
|
+
include HTTParty
|
26
|
+
base_uri 'http://www.digbig.com'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand doiop.com URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://doiop.com/dz8896")
|
7
|
+
#
|
8
|
+
class Doiop < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://doiop\.com(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Custom fetcher.
|
18
|
+
def fetch_url(path)
|
19
|
+
url = super(path)
|
20
|
+
raise UrlExpander::Error.new('page not found',404) if url == "http://doiop.com/?error=404"
|
21
|
+
url
|
22
|
+
end
|
23
|
+
|
24
|
+
class Request
|
25
|
+
include HTTParty
|
26
|
+
base_uri 'http://doiop.com'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand easyurl.jp URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://easyurl.jp/1qdv")
|
7
|
+
#
|
8
|
+
class Easyurljp < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://easyurl\.jp(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
class Request
|
18
|
+
include HTTParty
|
19
|
+
base_uri 'http://easyurl.jp'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand just.as URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://just.as/amMF3i")
|
7
|
+
#
|
8
|
+
class Justas < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://just\.as(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
class Request
|
18
|
+
include HTTParty
|
19
|
+
base_uri 'http://just.as'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand moourl.com URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://moourl.com/flsho")
|
7
|
+
#
|
8
|
+
class Moourl < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://moourl\.com(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch_url(path)
|
18
|
+
url = super(path)
|
19
|
+
raise UrlExpander::Error.new('page not found',404) if url == '/404/'
|
20
|
+
url
|
21
|
+
end
|
22
|
+
|
23
|
+
class Request
|
24
|
+
include HTTParty
|
25
|
+
base_uri 'http://moourl.com'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand notlong.com URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://moski.notlong.com")
|
7
|
+
#
|
8
|
+
class Notlong < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://([\w/]+)\.notlong\.com)'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Custom fetcher.
|
18
|
+
def fetch_url(path)
|
19
|
+
super("/#{path}")
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
class Request
|
24
|
+
include HTTParty
|
25
|
+
base_uri 'notlong.com'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand nutshellurl.com URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://nutshellurl.com/1v38")
|
7
|
+
#
|
8
|
+
class Nutshellurl < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://nutshellurl\.com/([\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Custom fetcher.
|
18
|
+
def fetch_url(path)
|
19
|
+
url = super("/nutshells/nut#{path}.php")
|
20
|
+
raise UrlExpander::Error.new('page not found',404) if url == "http://nutshellurl.com/notfound.php"
|
21
|
+
url
|
22
|
+
end
|
23
|
+
|
24
|
+
class Request
|
25
|
+
include HTTParty
|
26
|
+
base_uri 'http://nutshellurl.com'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand ow.ly URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://ow.ly/5EVkL")
|
7
|
+
#
|
8
|
+
class Owly < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://ow\.ly(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
class Request
|
18
|
+
include HTTParty
|
19
|
+
base_uri 'ow.ly'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand shrt.st URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://shrt.st/148u")
|
7
|
+
#
|
8
|
+
class Shrtst < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://shrt\.st(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
class Request
|
18
|
+
include HTTParty
|
19
|
+
base_uri 'http://shrt.st'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand snipurl.com URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://snipurl.com/209hem")
|
7
|
+
# UrlExpander::Client.expand("http://sn.im/209hem")
|
8
|
+
#
|
9
|
+
# @NOTE: This service does provide an api but it is not working
|
10
|
+
#
|
11
|
+
class Snipurl < UrlExpander::Expanders::Basic
|
12
|
+
PATTERN = %r'(http://(?:snipurl\.com|sn\.im|cl\.lk|snipr\.com|snurl\.com)(/[\w/]+))'
|
13
|
+
attr_reader :parent_klass
|
14
|
+
|
15
|
+
def initialize(short_url="", options={})
|
16
|
+
@parent_klass = self
|
17
|
+
super(short_url, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
class Request
|
21
|
+
include HTTParty
|
22
|
+
base_uri 'http://snipurl.com'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand Twitter shortner t.co
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://t.co/ZGEGdas")
|
7
|
+
#
|
8
|
+
class Tco < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://t\.co(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
class Request
|
18
|
+
include HTTParty
|
19
|
+
base_uri 'http://t.co'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand Tighturl URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://tighturl.com/3eoz")
|
7
|
+
#
|
8
|
+
class Tighturl < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://tighturl\.com(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
class Request
|
18
|
+
include HTTParty
|
19
|
+
base_uri 'http://tighturl.com'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand tiny.cc URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://tiny.cc/pabx5")
|
7
|
+
#
|
8
|
+
class Tinycc < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://tiny\.cc(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch_url(path)
|
18
|
+
url = super(path)
|
19
|
+
raise UrlExpander::Error.new('page not found',404) if url == 'http://tiny.cc/notfound'
|
20
|
+
url
|
21
|
+
end
|
22
|
+
|
23
|
+
class Request
|
24
|
+
include HTTParty
|
25
|
+
base_uri 'tiny.cc'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
|
4
|
+
#
|
5
|
+
# Expand Tinyurl URLS
|
6
|
+
# Usage:
|
7
|
+
# UrlExpander::Client.expand("http://tinyurl.com/66sekq5")
|
8
|
+
#
|
9
|
+
class Tinyurl < UrlExpander::Expanders::Basic
|
10
|
+
|
11
|
+
PATTERN = %r'(http://tinyurl\.com(/[\w/]+))'
|
12
|
+
attr_reader :parent_klass
|
13
|
+
|
14
|
+
def initialize(short_url="", options={})
|
15
|
+
@parent_klass = self
|
16
|
+
super(short_url, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
class Request
|
20
|
+
include HTTParty
|
21
|
+
base_uri 'http://tinyurl.com'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
|
4
|
+
#
|
5
|
+
# Expand Twurl.nl URLS
|
6
|
+
# Usage:
|
7
|
+
# UrlExpander::Client.expand("http://twurl.nl/e6mglc")
|
8
|
+
#
|
9
|
+
class Twurlnl < UrlExpander::Expanders::Basic
|
10
|
+
|
11
|
+
PATTERN = %r'(http://twurl\.nl(/[\w/]+))'
|
12
|
+
attr_reader :parent_klass
|
13
|
+
|
14
|
+
def initialize(short_url="",options={})
|
15
|
+
@parent_klass = self
|
16
|
+
super(short_url,options)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Custom fetcher.
|
20
|
+
def fetch_url(path)
|
21
|
+
url = super(path)
|
22
|
+
raise UrlExpander::Error.new('page not found',404) if url == "http://tweetburner.com/pages/blocked"
|
23
|
+
url
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
class Request
|
28
|
+
include HTTParty
|
29
|
+
base_uri 'http://twurl.nl'
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand url.ie URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://url.ie/cert")
|
7
|
+
#
|
8
|
+
class Urlie < UrlExpander::Expanders::Basic
|
9
|
+
PATTERN = %r'(http://url\.ie(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
class Request
|
18
|
+
include HTTParty
|
19
|
+
base_uri 'http://url.ie'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand Youtu.be URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://youtu.be/bINUfbLV_0M")
|
7
|
+
# UrlExpander::Client.expand("http://y2u.be/bINUfbLV_0M")
|
8
|
+
#
|
9
|
+
class Youtube < UrlExpander::Expanders::Basic
|
10
|
+
PATTERN = %r'(http://(?:youtu\.be|y2u\.be)(/[\w/]+))'
|
11
|
+
attr_reader :parent_klass
|
12
|
+
|
13
|
+
def initialize(short_url="", options={})
|
14
|
+
@parent_klass = self
|
15
|
+
super(short_url, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
class Request
|
19
|
+
include HTTParty
|
20
|
+
base_uri 'http://youtu.be'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
|
4
|
+
#
|
5
|
+
# This is the basic class for all simple Net::HTTPMovedPermanently
|
6
|
+
# Each subclass must define a url Pattern and a Reqest class for httpartty.
|
7
|
+
# Ex:
|
8
|
+
# module UrlExpander
|
9
|
+
# module Expanders
|
10
|
+
# class Tinyurl < UrlExpander::Expanders::Basic
|
11
|
+
# class Request
|
12
|
+
# include HTTParty
|
13
|
+
# base_uri 'http://tinyurl.com'
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# PATTERN = %r'(http://tinyurl\.com(/[\w/]+))'
|
17
|
+
# attr_reader :parent_klass
|
18
|
+
#
|
19
|
+
# def initialize(short_url="",options={})
|
20
|
+
# @parent_klass = self.class
|
21
|
+
# super(shot_url,options)
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# Usage:
|
28
|
+
# client = UrlExpander::Client.new
|
29
|
+
# client.expand("http://tinyurl.com/asdf")
|
30
|
+
#
|
31
|
+
class Basic
|
32
|
+
attr_accessor :long_url
|
33
|
+
attr_reader :parttern, :parent_klass
|
34
|
+
|
35
|
+
|
36
|
+
def initialize(short_url="",options={})
|
37
|
+
if short_url.match(parent_klass.class::PATTERN)
|
38
|
+
@long_url = parent_klass.fetch_url($2)
|
39
|
+
else
|
40
|
+
raise 'invalid pattern'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
# Common fetcher used my most expanders.
|
47
|
+
def fetch_url(path)
|
48
|
+
url = nil
|
49
|
+
result = parent_klass.class::Request.head(path, :follow_redirects => false)
|
50
|
+
case result.response
|
51
|
+
when Net::HTTPMovedPermanently
|
52
|
+
url = result['Location']
|
53
|
+
when Net::HTTPFound
|
54
|
+
url = result['location']
|
55
|
+
end
|
56
|
+
|
57
|
+
raise UrlExpander::Error.new('page not found',404) if url.nil?
|
58
|
+
url
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'url_expander/expanders/basic'
|
4
|
+
require 'url_expander/expanders/api'
|
5
|
+
require 'url_expander/expanders/scrape'
|
6
|
+
|
7
|
+
|
8
|
+
module UrlExpander
|
9
|
+
module Expanders
|
10
|
+
autoload :Tinyurl, 'basic/tinyurl'
|
11
|
+
autoload :Twurlnl, 'basic/twurlnl'
|
12
|
+
autoload :Shrtst, 'basic/shrtst'
|
13
|
+
autoload :Snipurl, 'basic/Snipurl'
|
14
|
+
autoload :Adjix, 'basic/adjix'
|
15
|
+
autoload :Youtube, 'basic/youtube'
|
16
|
+
autoload :Tinycc, 'basic/tinycc'
|
17
|
+
autoload :Owly, 'basic/owly'
|
18
|
+
autoload :Digbig, 'basic/digbig'
|
19
|
+
autoload :Doiop, 'basic/doiop'
|
20
|
+
autoload :Easyurljp, 'basic/easyurljp'
|
21
|
+
autoload :Justas, 'basic/justas'
|
22
|
+
autoload :Moourl, 'basic/moourl'
|
23
|
+
autoload :Notlong, 'basic/notlong'
|
24
|
+
autoload :Nutshellurl, 'basic/nutshellurl'
|
25
|
+
autoload :Tighturl, 'basic/tighturl'
|
26
|
+
autoload :Urlie, 'basic/urlie'
|
27
|
+
autoload :Tco, 'basic/tco'
|
28
|
+
|
29
|
+
# Using API
|
30
|
+
autoload :Bitly, 'api/bitly'
|
31
|
+
autoload :Foursq, 'api/4sq'
|
32
|
+
autoload :Tcrnch, 'api/tcrnch'
|
33
|
+
autoload :Nytims, 'api/nytims'
|
34
|
+
autoload :Fxnws, 'api/fxnws'
|
35
|
+
|
36
|
+
autoload :Budurl, 'api/budurl'
|
37
|
+
autoload :Cligs, 'api/cligs'
|
38
|
+
autoload :Isgd, 'api/isgd'
|
39
|
+
autoload :Googl, 'api/googl'
|
40
|
+
autoload :Decenturl, 'api/decenturl'
|
41
|
+
autoload :Xrlus, 'api/xrlus'
|
42
|
+
|
43
|
+
# Using Scrapper
|
44
|
+
autoload :Qsrli, 'scrape/qsrli'
|
45
|
+
autoload :Shorl, 'scrape/shorl'
|
46
|
+
autoload :Simurl, 'scrape/simurl'
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand Qsrli URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://qsr.li/5Zg9")
|
7
|
+
#
|
8
|
+
class Qsrli < UrlExpander::Expanders::Scrape
|
9
|
+
PATTERN = %r'(http://qsr\.li(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass, :xpath
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self.class
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# How to scarpe the url from a Qsr.li html document
|
19
|
+
def self.scrape_url(html)
|
20
|
+
doc = Hpricot(html)
|
21
|
+
doc.at('//*[@id="framecontent"]').attributes["src"]
|
22
|
+
end
|
23
|
+
|
24
|
+
class Request
|
25
|
+
include HTTParty
|
26
|
+
base_uri 'http://qsr.li'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module UrlExpander
|
2
|
+
module Expanders
|
3
|
+
#
|
4
|
+
# Expand shorl.com URLS
|
5
|
+
# Usage:
|
6
|
+
# UrlExpander::Client.expand("http://shorl.com/nigekohalenu")
|
7
|
+
#
|
8
|
+
class Shorl < UrlExpander::Expanders::Scrape
|
9
|
+
PATTERN = %r'(http://shorl\.com(/[\w/]+))'
|
10
|
+
attr_reader :parent_klass, :xpath
|
11
|
+
|
12
|
+
def initialize(short_url="", options={})
|
13
|
+
@parent_klass = self.class
|
14
|
+
super(short_url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# How to scarpe the url from a shorl html document
|
19
|
+
def self.scrape_url(html)
|
20
|
+
doc = Hpricot(html)
|
21
|
+
doc.at('/html/body/div[3]/p/a').attributes["href"]
|
22
|
+
end
|
23
|
+
|
24
|
+
class Request
|
25
|
+
include HTTParty
|
26
|
+
base_uri 'http://shorl.com'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|