Class: ModerationAPI::Client
- Inherits:
-
Internal::Transport::BaseClient
- Object
- Internal::Transport::BaseClient
- ModerationAPI::Client
- Defined in:
- lib/moderation_api/client.rb
Constant Summary collapse
- DEFAULT_MAX_RETRIES =
Default max number of retries to attempt after a failed retryable request.
2- DEFAULT_TIMEOUT_IN_SECONDS =
Default per-request timeout.
60.0- DEFAULT_INITIAL_RETRY_DELAY =
Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.
0.5- DEFAULT_MAX_RETRY_DELAY =
Default max retry delay in seconds.
8.0
Constants inherited from Internal::Transport::BaseClient
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS
Instance Attribute Summary collapse
- #account ⇒ ModerationAPI::Resources::Account readonly
- #actions ⇒ ModerationAPI::Resources::Actions readonly
- #auth ⇒ ModerationAPI::Resources::Auth readonly
- #authors ⇒ ModerationAPI::Resources::Authors readonly
- #content ⇒ ModerationAPI::Resources::Content readonly
- #queue ⇒ ModerationAPI::Resources::Queue readonly
- #secret_key ⇒ String readonly
- #wordlist ⇒ ModerationAPI::Resources::Wordlist readonly
Attributes inherited from Internal::Transport::BaseClient
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout
Instance Method Summary collapse
-
#initialize(secret_key: ENV["MODAPI_SECRET_KEY"], base_url: ENV["MODERATION_API_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client
constructor
Creates and returns a new client for interacting with the API.
Methods inherited from Internal::Transport::BaseClient
follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!
Methods included from Internal::Util::SorbetRuntimeSupport
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type
Constructor Details
#initialize(secret_key: ENV["MODAPI_SECRET_KEY"], base_url: ENV["MODERATION_API_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client
Creates and returns a new client for interacting with the API.
‘“api.example.com/v2/”`. Defaults to `ENV`
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/moderation_api/client.rb', line 65 def initialize( secret_key: ENV["MODAPI_SECRET_KEY"], base_url: ENV["MODERATION_API_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY ) base_url ||= "https://api.moderationapi.com/v1" if secret_key.nil? raise ArgumentError.new("secret_key is required, and can be set via environ: \"MODAPI_SECRET_KEY\"") end @secret_key = secret_key.to_s super( base_url: base_url, timeout: timeout, max_retries: max_retries, initial_retry_delay: initial_retry_delay, max_retry_delay: max_retry_delay ) @authors = ModerationAPI::Resources::Authors.new(client: self) @queue = ModerationAPI::Resources::Queue.new(client: self) @actions = ModerationAPI::Resources::Actions.new(client: self) @content = ModerationAPI::Resources::Content.new(client: self) @account = ModerationAPI::Resources::Account.new(client: self) @auth = ModerationAPI::Resources::Auth.new(client: self) @wordlist = ModerationAPI::Resources::Wordlist.new(client: self) end |
Instance Attribute Details
#account ⇒ ModerationAPI::Resources::Account (readonly)
34 35 36 |
# File 'lib/moderation_api/client.rb', line 34 def account @account end |
#actions ⇒ ModerationAPI::Resources::Actions (readonly)
28 29 30 |
# File 'lib/moderation_api/client.rb', line 28 def actions @actions end |
#auth ⇒ ModerationAPI::Resources::Auth (readonly)
37 38 39 |
# File 'lib/moderation_api/client.rb', line 37 def auth @auth end |
#authors ⇒ ModerationAPI::Resources::Authors (readonly)
22 23 24 |
# File 'lib/moderation_api/client.rb', line 22 def @authors end |
#content ⇒ ModerationAPI::Resources::Content (readonly)
31 32 33 |
# File 'lib/moderation_api/client.rb', line 31 def content @content end |
#queue ⇒ ModerationAPI::Resources::Queue (readonly)
25 26 27 |
# File 'lib/moderation_api/client.rb', line 25 def queue @queue end |
#secret_key ⇒ String (readonly)
19 20 21 |
# File 'lib/moderation_api/client.rb', line 19 def secret_key @secret_key end |
#wordlist ⇒ ModerationAPI::Resources::Wordlist (readonly)
40 41 42 |
# File 'lib/moderation_api/client.rb', line 40 def wordlist @wordlist end |