Class: Agilibox::GetHTTP
- Defined in:
- app/libs/agilibox/get_http.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- EXCEPTIONS_TO_RERAISE =
[ IOError, Net::HTTPBadResponse, Net::HTTPExceptions, Net::HTTPHeaderSyntaxError, OpenSSL::SSL::SSLError, SocketError, SystemCallError, Timeout::Error, Zlib::Error, ]
- TIMEOUT =
10
Instance Method Summary collapse
Methods inherited from Service
Instance Method Details
#call ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/libs/agilibox/get_http.rb', line 27 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. end |
#uri ⇒ Object
21 22 23 24 25 |
# File 'app/libs/agilibox/get_http.rb', line 21 def uri uri = URI(url.to_s) raise Error, "invalid URI type : #{uri.class}" unless uri.is_a?(URI::HTTP) uri end |