diff options
author | gebele <gebele@in-silico.ch> | 2015-04-09 16:19:48 +0200 |
---|---|---|
committer | gebele <gebele@in-silico.ch> | 2015-04-09 16:19:48 +0200 |
commit | b2f8b7cba9d89fdbe6e3a94487626fd451e91ee8 (patch) | |
tree | 8f88c1195e7690237e39d601a8688f52fc3ae730 | |
parent | 618712edd3d5a2c6af95452def2e605ae382f163 (diff) |
consistent use of RestClientWrapper (update and sparql)
-rw-r--r-- | lib/4store.rb | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/lib/4store.rb b/lib/4store.rb index 8b86c29..98bd575 100644 --- a/lib/4store.rb +++ b/lib/4store.rb @@ -52,19 +52,7 @@ module OpenTox end def self.update sparql - #TODO consider RestClientWrapper call - attempts = 0 - begin - attempts += 1 - RestClient::Resource.new(update_uri, :verify_ssl => 0).post(:update => sparql ) - rescue - if attempts < 4 # 4store may return errors under heavy load - sleep 1 - retry - else - bad_request_error $!.message, update_uri, $!.backtrace - end - end + RestClientWrapper.post update_uri, {:update => sparql} end def self.query sparql, mime_type @@ -72,11 +60,12 @@ module OpenTox # return list unless mime_type case mime_type when 'application/sparql-results+xml' - RestClient::Resource.new(sparql_uri, :verify_ssl => 0).get(:params => { :query => sparql }, :accept => mime_type) + RestClientWrapper.get(sparql_uri+"?query=#{CGI.escape(sparql)}",{}, { :accept => mime_type }) when 'application/json' - RestClient::Resource.new(sparql_uri, :verify_ssl => 0).get(:params => { :query => sparql }, :accept => mime_type) + RestClientWrapper.get(sparql_uri+"?query=#{CGI.escape(sparql)}",{}, { :accept => mime_type }) when /(uri-list|html)/ - uri_list = RestClient::Resource.new(sparql_uri, :verify_ssl => 0).get(:params => { :query => sparql }, :accept => "text/plain").gsub(/"|<|>/,'').split("\n").drop(1).join("\n") + uri_list = RestClientWrapper.get(sparql_uri+"?query=#{CGI.escape(sparql)}",{}, { :accept => "text/plain" }) + uri_list = uri_list.gsub(/"|<|>/,"").split("\n").drop(1).join("\n") uri_list = uri_list.to_html if mime_type=~/html/ return uri_list else @@ -85,9 +74,9 @@ module OpenTox elsif sparql =~ /CONSTRUCT/i case mime_type when "text/plain", "application/rdf+xml" - RestClient::Resource.new(sparql_uri, :verify_ssl => 0).get(:params => { :query => sparql }, :accept => mime_type) + RestClientWrapper.get(sparql_uri+"?query=#{CGI.escape(sparql)}",{}, { :accept => mime_type}) when /turtle/ - nt = RestClient::Resource.new(sparql_uri, :verify_ssl => 0).get(:params => { :query => sparql }, :accept => "text/tab-separated-values") # 4store returns ntriples for turtle + nt = RestClientWrapper.get(sparql_uri+"?query=#{CGI.escape(sparql)}",{},{ :accept => "text/tab-separated-values"}) if !nt.empty? rdf = RDF::Graph.new RDF::Reader.for(:ntriples).new(nt) do |reader| @@ -105,7 +94,7 @@ module OpenTox when /html/ # modified ntriples output, delivers large datasets #TODO optimize representation - nt = RestClient::Resource.new(sparql_uri, :verify_ssl => 0).get(:params => { :query => sparql }, :accept => "text/plain") + nt = RestClientWrapper.get(sparql_uri+"?query=#{CGI.escape(sparql)}",{}, {:accept => "text/plain" }) if !nt.empty? regex = Regexp.new '(https?:\/\/[\S]+)([>"])' bnode = Regexp.new '_:[a-z0-9]*' |