forked from wezm/wezm.net
Handle Bit.ly exceptions
Mainly for when there is no internet connection
This commit is contained in:
parent
194890e733
commit
9114181bfe
1 changed files with 12 additions and 8 deletions
|
@ -24,14 +24,18 @@ module WezM
|
|||
end
|
||||
|
||||
def short_url(url)
|
||||
@bitly ||= Bitly.new('wezm', 'R_f2bfdace56c886671086eb0c8acb9ce7')
|
||||
@cache ||= {}
|
||||
unless u = @cache[url]
|
||||
u = @bitly.shorten(url)
|
||||
else
|
||||
puts "Cache hit on #{url}"
|
||||
begin
|
||||
@bitly ||= Bitly.new('wezm', 'R_f2bfdace56c886671086eb0c8acb9ce7')
|
||||
@cache ||= {}
|
||||
unless u = @cache[url]
|
||||
u = @bitly.shorten(url)
|
||||
else
|
||||
puts "Cache hit on #{url}"
|
||||
end
|
||||
u.short_url
|
||||
rescue BitlyError
|
||||
nil
|
||||
end
|
||||
u.short_url
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue