Class: Cloudflare::RealtimeKit::App

Inherits:
Cloudflare::Resource show all
Defined in:
lib/cloudflare/realtime_kit/app.rb

Overview

An app in your Cloudflare RealtimeKit account. Apps are the top-level tenant — meetings, sessions, recordings, presets, webhooks, livestreams, and analytics all live underneath an app.

Apps are list+create only; the API doesn’t expose a member endpoint (no GET /apps/Cloudflare::Resource#id, no PATCH, no DELETE).

Cloudflare.configure do |c|
  c.api_token  = ENV["CLOUDFLARE_API_TOKEN"]
  c. = ENV["CLOUDFLARE_ACCOUNT_ID"]
end

app = Cloudflare::RealtimeKit::App.create(name: "Production")
app.id         # => "abc123"
app.name       # => "Production"
app.created_at # => Time

Cloudflare::RealtimeKit::App.all

# Inspect the app the rest of the SDK is configured to use:
Cloudflare::RealtimeKit::App.current

Constant Summary

Constants inherited from Cloudflare::Resource

Cloudflare::Resource::ENVELOPE_KEYS

Instance Attribute Summary

Attributes inherited from Cloudflare::Resource

#scope

Class Method Summary collapse

Methods inherited from Cloudflare::Resource

#==, #[], attribute, attributes, #attributes, collection_path, configured_api_token, #destroy, find, has_many, has_one, #hash, #id, #initialize, member_path, read_only, read_only?, #reload, request, scope_params, scope_required, #set_attrs_from_response, #to_h, to_wire_keys, unwrap_envelope, #update, wire_kwarg, wire_name_for_request, wire_name_for_response

Constructor Details

This class inherits a constructor from Cloudflare::Resource

Class Method Details

.all(account_id: nil) ⇒ Object

GET /accounts/account_id/realtime/kit/apps



45
46
47
48
49
# File 'lib/cloudflare/realtime_kit/app.rb', line 45

def all(account_id: nil)
  scope    = build_scope(account_id: )
  response = request(:get, interpolate(_collection_path, scope))
  Array(unwrap_envelope(response)).map { new(_1, scope: scope) }
end

.create(name:, account_id: nil) ⇒ Object

POST /accounts/account_id/realtime/kit/apps

The create response double-wraps the app payload as { data: { app: {…} } }, so we peel both layers before constructing the instance. List responses use the standard { data: […] } envelope and don’t need this dance.



38
39
40
41
42
# File 'lib/cloudflare/realtime_kit/app.rb', line 38

def create(name:, account_id: nil)
  scope    = build_scope(account_id: )
  response = request(:post, interpolate(_collection_path, scope), body: { "name" => name })
  new(unwrap_create_payload(response), scope: scope)
end

.current(account_id: nil) ⇒ Object

Returns the App whose id matches Cloudflare::RealtimeKit.app_id, or nil if no such app exists in the account. Convenience for verifying that the configured app_id is valid and inspecting the app’s name / created_at.

Implemented over GET /apps + client-side filter because upstream doesn’t expose GET /apps/Cloudflare::Resource#id — see the Resource class docs above for the apps surface.

Cloudflare::RealtimeKit::App.current
# => #<App id="...", name="tokimonki-exchange-development">

Raises:

  • (ArgumentError)


62
63
64
65
66
# File 'lib/cloudflare/realtime_kit/app.rb', line 62

def current(account_id: nil)
  target = RealtimeKit.app_id
  raise ArgumentError, "Cloudflare::RealtimeKit.app_id not configured" if target.nil?
  all(account_id: ).find { |app| app.id == target }
end