diff options
author | rautenberg <rautenberg@in-silico.ch> | 2012-03-28 18:26:19 +0200 |
---|---|---|
committer | rautenberg <rautenberg@in-silico.ch> | 2012-03-28 18:26:19 +0200 |
commit | 0d457e40c005ba4209ec7e3093aa06d73d65a442 (patch) | |
tree | 62e94cb7a05043450405be188b6b40d549d5e0fe | |
parent | 50c3b14a2aa57bff84fe9477c17328e9a382e7ac (diff) |
change for new aa variables
-rw-r--r-- | lib/overwrite.rb | 4 | ||||
-rw-r--r-- | lib/rest-client-wrapper.rb | 5 |
2 files changed, 5 insertions, 4 deletions
diff --git a/lib/overwrite.rb b/lib/overwrite.rb index 4ba6811..d98769e 100644 --- a/lib/overwrite.rb +++ b/lib/overwrite.rb @@ -30,13 +30,13 @@ module URI URI.parse(uri).instance_of? URI::HTTPS end - def self.accessible? uri, subjectid=nil + def self.accessible?(uri, subjectid=nil) if URI.task? uri or URI.compound? uri # just try to get a response, valid tasks may return codes > 400 Net::HTTP.get_response(URI.parse(uri)) true else - Net::HTTP.get_response(URI.parse(uri)).code.to_i < 400 + Net::HTTP.get_response(URI.parse(uri + (subjectid ? "?subjectid=#{CGI.escape subjectid}" : ""))).code.to_i < 400 end rescue false diff --git a/lib/rest-client-wrapper.rb b/lib/rest-client-wrapper.rb index 13ccf09..30292de 100644 --- a/lib/rest-client-wrapper.rb +++ b/lib/rest-client-wrapper.rb @@ -16,12 +16,13 @@ module OpenTox define_singleton_method method do |uri,payload={},headers={}| # check input + @subjectid = headers[:subjectid] ? headers[:subjectid] : nil bad_request_error "Invalid URI: '#{uri}'" unless URI.valid? uri - not_found_error "URI '#{uri}' not found." unless URI.accessible? uri unless URI.ssl?(uri) + not_found_error "URI '#{uri}' not found." unless URI.accessible?(uri, @subjectid) unless URI.ssl?(uri) bad_request_error "Headers are not a hash: #{headers.inspect}" 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| - bad_request_error "#{header} should be submitted in the headers" if payload and payload.is_a?(Hash) and payload[header] unless URI(uri).host == URI(AA).host + bad_request_error "#{header} should be submitted in the headers" if payload and payload.is_a?(Hash) and payload[header] unless URI(uri).host == URI($aa[:uri]).host end # create request |