summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Gemfile6
-rw-r--r--VERSION1
-rw-r--r--api/api.json148
-rw-r--r--application.rb20
-rw-r--r--config.ru5
-rw-r--r--lazar-rest.gemspec23
-rw-r--r--test/api.rb9
-rw-r--r--test/setup.rb6
-rw-r--r--unicorn.rb2
9 files changed, 220 insertions, 0 deletions
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..04af6bd
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,6 @@
+source "https://rubygems.org"
+gemspec
+gem "sinatra"
+gem "haml"
+gem "sass"
+gem "lazar", :path => "../lazar" \ No newline at end of file
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..a13cb90
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.0.1beta \ No newline at end of file
diff --git a/api/api.json b/api/api.json
new file mode 100644
index 0000000..6f9a037
--- /dev/null
+++ b/api/api.json
@@ -0,0 +1,148 @@
+{
+ "swagger": "2.0",
+ "info": {
+ "description": "An REST Webservice for lazar\n",
+ "version": "0.0.1",
+ "title": "Lazar REST Service",
+ "contact": {
+ "name": "in silico toxicology",
+ "email": "service@in-silico.ch"
+ },
+ "license": {
+ "name": "GNU GENERAL PUBLIC LICENSE",
+ "url": "https://github.com/opentox/lazar-rest/blob/master/LICENSE"
+ }
+ },
+ "host": "mr-test.in-silico.ch",
+ "basePath": "/",
+ "schemes": [
+ "https"
+ ],
+ "paths": {
+ "/model": {
+ "get": {
+ "tags": [
+ "model"
+ ],
+ "description": "Get a list of all prediction models",
+ "parameters": [
+ {
+ "name": "accept",
+ "in": "header",
+ "description": "requested Content-Type",
+ "required": true,
+ "type": "string",
+ "enum": [
+ "text/uri-list",
+ "application/json"
+ ]
+ }
+ ],
+ "produces": [
+ "text/uri-list",
+ "application/json"
+ ],
+ "responses": {
+ "200": {
+ "$ref": "#/responses/200"
+ },
+ "400": {
+ "$ref": "#/responses/400"
+ },
+ "401": {
+ "$ref": "#/responses/401"
+ },
+ "404": {
+ "$ref": "#/responses/404"
+ },
+ "500": {
+ "$ref": "#/responses/500"
+ }
+ }
+ }
+ },
+ "/model/{id}": {
+ "post": {
+ "tags": [
+ "model"
+ ],
+ "description": "Predict a compound",
+ "parameters": [
+ {
+ "name": "Content-Type",
+ "in": "header",
+ "description": "body Content-Type",
+ "required": true,
+ "type": "string",
+ "enum": [
+ "text/plain"
+ ]
+ },
+ {
+ "name": "compound",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "$ref": "#/parameters/modelid"
+ }
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "consumes": [
+ "text/plain"
+ ],
+ "responses": {
+ "200": {
+ "$ref": "#/responses/200"
+ },
+ "400": {
+ "$ref": "#/responses/400"
+ },
+ "404": {
+ "$ref": "#/responses/404"
+ }
+ }
+ }
+ }
+ },
+ "parameters": {
+ "modelid": {
+ "name": "id",
+ "in": "path",
+ "description": "model id",
+ "required": true,
+ "type": "string"
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "OK"
+ },
+ "202": {
+ "description": "Accepted"
+ },
+ "400": {
+ "description": "Bad Request"
+ },
+ "401": {
+ "description": "Unauthorized"
+ },
+ "404": {
+ "description": "Resource Not Found"
+ },
+ "500": {
+ "description": "Server Error"
+ }
+ },
+ "tags": [
+ {
+ "name": "model",
+ "description": "Lazar Model Service"
+ }
+ ]
+} \ No newline at end of file
diff --git a/application.rb b/application.rb
new file mode 100644
index 0000000..37de1d0
--- /dev/null
+++ b/application.rb
@@ -0,0 +1,20 @@
+include OpenTox
+
+# add CORS support for swagger
+use Rack::Cors do |config|
+ config.allow do |allow|
+ allow.origins '*'
+ allow.resource "/#{SERVICE}/*",
+ :methods => [:head, :get, :post, :put, :delete, :options],
+ :headers => :any,
+ :max_age => 0
+ end
+end
+
+# route to swagger API file
+get "/api/api.json" do
+ response['Content-Type'] = "application/json"
+ api_file = File.join("api", "api.json")
+ bad_request_error "API Documentation in Swagger JSON is not implemented.", uri("/#{SERVICE}/api") unless File.exists?(api_file)
+ File.read(api_file)
+end
diff --git a/config.ru b/config.ru
new file mode 100644
index 0000000..8a70672
--- /dev/null
+++ b/config.ru
@@ -0,0 +1,5 @@
+SERVICE = "lazar-rest"
+require 'bundler'
+Bundler.require
+require File.expand_path './application.rb'
+run Sinatra::Application \ No newline at end of file
diff --git a/lazar-rest.gemspec b/lazar-rest.gemspec
new file mode 100644
index 0000000..525865f
--- /dev/null
+++ b/lazar-rest.gemspec
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = "lazar-rest"
+ s.version = File.read("./VERSION")
+ s.authors = ["Christoph Helma","Micha Rautenberg","Denis Gebele"]
+ s.email = ["helma@in-silico.ch","rautenberg@in-silico.ch","gebele@in-silico.ch"]
+ s.homepage = "http://github.com/opentox/lazar-rest"
+ s.summary = %q{lazar-rest}
+ s.description = %q{REST Interface for Lazar Toxicology Predictions}
+ s.license = 'GPL-3'
+
+ s.rubyforge_project = "lazar-rest"
+
+ s.files = `git ls-files`.split("\n")
+ s.required_ruby_version = '>= 1.9.2'
+
+ s.add_runtime_dependency "lazar"
+ s.add_runtime_dependency "sinatra"
+ s.add_runtime_dependency "haml"
+ s.add_runtime_dependency "sass"
+ s.add_runtime_dependency "unicorn"
+end \ No newline at end of file
diff --git a/test/api.rb b/test/api.rb
new file mode 100644
index 0000000..d4987e2
--- /dev/null
+++ b/test/api.rb
@@ -0,0 +1,9 @@
+require_relative "setup.rb"
+
+class ApiTest < MiniTest::Test
+
+ def test_0_api_get
+
+ end
+
+end \ No newline at end of file
diff --git a/test/setup.rb b/test/setup.rb
new file mode 100644
index 0000000..af95126
--- /dev/null
+++ b/test/setup.rb
@@ -0,0 +1,6 @@
+require 'minitest/autorun'
+
+require_relative '../../lazar/lib/lazar.rb'
+#include OpenTox
+TEST_DIR ||= File.expand_path(File.dirname(__FILE__))
+DATA_DIR ||= File.join(TEST_DIR,"data")
diff --git a/unicorn.rb b/unicorn.rb
new file mode 100644
index 0000000..f90ca3f
--- /dev/null
+++ b/unicorn.rb
@@ -0,0 +1,2 @@
+worker_processes 4
+timeout 6000 \ No newline at end of file