Skip to content

pustserg/sightengine_ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Ruby SDK for https://sightengine.com/

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors