diff options
author | Christoph Helma <helma@in-silico.de> | 2009-08-15 13:45:32 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.de> | 2009-08-15 13:45:32 +0200 |
commit | 5bf99a0df4e24aef86681814951a9a8c08f5a1e6 (patch) | |
tree | f255c26fc0f962030bb21ae951048ae95a79d69f /lib | |
parent | 75d79c2f6556b466898e40049058199fabfe6dd2 (diff) |
authentification helper added, lazar object added
Diffstat (limited to 'lib')
-rw-r--r-- | lib/helper.rb | 26 | ||||
-rw-r--r-- | lib/opentox-ruby-api-wrapper.rb | 22 |
2 files changed, 44 insertions, 4 deletions
diff --git a/lib/helper.rb b/lib/helper.rb new file mode 100644 index 0000000..a9f451e --- /dev/null +++ b/lib/helper.rb @@ -0,0 +1,26 @@ +helpers do + + # Authentification + def protected! + response['WWW-Authenticate'] = %(Basic realm="Testing HTTP Auth") and \ + throw(:halt, [401, "Not authorized\n"]) and \ + return unless authorized? + end + + def authorized? + @auth ||= Rack::Auth::Basic::Request.new(request.env) + @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['api', API_KEY] + end + + +=begin + def xml(object) + builder do |xml| + xml.instruct! + object.to_xml + end + end +=end + +end + diff --git a/lib/opentox-ruby-api-wrapper.rb b/lib/opentox-ruby-api-wrapper.rb index 70a4580..8e4e28e 100644 --- a/lib/opentox-ruby-api-wrapper.rb +++ b/lib/opentox-ruby-api-wrapper.rb @@ -1,11 +1,12 @@ -require 'rest_client' -require 'crack/xml' -require 'spork' +[ 'rest_client', 'crack/xml', 'spork', 'helper' ].each do |lib| + require lib +end ENV['OPENTOX_COMPOUND'] = 'http://webservices.in-silico.ch/compound/v0/' unless ENV['OPENTOX_COMPOUND'] ENV['OPENTOX_FEATURE'] = 'http://webservices.in-silico.ch/feature/v0/' unless ENV['OPENTOX_FEATURE'] ENV['OPENTOX_DATASET'] = 'http://webservices.in-silico.ch/dataset/v0/' unless ENV['OPENTOX_DATASET'] ENV['OPENTOX_FMINER'] = 'http://webservices.in-silico.ch/fminer/v0/' unless ENV['OPENTOX_FMINER'] +ENV['OPENTOX_LAZAR'] = 'http://webservices.in-silico.ch/lazar/v0/' unless ENV['OPENTOX_LAZAR'] module OpenTox @@ -86,7 +87,6 @@ module OpenTox @uri = params[:uri].to_s elsif params[:name] @uri = RestClient.post ENV['OPENTOX_DATASET'], :name => params[:name] - RestClient.delete @uri + '/associations' end end @@ -140,4 +140,18 @@ module OpenTox end + class Lazar < OpenTox + + # Create a new prediction model from a dataset + def initialize(training_dataset) + @uri = RestClient.post ENV['OPENTOX_LAZAR'] + 'models/' , :dataset_uri => training_dataset.uri + end + + # Predict a compound + def predict(compound) + RestClient.post @uri, :compound_uri => compound.uri + end + + end + end |