From 5bf99a0df4e24aef86681814951a9a8c08f5a1e6 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Sat, 15 Aug 2009 13:45:32 +0200 Subject: authentification helper added, lazar object added --- lib/helper.rb | 26 ++++++++++++++++++++++++++ lib/opentox-ruby-api-wrapper.rb | 22 ++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 lib/helper.rb (limited to 'lib') 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 -- cgit v1.2.3