Class: SafetyKit::Client
- Inherits:
-
Internal::Transport::BaseClient
- Object
- Internal::Transport::BaseClient
- SafetyKit::Client
- Defined in:
- lib/safety_kit/client.rb,
sig/safety_kit/client.rbs
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, Internal::Transport::BaseClient::SafetyKit
Instance Attribute Summary collapse
-
#access_tokens ⇒ SafetyKit::Resources::AccessTokens
readonly
Exchange a long-lived API key for a short-lived access token suitable for delegated or time-boxed use.
-
#agent_decisions ⇒ SafetyKit::Resources::AgentDecisions
readonly
Send human reviewer final verdicts to SafetyKit.
-
#api_key ⇒ String
readonly
PropelAuth JWT token.
-
#async ⇒ SafetyKit::Resources::Async
readonly
Beta.
- #beta ⇒ SafetyKit::Resources::Beta readonly
-
#client_sessions ⇒ SafetyKit::Resources::ClientSessions
readonly
Beta.
-
#data ⇒ SafetyKit::Resources::Data
readonly
Ingest data for fraud detection and risk analysis.
-
#deletion_requests ⇒ SafetyKit::Resources::DeletionRequests
readonly
Submit end-user deletion requests.
-
#streams ⇒ SafetyKit::Resources::Streams
readonly
Ingest and monitor livestream content.
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
- #base_url_overridden? ⇒ Boolean private
-
#initialize(api_key: ENV["SAFETYKIT_API_KEY"], base_url: ENV["SAFETYKIT_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(api_key: ENV["SAFETYKIT_API_KEY"], base_url: ENV["SAFETYKIT_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.
"https://api.example.com/v2/". Defaults to ENV["SAFETYKIT_BASE_URL"]
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/safety_kit/client.rb', line 86 def initialize( api_key: ENV["SAFETYKIT_API_KEY"], base_url: ENV["SAFETYKIT_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_overridden = !base_url.nil? base_url ||= "https://api.safetykit.com" if api_key.nil? raise ArgumentError.new("api_key is required, and can be set via environ: \"SAFETYKIT_API_KEY\"") end headers = {} custom_headers_env = ENV["SAFETYKIT_CUSTOM_HEADERS"] unless custom_headers_env.nil? parsed = {} custom_headers_env.split("\n").each do |line| colon = line.index(":") unless colon.nil? parsed[line[0...colon].strip] = line[(colon + 1)..].strip end end headers = parsed.merge(headers) end @api_key = api_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, headers: headers ) @data = SafetyKit::Resources::Data.new(client: self) @streams = SafetyKit::Resources::Streams.new(client: self) @agent_decisions = SafetyKit::Resources::AgentDecisions.new(client: self) @access_tokens = SafetyKit::Resources::AccessTokens.new(client: self) @async = SafetyKit::Resources::Async.new(client: self) @deletion_requests = SafetyKit::Resources::DeletionRequests.new(client: self) @client_sessions = SafetyKit::Resources::ClientSessions.new(client: self) @beta = SafetyKit::Resources::Beta.new(client: self) end |
Instance Attribute Details
#access_tokens ⇒ SafetyKit::Resources::AccessTokens (readonly)
Exchange a long-lived API key for a short-lived access token suitable for delegated or time-boxed use.
38 39 40 |
# File 'lib/safety_kit/client.rb', line 38 def access_tokens @access_tokens end |
#agent_decisions ⇒ SafetyKit::Resources::AgentDecisions (readonly)
Send human reviewer final verdicts to SafetyKit. This feedback improves the accuracy of SafetyKit's automated decisions over time.
33 34 35 |
# File 'lib/safety_kit/client.rb', line 33 def agent_decisions @agent_decisions end |
#api_key ⇒ String (readonly)
PropelAuth JWT token
20 21 22 |
# File 'lib/safety_kit/client.rb', line 20 def api_key @api_key end |
#async ⇒ SafetyKit::Resources::Async (readonly)
Beta. Send backend events for account, content, user interaction, report, appeal, and moderation activity.
43 44 45 |
# File 'lib/safety_kit/client.rb', line 43 def async @async end |
#beta ⇒ SafetyKit::Resources::Beta (readonly)
56 57 58 |
# File 'lib/safety_kit/client.rb', line 56 def beta @beta end |
#client_sessions ⇒ SafetyKit::Resources::ClientSessions (readonly)
Beta. Create browser-safe Webapp SDK session tokens from authenticated server-side code.
53 54 55 |
# File 'lib/safety_kit/client.rb', line 53 def client_sessions @client_sessions end |
#data ⇒ SafetyKit::Resources::Data (readonly)
Ingest data for fraud detection and risk analysis.
24 25 26 |
# File 'lib/safety_kit/client.rb', line 24 def data @data end |
#deletion_requests ⇒ SafetyKit::Resources::DeletionRequests (readonly)
Submit end-user deletion requests. Accepted requests are processed asynchronously.
48 49 50 |
# File 'lib/safety_kit/client.rb', line 48 def deletion_requests @deletion_requests end |
#streams ⇒ SafetyKit::Resources::Streams (readonly)
Ingest and monitor livestream content.
28 29 30 |
# File 'lib/safety_kit/client.rb', line 28 def streams @streams end |
Instance Method Details
#base_url_overridden? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 |
# File 'lib/safety_kit/client.rb', line 70 def base_url_overridden? = @base_url_overridden |