Class: Telnyx::Resources::Storage::Kvs::Keys

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/resources/storage/kvs/keys.rb,
sig/telnyx/resources/storage/kvs/keys.rbs

Overview

Read and write keys within a KV namespace

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Keys

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

Parameters:



148
149
150
# File 'lib/telnyx/resources/storage/kvs/keys.rb', line 148

def initialize(client:)
  @client = client
end

Instance Method Details

#delete(key, id:, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Storage::Kvs::KeyDeleteParams for more details.

Deletes a key. Idempotent: deleting a key that does not exist still succeeds. The namespace itself must exist and be provisioned.

Parameters:

  • key (String)

    Key name. Allowed characters: a-z A-Z 0-9 - _ / = .; maximum 256 characters; n

  • id (String)

    KV namespace ID

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

Returns:

  • (nil)

See Also:



131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/telnyx/resources/storage/kvs/keys.rb', line 131

def delete(key, params)
  parsed, options = Telnyx::Storage::Kvs::KeyDeleteParams.dump_request(params)
  id =
    parsed.delete(:id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["storage/kvs/%1$s/keys/%2$s", id, key],
    model: NilClass,
    options: options
  )
end

#list(id, cursor: nil, limit: nil, prefix: nil, request_options: {}) ⇒ Telnyx::Internal::CursorFlatPagination<Telnyx::Models::Storage::Kvs::KeyListResponse>

Lists the keys in a namespace. Returns key names and metadata only, never values. Results are paginated with limit and an opaque cursor.

Parameters:

  • id (String)

    KV namespace ID

  • cursor (String)

    Opaque pagination cursor from a previous response's meta.cursor.

  • limit (Integer)

    Maximum number of keys to return. Values above 1000 are treated as 1000.

  • prefix (String)

    Return only keys that start with this prefix.

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

Returns:

See Also:



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/telnyx/resources/storage/kvs/keys.rb', line 101

def list(id, params = {})
  parsed, options = Telnyx::Storage::Kvs::KeyListParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["storage/kvs/%1$s/keys", id],
    query: query,
    page: Telnyx::Internal::CursorFlatPagination,
    model: Telnyx::Models::Storage::Kvs::KeyListResponse,
    options: options
  )
end

#retrieve(key, id:, request_options: {}) ⇒ StringIO

Some parameter documentations has been truncated, see Models::Storage::Kvs::KeyRetrieveParams for more details.

Returns the raw stored value for a key. The response body is the value exactly as it was written; the Content-Type header echoes the value's stored content type (defaults to application/octet-stream).

Parameters:

  • key (String)

    Key name. Allowed characters: a-z A-Z 0-9 - _ / = .; maximum 256 characters; n

  • id (String)

    KV namespace ID

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

Returns:

  • (StringIO)

See Also:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/telnyx/resources/storage/kvs/keys.rb', line 27

def retrieve(key, params)
  parsed, options = Telnyx::Storage::Kvs::KeyRetrieveParams.dump_request(params)
  id =
    parsed.delete(:id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["storage/kvs/%1$s/keys/%2$s", id, key],
    headers: {"accept" => "application/octet-stream"},
    model: StringIO,
    options: options
  )
end

#update(key, id:, body:, ttl_secs: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Storage::Kvs::KeyUpdateParams for more details.

Creates or replaces the value for a key. The request body is stored verbatim as the value — no base64, no JSON envelope — up to 1 MiB. The request's Content-Type header is stored with the value and echoed back on retrieval. Returns 201 when the key is created and 200 when an existing key is updated.

Parameters:

  • key (String)

    Path param: Key name. Allowed characters: a-z A-Z 0-9 - _ / = .; maximum 256 c

  • id (String)

    Path param: KV namespace ID

  • body (Pathname, StringIO, IO, String, Telnyx::FilePart)

    Body param: Raw value bytes, stored verbatim.

  • ttl_secs (Integer)

    Query param: Time-to-live in seconds. When set, the key expires and is deleted a

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

Returns:

  • (nil)

See Also:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/telnyx/resources/storage/kvs/keys.rb', line 65

def update(key, params)
  parsed, options = Telnyx::Storage::Kvs::KeyUpdateParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed.except(:body))
  id =
    parsed.delete(:id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["storage/kvs/%1$s/keys/%2$s", id, key],
    query: query,
    headers: {"content-type" => "application/octet-stream"},
    body: parsed[:body],
    model: NilClass,
    options: options
  )
end