Sha256: 1733d24edd350d170837abafa0807d2d1acee14bde6171febf2d403fadbffe25

Contents?: true

Size: 1020 Bytes

Versions: 4

Compression:

Stored size: 1020 Bytes

Contents

# Get all substances
get "/api/substance/?" do
  substances = Substance.all
  case @accept
  when "text/uri-list"
    uri_list = substances.collect{|substance| uri("/substance/#{substance.id}")}
    return uri_list.join("\n") + "\n"
  when "application/json"
    list = substances.collect{|substance| uri("/substance/#{substance.id}")}
    substances = JSON.parse list.to_json
    return JSON.pretty_generate substances
  else
    halt 400, "Mime type #{@accept} is not supported."
  end
end

# Get a substance by ID
get "/api/substance/:id/?" do
  case @accept
  when "application/json"
    substance = Substance.find params[:id]
    if substance
      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 #{params[:id]} not found."
    end
  else
    halt 400, "Mime type #{@accept} is not supported."
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lazar-gui-1.4.2 lib/substance.rb
lazar-gui-1.4.1 lib/substance.rb
lazar-gui-1.4.0 lib/substance.rb
lazar-gui-1.4.0.pre.0 lib/substance.rb