Dice Roller API - Ruby Gem

Dice Roller is a tool for rolling dice using standard RPG notation (XdY format). It supports multiple dice, various die sizes, modifiers, and provides statistics including min, max, average, and theoretical values for gaming and simulations.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_diceroller'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_diceroller

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_diceroller'

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

# Make a request
response = client.execute({
  dice: "1d6",
  modifier: 5
})

# Print the response
puts response

Error Handling

begin
  response = client.execute({ dice: "1d6", modifier: 5 })
  puts response["data"]
rescue APIVerve::Diceroller::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Diceroller::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

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

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "dice_notation": "3d6",
    "num_dice": 3,
    "num_sides": 6,
    "modifier": 5,
    "rolls": [
      6,
      4,
      4
    ],
    "total": 14,
    "total_with_modifier": 19,
    "min_roll": 4,
    "max_roll": 6,
    "average_roll": 4.67,
    "theoretical_min": 3,
    "theoretical_max": 18,
    "theoretical_average": 10.5,
    "expression": "3d6+5"
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.