Class: Datadog::AIGuard::HTTPClient Private
- Inherits:
-
Object
- Object
- Datadog::AIGuard::HTTPClient
- Defined in:
- lib/datadog/ai_guard/http_client.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
HTTP client for the AI Guard API Uses net/http to perform requests, raises on client and server errors
Constant Summary collapse
- DEFAULT_SITE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"app.datadoghq.com"- DEFAULT_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"/api/v2/ai-guard"
Instance Method Summary collapse
-
#initialize(endpoint:, api_key:, application_key:, timeout:) ⇒ HTTPClient
constructor
private
A new instance of HTTPClient.
- #post(path, body:) ⇒ Object private
Constructor Details
#initialize(endpoint:, api_key:, application_key:, timeout:) ⇒ HTTPClient
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.
Returns a new instance of HTTPClient.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/datadog/ai_guard/http_client.rb', line 17 def initialize(endpoint:, api_key:, application_key:, timeout:) @timeout = timeout site = Datadog.configuration.site @endpoint_uri = if endpoint URI(endpoint) #: URI::HTTP elsif site host = site.dup host.prepend("app.") if host.count(".") == 1 URI::HTTPS.build(host: host, path: DEFAULT_PATH) else URI::HTTPS.build(host: DEFAULT_SITE, path: DEFAULT_PATH) end @headers = { "DD-API-KEY": api_key.to_s, "DD-APPLICATION-KEY": application_key.to_s, "DD-AI-GUARD-VERSION": Datadog::VERSION::STRING, "DD-AI-GUARD-SOURCE": "SDK", "DD-AI-GUARD-LANGUAGE": "ruby", "content-type": "application/json", }.freeze end |
Instance Method Details
#post(path, body:) ⇒ Object
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.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/datadog/ai_guard/http_client.rb', line 42 def post(path, body:) Net::HTTP.start(@endpoint_uri.host.to_s, @endpoint_uri.port, use_ssl: use_ssl?, read_timeout: @timeout) do |http| request = Net::HTTP::Post.new(@endpoint_uri.request_uri + path, @headers) request.body = body.to_json response = http.request(request) raise_on_http_error!(response) parse_response_body(response.body) end rescue Net::ReadTimeout raise AIGuardClientError, "Request to AI Guard timed out" end |