Class: SafetyKit::Resources::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/safety_kit/resources/data.rb,
sig/safety_kit/resources/data.rbs

Overview

Ingest data for fraud detection and risk analysis.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Data

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 Data.

Parameters:



119
120
121
# File 'lib/safety_kit/resources/data.rb', line 119

def initialize(client:)
  @client = client
end

Instance Method Details

#add(namespace, data:, request_options: {}) ⇒ SafetyKit::Models::DataAddResponse

Some parameter documentations has been truncated, see Models::DataAddParams for more details.

Add data to a namespace, returning immediately. Processing happens asynchronously in the background.

Parameters:

Returns:

See Also:



24
25
26
27
28
29
30
31
32
33
# File 'lib/safety_kit/resources/data.rb', line 24

def add(namespace, params)
  parsed, options = SafetyKit::DataAddParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["v1/data/%1$s", namespace],
    body: parsed,
    model: SafetyKit::Models::DataAddResponse,
    options: options
  )
end

#create_upload_url(namespace, request_options: {}) ⇒ SafetyKit::Models::DataCreateUploadURLResponse

Request a pre-signed upload URL for large JSONL batches into a namespace. After receiving upload_url, upload your JSONL file using PUT {upload_url} with header Content-Type: application/json; put each JSON object on a new line.

Parameters:

  • namespace (String)

    The namespace to ingest data into

  • request_options (SafetyKit::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



48
49
50
51
52
53
54
55
# File 'lib/safety_kit/resources/data.rb', line 48

def create_upload_url(namespace, params = {})
  @client.request(
    method: :post,
    path: ["v1/data/%1$s/requests/upload-url", namespace],
    model: SafetyKit::Models::DataCreateUploadURLResponse,
    options: params[:request_options]
  )
end

#get_download_url(request_id, namespace:, request_options: {}) ⇒ SafetyKit::Models::DataGetDownloadURLResponse

Retrieve the status of a data ingestion request and, once complete, a temporary S3 URL for the full result file. This endpoint always uses the URL-based response shape regardless of request size.

Parameters:

  • request_id (String)

    The request ID returned when the ingest request was created

  • namespace (String)

    The namespace the data was ingested into

  • request_options (SafetyKit::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/safety_kit/resources/data.rb', line 72

def get_download_url(request_id, params)
  parsed, options = SafetyKit::DataGetDownloadURLParams.dump_request(params)
  namespace =
    parsed.delete(:namespace) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["v1/data/%1$s/requests/%2$s/results/download-url", namespace, request_id],
    model: SafetyKit::Models::DataGetDownloadURLResponse,
    options: options
  )
end

#get_status(request_id, namespace:, request_options: {}) ⇒ SafetyKit::Models::DataGetStatusResponse

Retrieve the status of a data ingestion request and, once complete, return processed objects inline. If the processed output exceeds the 5 MiB inline response limit, this endpoint returns an error instructing you to use the download endpoint instead.

Parameters:

  • request_id (String)

    The request ID returned when the ingest request was created

  • namespace (String)

    The namespace the data was ingested into

  • request_options (SafetyKit::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/safety_kit/resources/data.rb', line 102

def get_status(request_id, params)
  parsed, options = SafetyKit::DataGetStatusParams.dump_request(params)
  namespace =
    parsed.delete(:namespace) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["v1/data/%1$s/requests/%2$s", namespace, request_id],
    model: SafetyKit::Models::DataGetStatusResponse,
    options: options
  )
end