unshorten 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/unshorten.rb CHANGED
@@ -11,6 +11,7 @@ class Unshorten
11
11
  DEFAULT_OPTIONS = {
12
12
  :max_level => 10,
13
13
  :timeout => 2,
14
+ :short_hosts => /.*/,
14
15
  :use_cache => true,
15
16
  :add_missing_http => true
16
17
  }
@@ -25,6 +26,9 @@ class Unshorten
25
26
  # @param options [Hash] A set of options
26
27
  # @option options [Integer] :max_level Max redirect times
27
28
  # @option options [Integer] :timeout Timeout in seconds, for every request
29
+ # @option options [Regexp] :short_hosts Hosts that provides short url
30
+ # services, only send requests if
31
+ # host matches this regexp
28
32
  # @option options [Boolean] :use_cache Use cached result if available
29
33
  # @option options [Boolean] :add_missing_http add 'http://' if missing
30
34
  # @see DEFAULT_OPTIONS
@@ -65,6 +69,9 @@ class Unshorten
65
69
  return url if level >= options[:max_level]
66
70
 
67
71
  uri = URI.parse(url)
72
+
73
+ return url unless uri.host =~ options[:short_hosts]
74
+
68
75
  http = Net::HTTP.new(uri.host, uri.port)
69
76
  http.read_timeout = options[:timeout]
70
77
 
@@ -13,4 +13,7 @@ class UnshortenTest < Test::Unit::TestCase
13
13
  assert_equal SHORTENED_URL, Unshorten.unshorten(SHORTENED_URL, :max_level => 0, :use_cache => false)
14
14
  end
15
15
 
16
+ def test_option_short_hosts
17
+ assert_equal SHORTENED_URL, Unshorten.unshorten(SHORTENED_URL, :short_hosts => /jmp/, :use_cache => false)
18
+ end
16
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unshorten
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: