Handle Bit.ly exceptions

Mainly for when there is no internet connection
This commit is contained in:
Wesley Moore 2010-03-03 08:03:51 +11:00
parent 194890e733
commit 9114181bfe

View file

@ -24,14 +24,18 @@ module WezM
end end
def short_url(url) def short_url(url)
@bitly ||= Bitly.new('wezm', 'R_f2bfdace56c886671086eb0c8acb9ce7') begin
@cache ||= {} @bitly ||= Bitly.new('wezm', 'R_f2bfdace56c886671086eb0c8acb9ce7')
unless u = @cache[url] @cache ||= {}
u = @bitly.shorten(url) unless u = @cache[url]
else u = @bitly.shorten(url)
puts "Cache hit on #{url}" else
puts "Cache hit on #{url}"
end
u.short_url
rescue BitlyError
nil
end end
u.short_url
end end
end end