Class: Mailkube::Client
- Inherits:
-
Object
- Object
- Mailkube::Client
- Defined in:
- lib/mailkube/client.rb,
sig/mailkube/client.rbs
Overview
The API client, and this gem's composition root.
Create one and reuse it. It is frozen after construction and safe to share across threads
(and across fibers, where a scheduler is installed); spec/concurrency_spec.rb proves it
rather than asserting it.
client = Mailkube.new # reads MAILKUBE_API_KEY
email = client.emails.send(
from: "Acme <hello@yourdomain.com>",
to: "customer@example.com",
subject: "Hello world",
html: "<p>It works!</p>"
)
There are deliberately no built-in retries. A RateLimitError carries retry_after and a
ServerError is safe to retry with backoff, so the calling application decides. Pass
idempotency_key: to make a retry safe.
This client is synchronous, which is the contract's sync-only case: concurrency here is
the caller's concern rather than an API-surface decision. See .rules/SDK_DESIGN.md.
Instance Attribute Summary collapse
-
#emails ⇒ Resources::Emails
readonly
The emails namespace.
-
#scheduled_emails ⇒ Resources::ScheduledEmails
readonly
The scheduled-emails namespace.
Instance Method Summary collapse
-
#base_url ⇒ String
The resolved API base URL.
-
#initialize(api_key: nil, base_url: nil, timeout: Config::DEFAULT_TIMEOUT, http: nil) ⇒ Client
constructor
Create a client, resolving configuration from the arguments then the environment.
Constructor Details
#initialize(api_key: nil, base_url: nil, timeout: Config::DEFAULT_TIMEOUT, http: nil) ⇒ Client
Create a client, resolving configuration from the arguments then the environment.
39 40 41 42 43 44 45 46 47 |
# File 'lib/mailkube/client.rb', line 39 def initialize(api_key: nil, base_url: nil, timeout: Config::DEFAULT_TIMEOUT, http: nil) config = Config.new(api_key: api_key, base_url: base_url, timeout: timeout) transport = Transport.new(config, http || NetHttpAdapter.new(timeout: timeout)) @config = config @emails = Resources::Emails.new(transport) @scheduled_emails = Resources::ScheduledEmails.new(transport) freeze end |
Instance Attribute Details
#emails ⇒ Resources::Emails (readonly)
Returns the emails namespace.
26 27 28 |
# File 'lib/mailkube/client.rb', line 26 def emails @emails end |
#scheduled_emails ⇒ Resources::ScheduledEmails (readonly)
Returns the scheduled-emails namespace.
28 29 30 |
# File 'lib/mailkube/client.rb', line 28 def scheduled_emails @scheduled_emails end |
Instance Method Details
#base_url ⇒ String
Returns the resolved API base URL.
50 |
# File 'lib/mailkube/client.rb', line 50 def base_url = @config.base_url |