unshorten 0.3.2 → 0.3.4

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.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/lib/unshorten.rb +13 -17
  3. data/lib/version.rb +1 -1
  4. metadata +6 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 786f091853e66b01791b84ea4e1dae0fb45e0966
4
- data.tar.gz: 533d25ed2aceed116ebbc6f682c533f00f6357b2
2
+ SHA256:
3
+ metadata.gz: f71bd42a847a3193aabafa13444f18928266623c76aedd6af6f12389569509e8
4
+ data.tar.gz: cfae371349808af56e9b44683f6fba7614a98d10e3f5ad3dbc39ede28419990f
5
5
  SHA512:
6
- metadata.gz: 0be3b4e703d81938bb376198d44f95db28ce3d18f4434d235bac00b91aeea3a29ce767ef7876314b96ca1f8e6f9c89fff0f60f35c1c31a43a40ee942742fc4c7
7
- data.tar.gz: 987b63583edf60f3dd90046efb29ee7b6ede8f02b174ee0e0e6a7e2e7c397731ed43d806fd834a792350d6d69fe97ebe7e0a299f4d58000111a855b6ff0753ad
6
+ metadata.gz: ac6e05dbf7dfaa3ec4712b049995a8f230a9204564f6fd16bcba1250ea7dd6c12e8a5b90a5d5996c11607c6c56bcd05b2e63d524768dc6382be917883da39b5d
7
+ data.tar.gz: 1bc7bc938c52d92bf68095e8cc70f1232a485740cc8c81d866da4208078afc81e76dd4a3735ce66da6918a749ac40b486b6b0afabcc90efed015e24f84b6a0f1
data/lib/unshorten.rb CHANGED
@@ -14,6 +14,7 @@ module Unshorten
14
14
  :timeout => 2,
15
15
  :short_hosts => false,
16
16
  :short_urls => /^(?:https?:)?\/*[^\/]*\/*[^\/]*$/,
17
+ :follow_codes => [302, 301],
17
18
  :use_cache => true,
18
19
  :add_missing_http => true
19
20
  }
@@ -36,6 +37,11 @@ module Unshorten
36
37
  # Only send requests when the URL
37
38
  # match this regexp. Set to nil to
38
39
  # follow all redirects.
40
+ # @option options [Array] :follow_codes An array of HTTP status codes
41
+ # (intergers). Only follow a
42
+ # redirect if the response HTTP
43
+ # code matches one item of the
44
+ # array.
39
45
  # @option options [Boolean] :use_cache Use cached result if available
40
46
  # @option options [Boolean] :add_missing_http add 'http://' if missing
41
47
  # @see DEFAULT_OPTIONS
@@ -55,12 +61,6 @@ module Unshorten
55
61
  @@cache = { }
56
62
  end
57
63
 
58
- def mix_options(old, *new) #:nodoc:
59
- options = old.dup
60
- new.each { |n| n.each { |k, v| options[k] = v } }
61
- options
62
- end
63
-
64
64
  def add_missing_http(url) #:nodoc:
65
65
  if url =~ /^https?:/i
66
66
  url
@@ -83,19 +83,16 @@ module Unshorten
83
83
  http = Net::HTTP.new(uri.host, uri.port)
84
84
  http.open_timeout = options[:timeout]
85
85
  http.read_timeout = options[:timeout]
86
- http.use_ssl = true if uri.scheme == "https"
86
+ http.use_ssl = true if uri.scheme == 'https'
87
87
 
88
- if uri.path && uri.query
89
- response = http.request_head("#{uri.path}?#{uri.query}") rescue nil
90
- elsif uri.path && !uri.query
91
- response = http.request_head(uri.path) rescue nil
92
- else
93
- response = http.request_head('/') rescue nil
94
- end
88
+ path = uri.path
89
+ path = '/' if !path || path.empty?
90
+ path += "?#{uri.query}" if uri.query
91
+ response = http.request_head(path) rescue nil
95
92
 
96
- if response.is_a? Net::HTTPRedirection and response['location'] then
93
+ if response.is_a?(Net::HTTPRedirection) && options[:follow_codes].include?(response.code.to_i) && response['location'] then
97
94
  expire_cache if @@cache.size > CACHE_SIZE_LIMIT
98
- location = URI.encode(response['location'])
95
+ location = Addressable::URI.encode(response['location'])
99
96
  location = (uri + location).to_s if location
100
97
  @@cache[url] = follow(location, options, level + 1)
101
98
  else
@@ -108,4 +105,3 @@ module Unshorten
108
105
  end
109
106
 
110
107
  # vim:et:ts=2 sw=2
111
-
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Unshorten
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unshorten
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
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-08-20 00:00:00.000000000 Z
11
+ date: 2023-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.1'
33
+ version: '13.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
- version: '10.1'
40
+ version: '13.0'
41
41
  description: Get original URLs from shortened ones
42
42
  email: quark@lihdd.net
43
43
  executables:
@@ -51,7 +51,7 @@ files:
51
51
  - test/test_unshorten.rb
52
52
  homepage: https://github.com/quark-zju/unshorten
53
53
  licenses:
54
- - BSD
54
+ - BSD-2-Clause
55
55
  metadata: {}
56
56
  post_install_message:
57
57
  rdoc_options: []
@@ -68,8 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubyforge_project:
72
- rubygems_version: 2.2.0
71
+ rubygems_version: 3.2.5
73
72
  signing_key:
74
73
  specification_version: 4
75
74
  summary: Unshorten URLs