Class: Courier::Client
- Inherits:
-
Internal::Transport::BaseClient
- Object
- Internal::Transport::BaseClient
- Courier::Client
- Defined in:
- lib/courier/client.rb,
sig/courier/client.rbs
Constant Summary collapse
- DEFAULT_MAX_RETRIES =
Default max number of retries to attempt after a failed retryable request.
2- DEFAULT_TIMEOUT_IN_SECONDS =
Default per-request timeout.
60.0- DEFAULT_INITIAL_RETRY_DELAY =
Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.
0.5- DEFAULT_MAX_RETRY_DELAY =
Default max retry delay in seconds.
8.0
Constants inherited from Internal::Transport::BaseClient
Internal::Transport::BaseClient::Courier, Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS
Instance Attribute Summary collapse
- #api_key ⇒ String readonly
-
#audiences ⇒ Courier::Resources::Audiences
readonly
Define filter-based groups whose membership Courier recalculates as user profiles change.
-
#audit_events ⇒ Courier::Resources::AuditEvents
readonly
Read the audit trail of configuration and access changes in your workspace.
-
#auth ⇒ Courier::Resources::Auth
readonly
Issue scoped, short-lived JWTs so client-side SDKs — Inbox, Preferences, and the embedded designer — can call Courier as a single user.
-
#automations ⇒ Courier::Resources::Automations
readonly
Invoke a stored automation template or an ad hoc automation defined in the request.
-
#brands ⇒ Courier::Resources::Brands
readonly
Manage the logos, colors, and layout that give the templates you send a consistent look.
-
#broadcasts ⇒ Courier::Resources::Broadcasts
readonly
Create a one-off send to a list or audience, author its content, then send it immediately or schedule it for later.
- #digests ⇒ Courier::Resources::Digests readonly
-
#inbound ⇒ Courier::Resources::Inbound
readonly
Record an inbound event that triggers the journeys and automations mapped to it.
-
#journeys ⇒ Courier::Resources::Journeys
readonly
Build, version, publish, invoke, and cancel multi-step notification workflows, along with the templates scoped to them.
-
#lists ⇒ Courier::Resources::Lists
readonly
Manage static groups of users that you subscribe explicitly, and send to them by list id or list pattern.
-
#messages ⇒ Courier::Resources::Messages
readonly
Look up the messages Courier has accepted, inspect their delivery history and rendered output, and cancel, resend, or archive them.
-
#notifications ⇒ Courier::Resources::Notifications
readonly
Create, update, version, publish, and localize notification templates and their content.
-
#profiles ⇒ Courier::Resources::Profiles
readonly
Store the contact information Courier delivers to for each user — email, phone number, push tokens, and any custom data you send to.
-
#providers ⇒ Courier::Resources::Providers
readonly
Configure the channel providers Courier delivers through, and browse the provider types it supports.
-
#requests ⇒ Courier::Resources::Requests
readonly
Look up the messages Courier has accepted, inspect their delivery history and rendered output, and cancel, resend, or archive them.
-
#routing_strategies ⇒ Courier::Resources::RoutingStrategies
readonly
Define reusable channel routing and failover strategies, and see which templates use them.
-
#send_ ⇒ Courier::Resources::Send
readonly
Send a message to one or more recipients — users, lists, audiences, or tenants — across every channel you have configured.
-
#tenants ⇒ Courier::Resources::Tenants
readonly
Manage tenants — the organizations, teams, or accounts your users belong to — along with their users and default preferences.
-
#translations ⇒ Courier::Resources::Translations
readonly
Store and retrieve the translation strings Courier uses to render localized template content.
- #users ⇒ Courier::Resources::Users readonly
-
#workspace_preferences ⇒ Courier::Resources::WorkspacePreferences
readonly
Manage the workspace catalog of subscription topics, the sections that group them, and publishing the preference page.
Attributes inherited from Internal::Transport::BaseClient
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout
Instance Method Summary collapse
-
#initialize(api_key: ENV["COURIER_API_KEY"], base_url: ENV["COURIER_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client
constructor
Creates and returns a new client for interacting with the API.
Methods inherited from Internal::Transport::BaseClient
follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!
Methods included from Internal::Util::SorbetRuntimeSupport
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type
Constructor Details
#initialize(api_key: ENV["COURIER_API_KEY"], base_url: ENV["COURIER_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client
Creates and returns a new client for interacting with the API.
"https://api.example.com/v2/". Defaults to ENV["COURIER_BASE_URL"]
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/courier/client.rb', line 144 def initialize( api_key: ENV["COURIER_API_KEY"], base_url: ENV["COURIER_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY ) base_url ||= "https://api.courier.com" if api_key.nil? raise ArgumentError.new("api_key is required, and can be set via environ: \"COURIER_API_KEY\"") end headers = {} custom_headers_env = ENV["COURIER_CUSTOM_HEADERS"] unless custom_headers_env.nil? parsed = {} custom_headers_env.split("\n").each do |line| colon = line.index(":") unless colon.nil? parsed[line[0...colon].strip] = line[(colon + 1)..].strip end end headers = parsed.merge(headers) end @api_key = api_key.to_s super( base_url: base_url, timeout: timeout, max_retries: max_retries, initial_retry_delay: initial_retry_delay, max_retry_delay: max_retry_delay, headers: headers ) @send_ = Courier::Resources::Send.new(client: self) @audiences = Courier::Resources::Audiences.new(client: self) @providers = Courier::Resources::Providers.new(client: self) @audit_events = Courier::Resources::AuditEvents.new(client: self) @auth = Courier::Resources::Auth.new(client: self) @automations = Courier::Resources::Automations.new(client: self) @journeys = Courier::Resources::Journeys.new(client: self) @broadcasts = Courier::Resources::Broadcasts.new(client: self) @brands = Courier::Resources::Brands.new(client: self) @digests = Courier::Resources::Digests.new(client: self) @inbound = Courier::Resources::Inbound.new(client: self) @lists = Courier::Resources::Lists.new(client: self) @messages = Courier::Resources::Messages.new(client: self) @requests = Courier::Resources::Requests.new(client: self) @notifications = Courier::Resources::Notifications.new(client: self) @routing_strategies = Courier::Resources::RoutingStrategies.new(client: self) @workspace_preferences = Courier::Resources::WorkspacePreferences.new(client: self) @profiles = Courier::Resources::Profiles.new(client: self) @tenants = Courier::Resources::Tenants.new(client: self) @translations = Courier::Resources::Translations.new(client: self) @users = Courier::Resources::Users.new(client: self) end |
Instance Attribute Details
#api_key ⇒ String (readonly)
19 20 21 |
# File 'lib/courier/client.rb', line 19 def api_key @api_key end |
#audiences ⇒ Courier::Resources::Audiences (readonly)
Define filter-based groups whose membership Courier recalculates as user profiles change.
29 30 31 |
# File 'lib/courier/client.rb', line 29 def audiences @audiences end |
#audit_events ⇒ Courier::Resources::AuditEvents (readonly)
Read the audit trail of configuration and access changes in your workspace.
38 39 40 |
# File 'lib/courier/client.rb', line 38 def audit_events @audit_events end |
#auth ⇒ Courier::Resources::Auth (readonly)
Issue scoped, short-lived JWTs so client-side SDKs — Inbox, Preferences, and the embedded designer — can call Courier as a single user. Server-side requests authenticate with your workspace API key instead.
44 45 46 |
# File 'lib/courier/client.rb', line 44 def auth @auth end |
#automations ⇒ Courier::Resources::Automations (readonly)
Invoke a stored automation template or an ad hoc automation defined in the request.
49 50 51 |
# File 'lib/courier/client.rb', line 49 def automations @automations end |
#brands ⇒ Courier::Resources::Brands (readonly)
Manage the logos, colors, and layout that give the templates you send a consistent look.
64 65 66 |
# File 'lib/courier/client.rb', line 64 def brands @brands end |
#broadcasts ⇒ Courier::Resources::Broadcasts (readonly)
Create a one-off send to a list or audience, author its content, then send it immediately or schedule it for later.
59 60 61 |
# File 'lib/courier/client.rb', line 59 def broadcasts @broadcasts end |
#digests ⇒ Courier::Resources::Digests (readonly)
67 68 69 |
# File 'lib/courier/client.rb', line 67 def digests @digests end |
#inbound ⇒ Courier::Resources::Inbound (readonly)
Record an inbound event that triggers the journeys and automations mapped to it.
71 72 73 |
# File 'lib/courier/client.rb', line 71 def inbound @inbound end |
#journeys ⇒ Courier::Resources::Journeys (readonly)
Build, version, publish, invoke, and cancel multi-step notification workflows, along with the templates scoped to them.
54 55 56 |
# File 'lib/courier/client.rb', line 54 def journeys @journeys end |
#lists ⇒ Courier::Resources::Lists (readonly)
Manage static groups of users that you subscribe explicitly, and send to them by list id or list pattern.
76 77 78 |
# File 'lib/courier/client.rb', line 76 def lists @lists end |
#messages ⇒ Courier::Resources::Messages (readonly)
Look up the messages Courier has accepted, inspect their delivery history and rendered output, and cancel, resend, or archive them.
81 82 83 |
# File 'lib/courier/client.rb', line 81 def @messages end |
#notifications ⇒ Courier::Resources::Notifications (readonly)
Create, update, version, publish, and localize notification templates and their content.
91 92 93 |
# File 'lib/courier/client.rb', line 91 def notifications @notifications end |
#profiles ⇒ Courier::Resources::Profiles (readonly)
Store the contact information Courier delivers to for each user — email, phone number, push tokens, and any custom data you send to.
106 107 108 |
# File 'lib/courier/client.rb', line 106 def profiles @profiles end |
#providers ⇒ Courier::Resources::Providers (readonly)
Configure the channel providers Courier delivers through, and browse the provider types it supports.
34 35 36 |
# File 'lib/courier/client.rb', line 34 def providers @providers end |
#requests ⇒ Courier::Resources::Requests (readonly)
Look up the messages Courier has accepted, inspect their delivery history and rendered output, and cancel, resend, or archive them.
86 87 88 |
# File 'lib/courier/client.rb', line 86 def requests @requests end |
#routing_strategies ⇒ Courier::Resources::RoutingStrategies (readonly)
Define reusable channel routing and failover strategies, and see which templates use them.
96 97 98 |
# File 'lib/courier/client.rb', line 96 def routing_strategies @routing_strategies end |
#send_ ⇒ Courier::Resources::Send (readonly)
Send a message to one or more recipients — users, lists, audiences, or tenants — across every channel you have configured.
24 25 26 |
# File 'lib/courier/client.rb', line 24 def send_ @send_ end |
#tenants ⇒ Courier::Resources::Tenants (readonly)
Manage tenants — the organizations, teams, or accounts your users belong to — along with their users and default preferences.
111 112 113 |
# File 'lib/courier/client.rb', line 111 def tenants @tenants end |
#translations ⇒ Courier::Resources::Translations (readonly)
Store and retrieve the translation strings Courier uses to render localized template content.
116 117 118 |
# File 'lib/courier/client.rb', line 116 def translations @translations end |
#users ⇒ Courier::Resources::Users (readonly)
119 120 121 |
# File 'lib/courier/client.rb', line 119 def users @users end |
#workspace_preferences ⇒ Courier::Resources::WorkspacePreferences (readonly)
Manage the workspace catalog of subscription topics, the sections that group them, and publishing the preference page.
101 102 103 |
# File 'lib/courier/client.rb', line 101 def workspace_preferences @workspace_preferences end |