BMI Calculator API - Ruby Gem
BMI Calculator computes Body Mass Index along with ideal weight ranges, BMR (Basal Metabolic Rate), TDEE (Total Daily Energy Expenditure), calorie targets, and macronutrient recommendations for fitness and health applications.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_bmicalculator'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_bmicalculator
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_bmicalculator'
# Initialize the client
client = APIVerve::Bmicalculator::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({
weight: 180,
height: 70,
unit: "imperial",
age: 30,
gender: "male",
activityLevel: "moderate"
})
# Print the response
puts response
Error Handling
begin
response = client.execute({ weight: 180, height: 70, unit: "imperial", age: 30, gender: "male", activityLevel: "moderate" })
puts response["data"]
rescue APIVerve::Bmicalculator::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Bmicalculator::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Bmicalculator::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"height": "170 cm",
"weight": "70 kg",
"bmi": 24.221453287197235,
"risk": "Low risk",
"summary": "This weight is normal and you are healthy.",
"recommendation": "A BMI between 18.5 and 24.9 falls within the 'normal' weight range according to the World Health Organization. This range is associated with the lowest health risk for conditions such as heart disease, diabetes, and certain cancers. However, it's important to note that BMI is not a perfect measure as it does not account for muscle mass, bone density, overall body composition, and racial and sex differences. Therefore, while it's a useful starting point, it should not be the only measure of one's health."
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://apiverve.com/marketplace/bmicalculator?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.