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
-
#global_suppressions ⇒ Object
The installation-wide suppression list.
-
#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, html_body: nil, include_unsubscribe_link: nil) ⇒ Object
Thin convenience wrapper around
transactionals.create. - #sequences ⇒ Object
- #skill ⇒ Object
- #status ⇒ Object
-
#subscribers ⇒ Object
--- Resource sub-clients ---.
-
#suppressions ⇒ Object
The current channel's suppression list (plus
check, which reads the global list too). - #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
118 119 120 |
# File 'lib/broadcast/client.rb', line 118 def autopilots @autopilots ||= Resources::Autopilots.new(self) end |
#broadcasts ⇒ Object
90 91 92 |
# File 'lib/broadcast/client.rb', line 90 def broadcasts @broadcasts ||= Resources::Broadcasts.new(self) end |
#discovery ⇒ Object
122 123 124 |
# File 'lib/broadcast/client.rb', line 122 def discovery @discovery ||= Resources::Discovery.new(self) end |
#email_servers ⇒ Object
114 115 116 |
# File 'lib/broadcast/client.rb', line 114 def email_servers @email_servers ||= Resources::EmailServers.new(self) end |
#get_email(id) ⇒ Object
58 59 60 |
# File 'lib/broadcast/client.rb', line 58 def get_email(id) transactionals.get_transactional(id) end |
#global_suppressions ⇒ Object
The installation-wide suppression list. Requires an admin (system) API token.
134 135 136 |
# File 'lib/broadcast/client.rb', line 134 def global_suppressions @global_suppressions ||= Resources::GlobalSuppressions.new(self) end |
#migration ⇒ Object
Read-only export endpoints under /api/migration/v1. Requires an admin (system) API token.
140 141 142 |
# File 'lib/broadcast/client.rb', line 140 def migration @migration ||= Resources::Migration.new(self) end |
#opt_in_forms ⇒ Object
110 111 112 |
# File 'lib/broadcast/client.rb', line 110 def opt_in_forms @opt_in_forms ||= Resources::OptInForms.new(self) end |
#prime ⇒ Object
72 73 74 |
# File 'lib/broadcast/client.rb', line 72 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.
145 146 147 148 |
# File 'lib/broadcast/client.rb', line 145 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
94 95 96 |
# File 'lib/broadcast/client.rb', line 94 def segments @segments ||= Resources::Segments.new(self) end |
#send_email(to:, subject: nil, body: nil, reply_to: nil, html_body: nil, include_unsubscribe_link: 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.
html_body tells Broadcast the body is already HTML. Without it the send
is recorded as plain text and the payload is wrapped in Broadcast's own
include_unsubscribe_link lets the caller suppress the unsubscribe
footer and List-Unsubscribe header. Transactional mail wants that off: a
one-click unsubscribe on a password reset marks the person unsubscribed
and silently drops them from every sequence and broadcast.
rubocop:disable Metrics/ParameterLists -- mirrors the API's flat param surface
48 49 50 51 52 53 54 55 56 |
# File 'lib/broadcast/client.rb', line 48 def send_email(to:, subject: nil, body: nil, reply_to: nil, html_body: nil, include_unsubscribe_link: nil) # rubocop:enable Metrics/ParameterLists opts = { to: to, subject: subject, body: body, reply_to: reply_to } opts[:html_body] = html_body unless html_body.nil? opts[:include_unsubscribe_link] = include_unsubscribe_link unless include_unsubscribe_link.nil? transactionals.create(**opts) end |
#sequences ⇒ Object
86 87 88 |
# File 'lib/broadcast/client.rb', line 86 def sequences @sequences ||= Resources::Sequences.new(self) end |
#skill ⇒ Object
76 77 78 |
# File 'lib/broadcast/client.rb', line 76 def skill discovery.skill end |
#status ⇒ Object
68 69 70 |
# File 'lib/broadcast/client.rb', line 68 def status discovery.status end |
#subscribers ⇒ Object
--- Resource sub-clients ---
82 83 84 |
# File 'lib/broadcast/client.rb', line 82 def subscribers @subscribers ||= Resources::Subscribers.new(self) end |
#suppressions ⇒ Object
The current channel's suppression list (plus check, which reads the
global list too).
128 129 130 |
# File 'lib/broadcast/client.rb', line 128 def suppressions @suppressions ||= Resources::Suppressions.new(self) end |
#templates ⇒ Object
98 99 100 |
# File 'lib/broadcast/client.rb', line 98 def templates @templates ||= Resources::Templates.new(self) end |
#transactionals ⇒ Object
106 107 108 |
# File 'lib/broadcast/client.rb', line 106 def transactionals @transactionals ||= Resources::Transactionals.new(self) end |
#webhook_endpoints ⇒ Object
102 103 104 |
# File 'lib/broadcast/client.rb', line 102 def webhook_endpoints @webhook_endpoints ||= Resources::WebhookEndpoints.new(self) end |
#whoami ⇒ Object
--- Discovery (convenience shims) ---
64 65 66 |
# File 'lib/broadcast/client.rb', line 64 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 |