diff options
Diffstat (limited to 'lib/substance.rb')
-rw-r--r-- | lib/substance.rb | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/substance.rb b/lib/substance.rb index f493714..5d57505 100644 --- a/lib/substance.rb +++ b/lib/substance.rb @@ -1,5 +1,5 @@ # Get all substances -get "/substance/?" do +get "/api/substance/?" do substances = Substance.all case @accept when "text/uri-list" @@ -10,25 +10,25 @@ get "/substance/?" do substances = JSON.parse list.to_json return JSON.pretty_generate substances else - bad_request_error "Mime type #{@accept} is not supported." + halt 400, "Mime type #{@accept} is not supported." end end # Get a substance by ID -get "/substance/:id/?" do +get "/api/substance/:id/?" do case @accept when "application/json" - mongoid = /^[a-f\d]{24}$/i - halt 400, "Input #{params[:id]} is no valid ID.".to_json unless params[:id].match(mongoid) substance = Substance.find params[:id] if substance - out = {"compound": {"id": substance.id, "inchi": substance.inchi, "smiles": substance.smiles, "warnings": substance.warnings}} - response['Content-Type'] = @accept + out = {"compound": {"id": substance.id, + "inchi": substance.inchi, + "smiles": substance.smiles + }} return JSON.pretty_generate JSON.parse(out.to_json) else - halt 400, "Substance with ID #{input} not found." + halt 400, "Substance with ID #{params[:id]} not found." end else - bad_request_error "Mime type #{@accept} is not supported." + halt 400, "Mime type #{@accept} is not supported." end end |