diff options
Diffstat (limited to 'lib/rest-client-wrapper.rb')
-rw-r--r-- | lib/rest-client-wrapper.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/rest-client-wrapper.rb b/lib/rest-client-wrapper.rb index 1258339..f3c56c8 100644 --- a/lib/rest-client-wrapper.rb +++ b/lib/rest-client-wrapper.rb @@ -13,13 +13,13 @@ module OpenTox # @return [RestClient::Response] REST call response [:head,:get,:post,:put,:delete].each do |method| - define_singleton_method method do |uri,payload={},headers={}| + define_singleton_method method do |uri,payload={},headers={},waiting_task=nil| - # check input + # check input + bad_request_error "Headers are not a hash: #{headers.inspect}", uri unless headers==nil or headers.is_a?(Hash) @subjectid = headers[:subjectid] ? headers[:subjectid] : nil bad_request_error "Invalid URI: '#{uri}'", uri unless URI.valid? uri #resource_not_found_error "URI '#{uri}' not found.", uri unless URI.accessible?(uri, @subjectid) unless URI.ssl?(uri) - bad_request_error "Headers are not a hash: #{headers.inspect}", uri unless headers==nil or headers.is_a?(Hash) # make sure that no header parameters are set in the payload [:accept,:content_type,:subjectid].each do |header| if defined? $aa || URI(uri).host == URI($aa[:uri]).host @@ -36,6 +36,8 @@ module OpenTox args[:payload] = payload headers.each{ |k,v| headers.delete(k) if v==nil } if headers #remove keys with empty values, as this can cause problems args[:headers] = headers + + $logger.debug "POST #{uri} #{payload.inspect}" if method.to_s=="post" && payload.is_a?(Hash) @request = RestClient::Request.new(args) # ignore error codes from Task services (may return error codes >= 400 according to API, which causes exceptions in RestClient and RDF::Reader) @@ -45,7 +47,8 @@ module OpenTox elsif response.code >= 400 and !URI.task?(uri) message = response.to_s parameters = request.args - parameters[:headers][:subjectid] = "REMOVED" if parameters[:headers] and parameters[:headers][:subjectid] + parameters[:headers][:subjectid] = "REMOVED" if parameters[:headers] and parameters[:headers][:subjectid] + parameters[:url] = parameters[:url].gsub(/(http|https|)\:\/\/[a-zA-Z0-9\-]+\:[a-zA-Z0-9]+\@/, "REMOVED@") if parameters[:url] message += "\nREST parameters:\n#{parameters.inspect}" error = known_errors.collect{|e| e if e[:code] == response.code}.compact.first Object.method(error[:method]).call message, uri # call error method |