Periodic Table API - Ruby Gem
Periodic Table is a simple tool for getting information about chemical elements. It returns information such as the atomic number, symbol, and more based on the element provided.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_periodictable'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_periodictable
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_periodictable'
# Initialize the client
client = APIVerve::Periodictable::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({ name: "hydrogen" })
# Print the response
puts response
Error Handling
begin
response = client.execute({ name: "hydrogen" })
puts response["data"]
rescue APIVerve::Periodictable::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Periodictable::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Periodictable::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"name": "Hydrogen",
"appearance": "colorless gas",
"atomic_mass": 1.008,
"boil": 20.271,
"category": "diatomic nonmetal",
"density": 0.08988,
"discovered_by": "Henry Cavendish",
"melt": 13.99,
"molar_heat": 28.836,
"named_by": "Antoine Lavoisier",
"number": 1,
"period": 1,
"group": 1,
"phase": "Gas",
"source": "https://en.wikipedia.org/wiki/Hydrogen",
"summary": "Hydrogen is a chemical element with chemical symbol H and atomic number 1. With an atomic weight of 1.00794 u, hydrogen is the lightest element on the periodic table. Its monatomic form (H) is the most abundant chemical substance in the Universe, constituting roughly 75% of all baryonic mass.",
"symbol": "H",
"xpos": 1,
"ypos": 1,
"wxpos": 1,
"wypos": 1,
"shells": [
1
],
"electron_configuration": "1s1",
"electron_configuration_semantic": "1s1",
"electron_affinity": 72.769,
"electronegativity_pauling": 2.2,
"ionization_energies": [
1312
],
"cpk-hex": "ffffff",
"block": "s"
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://apiverve.com/marketplace/periodictable?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.