class RestClientWrapper
Public Class Methods
new()
click to toggle source
# File lib/cartocss_helper/util/rest-client_wrapper.rb, line 7 def initialize @last_url_fetched = nil end
Public Instance Methods
execute_fetch_data_from_url(url, request_timeout)
click to toggle source
# File lib/cartocss_helper/util/rest-client_wrapper.rb, line 31 def execute_fetch_data_from_url(url, request_timeout) data = RestClient::Request.execute(method: :get, url: url, timeout: request_timeout) # see https://github.com/rest-client/rest-client/issues/370, will be fixed in 2.0 # published versions listed on https://rubygems.org/gems/rest-client/versions/ return String.new(data) end
fetch_data_from_url(url, request_timeout)
click to toggle source
# File lib/cartocss_helper/util/rest-client_wrapper.rb, line 11 def fetch_data_from_url(url, request_timeout) wait if url == @last_url_fetched @last_url_fetched = url return execute_fetch_data_from_url(url, request_timeout) rescue RestClient::RequestTimeout => e raise RequestTimeout, e.to_s rescue RestClient::ExceptionWithResponse => e raise_exception_about_returned_response(e) rescue RestClient::SSLCertificateNotVerified, RestClient::ServerBrokeConnection, SocketError, URI::InvalidURIError raise ExceptionWithoutResponse.new(e), e.to_s rescue ArgumentError => e puts "url:" puts url raise_issue_359_exception(e) rescue => e puts 'unhandled exception! It is a clear bug!' puts "<#{e.class} error happened>" raise e, e.to_s end
raise_exception_about_returned_response(e)
click to toggle source
# File lib/cartocss_helper/util/rest-client_wrapper.rb, line 42 def raise_exception_about_returned_response(e) failure = ExceptionWithResponse.new(e) failure.http_code = e.http_code failure.response = e.response raise failure, e.to_s end
raise_issue_359_exception(e)
click to toggle source
# File lib/cartocss_helper/util/rest-client_wrapper.rb, line 38 def raise_issue_359_exception(e) raise BuggyRestClient, "ArgumentError from rest-client, most likely caused by https://github.com/rest-client/rest-client/issues/359 (requesting GBs of data) [#{e}]" end
wait()
click to toggle source
# File lib/cartocss_helper/util/rest-client_wrapper.rb, line 49 def wait progressbar = ProgressBar.create 100.times do sleep 4 progressbar.increment end end