unshorten 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/unshorten.rb +14 -10
  3. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9b5c2d553a05779d8a45cec5d288152a2ee9840
4
- data.tar.gz: 4a0c1dfe4bbfe38e0c276023d1f1d1a64a0e9465
3
+ metadata.gz: d6329c6a3dd7b90a2b2eed9cf4453a71ccf5f867
4
+ data.tar.gz: a2240e636da07934700d6be5907e4bb1f6873329
5
5
  SHA512:
6
- metadata.gz: 40481e8187e84d1d7921ae79b52836e9033813d0cebf6b27c6b1b7e331c28eb8ad3677e8b1ae03cee2402e180c28cc2c6d58cd16a315afbba08933280d908c04
7
- data.tar.gz: e4f1bd8db26b1801c8ffc57f503a0882197633faf9b95733fd2ecd32b1bfaf6c38b05f338b0622fd6669b360b3cedc50728be96ebda1473e4c41da5539f8bb3f
6
+ metadata.gz: 4737f041e8f4860a77774c43eb12f1f4e8de3405223928c6e8b69eb806c79e8f1b027aa8ce7083ff70901c496bd3e6bc6487851d551646bc80f9bf88c76942eb
7
+ data.tar.gz: e5c4b34c62a1589a9496c291aa27edfc7ab5b93b02b2713c184c5ea01a453699c7a03d9be7f0fcbbcab3b77e23d61211f1f0b4852a62aadd93a10737b5bc5d34
@@ -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
- :max_level => 10,
14
- :timeout => 2,
15
- :short_hosts => false,
16
- :short_urls => /^(?:https?:)?\/*[^\/]*\/*[^\/]*$/,
17
- :use_cache => true,
18
- :add_missing_http => true
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
- response = http.request_head(uri.path.empty? ? '/' : uri.path) rescue nil
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.0
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-03-09 00:00:00.000000000 Z
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: []