jakimowicz-longurl 0.0.3 → 0.0.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.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 3
2
+ :patch: 4
3
3
  :major: 0
4
4
  :minor: 0
@@ -10,6 +10,8 @@ module LongURL
10
10
  dest = answer['Location']
11
11
  (dest && dest[0, 7] == 'http://' && follow_redirections(dest)) || orig
12
12
  end
13
+ rescue Timeout::Error, Errno::ENETUNREACH, Errno::ETIMEDOUT, SocketError
14
+ raise LongURL::NetworkError
13
15
  end
14
16
  end
15
17
  end
@@ -20,6 +20,7 @@ module LongURL
20
20
  #
21
21
  # === Exceptions
22
22
  # * LongURL::InvalidURL : will occurs if given url is nil, empty or invalid
23
+ # * LongURL::NetworkError : a network (timeout, host could be reached, ...) error occurs
23
24
  # * LongURL::UnknownError : an unknown error occurs
24
25
  def expand(url, options = {})
25
26
  @@expander ||= Expander.new(:cache => options[:cache])
@@ -25,6 +25,7 @@ module LongURL
25
25
  # e.expand("http://is.gd/iUKg") # => "http://fabien.jakimowicz.com"
26
26
  # === Exceptions
27
27
  # * LongURL::InvalidURL : will occurs if given url is nil, empty or invalid
28
+ # * LongURL::NetworkError : a network (timeout, host could be reached, ...) error occurs
28
29
  # * LongURL::UnknownError : an unknown error occurs
29
30
  class Expander
30
31
  # Initialize a new Expander.
@@ -22,7 +22,7 @@ module LongURL
22
22
  end
23
23
 
24
24
  def cached_query(url)
25
- @@cache.get(url) || @@cache.set(url, query(url))
25
+ @@cache[url] ||= query(url)
26
26
  end
27
27
 
28
28
  def query(url)
@@ -30,7 +30,7 @@ module LongURL
30
30
  Net::HTTP.start(EndPoint.host, EndPoint.port) do |http|
31
31
  handle_response http.get("#{EndPoint.path}?format=json&url=#{escaped_url}")
32
32
  end
33
- rescue Timeout::Error, Errno::ENETUNREACH
33
+ rescue Timeout::Error, Errno::ENETUNREACH, Errno::ETIMEDOUT, SocketError
34
34
  raise LongURL::NetworkError
35
35
  end
36
36
 
@@ -59,7 +59,7 @@ module LongURL
59
59
  parsed = JSON.parse(response.body)
60
60
  parsed.values.flatten
61
61
  end
62
- rescue Timeout::Error, Errno::ENETUNREACH
62
+ rescue Timeout::Error, Errno::ENETUNREACH, Errno::ETIMEDOUT, SocketError
63
63
  raise LongURL::NetworkError
64
64
  end
65
65
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jakimowicz-longurl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabien Jakimowicz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-23 00:00:00 -08:00
12
+ date: 2009-03-06 00:00:00 -08:00
13
13
  default_executable: longurl
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency