Ruby Client
The Chemcaster Ruby client offers full access to the Chemcaster RESTful
API through a Ruby interface. It can be used together with a variety
of Ruby-specific tools such as the Ruby on Rails framework to build
rich chemistry applications.
Installation
$ gem sources -a http://gemcutter.org $ sudo gem install chemcaster
The Ruby Client may also be downloaded as a distribution and accessed via Git repository.
Example Use
Connect to Chemcaster
require 'rubygems' require 'chemcaster' service = Chemcaster::Service.connect 'username', 'password'
Because Chemcaster authenticates using SSL, you’ll need to make sure the Ruby HTTP library can find the root SSL certificates on your system. On Debian Linux systems, these files are found in /etc/ssl/certs. This is also the default location used by the Chemcaster Ruby Client.
To override the default SSL certificates path, pass the root_ca option to the connect method:
service = Chemcaster::Service.connect 'username', 'password', :root_ca => 'path/to/root_ssl_certs'
More information on Ruby and SSL can be found here:
Browse Registries
require 'rubygems' require 'chemcaster' service = Chemcaster::Service.connect 'username', 'password' registries = service.registries registries.size # => 3 registry = registries[0] # => a lazy-loaded Registry representation
Load a Registry from a Stored URI
Note: No assumptions should be made about Chemcaster URI layout. Once you receive a resource URI, you can expect it to work at any point in the future for random-access. But URI templates are unnecessary when accessing resources.
require 'rubygems' require 'chemcaster' Chemcaster::Service.connect 'username', 'password' link = Chemcaster::Link.new 'name'=> 'not used', 'uri' => 'https://chemcaster.com/registries/123456', 'media_type' => 'application/vnd.com.chemcaster.Registry+json' registry = link.get
Create a Registry
require 'rubygems' require 'chemcaster' service = Chemcaster::Service.connect 'username', 'password' registries = service.registries registry = registries.create :name => 'CarboBlocks, Inc.'
Change a Registry Name
require 'rubygems' require 'chemcaster' service = Chemcaster::Service.connect 'username', 'password' registry = service.registries[0] registry.update :name => 'CarboBlocks International, Inc.'
Register a Substance
require 'rubygems'
require 'chemcaster'
service = Chemcaster::Service.connect 'username', 'password'
registry = service.registries[0]
# either read a file or generate the string using other means
molfile = File.read '/path/to/stored/molfile'
registration = registry.registrations.create :templates => [
{
:multiplier => 1,
:serialization => molfile
}
]
substance = registration.substance
Development
The Chemcaster Ruby client is distributed under the MIT License and hosted on GitHub, which offers source code managment and issue tracking. The Chemcaster Ruby Gem is available from Gemcutter.
About Chemcaster
Chemcaster is a platform for rapidly creating websites needing chemical structure registration, imaging and search.
We're looking for developers interested in trying Chemcaster during its testing period. Sign up today for a free account!


