Unit Converter API - Ruby Gem

Unit Converter is a simple tool for converting units. It returns the converted value.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_unitconverter'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_unitconverter

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_unitconverter'

# Initialize the client
client = APIVerve::Unitconverter::Client.new(api_key: "YOUR_API_KEY")

# Make a request
response = client.execute({
  value: 100,
  from: "lb",
  to: "kg"
})

# Print the response
puts response

Error Handling

begin
  response = client.execute({ value: 100, from: "lb", to: "kg" })
  puts response["data"]
rescue APIVerve::Unitconverter::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Unitconverter::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

# Enable debug logging
client = APIVerve::Unitconverter::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "result": {
      "result": 45.36,
      "from": "100 lb",
      "to": "kg"
    },
    "unitDefinitions": {
      "from": {
        "abbr": "lb",
        "measure": "mass",
        "system": "imperial",
        "singular": "Pound",
        "plural": "Pounds"
      },
      "to": {
        "abbr": "kg",
        "measure": "mass",
        "system": "metric",
        "singular": "Kilogram",
        "plural": "Kilograms"
      }
    }
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.