moderation_api 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +59 -104
- data/lib/moderation_api/version.rb +1 -1
- data/lib/moderation_api/webhook.rb +41 -0
- data/moderation_api-1.2.0.gem +0 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b96c2a55f8eb106f72c0942c2baa3580e6953b62cd392b3eda65974e13e86a58
|
4
|
+
data.tar.gz: 898ea1fd212f0097a9a844fc2a406a942f98428cd53c8e5ac50d4a5506bc5153
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 803a8cbf6499f703a2b82560583d88e0b725a607c9598bcff15b5e88f41b920feab7af7d063cb021ecac171892842e6828d56c6d07be32460a876dc0a5303cf9
|
7
|
+
data.tar.gz: f9d66475f7832887ec37f105be250bcf7b58220dd9735a5a664e586f238ee65a89c9c26bfe037289e6e5651c1caa97b21ffc7c9023cde3e7eb0001d211112979
|
data/README.md
CHANGED
@@ -1,15 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# Moderation API Ruby library
|
2
2
|
|
3
|
-
|
3
|
+
The Moderation API Ruby library provides convenient access to the Moderation API from applications written in Ruby.
|
4
4
|
|
5
|
-
API for
|
5
|
+
Use the Moderation API to analyze text and images for offensive content, profanity, toxicity, discrimination, sentiment, language and more - or detect, hide, and extract data entities like emails, phone numbers, addresses and more.
|
6
6
|
|
7
|
-
|
7
|
+
## Documentation
|
8
8
|
|
9
|
-
|
10
|
-
- Package version: 1.2.0
|
11
|
-
- Generator version: 7.10.0
|
12
|
-
- Build package: org.openapitools.codegen.languages.RubyClientCodegen
|
9
|
+
See the [Moderation API docs](https://docs.moderationapi.com) for Ruby.
|
13
10
|
|
14
11
|
## Installation
|
15
12
|
|
@@ -31,114 +28,72 @@ Or install it yourself as:
|
|
31
28
|
gem install moderation_api
|
32
29
|
```
|
33
30
|
|
34
|
-
##
|
31
|
+
## Usage
|
35
32
|
|
36
|
-
|
33
|
+
The package needs to be configured with your project's API key, which is
|
34
|
+
available in your [Project Dashboard](https://moderationapi.com/app/projects). Configure the client with your key:
|
37
35
|
|
38
36
|
```ruby
|
39
|
-
# Load the gem
|
40
37
|
require 'moderation_api'
|
41
38
|
|
42
|
-
# Setup authorization
|
43
39
|
ModerationAPI.configure do |config|
|
44
|
-
|
45
|
-
config.access_token = 'YOUR_BEARER_TOKEN'
|
46
|
-
# Configure a proc to get access tokens in lieu of the static access_token configuration
|
47
|
-
config.access_token_getter = -> { 'YOUR TOKEN GETTER PROC' }
|
48
|
-
# Configure faraday connection
|
49
|
-
config.configure_faraday_connection { |connection| 'YOUR CONNECTION CONFIG PROC' }
|
40
|
+
config.access_token = 'proj_...'
|
50
41
|
end
|
51
42
|
|
52
|
-
|
43
|
+
api = ModerationAPI::ModerateApi.new
|
53
44
|
|
54
45
|
begin
|
55
|
-
|
56
|
-
|
57
|
-
p result
|
46
|
+
analysis = api.moderation_text({value: 'Hello world!'})
|
47
|
+
puts analysis.flagged
|
58
48
|
rescue ModerationAPI::ApiError => e
|
59
|
-
puts "
|
49
|
+
puts "Error: #{e}"
|
60
50
|
end
|
51
|
+
```
|
52
|
+
|
53
|
+
### Webhook signing
|
54
|
+
|
55
|
+
Moderation API can optionally sign the webhook events it sends to your endpoint, allowing you to validate that they were not sent by a third-party. You can read more about it [here](https://docs.moderationapi.com/review-queues/webhooks).
|
61
56
|
|
57
|
+
Here's an example using Rails:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
class WebhooksController < ApplicationController
|
61
|
+
skip_before_action :verify_authenticity_token
|
62
|
+
|
63
|
+
def create
|
64
|
+
payload = request.body.read
|
65
|
+
sig_header = request.env['HTTP_MODAPI_SIGNATURE']
|
66
|
+
|
67
|
+
begin
|
68
|
+
event_data = ModerationAPI::Webhook.construct_event(
|
69
|
+
payload, sig_header, ENV['MODAPI_WEBHOOK_SECRET']
|
70
|
+
)
|
71
|
+
rescue JSON::ParserError => e
|
72
|
+
return render plain: "Invalid payload: #{e}", status: 400
|
73
|
+
rescue ModerationAPI::Webhook::SignatureVerificationError => e
|
74
|
+
return render plain: "Invalid signature: #{e}", status: 400
|
75
|
+
end
|
76
|
+
|
77
|
+
# Handle the event
|
78
|
+
puts "Webhook received! #{event_data[:type]}"
|
79
|
+
|
80
|
+
head :ok
|
81
|
+
end
|
82
|
+
end
|
62
83
|
```
|
63
84
|
|
64
|
-
##
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
| _ModerationAPI::QueueActionsApi_ | [**actions_execute_deprecated**](docs/QueueActionsApi.md#actions_execute_deprecated) | **POST** /actions/{actionId}/execute | Execute an action |
|
80
|
-
| _ModerationAPI::QueueActionsApi_ | [**actions_get**](docs/QueueActionsApi.md#actions_get) | **GET** /actions/{id} | Get an action |
|
81
|
-
| _ModerationAPI::QueueActionsApi_ | [**actions_list**](docs/QueueActionsApi.md#actions_list) | **GET** /actions | List actions |
|
82
|
-
| _ModerationAPI::QueueActionsApi_ | [**actions_update**](docs/QueueActionsApi.md#actions_update) | **PUT** /actions/{id} | Update an action |
|
83
|
-
|
84
|
-
## Documentation for Models
|
85
|
-
|
86
|
-
- [ModerationAPI::AccountGet200Response](docs/AccountGet200Response.md)
|
87
|
-
- [ModerationAPI::AccountGet200ResponseCurrentProject](docs/AccountGet200ResponseCurrentProject.md)
|
88
|
-
- [ModerationAPI::ActionsCreateRequest](docs/ActionsCreateRequest.md)
|
89
|
-
- [ModerationAPI::ActionsCreateRequestWebhooksInner](docs/ActionsCreateRequestWebhooksInner.md)
|
90
|
-
- [ModerationAPI::ActionsDelete200Response](docs/ActionsDelete200Response.md)
|
91
|
-
- [ModerationAPI::ActionsExecute200Response](docs/ActionsExecute200Response.md)
|
92
|
-
- [ModerationAPI::ActionsExecuteDeprecatedRequest](docs/ActionsExecuteDeprecatedRequest.md)
|
93
|
-
- [ModerationAPI::ActionsExecuteRequest](docs/ActionsExecuteRequest.md)
|
94
|
-
- [ModerationAPI::ActionsGet200Response](docs/ActionsGet200Response.md)
|
95
|
-
- [ModerationAPI::ActionsGet200ResponseWebhooksInner](docs/ActionsGet200ResponseWebhooksInner.md)
|
96
|
-
- [ModerationAPI::ActionsList200ResponseInner](docs/ActionsList200ResponseInner.md)
|
97
|
-
- [ModerationAPI::ActionsList200ResponseInnerPossibleValuesInner](docs/ActionsList200ResponseInnerPossibleValuesInner.md)
|
98
|
-
- [ModerationAPI::ActionsList400Response](docs/ActionsList400Response.md)
|
99
|
-
- [ModerationAPI::ActionsList400ResponseIssuesInner](docs/ActionsList400ResponseIssuesInner.md)
|
100
|
-
- [ModerationAPI::ActionsUpdateRequest](docs/ActionsUpdateRequest.md)
|
101
|
-
- [ModerationAPI::ModerationAudioRequest](docs/ModerationAudioRequest.md)
|
102
|
-
- [ModerationAPI::ModerationImage200Response](docs/ModerationImage200Response.md)
|
103
|
-
- [ModerationAPI::ModerationImage200ResponseLabelsInner](docs/ModerationImage200ResponseLabelsInner.md)
|
104
|
-
- [ModerationAPI::ModerationImageRequest](docs/ModerationImageRequest.md)
|
105
|
-
- [ModerationAPI::ModerationObject200Response](docs/ModerationObject200Response.md)
|
106
|
-
- [ModerationAPI::ModerationObject200ResponseAllOfEntitiesInner](docs/ModerationObject200ResponseAllOfEntitiesInner.md)
|
107
|
-
- [ModerationAPI::ModerationObject200ResponseAllOfFieldsInner](docs/ModerationObject200ResponseAllOfFieldsInner.md)
|
108
|
-
- [ModerationAPI::ModerationObject200ResponseAllOfLabelsInner](docs/ModerationObject200ResponseAllOfLabelsInner.md)
|
109
|
-
- [ModerationAPI::ModerationObjectRequest](docs/ModerationObjectRequest.md)
|
110
|
-
- [ModerationAPI::ModerationObjectRequestValue](docs/ModerationObjectRequestValue.md)
|
111
|
-
- [ModerationAPI::ModerationObjectRequestValueDataValue](docs/ModerationObjectRequestValueDataValue.md)
|
112
|
-
- [ModerationAPI::ModerationText200Response](docs/ModerationText200Response.md)
|
113
|
-
- [ModerationAPI::ModerationText200ResponseAllOfAddress](docs/ModerationText200ResponseAllOfAddress.md)
|
114
|
-
- [ModerationAPI::ModerationText200ResponseAllOfEmail](docs/ModerationText200ResponseAllOfEmail.md)
|
115
|
-
- [ModerationAPI::ModerationText200ResponseAllOfName](docs/ModerationText200ResponseAllOfName.md)
|
116
|
-
- [ModerationAPI::ModerationText200ResponseAllOfNsfw](docs/ModerationText200ResponseAllOfNsfw.md)
|
117
|
-
- [ModerationAPI::ModerationText200ResponseAllOfNsfwLabelScores](docs/ModerationText200ResponseAllOfNsfwLabelScores.md)
|
118
|
-
- [ModerationAPI::ModerationText200ResponseAllOfPhone](docs/ModerationText200ResponseAllOfPhone.md)
|
119
|
-
- [ModerationAPI::ModerationText200ResponseAllOfProfanity](docs/ModerationText200ResponseAllOfProfanity.md)
|
120
|
-
- [ModerationAPI::ModerationText200ResponseAllOfPropriety](docs/ModerationText200ResponseAllOfPropriety.md)
|
121
|
-
- [ModerationAPI::ModerationText200ResponseAllOfProprietyLabelScores](docs/ModerationText200ResponseAllOfProprietyLabelScores.md)
|
122
|
-
- [ModerationAPI::ModerationText200ResponseAllOfQuality](docs/ModerationText200ResponseAllOfQuality.md)
|
123
|
-
- [ModerationAPI::ModerationText200ResponseAllOfQualityLabelScores](docs/ModerationText200ResponseAllOfQualityLabelScores.md)
|
124
|
-
- [ModerationAPI::ModerationText200ResponseAllOfRequest](docs/ModerationText200ResponseAllOfRequest.md)
|
125
|
-
- [ModerationAPI::ModerationText200ResponseAllOfSensitive](docs/ModerationText200ResponseAllOfSensitive.md)
|
126
|
-
- [ModerationAPI::ModerationText200ResponseAllOfSentiment](docs/ModerationText200ResponseAllOfSentiment.md)
|
127
|
-
- [ModerationAPI::ModerationText200ResponseAllOfSentimentLabelScores](docs/ModerationText200ResponseAllOfSentimentLabelScores.md)
|
128
|
-
- [ModerationAPI::ModerationText200ResponseAllOfToxicity](docs/ModerationText200ResponseAllOfToxicity.md)
|
129
|
-
- [ModerationAPI::ModerationText200ResponseAllOfToxicityLabelScores](docs/ModerationText200ResponseAllOfToxicityLabelScores.md)
|
130
|
-
- [ModerationAPI::ModerationText200ResponseAllOfUrl](docs/ModerationText200ResponseAllOfUrl.md)
|
131
|
-
- [ModerationAPI::ModerationText200ResponseAllOfUsername](docs/ModerationText200ResponseAllOfUsername.md)
|
132
|
-
- [ModerationAPI::ModerationText200ResponseAllOfWordlist](docs/ModerationText200ResponseAllOfWordlist.md)
|
133
|
-
- [ModerationAPI::ModerationText200ResponseAllOfWordlistsInner](docs/ModerationText200ResponseAllOfWordlistsInner.md)
|
134
|
-
- [ModerationAPI::ModerationTextRequest](docs/ModerationTextRequest.md)
|
135
|
-
- [ModerationAPI::ModerationVideo200Response](docs/ModerationVideo200Response.md)
|
136
|
-
- [ModerationAPI::ModerationVideoRequest](docs/ModerationVideoRequest.md)
|
137
|
-
|
138
|
-
## Documentation for Authorization
|
139
|
-
|
140
|
-
Authentication schemes defined for the API:
|
141
|
-
|
142
|
-
### Authorization
|
143
|
-
|
144
|
-
- **Type**: Bearer authentication
|
85
|
+
## Support
|
86
|
+
|
87
|
+
New features and bug fixes are released on the latest major version of the `moderation_api` gem. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.
|
88
|
+
|
89
|
+
## Email support
|
90
|
+
|
91
|
+
Reach out at [support@moderationapi.com](mailto:support@moderationapi.com)
|
92
|
+
|
93
|
+
## More Information
|
94
|
+
|
95
|
+
- [REST API Reference](https://docs.moderationapi.com/api-reference/introduction)
|
96
|
+
- [Rate limits](https://docs.moderationapi.com/api-reference/rate-limits)
|
97
|
+
- [Error Handling](https://docs.moderationapi.com/api-reference/errors)
|
98
|
+
- [Documentation](https://docs.moderationapi.com/get-started/introduction)
|
99
|
+
- [Test your API key](https://docs.moderationapi.com/api-reference/authentication)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'openssl'
|
5
|
+
|
6
|
+
module ModerationAPI
|
7
|
+
class Webhook
|
8
|
+
class SignatureVerificationError < StandardError; end
|
9
|
+
|
10
|
+
# This method attempts to verify the webhook signature from Moderation API.
|
11
|
+
# payload: The raw request body
|
12
|
+
# sig_header: The 'HTTP_MODAPI_SIGNATURE' header from the request
|
13
|
+
# secret: Your webhook signing secret
|
14
|
+
#
|
15
|
+
def self.construct_event(payload, sig_header, secret)
|
16
|
+
# Verify the signature
|
17
|
+
digest = OpenSSL::Digest.new('sha256')
|
18
|
+
signed = OpenSSL::HMAC.hexdigest(digest, secret, payload)
|
19
|
+
|
20
|
+
if secure_compare(signed, sig_header)
|
21
|
+
JSON.parse(payload, symbolize_names: true)
|
22
|
+
else
|
23
|
+
raise SignatureVerificationError, 'Signature verification failed'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Compares the signature in a way that mitigates timing attacks
|
30
|
+
#
|
31
|
+
def self.secure_compare(a, b)
|
32
|
+
return false unless a.bytesize == b.bytesize
|
33
|
+
|
34
|
+
l = a.unpack "C#{a.bytesize}"
|
35
|
+
|
36
|
+
res = 0
|
37
|
+
b.each_byte { |byte| res |= byte ^ l.shift }
|
38
|
+
res == 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moderation_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moderation API
|
@@ -201,6 +201,8 @@ files:
|
|
201
201
|
- lib/moderation_api/models/moderation_video200_response.rb
|
202
202
|
- lib/moderation_api/models/moderation_video_request.rb
|
203
203
|
- lib/moderation_api/version.rb
|
204
|
+
- lib/moderation_api/webhook.rb
|
205
|
+
- moderation_api-1.2.0.gem
|
204
206
|
- moderation_api.gemspec
|
205
207
|
- spec/api/account_api_spec.rb
|
206
208
|
- spec/api/moderate_api_spec.rb
|