lib/itrigga/net_helper.rb in itrigga-net_helper-0.0.2 vs lib/itrigga/net_helper.rb in itrigga-net_helper-0.0.3

- old
+ new

@@ -149,31 +149,31 @@ IPSocket::getaddress(server) end # uses the url shortener service defined for this site # by default will use bit.ly - def shorten_url(raw_url,attempts = 0) + def shorten_url(opts={}) + opts[:attempts] ||= 0 + return opts[:url] if opts[:attempts] > 3 - return raw_url if attempts > 3 + api_url = self.format_url_shortener_api_url(opts[:url], opts[:config]) - url = self.format_url_shortener_api_url(raw_url) - begin - response = NetHelper.get :url => url + response = NetHelper.get :url => api_url rescue Exception => e sleep 10 unless defined?(RAILS_ENV) && RAILS_ENV == "test" - return shorten_url(raw_url,attempts+1) + return shorten_url(:url=>opts[:url], :attempts=>opts[:attempts]+1) end data = JSON.parse(response).recursive_symbolize_keys! if data[:status_code] == 200 return data[:data][:url] else # theres been a problem, try again if we have tries left sleep 10 unless defined?(RAILS_ENV) && RAILS_ENV == "test" - return shorten_url(raw_url,attempts+1) + return shorten_url(:url=>opts[:url], :attempts=>opts[:attempts]+1) end end