Class: SafetyKit::Resources::Streams

Inherits:
Object
  • Object
show all
Defined in:
lib/safety_kit/resources/streams.rb

Overview

Ingest and monitor livestream content.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Streams

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

Parameters:



108
109
110
# File 'lib/safety_kit/resources/streams.rb', line 108

def initialize(client:)
  @client = client
end

Instance Method Details

#add(namespace, id:, stream_url:, request_options: {}) ⇒ SafetyKit::Models::StreamAddResponse

Monitor the livestream at the given stream URL. This method returns immediately.

Parameters:

  • namespace (String)

    The namespace to ingest stream data into

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

Returns:

See Also:



22
23
24
25
26
27
28
29
30
31
# File 'lib/safety_kit/resources/streams.rb', line 22

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

#add_frame(namespace, image_data_uri:, stream_id:, timestamp:, request_options: {}) ⇒ SafetyKit::Models::StreamAddFrameResponse

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

Ingest a single livestream frame as an image data URI plus relative timestamp in milliseconds. The stream does not need to be created beforehand. Only image/jpeg, image/png, and image/webp are accepted. The decoded bytes must match the declared mime type, decode as a valid image, stay within 5 MB, and stay within 4096x4096 / 16,000,000 total pixels. Timestamps are relative milliseconds from stream start and must be unique and strictly increasing within a stream. Duplicate or out-of-order frame timestamps are accepted at the API boundary but ignored by downstream processing. This method returns immediately after the frame has been accepted for processing.

Parameters:

  • namespace (String)

    The namespace to ingest stream data into

  • image_data_uri (String)

    A data URI containing a base64-encoded frame image. Only image/jpeg, image/png,

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

Returns:

See Also:



61
62
63
64
65
66
67
68
69
70
# File 'lib/safety_kit/resources/streams.rb', line 61

def add_frame(namespace, params)
  parsed, options = SafetyKit::StreamAddFrameParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["v1/streams/%1$s/frames", namespace],
    body: parsed,
    model: SafetyKit::Models::StreamAddFrameResponse,
    options: options
  )
end

#add_transcript(namespace, stream_id:, text:, timestamp:, request_options: {}) ⇒ SafetyKit::Models::StreamAddTranscriptResponse

Ingest a single transcript segment for a livestream using a relative timestamp in milliseconds. The stream does not need to be created beforehand. Transcript timestamps are relative milliseconds from stream start and should be monotonically increasing within a stream so transcript context lines up correctly with later frames. This method returns immediately after the transcript has been accepted for processing.

Parameters:

  • namespace (String)

    The namespace to ingest stream data into

  • stream_id (String)
  • text (String)
  • timestamp (Integer)
  • request_options (SafetyKit::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



94
95
96
97
98
99
100
101
102
103
# File 'lib/safety_kit/resources/streams.rb', line 94

def add_transcript(namespace, params)
  parsed, options = SafetyKit::StreamAddTranscriptParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["v1/streams/%1$s/transcripts", namespace],
    body: parsed,
    model: SafetyKit::Models::StreamAddTranscriptResponse,
    options: options
  )
end