Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "2.17.1"
".": "2.18.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 27
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api/moderation-api-e864d762f50e49c0584bbf35eacc43cdb1397f805cca52cb8d4c07781739d0a3.yml
openapi_spec_hash: f511fefb34946e5878ac17f2b3056b1f
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api/moderation-api-3bb06bde0f76baa35ecc698b0c60371c9eadfd7b58c00b77cbc124d5be5dcb8b.yml
openapi_spec_hash: b4339d93d43fb725be0e98bd3bbf4f0b
config_hash: 9d144cc6c49d3fd53e5b4472c1e22165
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 2.18.0 (2026-05-19)

Full Changelog: [v2.17.1...v2.18.0](https://github.com/moderation-api/sdk-ruby/compare/v2.17.1...v2.18.0)

### Features

* **api:** api update ([0b267b1](https://github.com/moderation-api/sdk-ruby/commit/0b267b13d3574e2c3b9d88114502d81541f595c1))

## 2.17.1 (2026-05-14)

Full Changelog: [v2.17.0...v2.17.1](https://github.com/moderation-api/sdk-ruby/compare/v2.17.0...v2.17.1)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GIT
PATH
remote: .
specs:
moderation_api (2.17.1)
moderation_api (2.18.0)
cgi
connection_pool

Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To use this gem, install via Bundler by adding the following to your application
<!-- x-release-please-start-version -->

```ruby
gem "moderation_api", "~> 2.17.1"
gem "moderation_api", "~> 2.18.0"
```

<!-- x-release-please-end -->
Expand All @@ -30,7 +30,7 @@ moderation_api = ModerationAPI::Client.new(
secret_key: ENV["MODAPI_SECRET_KEY"] # This is the default and can be omitted
)

response = moderation_api.content.submit(content: {text: "x", type: "text"})
response = moderation_api.content.submit(content: {text: "text", type: "text"})

puts(response.recommendation)
```
Expand All @@ -41,7 +41,7 @@ When the library is unable to connect to the API, or if the API returns a non-su

```ruby
begin
content = moderation_api.content.submit(content: {text: "x", type: "text"})
content = moderation_api.content.submit(content: {text: "text", type: "text"})
rescue ModerationAPI::Errors::APIConnectionError => e
puts("The server could not be reached")
puts(e.cause) # an underlying Exception, likely raised within `net/http`
Expand Down Expand Up @@ -84,7 +84,7 @@ moderation_api = ModerationAPI::Client.new(
)

# Or, configure per-request:
moderation_api.content.submit(content: {text: "x", type: "text"}, request_options: {max_retries: 5})
moderation_api.content.submit(content: {text: "text", type: "text"}, request_options: {max_retries: 5})
```

### Timeouts
Expand All @@ -98,7 +98,7 @@ moderation_api = ModerationAPI::Client.new(
)

# Or, configure per-request:
moderation_api.content.submit(content: {text: "x", type: "text"}, request_options: {timeout: 5})
moderation_api.content.submit(content: {text: "text", type: "text"}, request_options: {timeout: 5})
```

On timeout, `ModerationAPI::Errors::APITimeoutError` is raised.
Expand Down Expand Up @@ -130,7 +130,7 @@ Note: the `extra_` parameters of the same name overrides the documented paramete
```ruby
response =
moderation_api.content.submit(
content: {text: "x", type: "text"},
content: {text: "text", type: "text"},
request_options: {
extra_query: {my_query_parameter: value},
extra_body: {my_body_parameter: value},
Expand Down Expand Up @@ -176,18 +176,20 @@ This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitio
You can provide typesafe request parameters like so:

```ruby
moderation_api.content.submit(content: ModerationAPI::ContentSubmitParams::Content::Text.new(text: "x"))
moderation_api.content.submit(
content: ModerationAPI::ContentSubmitParams::Content::Text.new(text: "text")
)
```

Or, equivalently:

```ruby
# Hashes work, but are not typesafe:
moderation_api.content.submit(content: {text: "x", type: "text"})
moderation_api.content.submit(content: {text: "text", type: "text"})

# You can also splat a full Params class:
params = ModerationAPI::ContentSubmitParams.new(
content: ModerationAPI::ContentSubmitParams::Content::Text.new(text: "x")
content: ModerationAPI::ContentSubmitParams::Content::Text.new(text: "text")
)
moderation_api.content.submit(**params)
```
Expand Down
2 changes: 1 addition & 1 deletion lib/moderation_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ModerationAPI
VERSION = "2.17.1"
VERSION = "2.18.0"
end
36 changes: 21 additions & 15 deletions test/moderation_api/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_client_default_request_default_retry_attempts
moderation_api = ModerationAPI::Client.new(base_url: "http://localhost", secret_key: "My Secret Key")

assert_raises(ModerationAPI::Errors::InternalServerError) do
moderation_api.content.submit(content: {text: "x", type: :text})
moderation_api.content.submit(content: {text: "text", type: :text})
end

assert_requested(:any, /./, times: 3)
Expand All @@ -53,7 +53,7 @@ def test_client_given_request_default_retry_attempts
ModerationAPI::Client.new(base_url: "http://localhost", secret_key: "My Secret Key", max_retries: 3)

assert_raises(ModerationAPI::Errors::InternalServerError) do
moderation_api.content.submit(content: {text: "x", type: :text})
moderation_api.content.submit(content: {text: "text", type: :text})
end

assert_requested(:any, /./, times: 4)
Expand All @@ -65,7 +65,7 @@ def test_client_default_request_given_retry_attempts
moderation_api = ModerationAPI::Client.new(base_url: "http://localhost", secret_key: "My Secret Key")

assert_raises(ModerationAPI::Errors::InternalServerError) do
moderation_api.content.submit(content: {text: "x", type: :text}, request_options: {max_retries: 3})
moderation_api.content.submit(content: {text: "text", type: :text}, request_options: {max_retries: 3})
end

assert_requested(:any, /./, times: 4)
Expand All @@ -78,7 +78,7 @@ def test_client_given_request_given_retry_attempts
ModerationAPI::Client.new(base_url: "http://localhost", secret_key: "My Secret Key", max_retries: 3)

assert_raises(ModerationAPI::Errors::InternalServerError) do
moderation_api.content.submit(content: {text: "x", type: :text}, request_options: {max_retries: 4})
moderation_api.content.submit(content: {text: "text", type: :text}, request_options: {max_retries: 4})
end

assert_requested(:any, /./, times: 5)
Expand All @@ -95,7 +95,7 @@ def test_client_retry_after_seconds
ModerationAPI::Client.new(base_url: "http://localhost", secret_key: "My Secret Key", max_retries: 1)

assert_raises(ModerationAPI::Errors::InternalServerError) do
moderation_api.content.submit(content: {text: "x", type: :text})
moderation_api.content.submit(content: {text: "text", type: :text})
end

assert_requested(:any, /./, times: 2)
Expand All @@ -116,7 +116,7 @@ def test_client_retry_after_date

Thread.current.thread_variable_set(:time_now, time_now)
assert_raises(ModerationAPI::Errors::InternalServerError) do
moderation_api.content.submit(content: {text: "x", type: :text})
moderation_api.content.submit(content: {text: "text", type: :text})
end
Thread.current.thread_variable_set(:time_now, nil)

Expand All @@ -135,7 +135,7 @@ def test_client_retry_after_ms
ModerationAPI::Client.new(base_url: "http://localhost", secret_key: "My Secret Key", max_retries: 1)

assert_raises(ModerationAPI::Errors::InternalServerError) do
moderation_api.content.submit(content: {text: "x", type: :text})
moderation_api.content.submit(content: {text: "text", type: :text})
end

assert_requested(:any, /./, times: 2)
Expand All @@ -148,7 +148,7 @@ def test_retry_count_header
moderation_api = ModerationAPI::Client.new(base_url: "http://localhost", secret_key: "My Secret Key")

assert_raises(ModerationAPI::Errors::InternalServerError) do
moderation_api.content.submit(content: {text: "x", type: :text})
moderation_api.content.submit(content: {text: "text", type: :text})
end

3.times do
Expand All @@ -163,7 +163,7 @@ def test_omit_retry_count_header

assert_raises(ModerationAPI::Errors::InternalServerError) do
moderation_api.content.submit(
content: {text: "x", type: :text},
content: {text: "text", type: :text},
request_options: {extra_headers: {"x-stainless-retry-count" => nil}}
)
end
Expand All @@ -180,7 +180,7 @@ def test_overwrite_retry_count_header

assert_raises(ModerationAPI::Errors::InternalServerError) do
moderation_api.content.submit(
content: {text: "x", type: :text},
content: {text: "text", type: :text},
request_options: {extra_headers: {"x-stainless-retry-count" => "42"}}
)
end
Expand All @@ -202,7 +202,10 @@ def test_client_redirect_307
moderation_api = ModerationAPI::Client.new(base_url: "http://localhost", secret_key: "My Secret Key")

assert_raises(ModerationAPI::Errors::APIConnectionError) do
moderation_api.content.submit(content: {text: "x", type: :text}, request_options: {extra_headers: {}})
moderation_api.content.submit(
content: {text: "text", type: :text},
request_options: {extra_headers: {}}
)
end

recorded, = WebMock::RequestRegistry.instance.requested_signatures.hash.first
Expand Down Expand Up @@ -231,7 +234,10 @@ def test_client_redirect_303
moderation_api = ModerationAPI::Client.new(base_url: "http://localhost", secret_key: "My Secret Key")

assert_raises(ModerationAPI::Errors::APIConnectionError) do
moderation_api.content.submit(content: {text: "x", type: :text}, request_options: {extra_headers: {}})
moderation_api.content.submit(
content: {text: "text", type: :text},
request_options: {extra_headers: {}}
)
end

assert_requested(:get, "http://localhost/redirected", times: ModerationAPI::Client::MAX_REDIRECTS) do
Expand All @@ -256,7 +262,7 @@ def test_client_redirect_auth_keep_same_origin

assert_raises(ModerationAPI::Errors::APIConnectionError) do
moderation_api.content.submit(
content: {text: "x", type: :text},
content: {text: "text", type: :text},
request_options: {extra_headers: {"authorization" => "Bearer xyz"}}
)
end
Expand Down Expand Up @@ -286,7 +292,7 @@ def test_client_redirect_auth_strip_cross_origin

assert_raises(ModerationAPI::Errors::APIConnectionError) do
moderation_api.content.submit(
content: {text: "x", type: :text},
content: {text: "text", type: :text},
request_options: {extra_headers: {"authorization" => "Bearer xyz"}}
)
end
Expand All @@ -302,7 +308,7 @@ def test_default_headers

moderation_api = ModerationAPI::Client.new(base_url: "http://localhost", secret_key: "My Secret Key")

moderation_api.content.submit(content: {text: "x", type: :text})
moderation_api.content.submit(content: {text: "text", type: :text})

assert_requested(:any, /./) do |req|
headers = req.headers.transform_keys(&:downcase)
Expand Down
2 changes: 1 addition & 1 deletion test/moderation_api/resources/content_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ModerationAPI::Test::Resources::ContentTest < ModerationAPI::Test::Resourc
def test_submit_required_params
skip("Mock server tests are disabled")

response = @moderation_api.content.submit(content: {text: "x", type: :text})
response = @moderation_api.content.submit(content: {text: "text", type: :text})

assert_pattern do
response => ModerationAPI::Models::ContentSubmitResponse
Expand Down