unshorten 0.3.0 → 0.3.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.
- checksums.yaml +4 -4
- data/lib/unshorten.rb +14 -10
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6329c6a3dd7b90a2b2eed9cf4453a71ccf5f867
|
4
|
+
data.tar.gz: a2240e636da07934700d6be5907e4bb1f6873329
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4737f041e8f4860a77774c43eb12f1f4e8de3405223928c6e8b69eb806c79e8f1b027aa8ce7083ff70901c496bd3e6bc6487851d551646bc80f9bf88c76942eb
|
7
|
+
data.tar.gz: e5c4b34c62a1589a9496c291aa27edfc7ab5b93b02b2713c184c5ea01a453699c7a03d9be7f0fcbbcab3b77e23d61211f1f0b4852a62aadd93a10737b5bc5d34
|
data/lib/unshorten.rb
CHANGED
@@ -4,18 +4,17 @@ require 'uri'
|
|
4
4
|
|
5
5
|
# Get original URLs from shortened ones.
|
6
6
|
class Unshorten
|
7
|
-
|
8
7
|
# Cache entities limit
|
9
8
|
CACHE_SIZE_LIMIT = 1024
|
10
9
|
|
11
10
|
# Default options for unshorten
|
12
11
|
DEFAULT_OPTIONS = {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
:max_level => 10,
|
13
|
+
:timeout => 2,
|
14
|
+
:short_hosts => false,
|
15
|
+
:short_urls => /^(?:https?:)?\/*[^\/]*\/*[^\/]*$/,
|
16
|
+
:use_cache => true,
|
17
|
+
:add_missing_http => true
|
19
18
|
}
|
20
19
|
|
21
20
|
@@cache = { }
|
@@ -30,7 +29,7 @@ class Unshorten
|
|
30
29
|
# @option options [Integer] :timeout Timeout in seconds, for every request
|
31
30
|
# @option options [Regexp] :short_hosts Hosts that provides short url
|
32
31
|
# services, only send requests if
|
33
|
-
# host matches this regexp. Set to
|
32
|
+
# host matches this regexp. Set to
|
34
33
|
# nil to follow all redirects.
|
35
34
|
# @option options [Regexp] :short_urls URLs that looks like a short one.
|
36
35
|
# Only send requests when the URL
|
@@ -75,7 +74,6 @@ class Unshorten
|
|
75
74
|
return @@cache[url] if options[:use_cache] and @@cache[url]
|
76
75
|
return url if level >= options[:max_level]
|
77
76
|
return url if options[:short_urls] && ! (url =~ options[:short_urls])
|
78
|
-
|
79
77
|
uri = URI.parse(url) rescue nil
|
80
78
|
|
81
79
|
return url if uri.nil?
|
@@ -86,7 +84,13 @@ class Unshorten
|
|
86
84
|
http.read_timeout = options[:timeout]
|
87
85
|
http.use_ssl = true if uri.scheme == "https"
|
88
86
|
|
89
|
-
|
87
|
+
if uri.path.present? && uri.query.present?
|
88
|
+
response = http.request_head("#{uri.path}?#{uri.query}") rescue nil
|
89
|
+
elsif uri.path.present? && !uri.query
|
90
|
+
response = http.request_head(uri.path) rescue nil
|
91
|
+
else
|
92
|
+
response = http.request_head('/') rescue nil
|
93
|
+
end
|
90
94
|
|
91
95
|
if response.is_a? Net::HTTPRedirection and response['location'] then
|
92
96
|
expire_cache if @@cache.size > CACHE_SIZE_LIMIT
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unshorten
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jun Wu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Get original URLs from shortened ones
|
@@ -49,7 +49,8 @@ files:
|
|
49
49
|
- lib/unshorten.rb
|
50
50
|
- test/test_unshorten.rb
|
51
51
|
homepage: https://github.com/quark-zju/unshorten
|
52
|
-
licenses:
|
52
|
+
licenses:
|
53
|
+
- BSD
|
53
54
|
metadata: {}
|
54
55
|
post_install_message:
|
55
56
|
rdoc_options: []
|