cloudflare-ruby 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e55c381f1697329fa6cb8bd393493b4b63b31d0f3b4b672d43e61c2799c0c40
4
- data.tar.gz: dba84759f533e9203bb0f70404b4d719ece8509a883bb83d2aa5accd607d0375
3
+ metadata.gz: e840df4dc6ff74e2cb0fddaba160fc041c80472c52f7a583f9c23185d24b8765
4
+ data.tar.gz: 9a42b0db13ed3d842fb1bc1b9df86011de55223a6667a666e3431bd455d4e4fd
5
5
  SHA512:
6
- metadata.gz: e90e2f05d9b52b24195ff9d95c9849ff04290ac8d460ec0e59917869125e03cdc176a4717b2c1895891b463076d04ddbf30b17f4a8c52693d0f365bd6bef025f
7
- data.tar.gz: 364098f7920cebdb13e6751be1bd28c32ba74b144e5a6f06e947a333a1b49b27efd5da9ae6befa3361253171df1755aa51816494f2b2821ee0190830733337e5
6
+ metadata.gz: 71d24e6e2fbb63aee5c96e23e581f668207df71b7cc281cc02bfdb8c07e2e377e3a30e5a5888c90a5dd1acb0b0b4a4d734faf779bc9140b51a2400cad6029769
7
+ data.tar.gz: 9a73874dadf0b7847b5058a4ab40dec0acedb93765438d0c2b96632c376bddf1a9b23f04ee167206c7ee35a138ca8cfabca8c2e6eba66a20bd646050e13f5c7a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ - **Default `app_id` per process.** Set `Cloudflare::RealtimeKit.app_id`
6
+ once at boot and every RealtimeKit call defaults to it; pass `app_id:`
7
+ per-call only to override. Mirrors the existing `Cloudflare.account_id`
8
+ pattern. Eliminates `app_id:` repetition in apps that talk to a single
9
+ RealtimeKit app per process (the common case).
10
+ - `Resource.build_scope` and `extract_scope!` now consult a generic
11
+ `global_default_for(key)` helper that resolves `:account_id` against
12
+ `Cloudflare.account_id` and any other key against a same-named
13
+ accessor on the resource's product namespace
14
+ (e.g., `:app_id` → `Cloudflare::RealtimeKit.app_id`). Generalizes for
15
+ future product surfaces.
16
+ - `Recording.start_track`, `Recording.active_for`,
17
+ `Session.find_participant_by_peer_id`, `Analytics.daywise`, and
18
+ `Analytics.livestreams_overall` now accept `app_id:` as optional with
19
+ the default falling through.
20
+
3
21
  ## 0.1.2
4
22
 
5
23
  - Add `require "bundler/gem_tasks"` to the Rakefile so `rake release`
@@ -12,10 +12,15 @@ Cloudflare.configure do |c|
12
12
  c.account_id = ENV.fetch("CLOUDFLARE_ACCOUNT_ID")
13
13
  end
14
14
 
15
+ # Default app_id for every RealtimeKit call this process makes.
16
+ # Pass `app_id:` per-call only to override (e.g., admin tools that hop
17
+ # between apps).
18
+ Cloudflare::RealtimeKit.app_id = ENV.fetch("REALTIMEKIT_APP_ID")
19
+
15
20
  RK = Cloudflare::RealtimeKit # alias to taste
16
21
  ```
17
22
 
18
- After that, `account_id:` is implicit on every call — pass it per-call only to override.
23
+ After that, both `account_id:` and `app_id:` are implicit on every call — pass either per-call only to override.
19
24
 
20
25
  ## Apps
21
26
 
@@ -28,6 +33,8 @@ RK::App.all # GET /apps
28
33
 
29
34
  ## Meetings
30
35
 
36
+ Most calls below show `app_id:` for clarity. With `Cloudflare::RealtimeKit.app_id` set globally (see Setup), you can omit it.
37
+
31
38
  ```ruby
32
39
  meeting = RK::Meeting.create(app_id: app.id, title: "Standup", record_on_start: true)
33
40
  meeting.id # => "mtg-…"
@@ -18,14 +18,14 @@ module Cloudflare
18
18
  module Analytics
19
19
  class << self
20
20
  # GET /analytics/daywise — daily breakdown of meeting activity.
21
- def daywise(app_id:, start_date:, end_date:, account_id: nil)
21
+ def daywise(start_date:, end_date:, app_id: nil, account_id: nil)
22
22
  fetch("/accounts/{account_id}/realtime/kit/{app_id}/analytics/daywise",
23
23
  app_id: app_id, account_id: account_id,
24
24
  params: { start_date: start_date, end_date: end_date })
25
25
  end
26
26
 
27
27
  # GET /analytics/livestreams/overall — overall livestream metrics.
28
- def livestreams_overall(app_id:, start_time:, end_time:, account_id: nil)
28
+ def livestreams_overall(start_time:, end_time:, app_id: nil, account_id: nil)
29
29
  fetch("/accounts/{account_id}/realtime/kit/{app_id}/analytics/livestreams/overall",
30
30
  app_id: app_id, account_id: account_id,
31
31
  params: { start_time: start_time, end_time: end_time })
@@ -41,11 +41,16 @@ module Cloudflare
41
41
 
42
42
  # Local copies of the two private helpers from Resource — Analytics
43
43
  # isn't a Resource subclass (no instances, just a function namespace),
44
- # so it can't inherit the private class methods.
44
+ # so it can't inherit the private class methods. Falls back to
45
+ # +Cloudflare.account_id+ and +Cloudflare::RealtimeKit.app_id+ for
46
+ # the same per-process default behavior the Resource subclasses
47
+ # get for free.
45
48
  def build_scope(account_id:, app_id:)
46
49
  account = account_id || Cloudflare.account_id
50
+ app = app_id || RealtimeKit.app_id
47
51
  raise ArgumentError, "missing required scope param: account_id" unless account
48
- { account_id: account, app_id: app_id }
52
+ raise ArgumentError, "missing required scope param: app_id" unless app
53
+ { account_id: account, app_id: app }
49
54
  end
50
55
 
51
56
  def interpolate(path, values)
@@ -38,7 +38,7 @@ module Cloudflare
38
38
  # POST /recordings/track — start a multi-file (per-track) recording.
39
39
  # Different upstream endpoint than +create+; use this when you need
40
40
  # one media file per participant track.
41
- def start_track(meeting_id:, layers:, app_id:, account_id: nil, max_seconds: nil)
41
+ def start_track(meeting_id:, layers:, app_id: nil, account_id: nil, max_seconds: nil)
42
42
  scope = build_scope(account_id: account_id, app_id: app_id)
43
43
  path = interpolate("/accounts/{account_id}/realtime/kit/{app_id}/recordings/track", scope)
44
44
  response = Connection.instance.request(:post, path,
@@ -48,7 +48,7 @@ module Cloudflare
48
48
 
49
49
  # GET /recordings/active-recording/{meeting_id} — fetch the recording
50
50
  # currently in progress for a meeting (404 if none).
51
- def active_for(meeting_id:, app_id:, account_id: nil)
51
+ def active_for(meeting_id:, app_id: nil, account_id: nil)
52
52
  scope = build_scope(account_id: account_id, app_id: app_id)
53
53
  path = interpolate("/accounts/{account_id}/realtime/kit/{app_id}/recordings/active-recording/{meeting_id}",
54
54
  scope.merge(meeting_id: meeting_id))
@@ -41,7 +41,7 @@ module Cloudflare
41
41
  # GET /sessions/peer-report/{peer_id} — reverse lookup from a peer id.
42
42
  # Returns participant-shaped data, not a session, so we expose it as a
43
43
  # SessionParticipant instance.
44
- def find_participant_by_peer_id(peer_id, app_id:, account_id: nil, filters: nil)
44
+ def find_participant_by_peer_id(peer_id, app_id: nil, account_id: nil, filters: nil)
45
45
  scope = build_scope(account_id: account_id, app_id: app_id)
46
46
  path = interpolate("/accounts/{account_id}/realtime/kit/{app_id}/sessions/peer-report/{peer_id}",
47
47
  scope.merge(peer_id: peer_id))
@@ -2,7 +2,24 @@ module Cloudflare
2
2
  # Cloudflare RealtimeKit (formerly Dyte) — managed video/audio infrastructure
3
3
  # for meetings, livestreams, recordings, sessions, and analytics. Each
4
4
  # resource maps to a hand-written class under this namespace.
5
+ #
6
+ # == Default app_id
7
+ #
8
+ # Most resources (Meeting, Participant, Recording, ...) live under an app.
9
+ # Set +app_id+ once at process boot and every call defaults to it; pass
10
+ # +app_id:+ per-call only to override.
11
+ #
12
+ # Cloudflare::RealtimeKit.app_id = ENV["REALTIMEKIT_APP_ID"]
13
+ #
14
+ # Cloudflare::RealtimeKit::Meeting.create(title: "Standup") # uses default
15
+ # Cloudflare::RealtimeKit::Meeting.find(id, app_id: "other-app-id") # override
5
16
  module RealtimeKit
17
+ class << self
18
+ # Default app_id used when a resource call doesn't pass one explicitly.
19
+ # Mirrors how +Cloudflare.account_id+ defaults the account scope.
20
+ attr_accessor :app_id
21
+ end
22
+
6
23
  autoload :App, "cloudflare/realtime_kit/app"
7
24
  autoload :Meeting, "cloudflare/realtime_kit/meeting"
8
25
  autoload :Participant, "cloudflare/realtime_kit/participant"
@@ -180,11 +180,12 @@ module Cloudflare
180
180
  end
181
181
 
182
182
  private
183
- # Pulls scope params out of the kwargs hash (mutating). Defaults
184
- # account_id from global config if not provided.
183
+ # Pulls scope params out of the kwargs hash (mutating). Falls back
184
+ # to product-level defaults (see +global_default_for+) when a key
185
+ # isn't provided.
185
186
  def extract_scope!(attrs)
186
187
  scope_params.each_with_object({}) do |key, h|
187
- value = attrs.delete(key) || (key == :account_id && Cloudflare.account_id)
188
+ value = attrs.delete(key) || global_default_for(key)
188
189
  raise ArgumentError, "missing required scope param: #{key}" unless value
189
190
  h[key] = value
190
191
  end
@@ -192,12 +193,35 @@ module Cloudflare
192
193
 
193
194
  def build_scope(provided)
194
195
  scope_params.each_with_object({}) do |key, h|
195
- value = provided[key] || (key == :account_id && Cloudflare.account_id)
196
+ value = provided[key] || global_default_for(key)
196
197
  raise ArgumentError, "missing required scope param: #{key}" unless value
197
198
  h[key] = value
198
199
  end
199
200
  end
200
201
 
202
+ # Resolve a scope key to its module-level default:
203
+ # +:account_id+ → +Cloudflare.account_id+ (top-level config), and any
204
+ # other key → a same-named accessor on the resource's product
205
+ # namespace (e.g., +:app_id+ → +Cloudflare::RealtimeKit.app_id+).
206
+ # Lets callers configure once per process and stop repeating
207
+ # +app_id:+ at every call site. Returns nil when no default is set,
208
+ # which lets the caller raise the +missing required scope+ error.
209
+ def global_default_for(key)
210
+ return Cloudflare.account_id if key == :account_id
211
+ namespace = product_namespace
212
+ namespace&.respond_to?(key) ? namespace.public_send(key) : nil
213
+ end
214
+
215
+ # +Cloudflare::RealtimeKit::Meeting+ → +Cloudflare::RealtimeKit+.
216
+ # Returns nil for resources without a product namespace (i.e.,
217
+ # +Cloudflare::Resource+ direct subclasses, which we don't have in
218
+ # practice).
219
+ def product_namespace
220
+ parts = name.split("::")
221
+ return nil if parts.size < 3
222
+ parts[0..-2].inject(Object) { |const, seg| const.const_get(seg) }
223
+ end
224
+
201
225
  def interpolate(path, values)
202
226
  path.gsub(/\{(\w+)\}/) do
203
227
  key = $1.to_sym
@@ -1,3 +1,3 @@
1
1
  module Cloudflare
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflare-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tokimonki