Color Brightness Calculator API - Ruby Gem

Color Brightness Calculator is a tool for calculating color brightness and luminance. It determines if a color is light or dark using WCAG 2.0 standards and provides contrast ratios for accessibility compliance.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_colorbrightness'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_colorbrightness

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_colorbrightness'

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

# Make a request
response = client.execute({ hex: "FF5733" })

# Print the response
puts response

Error Handling

begin
  response = client.execute({ hex: "FF5733" })
  puts response["data"]
rescue APIVerve::Colorbrightness::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Colorbrightness::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

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

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "hex": "#FF5733",
    "rgb": {
      "r": 255,
      "g": 87,
      "b": 51
    },
    "luminance": 0.2832,
    "perceived_brightness": 131,
    "yiq": 133.13,
    "is_light": false,
    "is_dark": true,
    "brightness_category": "dark",
    "recommended_text_color": "#FFFFFF",
    "contrast_ratio_with_white": 3.15,
    "contrast_ratio_with_black": 6.66,
    "wcag_aa_compliant_with_white": false,
    "wcag_aa_compliant_with_black": true,
    "wcag_aaa_compliant_with_white": false,
    "wcag_aaa_compliant_with_black": false
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.