unshorten 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/unshorten.rb +12 -16
  3. data/lib/version.rb +1 -1
  4. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 786f091853e66b01791b84ea4e1dae0fb45e0966
4
- data.tar.gz: 533d25ed2aceed116ebbc6f682c533f00f6357b2
3
+ metadata.gz: c2b9a42013ddf0cf926f0140c790e5d4e2025b97
4
+ data.tar.gz: 6f4c7e0760df2695d85431f7e96a55b07bf109ac
5
5
  SHA512:
6
- metadata.gz: 0be3b4e703d81938bb376198d44f95db28ce3d18f4434d235bac00b91aeea3a29ce767ef7876314b96ca1f8e6f9c89fff0f60f35c1c31a43a40ee942742fc4c7
7
- data.tar.gz: 987b63583edf60f3dd90046efb29ee7b6ede8f02b174ee0e0e6a7e2e7c397731ed43d806fd834a792350d6d69fe97ebe7e0a299f4d58000111a855b6ff0753ad
6
+ metadata.gz: 5d50404774d8857a80fc6211e007af764c698482ebb46e79f8ede636b14a10713fa308e964b1d1d0e2afa39edd18ada8a825dcb1a209465d4ed160cccc8a0b50
7
+ data.tar.gz: 401735be116ba7642315be8582f0a1699edfcf6d8512649ea2f7a8949db059a9aa27292bd11ee31d67f4a79ddc45487cb7f7f1f4da4e4153f44d501fa21a5722
@@ -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,17 +83,14 @@ 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
95
  location = URI.encode(response['location'])
99
96
  location = (uri + location).to_s if location
@@ -108,4 +105,3 @@ module Unshorten
108
105
  end
109
106
 
110
107
  # vim:et:ts=2 sw=2
111
-
@@ -1,3 +1,3 @@
1
1
  module Unshorten
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
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.3
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: 2015-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -75,3 +75,4 @@ specification_version: 4
75
75
  summary: Unshorten URLs
76
76
  test_files:
77
77
  - test/test_unshorten.rb
78
+ has_rdoc: