Sha256: b94aae27f6aadf04cb7ad30d4f141b3df6cf566f694fb07a310a6af8142e4ca4
Contents?: true
Size: 882 Bytes
Versions: 6
Compression:
Stored size: 882 Bytes
Contents
class Agilibox::GetHTTP < Agilibox::Service class Error < StandardError end EXCEPTIONS_TO_RERAISE = [ IOError, Net::HTTPBadResponse, Net::HTTPExceptions, Net::HTTPHeaderSyntaxError, OpenSSL::SSL::SSLError, SocketError, SystemCallError, Timeout::Error, Zlib::Error, ] TIMEOUT = 10 initialize_with :url def uri uri = URI(url.to_s) raise Error, "invalid URI type : #{uri.class}" unless uri.is_a?(URI::HTTP) uri end def call response = Timeout.timeout(TIMEOUT) do Net::HTTP.get_response(uri) end if response.code.start_with?("3") @url = response["Location"] return call end unless response.code.start_with?("2") raise Error, "invalid response code : #{response.code}" end response.body rescue *EXCEPTIONS_TO_RERAISE => e raise Error, e.message end end
Version data entries
6 entries across 6 versions & 1 rubygems