Class: Broadcast::Client
- Inherits:
-
Object
- Object
- Broadcast::Client
- Defined in:
- lib/broadcast/client.rb
Constant Summary collapse
- CHANNEL_OVERRIDE_KEY =
:__broadcast_ruby_channel_override
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #autopilots ⇒ Object
- #broadcasts ⇒ Object
- #discovery ⇒ Object
- #email_servers ⇒ Object
- #get_email(id) ⇒ Object
-
#initialize(**settings) ⇒ Client
constructor
A new instance of Client.
-
#migration ⇒ Object
Read-only export endpoints under /api/migration/v1.
- #opt_in_forms ⇒ Object
- #prime ⇒ Object
- #request(method, path, body_or_params = nil, headers: {}, raw: false) ⇒ Object private
- #segments ⇒ Object
-
#send_email(to:, subject: nil, body: nil, reply_to: nil) ⇒ Object
Thin convenience wrapper around
transactionals.create. - #sequences ⇒ Object
- #skill ⇒ Object
- #status ⇒ Object
-
#subscribers ⇒ Object
--- Resource sub-clients ---.
- #templates ⇒ Object
- #transactionals ⇒ Object
- #webhook_endpoints ⇒ Object
-
#whoami ⇒ Object
--- Discovery (convenience shims) ---.
-
#with_channel(broadcast_channel_id) ⇒ Object
Run a block with a temporary broadcast_channel_id override that will be auto-included on every request inside the block.
Constructor Details
#initialize(**settings) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 |
# File 'lib/broadcast/client.rb', line 9 def initialize(**settings) @config = Configuration.new settings.each { |k, v| @config.public_send(:"#{k}=", v) } @config.validate! @connection = Connection.new(@config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/broadcast/client.rb', line 7 def config @config end |
Instance Method Details
#autopilots ⇒ Object
103 104 105 |
# File 'lib/broadcast/client.rb', line 103 def autopilots @autopilots ||= Resources::Autopilots.new(self) end |
#broadcasts ⇒ Object
75 76 77 |
# File 'lib/broadcast/client.rb', line 75 def broadcasts @broadcasts ||= Resources::Broadcasts.new(self) end |
#discovery ⇒ Object
107 108 109 |
# File 'lib/broadcast/client.rb', line 107 def discovery @discovery ||= Resources::Discovery.new(self) end |
#email_servers ⇒ Object
99 100 101 |
# File 'lib/broadcast/client.rb', line 99 def email_servers @email_servers ||= Resources::EmailServers.new(self) end |
#get_email(id) ⇒ Object
43 44 45 |
# File 'lib/broadcast/client.rb', line 43 def get_email(id) transactionals.get_transactional(id) end |
#migration ⇒ Object
Read-only export endpoints under /api/migration/v1. Requires an admin (system) API token.
113 114 115 |
# File 'lib/broadcast/client.rb', line 113 def migration @migration ||= Resources::Migration.new(self) end |
#opt_in_forms ⇒ Object
95 96 97 |
# File 'lib/broadcast/client.rb', line 95 def opt_in_forms @opt_in_forms ||= Resources::OptInForms.new(self) end |
#prime ⇒ Object
57 58 59 |
# File 'lib/broadcast/client.rb', line 57 def prime discovery.prime end |
#request(method, path, body_or_params = nil, headers: {}, raw: false) ⇒ Object
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.
118 119 120 121 |
# File 'lib/broadcast/client.rb', line 118 def request(method, path, body_or_params = nil, headers: {}, raw: false) payload = inject_channel_scope(body_or_params) @connection.request(method, path, payload, headers: headers, raw: raw) end |
#segments ⇒ Object
79 80 81 |
# File 'lib/broadcast/client.rb', line 79 def segments @segments ||= Resources::Segments.new(self) end |
#send_email(to:, subject: nil, body: nil, reply_to: nil) ⇒ Object
Thin convenience wrapper around transactionals.create. Use
client.transactionals.create directly for template_id, double_opt_in,
preheader, idempotency_key, and other advanced options.
39 40 41 |
# File 'lib/broadcast/client.rb', line 39 def send_email(to:, subject: nil, body: nil, reply_to: nil) transactionals.create(to: to, subject: subject, body: body, reply_to: reply_to) end |
#sequences ⇒ Object
71 72 73 |
# File 'lib/broadcast/client.rb', line 71 def sequences @sequences ||= Resources::Sequences.new(self) end |
#skill ⇒ Object
61 62 63 |
# File 'lib/broadcast/client.rb', line 61 def skill discovery.skill end |
#status ⇒ Object
53 54 55 |
# File 'lib/broadcast/client.rb', line 53 def status discovery.status end |
#subscribers ⇒ Object
--- Resource sub-clients ---
67 68 69 |
# File 'lib/broadcast/client.rb', line 67 def subscribers @subscribers ||= Resources::Subscribers.new(self) end |
#templates ⇒ Object
83 84 85 |
# File 'lib/broadcast/client.rb', line 83 def templates @templates ||= Resources::Templates.new(self) end |
#transactionals ⇒ Object
91 92 93 |
# File 'lib/broadcast/client.rb', line 91 def transactionals @transactionals ||= Resources::Transactionals.new(self) end |
#webhook_endpoints ⇒ Object
87 88 89 |
# File 'lib/broadcast/client.rb', line 87 def webhook_endpoints @webhook_endpoints ||= Resources::WebhookEndpoints.new(self) end |
#whoami ⇒ Object
--- Discovery (convenience shims) ---
49 50 51 |
# File 'lib/broadcast/client.rb', line 49 def whoami discovery.whoami end |
#with_channel(broadcast_channel_id) ⇒ Object
Run a block with a temporary broadcast_channel_id override that will be auto-included on every request inside the block. Useful for admin/system tokens that need to scope each call to a specific channel.
client.with_channel(123) do
client.email_servers.list
end
25 26 27 28 29 30 31 32 |
# File 'lib/broadcast/client.rb', line 25 def with_channel(broadcast_channel_id) key = channel_override_key previous = Thread.current[key] Thread.current[key] = broadcast_channel_id yield self ensure Thread.current[key] = previous end |