Coin Flipper API - Ruby Gem
Coin Flipper is a tool for simulating coin flips. It can flip multiple coins at once and provides statistics including heads/tails counts, percentages, streaks, and fairness analysis for probability experiments and gaming.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_coinflipper'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_coinflipper
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_coinflipper'
# Initialize the client
client = APIVerve::Coinflipper::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({ flips: 1 })
# Print the response
puts response
Error Handling
begin
response = client.execute({ flips: 1 })
puts response["data"]
rescue APIVerve::Coinflipper::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Coinflipper::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Coinflipper::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"total_flips": 10,
"flips": [
"Tails",
"Heads",
"Heads",
"Tails",
"Tails",
"Heads",
"Tails",
"Tails",
"Tails",
"Tails"
],
"heads_count": 3,
"tails_count": 7,
"heads_percentage": 30,
"tails_percentage": 70,
"longest_streak": {
"length": 4,
"type": "Tails"
},
"first_flip": "Tails",
"last_flip": "Tails",
"is_fair": false
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://apiverve.com/marketplace/coinflipper?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.