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
- #digests ⇒ Courier::Resources::Digests readonly
-
#inbound ⇒ Courier::Resources::Inbound
readonly
Record an inbound event that triggers the journeys and automations mapped to it.
- #inbox ⇒ Courier::Resources::Inbox readonly
-
#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"]
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 204 205 |
# File 'lib/courier/client.rb', line 145 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) @inbox = Courier::Resources::Inbox.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.
62 63 64 |
# File 'lib/courier/client.rb', line 62 def brands @brands end |
#broadcasts ⇒ Courier::Resources::Broadcasts (readonly)
57 58 59 |
# File 'lib/courier/client.rb', line 57 def broadcasts @broadcasts end |
#digests ⇒ Courier::Resources::Digests (readonly)
65 66 67 |
# File 'lib/courier/client.rb', line 65 def digests @digests end |
#inbound ⇒ Courier::Resources::Inbound (readonly)
Record an inbound event that triggers the journeys and automations mapped to it.
69 70 71 |
# File 'lib/courier/client.rb', line 69 def inbound @inbound end |
#inbox ⇒ Courier::Resources::Inbox (readonly)
77 78 79 |
# File 'lib/courier/client.rb', line 77 def inbox @inbox 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.
74 75 76 |
# File 'lib/courier/client.rb', line 74 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.
82 83 84 |
# File 'lib/courier/client.rb', line 82 def @messages end |
#notifications ⇒ Courier::Resources::Notifications (readonly)
Create, update, version, publish, and localize notification templates and their content.
92 93 94 |
# File 'lib/courier/client.rb', line 92 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.
107 108 109 |
# File 'lib/courier/client.rb', line 107 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.
87 88 89 |
# File 'lib/courier/client.rb', line 87 def requests @requests end |
#routing_strategies ⇒ Courier::Resources::RoutingStrategies (readonly)
Define reusable channel routing and failover strategies, and see which templates use them.
97 98 99 |
# File 'lib/courier/client.rb', line 97 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.
112 113 114 |
# File 'lib/courier/client.rb', line 112 def tenants @tenants end |
#translations ⇒ Courier::Resources::Translations (readonly)
Store and retrieve the translation strings Courier uses to render localized template content.
117 118 119 |
# File 'lib/courier/client.rb', line 117 def translations @translations end |
#users ⇒ Courier::Resources::Users (readonly)
120 121 122 |
# File 'lib/courier/client.rb', line 120 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.
102 103 104 |
# File 'lib/courier/client.rb', line 102 def workspace_preferences @workspace_preferences end |