0.0
No release in over 3 years
This gem provides a convenient way to interact with the Sightengine API for content moderation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 3.18

Runtime

>= 0.18.0
 Project Readme

SightengineRb

This gem provides a convenient way to interact with the Sightengine API for content moderation.

Installation

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

Usage

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'
end

Then, you can create a client instance:

client = SightengineRb::Client.new

And 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')

Text Moderation

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.

Development

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.

Contributing

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.