https://github.com/basecamp/rspamd-ruby
Ruby client for Rspamd’s HTTP API
https://github.com/basecamp/rspamd-ruby
Last synced: 11 months ago
JSON representation
Ruby client for Rspamd’s HTTP API
- Host: GitHub
- URL: https://github.com/basecamp/rspamd-ruby
- Owner: basecamp
- License: mit
- Created: 2020-01-21T22:56:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-08-24T02:50:05.000Z (almost 3 years ago)
- Last Synced: 2025-07-18T05:34:51.010Z (11 months ago)
- Language: Ruby
- Size: 36.1 KB
- Stars: 33
- Watchers: 24
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# rspamd-ruby

[](https://rubygems.org/gems/rspamd-ruby)
Ruby client for [Rspamd’s HTTP API](https://rspamd.com/doc/architecture/protocol.html)
## Get started
To install the latest version using [Bundler][bundler]:
```ruby
gem "rspamd-ruby"
```
To manually install `rspamd-ruby` via [Rubygems][rubygems] simply gem install:
```bash
gem install rspamd-ruby
```
If you're not using [Bundler][bundler], you'll need to add `require "rspamd-ruby"` to your Ruby file.
## Usage
Initialize a client with the host and port of an Rspamd controller process:
```ruby
client = Rspamd::Client.new(host: "localhost", port: 11334)
```
Check a message:
```ruby
result = client.check(<<~MIME)
Date: Tue, 21 Jan 2020 21:04:42 +0000
From: Alice
To: Bob
Message-ID: <975bad33-2e76-40c3-89aa-7fe1edcbe7ce@example.com>
Subject: Hello
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Delivered-To: bob@example.com
Hi Bob!
-Alice
MIME
result.spam? # => false
result.ham? # => true
result.score # => 1.2
result.required_score # => 15
result.action # => "no action"
```
Report a message as spam:
```ruby
client.spam!(<<~MIME)
Date: Tue, 21 Jan 2020 21:04:42 +0000
From: Spammer
To: Bob
Message-ID: <975bad33-2e76-40c3-89aa-7fe1edcbe7ce@example.com>
Subject: Hello
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Delivered-To: bob@example.com
Buy some stuff?
MIME
```
Report a message as ham:
```ruby
client.ham!(<<~MIME)
Date: Tue, 21 Jan 2020 21:04:42 +0000
From: Alice
To: Bob
Message-ID: <975bad33-2e76-40c3-89aa-7fe1edcbe7ce@example.com>
Subject: Hello
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Delivered-To: bob@example.com
Hi Bob!
-Alice
MIME
```
## Acknowledgments
rspamd-ruby is [MIT-licensed](MIT-LICENSE) open-source software from [37signals](https://37signals.com/), the creators of [Ruby on Rails](https://rubyonrails.org).
---
© 2023 37signals, LLC.
[bundler]: https://bundler.io
[rubygems]: https://rubygems.org