This gem provides a convenient way to interact with the Sightengine API for content moderation.
Add this line to your application's Gemfile:
gem 'sightengine-rb'And then execute:
$ bundle install
Or install it yourself as:
$ gem install sightengine-rb
First, configure the client with your API user and secret. You can do this in an initializer file (e.g., config/initializers/sightengine.rb):
SightengineRb.configure do |config|
config.api_user = 'YOUR_API_USER'
config.api_secret = 'YOUR_API_SECRET'
endThen, you can create a client instance:
client = SightengineRb::Client.newAnd make requests to the API. For example, to check an image for nudity:
# Check a remote image
response = client.check('nudity', image_url: 'https://example.com/image.jpg')
# Check a local image
response = client.check('nudity', file: 'path/to/image.jpg')You can moderate text content using rule-based detection:
# Basic text check with default categories
response = client.check_text('Some text to moderate', lang: 'en')
# Check with specific categories
response = client.check_text(
'Some text to moderate',
lang: 'en',
categories: %w[profanity personal link drug weapon]
)
# Check with multiple languages
response = client.check_text('Text to check', lang: 'en,fr,es')
# Check with phone number country detection
response = client.check_text(
'Call me at 555-1234',
lang: 'en',
opt_countries: %w[US CA]
)
# Check with custom blacklist
response = client.check_text('Text to check', lang: 'en', list_id: 'your-list-id')Available categories: profanity, personal, link, drug, weapon, spam, content-trade, money-transaction, extremism, violence, self-harm, medical.
After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/pustserg/sightengine_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.