lib/potato/damn/token.rb in potato-0.0.12 vs lib/potato/damn/token.rb in potato-0.0.13

- old
+ new

@@ -13,10 +13,23 @@ '%' + $1.unpack("U*")[0].to_s(16) end end.join("&") end + def wait_for_internet + begin + s = TCPSocket.new("google.com", 80) + s.close + rescue Errno::ECONNREFUSED + return true + rescue SocketError + sleep 10 + retry + end + return true + end + # Gets an authtoken. # @param [String] username # @param [String] password # @return [String, nil] def get username, password @@ -44,9 +57,13 @@ end end rescue Errno::ECONNRESET warn "Connection reset by peer when attempting to retrieve authtoken." nil + rescue SocketError + warn "Lost internet connection. Waiting for availability." + wait_for_internet + retry end end end end end \ No newline at end of file