Class: Broadcast::Resources::Migration
- Defined in:
- lib/broadcast/resources/migration.rb
Overview
Read-only export endpoints under /api/migration/v1 — the surface behind backups and instance-to-instance migration.
Two things differ from the v1 API:
- Admin tokens only. Channel-scoped tokens are rejected outright; the controller looks up AdminApiToken and nothing else.
- broadcast_channel_id is required on every call. Set it once via
Client.new(broadcast_channel_id:)orclient.with_channel(id)and the gem attaches it automatically; otherwise pass it per call.
Every list endpoint pages with limit: (1..250, default 250) and
offset:, and returns {"data" => [...], "pagination" => {...}}.
Constant Summary collapse
- COLLECTIONS =
Endpoints that are a plain paginated list of the channel's records.
%i[ channels subscribers templates segments sequences email_servers opt_in_forms broadcasts outbound_receipts webhook_endpoints tokens suppressions tags users link_redirects link_clicks subscriber_histories file_assets ].freeze
Instance Method Summary collapse
-
#download_file_asset(id, **params) ⇒ Object
Binary contents of a stored file asset.
-
#each_record(collection, limit: 250, **params, &block) ⇒ Object
Pages through a collection, yielding each record.
-
#manifest(**params) ⇒ Object
Export summary: format version, channel identity, per-resource counts, and recent-history totals.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Broadcast::Resources::Base
Instance Method Details
#download_file_asset(id, **params) ⇒ Object
Binary contents of a stored file asset. Returns a String of bytes, not JSON — write it straight to disk.
44 45 46 |
# File 'lib/broadcast/resources/migration.rb', line 44 def download_file_asset(id, **params) @client.request(:get, "/api/migration/v1/file_assets/#{id}/download", params, raw: true) end |
#each_record(collection, limit: 250, **params, &block) ⇒ Object
Pages through a collection, yielding each record.
client.migration.each_record(:subscribers) { |sub| csv << sub }
Stops when the server reports has_more: false, so it stays correct if
the page size is clamped server-side.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/broadcast/resources/migration.rb', line 54 def each_record(collection, limit: 250, **params, &block) return enum_for(:each_record, collection, limit: limit, **params) unless block_given? offset = 0 loop do page = public_send(collection, limit: limit, offset: offset, **params) records = Array(page['data']) records.each(&block) pagination = page['pagination'] || {} break unless pagination['has_more'] # Advance by what the server actually returned — it clamps `limit`. advanced = pagination['limit'] || records.size break if advanced.to_i.zero? offset += advanced.to_i end end |
#manifest(**params) ⇒ Object
Export summary: format version, channel identity, per-resource counts, and recent-history totals. Call this first to size an export.
38 39 40 |
# File 'lib/broadcast/resources/migration.rb', line 38 def manifest(**params) get('/api/migration/v1/manifest', params) end |