jakimowicz-longurl 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/longurl/direct.rb +2 -0
- data/lib/longurl/expand.rb +1 -0
- data/lib/longurl/expander.rb +1 -0
- data/lib/longurl/service.rb +3 -3
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/longurl/direct.rb
CHANGED
data/lib/longurl/expand.rb
CHANGED
@@ -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])
|
data/lib/longurl/expander.rb
CHANGED
@@ -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.
|
data/lib/longurl/service.rb
CHANGED
@@ -22,7 +22,7 @@ module LongURL
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def cached_query(url)
|
25
|
-
@@cache
|
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.
|
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-
|
12
|
+
date: 2009-03-06 00:00:00 -08:00
|
13
13
|
default_executable: longurl
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|