Class: Cadenya::Resources::Widgets

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

Overview

Manage embeddable chat widgets. A widget binds an agent to a globally unique hostname with a per-widget origin allowlist; browsers reach it with session tokens minted via WidgetSessionService.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Widgets

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

Parameters:



257
258
259
# File 'lib/cadenya/resources/widgets.rb', line 257

def initialize(client:)
  @client = client
end

Instance Method Details

#archive(id, workspace_id: nil, request_options: {}) ⇒ Cadenya::Models::Widget

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

Transitions a widget to STATE_ARCHIVED. The hostname stops serving at the edge, existing sessions are revoked, and no new sessions can be minted. Reversible via :unarchive.

Parameters:

  • id (String)

    Widget ID. Accepts the canonical wgt_… form or the external_id:<value> form.

  • workspace_id (String)

    Workspace ID.

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

Returns:

See Also:



209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/cadenya/resources/widgets.rb', line 209

def archive(id, params = {})
  parsed, options = Cadenya::WidgetArchiveParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :post,
    path: ["v1/workspaces/%1$s/widgets/%2$s:archive", workspace_id, id],
    model: Cadenya::Widget,
    options: options
  )
end

#create(metadata:, spec:, workspace_id: nil, request_options: {}) ⇒ Cadenya::Models::Widget

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

Creates a widget bound to an agent. The widget's DNS label and hostname are generated by the server and returned in info. The hostname may take up to a minute to become reachable while the edge propagates.

Parameters:

Returns:

See Also:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cadenya/resources/widgets.rb', line 29

def create(params)
  parsed, options = Cadenya::WidgetCreateParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :post,
    path: ["v1/workspaces/%1$s/widgets", workspace_id],
    body: parsed,
    model: Cadenya::Widget,
    options: options
  )
end

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

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

Deletes a widget. Its hostname stops serving and all of its sessions are revoked.

Parameters:

  • id (String)

    Widget ID. Accepts the canonical wgt_… form or the external_id:<value> form.

  • workspace_id (String)

    Workspace ID.

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

Returns:

  • (nil)

See Also:



177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/cadenya/resources/widgets.rb', line 177

def delete(id, params = {})
  parsed, options = Cadenya::WidgetDeleteParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :delete,
    path: ["v1/workspaces/%1$s/widgets/%2$s", workspace_id, id],
    model: NilClass,
    options: options
  )
end

#list(workspace_id: nil, agent_id: nil, cursor: nil, include_info: nil, labels: nil, limit: nil, sort_order: nil, request_options: {}) ⇒ Cadenya::Internal::CursorPagination<Cadenya::Models::Widget>

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

Lists all widgets in a workspace

Parameters:

  • workspace_id (String)

    Path param: Workspace ID.

  • agent_id (String)

    Query param: Filter to widgets bound to a specific agent. Accepts the canonical

  • cursor (String)

    Query param: Pagination cursor from previous response.

  • include_info (Boolean)

    Query param: When true, the info field on each returned widget is populated.

  • labels (String)

    Query param: Filters by metadata labels. Comma-separated key=value pairs,

  • limit (Integer)

    Query param: Maximum number of results to return.

  • sort_order (String)

    Query param: Sort order for results (asc or desc by creation time).

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

Returns:

See Also:



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/cadenya/resources/widgets.rb', line 139

def list(params = {})
  parsed, options = Cadenya::WidgetListParams.dump_request(params)
  query = Cadenya::Internal::Util.encode_query_params(parsed)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :get,
    path: ["v1/workspaces/%1$s/widgets", workspace_id],
    query: query.transform_keys(
      agent_id: "agentId",
      include_info: "includeInfo",
      sort_order: "sortOrder"
    ),
    page: Cadenya::Internal::CursorPagination,
    model: Cadenya::Widget,
    options: options
  )
end

#retrieve(id, workspace_id: nil, request_options: {}) ⇒ Cadenya::Models::Widget

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

Retrieves a widget by ID

Parameters:

  • id (String)

    Widget ID. Accepts the canonical wgt_… form or the external_id:<value> form.

  • workspace_id (String)

    Workspace ID.

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

Returns:

See Also:



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cadenya/resources/widgets.rb', line 60

def retrieve(id, params = {})
  parsed, options = Cadenya::WidgetRetrieveParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :get,
    path: ["v1/workspaces/%1$s/widgets/%2$s", workspace_id, id],
    model: Cadenya::Widget,
    options: options
  )
end

#unarchive(id, workspace_id: nil, request_options: {}) ⇒ Cadenya::Models::Widget

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

Transitions an archived widget back to STATE_ACTIVE so its hostname serves traffic again. Sessions revoked by archival stay revoked; mint new ones.

Parameters:

  • id (String)

    Widget ID. Accepts the canonical wgt_… form or the external_id:<value> form.

  • workspace_id (String)

    Workspace ID.

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

Returns:

See Also:



240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/cadenya/resources/widgets.rb', line 240

def unarchive(id, params = {})
  parsed, options = Cadenya::WidgetUnarchiveParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :post,
    path: ["v1/workspaces/%1$s/widgets/%2$s:unarchive", workspace_id, id],
    model: Cadenya::Widget,
    options: options
  )
end

#update(id, workspace_id: nil, metadata: nil, spec: nil, update_mask: nil, request_options: {}) ⇒ Cadenya::Models::Widget

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

Updates a widget's metadata or spec. The DNS label is immutable and cannot be updated. Re-pointing the agent affects new sessions only; in-flight conversations finish against the agent they started with.

Parameters:

  • id (String)

    Path param: Widget ID. Accepts the canonical wgt_… form or the `external_id:<v

  • workspace_id (String)

    Path param: Workspace ID.

  • metadata (Cadenya::Models::UpdateResourceMetadata)

    Body param: UpdateResourceMetadata contains the user-provided fields for updatin

  • spec (Cadenya::Models::WidgetSpec)

    Body param: WidgetSpec is the user-provided configuration for a widget.

  • update_mask (String)

    Body param: Fields to update.

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

Returns:

See Also:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/cadenya/resources/widgets.rb', line 98

def update(id, params = {})
  parsed, options = Cadenya::WidgetUpdateParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :patch,
    path: ["v1/workspaces/%1$s/widgets/%2$s", workspace_id, id],
    body: parsed,
    model: Cadenya::Widget,
    options: options
  )
end