{"id":20780733,"url":"https://github.com/coderobe/ruby-commonchemistry","last_synced_at":"2025-09-12T17:41:54.153Z","repository":{"id":261488037,"uuid":"884458704","full_name":"coderobe/ruby-commonchemistry","owner":"coderobe","description":"Ruby commonchemistry.cas.org api wrapper","archived":false,"fork":false,"pushed_at":"2024-11-06T20:10:26.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-17T21:58:00.905Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coderobe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-06T19:38:41.000Z","updated_at":"2024-11-06T22:42:40.000Z","dependencies_parsed_at":"2024-11-06T20:43:19.615Z","dependency_job_id":"c2e6eb0d-b0f4-41a5-ab6f-522259248a23","html_url":"https://github.com/coderobe/ruby-commonchemistry","commit_stats":null,"previous_names":["coderobe/ruby-commonchemistry"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/coderobe/ruby-commonchemistry","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderobe%2Fruby-commonchemistry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderobe%2Fruby-commonchemistry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderobe%2Fruby-commonchemistry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderobe%2Fruby-commonchemistry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderobe","download_url":"https://codeload.github.com/coderobe/ruby-commonchemistry/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderobe%2Fruby-commonchemistry/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271415496,"owners_count":24755639,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T13:39:00.423Z","updated_at":"2025-08-21T02:06:12.722Z","avatar_url":"https://github.com/coderobe.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CommonChemistry Ruby Library\n\nA Ruby client library for the [Common Chemistry API](https://commonchemistry.cas.org/api), providing easy access to chemical substance data including search functionality, detailed substance information, and data export capabilities.\n\n## Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n- [Getting Started](#getting-started)\n  - [Initialization](#initialization)\n  - [Search Substances](#search-substances)\n  - [Get Substance Details](#get-substance-details)\n  - [Export Substance Data](#export-substance-data)\n- [Classes and Data Models](#classes-and-data-models)\n- [Error Handling](#error-handling)\n\n## Features\n\n- **Search Substances**: Find substances by name, CAS Registry Number, or other identifiers.\n- **Detailed Information**: Retrieve comprehensive data about a substance, including molecular properties and synonyms.\n- **Data Export**: Export substance data in plain text format.\n- **Error Handling**: Custom exceptions for graceful error management.\n- **Easy Integration**: Designed to be simple and idiomatic for Ruby developers.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'commonchemistry'\n```\n\nOr install it yourself with:\n\n```shell\ngem install commonchemistry\n```\n\n**Note**: Depends on httparty:\n\n```shell\ngem install httparty\n```\n\n## Getting Started\n\n### Initialization\n\nBegin by requiring the library and initializing a new client:\n\n```ruby\nrequire 'commonchemistry'\n\nclient = CommonChemistry::Client.new\n```\n\n### Search Substances\n\nSearch for substances using the `search` method:\n\n```ruby\nsearch_results = client.search(q: 'water', offset: 0, size: 10)\n\nputs \"Total Results: #{search_results.count}\"\nsearch_results.results.each do |result|\n  puts \"Name: #{result.name}, RN: #{result.rn}\"\n  # Optionally save the SVG image\n  # result.save_image(\"#{result.rn}.svg\")\nend\n```\n\n**Parameters**:\n\n- `q` (String): The search query.\n- `offset` (Integer, optional): The offset for pagination.\n- `size` (Integer, optional): The number of results to return.\n\n### Get Substance Details\n\nRetrieve detailed information about a substance:\n\n```ruby\ndetail = client.detail(cas_rn: '7732-18-5')\n\nputs \"Name: #{detail.name}\"\nputs \"Molecular Formula: #{detail.molecular_formula}\"\nputs \"Molecular Mass: #{detail.molecular_mass}\"\n\n# Experimental Properties\ndetail.experimental_properties.each do |prop|\n  puts \"#{prop.name}: #{prop.property} (Source #{prop.source_number})\"\nend\n\n# Synonyms\nputs \"Synonyms: #{detail.synonyms.join(', ')}\"\n\n# Save the SVG image\n# detail.save_image(\"#{detail.rn}.svg\")\n```\n\n**Parameters**:\n\n- `cas_rn` (String, optional): The CAS Registry Number of the substance.\n- `uri` (String, optional): The URI of the substance.\n\n### Export Substance Data\n\nExport substance data in plain text format:\n\n```ruby\nexport_data = client.export(uri: detail.uri)\nputs export_data\n```\n\n**Parameters**:\n\n- `uri` (String): The URI of the substance.\n- `return_as_attachment` (Boolean, optional): Whether to return the data as an attachment.\n\n## Classes and Data Models\n\n### Client\n\nThe main class for interacting with the API.\n\n- `search(q:, offset: nil, size: nil)`: Searches for substances.\n- `detail(cas_rn: nil, uri: nil)`: Retrieves detailed substance information.\n- `export(uri:, return_as_attachment: false)`: Exports substance data.\n\n### SearchResponse\n\nRepresents the response from a search query.\n\n- `count` (Integer): Total number of results.\n- `results` (Array of `SearchResult`): List of search results.\n\n### SearchResult\n\nRepresents an individual search result.\n\n- `rn` (String): CAS Registry Number.\n- `name` (String): Substance name.\n- `image` (String): SVG image data.\n\n### DetailResult\n\nContains detailed information about a substance.\n\n- `uri` (String)\n- `rn` (String)\n- `name` (String)\n- `image` (String)\n- `inchi` (String)\n- `inchi_key` (String)\n- `smile` (String)\n- `canonical_smile` (String)\n- `molecular_formula` (String)\n- `molecular_mass` (Float)\n- `experimental_properties` (Array of `ExperimentalProperty`)\n- `property_citations` (Array of `PropertyCitation`)\n- `synonyms` (Array of `String`)\n- `replaced_rns` (Array of `String`)\n\n### ExperimentalProperty\n\nRepresents an experimental property of a substance.\n\n- `name` (String)\n- `property` (String)\n- `source_number` (Integer)\n\n### PropertyCitation\n\nRepresents a citation for a property.\n\n- `doc_uri` (String)\n- `source_number` (Integer)\n- `source` (String)\n\n## Error Handling\n\nThe library defines custom exceptions for better error management:\n\n- `CommonChemistry::InvalidRequestError`: Raised for invalid requests (HTTP 400, 404).\n- `CommonChemistry::ServerError`: Raised when the server returns an internal error (HTTP 500).\n- `CommonChemistry::UnexpectedResponseError`: Raised for any other unexpected HTTP responses.\n\n**Example**:\n\n```ruby\nbegin\n  detail = client.detail(cas_rn: 'invalid-cas-rn')\nrescue CommonChemistry::InvalidRequestError =\u003e e\n  puts \"Request Error: #{e.message}\"\nrescue CommonChemistry::ServerError =\u003e e\n  puts \"Server Error: #{e.message}\"\nrescue CommonChemistry::Error =\u003e e\n  puts \"An error occurred: #{e.message}\"\nend\n```\n\n---\n\n*Disclaimer: This library is not affiliated with or endorsed by its upstream. Use responsibly.*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderobe%2Fruby-commonchemistry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderobe%2Fruby-commonchemistry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderobe%2Fruby-commonchemistry/lists"}