Trivia Generator API - Ruby Gem
Trivia is a simple tool for getting trivia questions. It returns a random trivia question based on your selected category.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_trivia'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_trivia
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_trivia'
# Initialize the client
client = APIVerve::Trivia::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({ category: "general" })
# Print the response
puts response
Error Handling
begin
response = client.execute({ category: "general" })
puts response["data"]
rescue APIVerve::Trivia::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Trivia::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Trivia::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"question": "Is the Pink Cadillac the trademark of Mary Kay beauty products?",
"answer": "Yes",
"options": [
"A Yes",
"B No"
],
"category": "general"
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://apiverve.com/marketplace/trivia?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.