Class: Sentdm::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/sentdm/client.rb

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::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS

Instance Attribute Summary collapse

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

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["SENT_DM_API_KEY"], base_url: ENV["SENT_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.

‘sk_test_*` keys for sandbox/testing. Pass via the `x-api-key` header. Defaults to `ENV`

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • api_key (String, nil) (defaults to: ENV["SENT_DM_API_KEY"])

    Customer API key for authentication. Use ‘sk_live_*` keys for production and

  • base_url (String, nil) (defaults to: ENV["SENT_BASE_URL"])

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/sentdm/client.rb', line 78

def initialize(
  api_key: ENV["SENT_DM_API_KEY"],
  base_url: ENV["SENT_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.sent.dm"

  if api_key.nil?
    raise ArgumentError.new("api_key is required, and can be set via environ: \"SENT_DM_API_KEY\"")
  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
  )

  @webhooks = Sentdm::Resources::Webhooks.new(client: self)
  @users = Sentdm::Resources::Users.new(client: self)
  @templates = Sentdm::Resources::Templates.new(client: self)
  @profiles = Sentdm::Resources::Profiles.new(client: self)
  @numbers = Sentdm::Resources::Numbers.new(client: self)
  @messages = Sentdm::Resources::Messages.new(client: self)
  @contacts = Sentdm::Resources::Contacts.new(client: self)
  @me = Sentdm::Resources::Me.new(client: self)
end

Instance Attribute Details

#api_keyString (readonly)

Customer API key for authentication. Use ‘sk_live_*` keys for production and `sk_test_*` keys for sandbox/testing. Pass via the `x-api-key` header.

Returns:

  • (String)


21
22
23
# File 'lib/sentdm/client.rb', line 21

def api_key
  @api_key
end

#contactsSentdm::Resources::Contacts (readonly)

Create, update, and manage customer contact lists



49
50
51
# File 'lib/sentdm/client.rb', line 49

def contacts
  @contacts
end

#meSentdm::Resources::Me (readonly)

Retrieve account details



53
54
55
# File 'lib/sentdm/client.rb', line 53

def me
  @me
end

#messagesSentdm::Resources::Messages (readonly)

Send and track SMS and WhatsApp messages



45
46
47
# File 'lib/sentdm/client.rb', line 45

def messages
  @messages
end

#numbersSentdm::Resources::Numbers (readonly)

Manage and lookup phone numbers



41
42
43
# File 'lib/sentdm/client.rb', line 41

def numbers
  @numbers
end

#profilesSentdm::Resources::Profiles (readonly)

Manage organization profiles



37
38
39
# File 'lib/sentdm/client.rb', line 37

def profiles
  @profiles
end

#templatesSentdm::Resources::Templates (readonly)

Manage message templates with variable substitution



33
34
35
# File 'lib/sentdm/client.rb', line 33

def templates
  @templates
end

#usersSentdm::Resources::Users (readonly)

Invite, update, and manage organization users and roles



29
30
31
# File 'lib/sentdm/client.rb', line 29

def users
  @users
end

#webhooksSentdm::Resources::Webhooks (readonly)

Configure webhook endpoints for real-time event delivery



25
26
27
# File 'lib/sentdm/client.rb', line 25

def webhooks
  @webhooks
end